[Spice-commits] 2 commits - spice/controller_prot.h spice/foreign_menu_prot.h spice/macros.h spice/protocol.h spice/qxl_dev.h spice/stats.h spice/vdi_dev.h

Christophe Fergau teuf at kemper.freedesktop.org
Wed Aug 12 05:16:25 PDT 2015


 spice/controller_prot.h   |    3 +-
 spice/foreign_menu_prot.h |    3 +-
 spice/macros.h            |   63 ++++++++++++++++++++++++++++++++++++++++++++++
 spice/protocol.h          |    3 +-
 spice/qxl_dev.h           |    5 ++-
 spice/stats.h             |    3 +-
 spice/vdi_dev.h           |    3 +-
 7 files changed, 76 insertions(+), 7 deletions(-)

New commits:
commit 295d05e7330da45b705aa5081d140d7c84a931b0
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Aug 12 11:42:46 2015 +0100

    Define and use new SPICE_MAGIC_CONST macro
    
    This macro allow to define magic constants without using weird
    memory tweacks.
    This remove some possible warning from some compiler and
    make code more optimized as compiler is able to compute the
    constant.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/spice/controller_prot.h b/spice/controller_prot.h
index bca7804..91dbe6f 100644
--- a/spice/controller_prot.h
+++ b/spice/controller_prot.h
@@ -18,10 +18,11 @@
 #ifndef _H_CONTROLLER_PROT
 #define _H_CONTROLLER_PROT
 
+#include <spice/macros.h>
 #include <spice/types.h>
 #include <spice/start-packed.h>
 
-#define CONTROLLER_MAGIC      (*(uint32_t*)"CTRL")
+#define CONTROLLER_MAGIC      SPICE_MAGIC_CONST("CTRL")
 #define CONTROLLER_VERSION    1
 
 
diff --git a/spice/foreign_menu_prot.h b/spice/foreign_menu_prot.h
index f478e2a..2ee2552 100644
--- a/spice/foreign_menu_prot.h
+++ b/spice/foreign_menu_prot.h
@@ -18,10 +18,11 @@
 #ifndef _H_FOREIGN_MENU_PROT
 #define _H_FOREIGN_MENU_PROT
 
+#include <spice/macros.h>
 #include <spice/types.h>
 #include <spice/start-packed.h>
 
