/
spice-marshaller-sigbus.patch
56 lines (53 loc) · 3.45 KB
/
spice-marshaller-sigbus.patch
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
diff -urN spice-gtk-0.32/spice-common/common/generated_client_demarshallers1.c spice-gtk/spice-common/common/generated_client_demarshallers1.c
--- spice-gtk-0.32/spice-common/common/generated_client_demarshallers1.c 2016-06-21 10:19:56.000000000 -0400
+++ spice-gtk/spice-common/common/generated_client_demarshallers1.c 2016-08-25 14:11:28.923349799 -0400
@@ -64,10 +64,10 @@
#define write_int32(ptr, val) (*((int32_t *)(ptr))) = val
#define read_uint32(ptr) (*((uint32_t *)(ptr)))
#define write_uint32(ptr, val) (*((uint32_t *)(ptr))) = val
-#define read_int64(ptr) (*((int64_t *)(ptr)))
-#define write_int64(ptr, val) (*((int64_t *)(ptr))) = val
-#define read_uint64(ptr) (*((uint64_t *)(ptr)))
-#define write_uint64(ptr, val) (*((uint64_t *)(ptr))) = val
+static inline int64_t read_int64(uint8_t *ptr) { int64_t val; memcpy(&val, ptr, sizeof(int64_t)); return val; }
+static inline void write_int64(uint8_t *ptr, int64_t val) { memcpy(ptr, &val, sizeof(int64_t)); }
+static inline uint64_t read_uint64(uint8_t *ptr) { uint64_t val; memcpy(&val, ptr, sizeof(uint64_t)); return val; }
+static inline void write_uint64(uint8_t *ptr, uint64_t val) { memcpy(ptr, &val, sizeof(uint64_t)); }
#endif
static int8_t SPICE_GNUC_UNUSED consume_int8(uint8_t **ptr)
diff -urN spice-gtk-0.32/spice-common/common/generated_client_demarshallers.c spice-gtk/spice-common/common/generated_client_demarshallers.c
--- spice-gtk-0.32/spice-common/common/generated_client_demarshallers.c 2016-06-21 10:19:55.000000000 -0400
+++ spice-gtk/spice-common/common/generated_client_demarshallers.c 2016-08-25 14:11:50.327878917 -0400
@@ -64,10 +64,10 @@
#define write_int32(ptr, val) (*((int32_t *)(ptr))) = val
#define read_uint32(ptr) (*((uint32_t *)(ptr)))
#define write_uint32(ptr, val) (*((uint32_t *)(ptr))) = val
-#define read_int64(ptr) (*((int64_t *)(ptr)))
-#define write_int64(ptr, val) (*((int64_t *)(ptr))) = val
-#define read_uint64(ptr) (*((uint64_t *)(ptr)))
-#define write_uint64(ptr, val) (*((uint64_t *)(ptr))) = val
+static inline int64_t read_int64(uint8_t *ptr) { int64_t val; memcpy(&val, ptr, sizeof(int64_t)); return val; }
+static inline void write_int64(uint8_t *ptr, int64_t val) { memcpy(ptr, &val, sizeof(int64_t)); }
+static inline uint64_t read_uint64(uint8_t *ptr) { uint64_t val; memcpy(&val, ptr, sizeof(uint64_t)); return val; }
+static inline void write_uint64(uint8_t *ptr, uint64_t val) { memcpy(ptr, &val, sizeof(uint64_t)); }
#endif
static int8_t SPICE_GNUC_UNUSED consume_int8(uint8_t **ptr)
diff -urN spice-gtk-0.32/spice-common/common/marshaller.c spice-gtk/spice-common/common/marshaller.c
--- spice-gtk-0.32/spice-common/common/marshaller.c 2016-05-02 10:44:17.000000000 -0400
+++ spice-gtk/spice-common/common/marshaller.c 2016-08-25 14:12:19.888609500 -0400
@@ -44,8 +44,14 @@
#define write_uint16(ptr,v) (*((uint16_t *)(ptr)) = v)
#define write_int32(ptr,v) (*((int32_t *)(ptr)) = v)
#define write_uint32(ptr,v) (*((uint32_t *)(ptr)) = v)
-#define write_int64(ptr,v) (*((int64_t *)(ptr)) = v)
-#define write_uint64(ptr,v) (*((uint64_t *)(ptr)) = v)
+/*
+ * Thanks to shohyanglim@gmail.com for saving me time and discovering these
+ * hacks to avoid SIGBUS on some ARM processors.
+ *
+ * TODO: Find out whether something better can be done to avoid the SIGBUS.
+ */
+static inline void write_int64(uint8_t *ptr, int64_t val) { memcpy(ptr, &val, sizeof(int64_t)); }
+static inline void write_uint64(uint8_t *ptr, uint64_t val) { memcpy(ptr, &val, sizeof(uint64_t)); }
#endif
typedef struct {