[Spice-devel] [PATCH spice-protocol] qxl_dev: Align QXLRam to 4 bytes

Frediano Ziglio fziglio at redhat.com
Thu Jun 28 20:43:47 UTC 2018


This avoids compilers detect misaligned access.
The structure is allocated at the beginning of a page so surely
will be 4 bytes aligned.
Aligning to 4 bytes maintains the size of the structure unchanged
avoiding possible ABI changes.
clang currently generates an invalid function call if a misaligned
4 byte atomic operation is done.

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1565766

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 spice/end-packed.h   | 1 +
 spice/qxl_dev.h      | 2 +-
 spice/start-packed.h | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/spice/end-packed.h b/spice/end-packed.h
index 1acea18..0efd588 100644
--- a/spice/end-packed.h
+++ b/spice/end-packed.h
@@ -32,6 +32,7 @@
 /* See start-packed.h for details */
 
 #undef SPICE_ATTR_PACKED
+#undef SPICE_ATTR_ALIGNED
 
 #if defined(__MINGW32__) || !defined(__GNUC__)
 #pragma pack(pop)
diff --git a/spice/qxl_dev.h b/spice/qxl_dev.h
index 9e753c4..a9cc4f4 100644
--- a/spice/qxl_dev.h
+++ b/spice/qxl_dev.h
@@ -253,7 +253,7 @@ SPICE_RING_DECLARE(QXLReleaseRing, uint64_t, QXL_RELEASE_RING_SIZE);
 #define QXL_INTERRUPT_CLIENT_MONITORS_CONFIG  (1 << 5)
 
 /* qxl-1 compat: append only */
-typedef struct SPICE_ATTR_PACKED QXLRam {
+typedef struct SPICE_ATTR_ALIGNED(4) SPICE_ATTR_PACKED QXLRam {
     uint32_t magic;
     uint32_t int_pending;
     uint32_t int_mask;
diff --git a/spice/start-packed.h b/spice/start-packed.h
index ab3fa98..de0c595 100644
--- a/spice/start-packed.h
+++ b/spice/start-packed.h
@@ -48,6 +48,7 @@
 #ifdef __GNUC__
 
 #define SPICE_ATTR_PACKED __attribute__ ((__packed__))
+#define SPICE_ATTR_ALIGNED(n) __attribute__ ((__aligned__ (n)))
 
 #ifdef __MINGW32__
 #pragma pack(push,1)
@@ -58,6 +59,7 @@
 #pragma pack(push)
 #pragma pack(1)
 #define SPICE_ATTR_PACKED
+#define SPICE_ATTR_ALIGNED(n) __declspec (align (n))
 #pragma warning(disable:4200)
 #pragma warning(disable:4103)
 
-- 
2.17.1



More information about the Spice-devel mailing list