-#define FOREIGN_MENU_MAGIC      (*(uint32_t*)"FRGM")
+#define FOREIGN_MENU_MAGIC      SPICE_MAGIC_CONST("FRGM")
 #define FOREIGN_MENU_VERSION    1
 
 typedef struct SPICE_ATTR_PACKED FrgMenuInitHeader {
diff --git a/spice/macros.h b/spice/macros.h
index 3538989..679d68d 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -414,4 +414,12 @@
 #endif
 
 
+#if SPICE_ENDIAN == SPICE_ENDIAN_LITTLE
+#define SPICE_MAGIC_CONST(s) \
+    ((uint32_t)((s[0]&0xffu)|((s[1]&0xffu)<<8)|((s[2]&0xff)<<16)|((s[3]&0xffu)<<24)))
+#else
+#define SPICE_MAGIC_CONST(s) \
+    ((uint32_t)((s[3]&0xffu)|((s[2]&0xffu)<<8)|((s[1]&0xff)<<16)|((s[0]&0xffu)<<24)))
+#endif
+
 #endif /* _H_SPICE_MACROS */
diff --git a/spice/protocol.h b/spice/protocol.h
index d3c5962..0c265ee 100644
--- a/spice/protocol.h
+++ b/spice/protocol.h
@@ -33,9 +33,10 @@
 
 #include <spice/types.h>
 #include <spice/enums.h>
+#include <spice/macros.h>
 #include <spice/start-packed.h>
 
-#define SPICE_MAGIC (*(uint32_t*)"REDQ")
+#define SPICE_MAGIC SPICE_MAGIC_CONST("REDQ")
 #define SPICE_VERSION_MAJOR 2
 #define SPICE_VERSION_MINOR 2
 
diff --git a/spice/qxl_dev.h b/spice/qxl_dev.h
index a3e91a5..9e753c4 100644
--- a/spice/qxl_dev.h
+++ b/spice/qxl_dev.h
@@ -36,6 +36,7 @@
 #include <spice/barrier.h>
 #include <spice/ipc_ring.h>
 #include <spice/enums.h>
+#include <spice/macros.h>
 
 #include <spice/start-packed.h>
 
@@ -54,8 +55,8 @@ enum {
 #define QXL_DEVICE_ID_DEVEL 0x01ff
 #define QXL_REVISION_DEVEL 0x01
 
-#define QXL_ROM_MAGIC (*(const uint32_t*)"QXRO")
-#define QXL_RAM_MAGIC (*(const uint32_t*)"QXRA")
+#define QXL_ROM_MAGIC SPICE_MAGIC_CONST("QXRO")
+#define QXL_RAM_MAGIC SPICE_MAGIC_CONST("QXRA")
 
 enum {
     QXL_RAM_RANGE_INDEX,
diff --git a/spice/stats.h b/spice/stats.h
index 452d89e..46bbfed 100644
--- a/spice/stats.h
+++ b/spice/stats.h
@@ -31,11 +31,12 @@
 #ifndef _H_SPICE_STATS
 #define _H_SPICE_STATS
 
+#include <spice/macros.h>
 #include <spice/types.h>
 
 #define SPICE_STAT_SHM_NAME "/spice.%u"
 #define SPICE_STAT_NODE_NAME_MAX 20
-#define SPICE_STAT_MAGIC (*(uint32_t*)"STAT")
+#define SPICE_STAT_MAGIC SPICE_MAGIC_CONST("STAT")
 #define SPICE_STAT_VERSION 1
 
 enum {
diff --git a/spice/vdi_dev.h b/spice/vdi_dev.h
index def88fc..a27f395 100644
--- a/spice/vdi_dev.h
+++ b/spice/vdi_dev.h
@@ -34,6 +34,7 @@
 #include <spice/types.h>
 #include <spice/barrier.h>
 #include <spice/ipc_ring.h>
+#include <spice/macros.h>
 
 #include <spice/start-packed.h>
 
@@ -48,7 +49,7 @@
 
 #define VDI_PORT_INTERRUPT (1 << 0)
 
-#define VDI_PORT_MAGIC (*(uint32_t*)"VDIP")
+#define VDI_PORT_MAGIC SPICE_MAGIC_CONST("VDIP")
 
 typedef struct SPICE_ATTR_PACKED VDIPortPacket {
     uint32_t gen;
commit 3ab16f2dad821bafe596383659a084fdd01d717e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Aug 12 11:42:45 2015 +0100

    Detects processor endianess using preprocessor
    
    This allow to define macros based on endianess in public headers
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/spice/macros.h b/spice/macros.h
index 62157b4..3538989 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -359,4 +359,59 @@
 #endif /* generic */
 
 
+/* detect endianess */
+#undef SPICE_ENDIAN
+#define SPICE_ENDIAN_LITTLE 4321
+#define SPICE_ENDIAN_BIG    1234
+#define SPICE_ENDIAN_PDP    2143
+
+/* gcc already defined these, use them */
+#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \
+    && defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_PDP_ENDIAN__)
+#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#    define SPICE_ENDIAN SPICE_ENDIAN_LITTLE
+#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#    define SPICE_ENDIAN SPICE_ENDIAN_BIG
+#  elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
+#    define SPICE_ENDIAN SPICE_ENDIAN_PDP
+#  else
+#    error __BYTE_ORDER__ not defined correctly
+#  endif
+#endif
+
+/* use suggestions at http://sourceforge.net/p/predef/wiki/Endianness/ */
+#ifndef SPICE_ENDIAN
+#  if defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) \
+      || defined(__THUMBEL__) || defined(__AARCH64EL__) \
+      || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
+#    define SPICE_ENDIAN SPICE_ENDIAN_LITTLE
+#  endif
+#  if defined(__BIG_ENDIAN__) || defined(__ARMEB__) \
+      || defined(__THUMBEB__) || defined(__AARCH64EB__) \
+      || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
+#    ifdef SPICE_ENDIAN
+#      error Both little and big endian detected
+#    endif
+#    define SPICE_ENDIAN SPICE_ENDIAN_BIG
+#  endif
+#endif
+
+/* MS compiler */
+#if !defined(SPICE_ENDIAN) && defined(_MSC_VER)
+/* Windows support only little endian arm */
+#  if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) \
+      || defined(_M_ARM)
+#    define SPICE_ENDIAN SPICE_ENDIAN_LITTLE
+#  endif
+#endif
+
+#if !defined(SPICE_ENDIAN)
+#error Unable to detect processor endianess
+#endif
+
+#if SPICE_ENDIAN == SPICE_ENDIAN_PDP
+#error PDP endianess not supported by Spice
+#endif
+
+
 #endif /* _H_SPICE_MACROS */


More information about the Spice-commits mailing list