summaryrefslogtreecommitdiff
path: root/debian/patches/8141491.diff
blob: 6370c7c52a30627f3f42ac8788487f64d2f42991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# DP: JDK-8141491: Unaligned memory access in Bits.c

--- a/jdk/src/share/native/java/nio/Bits.c
+++ b/jdk/src/share/native/java/nio/Bits.c
@@ -67,16 +67,38 @@
 #define SWAPLONG(x)  ((jlong)(((jlong)SWAPINT((jint)(x)) << 32) | \
                               ((jlong)SWAPINT((jint)((x) >> 32)) & 0xffffffff)))
 
+/* The destination buffer passed to Java_java_nio_Bits_copyFromShor<type>tArray
+ * function and the source buffer passed to Java_java_nio_Bits_copyTo<type>Array
+ * may not be aligned on <type>'s boundary. Inform the compiler about this via
+ * 'unaligned' attribute, provided it supports this attribute. For recent 
+ * compilers, use __has_attribute preprocessor predicate; if it is not available,
+ * we know that GCC supports it.
+ */
+#ifndef __has_attribute
+#define __has_attribute(x) 0
+#endif
+
+#if defined(__GNUC__) || __has_attribute(aligned)
+typedef jshort __attribute__((aligned(1))) jshort_unaligned;
+typedef jint __attribute__((aligned(1))) jint_unaligned;
+typedef jlong __attribute__((aligned(1))) jlong_unaligned;
+#else
+typedef jshort jshort_unaligned;
+typedef jint jint_unaligned;
+typedef jlong jlong_unaligned;
+#endif
+
 JNIEXPORT void JNICALL
 Java_java_nio_Bits_copyFromShortArray(JNIEnv *env, jobject this, jobject src,
                                       jlong srcPos, jlong dstAddr, jlong length)
 {
     jbyte *bytes;
     size_t size;
-    jshort *srcShort, *dstShort, *endShort;
+    jshort *srcShort, *endShort;
+    jshort_unaligned *dstShort;
     jshort tmpShort;
 
-    dstShort = (jshort *)jlong_to_ptr(dstAddr);
+    dstShort = (jshort_unaligned *)jlong_to_ptr(dstAddr);
 
     while (length > 0) {
         /* do not change this if-else statement, see WARNING above */
@@ -108,10 +130,11 @@ Java_java_nio_Bits_copyToShortArray(JNIE
 {
     jbyte *bytes;
     size_t size;
-    jshort *srcShort, *dstShort, *endShort;
+    jshort_unaligned *srcShort, *endShort;
+    jshort *dstShort;
     jshort tmpShort;
 
-    srcShort = (jshort *)jlong_to_ptr(srcAddr);
+    srcShort = (jshort_unaligned *)jlong_to_ptr(srcAddr);
 
     while (length > 0) {
         /* do not change this if-else statement, see WARNING above */
@@ -143,10 +166,11 @@ Java_java_nio_Bits_copyFromIntArray(JNIE
 {
     jbyte *bytes;
     size_t size;
-    jint *srcInt, *dstInt, *endInt;
+    jint *srcInt, *endInt;
+    jint_unaligned *dstInt;
     jint tmpInt;
 
-    dstInt = (jint *)jlong_to_ptr(dstAddr);
+    dstInt = (jint_unaligned *)jlong_to_ptr(dstAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
@@ -178,10 +202,11 @@ Java_java_nio_Bits_copyToIntArray(JNIEnv
 {
     jbyte *bytes;
     size_t size;
-    jint *srcInt, *dstInt, *endInt;
+    jint_unaligned *srcInt, *endInt;
+    jint *dstInt;
     jint tmpInt;
 
-    srcInt = (jint *)jlong_to_ptr(srcAddr);
+    srcInt = (jint_unaligned *)jlong_to_ptr(srcAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
@@ -213,10 +238,11 @@ Java_java_nio_Bits_copyFromLongArray(JNI
 {
     jbyte *bytes;
     size_t size;
-    jlong *srcLong, *dstLong, *endLong;
+    jlong *srcLong, *endLong;
+    jlong_unaligned *dstLong;
     jlong tmpLong;
 
-    dstLong = (jlong *)jlong_to_ptr(dstAddr);
+    dstLong = (jlong_unaligned *)jlong_to_ptr(dstAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
@@ -248,10 +274,11 @@ Java_java_nio_Bits_copyToLongArray(JNIEn
 {
     jbyte *bytes;
     size_t size;
-    jlong *srcLong, *dstLong, *endLong;
+    jlong_unaligned *srcLong, *endLong;
+    jlong *dstLong;
     jlong tmpLong;
 
-    srcLong = (jlong *)jlong_to_ptr(srcAddr);
+    srcLong = (jlong_unaligned *)jlong_to_ptr(srcAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */