[PATCH 1/2] Detects processor endianess using preprocessor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allow to define macros based on endianess in public headers

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 spice/Makefile.am |  1 +
 spice/compiler.h  | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 spice/macros.h    |  1 +
 3 files changed, 91 insertions(+)
 create mode 100644 spice/compiler.h

diff --git a/spice/Makefile.am b/spice/Makefile.am
index 9be09ec..59732c6 100644
--- a/spice/Makefile.am
+++ b/spice/Makefile.am
@@ -17,6 +17,7 @@ spice_protocol_include_HEADERS =		\
 	start-packed.h				\
 	stats.h					\
 	types.h					\
+	compiler.h				\
 	vd_agent.h				\
 	vdi_dev.h				\
 	$(NULL)
diff --git a/spice/compiler.h b/spice/compiler.h
new file mode 100644
index 0000000..f1bb5d0
--- /dev/null
+++ b/spice/compiler.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2015 Red Hat, Inc.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are
+   met:
+
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in
+         the documentation and/or other materials provided with the
+         distribution.
+       * Neither the name of the copyright holder nor the names of its
+         contributors may be used to endorse or promote products derived
+         from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
+   IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+   PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _H_SPICE_COMPILER
+#define _H_SPICE_COMPILER
+
+/* 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_COMPILER */
diff --git a/spice/macros.h b/spice/macros.h
index 62157b4..018ff32 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -32,6 +32,7 @@
 #include <stddef.h>
 
 #include <spice/types.h>
+#include <spice/compiler.h>
 
 #if    __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 #define SPICE_GNUC_PURE __attribute__((__pure__))
-- 
2.1.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]