aboutsummaryrefslogtreecommitdiffstats
path: root/main/qemu/atomic-bswap.patch
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2019-02-25 12:23:39 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2019-02-25 15:52:32 +0100
commit10a108fff8075e91499a850f2ef6b824c33679a4 (patch)
treea8b023e847947cfb605805b30059e964773270af /main/qemu/atomic-bswap.patch
parent36fadf98ee839df30f4c331ab9168182f5bf59fd (diff)
downloadaports-10a108fff8075e91499a850f2ef6b824c33679a4.tar.gz
aports-10a108fff8075e91499a850f2ef6b824c33679a4.tar.bz2
aports-10a108fff8075e91499a850f2ef6b824c33679a4.tar.xz
main/qemu: workaround bug in qemu due to memcpy assumed to be atomic
Some functions using include/qemu/bswap.h assumes that the inline functions using memcpy are atomic. Qemu assumes that compiler will optimize away the memcpy call. Our fortify-headers seems to get in the way for this, so we work around it by explicitly use __builtin_memcpy. https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg06183.html (cherry picked from commit 228579f6c7663dc4107b1b418367e968513277f9)
Diffstat (limited to 'main/qemu/atomic-bswap.patch')
-rw-r--r--main/qemu/atomic-bswap.patch61
1 files changed, 61 insertions, 0 deletions
diff --git a/main/qemu/atomic-bswap.patch b/main/qemu/atomic-bswap.patch
new file mode 100644
index 0000000000..2c7bc41ff4
--- /dev/null
+++ b/main/qemu/atomic-bswap.patch
@@ -0,0 +1,61 @@
+workaround fortify-headers, due to some callers to those function depends
+on compiler to optimize away the memcpy call for atomicity.
+
+https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg06183.html
+
+diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
+index a684c1a..f298653 100644
+--- a/include/qemu/bswap.h
++++ b/include/qemu/bswap.h
+@@ -323,44 +323,44 @@ static inline void stb_p(void *ptr, uint8_t v)
+ static inline int lduw_he_p(const void *ptr)
+ {
+ uint16_t r;
+- memcpy(&r, ptr, sizeof(r));
++ __builtin_memcpy(&r, ptr, sizeof(r));
+ return r;
+ }
+
+ static inline int ldsw_he_p(const void *ptr)
+ {
+ int16_t r;
+- memcpy(&r, ptr, sizeof(r));
++ __builtin_memcpy(&r, ptr, sizeof(r));
+ return r;
+ }
+
+ static inline void stw_he_p(void *ptr, uint16_t v)
+ {
+- memcpy(ptr, &v, sizeof(v));
++ __builtin_memcpy(ptr, &v, sizeof(v));
+ }
+
+ static inline int ldl_he_p(const void *ptr)
+ {
+ int32_t r;
+- memcpy(&r, ptr, sizeof(r));
++ __builtin_memcpy(&r, ptr, sizeof(r));
+ return r;
+ }
+
+ static inline void stl_he_p(void *ptr, uint32_t v)
+ {
+- memcpy(ptr, &v, sizeof(v));
++ __builtin_memcpy(ptr, &v, sizeof(v));
+ }
+
+ static inline uint64_t ldq_he_p(const void *ptr)
+ {
+ uint64_t r;
+- memcpy(&r, ptr, sizeof(r));
++ __builtin_memcpy(&r, ptr, sizeof(r));
+ return r;
+ }
+
+ static inline void stq_he_p(void *ptr, uint64_t v)
+ {
+- memcpy(ptr, &v, sizeof(v));
++ __builtin_memcpy(ptr, &v, sizeof(v));
+ }
+
+ static inline int lduw_le_p(const void *ptr)