]> xenbits.xensource.com Git - xen.git/commitdiff
tools: lift BUILD_BUG_ON to a tools header file
authorWei Liu <wei.liu2@citrix.com>
Mon, 19 Sep 2016 14:25:52 +0000 (15:25 +0100)
committerWei Liu <wei.liu2@citrix.com>
Mon, 19 Sep 2016 16:03:20 +0000 (17:03 +0100)
Only define BUILD_BUG_ON when there isn't one already, because mini-os
currently leaks that.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
13 files changed:
tools/firmware/hvmloader/rombios.c
tools/firmware/hvmloader/smbios.c
tools/firmware/hvmloader/util.h
tools/include/xen-tools/libs.h [new file with mode: 0644]
tools/libxc/xc_core_arm.c
tools/libxc/xc_cpuid_x86.c
tools/libxc/xc_dom_arm.c
tools/libxc/xc_dom_bzimageloader.c
tools/libxc/xc_pm.c
tools/libxc/xc_private.h
tools/libxc/xc_sr_common.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_psr.c

index 9acf03fa5f0e3f395f100fcf6ce02e3af701959f..1e853ec1c957b8d0de4ff4f45e597f884c838e0b 100644 (file)
@@ -31,6 +31,7 @@
 #include "option_rom.h"
 
 #include <xen/hvm/params.h>
+#include <xen-tools/libs.h>
 
 #define ROM_INCLUDE_ROMBIOS
 #define ROM_INCLUDE_VGABIOS
index 210c7b0d3525a08e9c27485f0b13df9239bc45f3..0e61bd1950c337c433d8b70b94d4929be577f4fe 100644 (file)
@@ -26,6 +26,7 @@
 #include "util.h"
 #include "hypercall.h"
 #include <xen/hvm/hvm_xs_strings.h>
+#include <xen-tools/libs.h>
 
 /* SBMIOS handle base values */
 #define SMBIOS_HANDLE_TYPE0   0x0000
index 0fb266e95a5f359648b762304e9c851b491112eb..94292d6f2216d9e5de26022ec792b2867cbb3f47 100644 (file)
@@ -41,7 +41,6 @@ void __assert_failed(char *assertion, char *file, int line)
 void __bug(char *file, int line) __attribute__((noreturn));
 #define BUG() __bug(__FILE__, __LINE__)
 #define BUG_ON(p) do { if (p) BUG(); } while (0)
-#define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
 
 #define min_t(type,x,y) \
         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
diff --git a/tools/include/xen-tools/libs.h b/tools/include/xen-tools/libs.h
new file mode 100644 (file)
index 0000000..9d8b4ab
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __XEN_TOOLS_LIBS__
+
+#ifndef BUILD_BUG_ON
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); })
+#else
+#define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
+#endif
+#endif
+
+#endif /* __XEN_TOOLS_LIBS__ */
index d8570fd678a9241cd5f4f05c450b4c739b227d64..362c1a7fd10d3f3ce8a77d01c864e77e4eeba51b 100644 (file)
@@ -19,6 +19,8 @@
 #include "xg_private.h"
 #include "xc_core.h"
 
+#include <xen-tools/libs.h>
+
 int
 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
                               unsigned long pfn)
@@ -101,7 +103,7 @@ xc_core_arch_get_scratch_gpfn(xc_interface *xch, domid_t domid,
      * The Grant Table region space is not used until the guest is
      * booting. Use the first page for the scratch pfn.
      */
-    XC_BUILD_BUG_ON(GUEST_GNTTAB_SIZE < XC_PAGE_SIZE);
+    BUILD_BUG_ON(GUEST_GNTTAB_SIZE < XC_PAGE_SIZE);
 
     *gpfn = GUEST_GNTTAB_BASE >> XC_PAGE_SHIFT;
 
index fbbac9e25a843e597ab1f0731e9c583a76e95d0e..de06b32c1b99aa0da073aa0a79d963dd08a0535b 100644 (file)
@@ -25,6 +25,7 @@
 #include "xc_private.h"
 #include "xc_bitops.h"
 #include <xen/hvm/params.h>
+#include <xen-tools/libs.h>
 
 enum {
 #define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
@@ -98,12 +99,12 @@ const uint32_t *xc_get_static_cpu_featuremask(
         hvm_hap[FEATURESET_NR_ENTRIES] = INIT_HVM_HAP_FEATURES,
         deep_features[FEATURESET_NR_ENTRIES] = INIT_DEEP_FEATURES;
 
-    XC_BUILD_BUG_ON(ARRAY_SIZE(known) != FEATURESET_NR_ENTRIES);
-    XC_BUILD_BUG_ON(ARRAY_SIZE(special) != FEATURESET_NR_ENTRIES);
-    XC_BUILD_BUG_ON(ARRAY_SIZE(pv) != FEATURESET_NR_ENTRIES);
-    XC_BUILD_BUG_ON(ARRAY_SIZE(hvm_shadow) != FEATURESET_NR_ENTRIES);
-    XC_BUILD_BUG_ON(ARRAY_SIZE(hvm_hap) != FEATURESET_NR_ENTRIES);
-    XC_BUILD_BUG_ON(ARRAY_SIZE(deep_features) != FEATURESET_NR_ENTRIES);
+    BUILD_BUG_ON(ARRAY_SIZE(known) != FEATURESET_NR_ENTRIES);
+    BUILD_BUG_ON(ARRAY_SIZE(special) != FEATURESET_NR_ENTRIES);
+    BUILD_BUG_ON(ARRAY_SIZE(pv) != FEATURESET_NR_ENTRIES);
+    BUILD_BUG_ON(ARRAY_SIZE(hvm_shadow) != FEATURESET_NR_ENTRIES);
+    BUILD_BUG_ON(ARRAY_SIZE(hvm_hap) != FEATURESET_NR_ENTRIES);
+    BUILD_BUG_ON(ARRAY_SIZE(deep_features) != FEATURESET_NR_ENTRIES);
 
     switch ( mask )
     {
@@ -139,7 +140,7 @@ const uint32_t *xc_get_feature_deep_deps(uint32_t feature)
 
     unsigned int start = 0, end = ARRAY_SIZE(deep_deps);
 
-    XC_BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
+    BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
 
     /* deep_deps[] is sorted.  Perform a binary search. */
     while ( start < end )
index 64a8b6773408722b8946f26d0433fd50dac8cc15..a7e839ebbb62f4a66333dc47f7ece0a2a925aa13 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <xen/xen.h>
 #include <xen/io/protocols.h>
+#include <xen-tools/libs.h>
 
 #include "xg_private.h"
 #include "xc_dom.h"
@@ -69,7 +70,7 @@ static int alloc_magic_pages(struct xc_dom_image *dom)
     const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT;
     xen_pfn_t p2m[NR_MAGIC_PAGES];
 
-    XC_BUILD_BUG_ON(NR_MAGIC_PAGES > GUEST_MAGIC_SIZE >> XC_PAGE_SHIFT);
+    BUILD_BUG_ON(NR_MAGIC_PAGES > GUEST_MAGIC_SIZE >> XC_PAGE_SHIFT);
 
     DOMPRINTF_CALLED(dom->xch);
 
index 33ba06bd946a54de78245dc4a81fcf1e65fc26ef..a7d70cc7c6df9b8535f2722e79d7f1d1604b6de6 100644 (file)
@@ -34,6 +34,8 @@
 #include "xg_private.h"
 #include "xc_dom_decompress.h"
 
+#include <xen-tools/libs.h>
+
 #ifndef __MINIOS__
 
 #if defined(HAVE_BZLIB)
@@ -418,7 +420,7 @@ static int xc_try_lzo1x_decode(
      * lzo_uint should match size_t. Check that this is the case to be
      * sure we won't overflow various lzo_uint fields.
      */
-    XC_BUILD_BUG_ON(sizeof(lzo_uint) != sizeof(size_t));
+    BUILD_BUG_ON(sizeof(lzo_uint) != sizeof(size_t));
 
     ret = lzo_init();
     if ( ret != LZO_E_OK )
index 5b38cf13fd0eea55c3d13ebcc5c508d205e81eae..ae917bc6308156c25fa0c1a93156f292a43fe8bc 100644 (file)
@@ -21,6 +21,8 @@
 #include <stdbool.h>
 #include "xc_private.h"
 
+#include <xen-tools/libs.h>
+
 /*
  * Get PM statistic info
  */
@@ -274,8 +276,8 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
                 sys_para->scaling_governor, CPUFREQ_NAME_LEN);
 
         /* copy to user_para no matter what cpufreq governor */
-        XC_BUILD_BUG_ON(sizeof(((struct xc_get_cpufreq_para *)0)->u) !=
-                        sizeof(((struct xen_get_cpufreq_para *)0)->u));
+        BUILD_BUG_ON(sizeof(((struct xc_get_cpufreq_para *)0)->u) !=
+                    sizeof(((struct xen_get_cpufreq_para *)0)->u));
 
         memcpy(&user_para->u, &sys_para->u, sizeof(sys_para->u));
     }
index 75b761c2cce830e90b4d81737445482a7f49824a..97445ae1fe926be7e14f4b0d5e9aba7b87ff42b8 100644 (file)
@@ -72,13 +72,6 @@ struct iovec {
 #define PAGE_SIZE               XC_PAGE_SIZE
 #define PAGE_MASK               XC_PAGE_MASK
 
-/* Force a compilation error if condition is true */
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-#define XC_BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); })
-#else
-#define XC_BUILD_BUG_ON(p) ((void)sizeof(struct { int:-!!(p); }))
-#endif
-
 #ifndef ARRAY_SIZE /* MiniOS leaks ARRAY_SIZE into our namespace as part of a
                     * stubdom build.  It shouldn't... */
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
index b228a1550e302377f84e24e1fa3d4323288fad50..48fa676f4e9dc522cd9fe82ae1c3835bbdf66e74 100644 (file)
@@ -2,6 +2,8 @@
 
 #include "xc_sr_common.h"
 
+#include <xen-tools/libs.h>
+
 static const char *dhdr_types[] =
 {
     [DHDR_TYPE_X86_PV]  = "x86 PV",
@@ -140,17 +142,17 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)
 
 static void __attribute__((unused)) build_assertions(void)
 {
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_ihdr) != 24);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_dhdr) != 16);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rhdr) != 8);
-
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_page_data_header)  != 8);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_info)       != 8);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_p2m_frames) != 8);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_vcpu_hdr)   != 8);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_tsc_info)          != 24);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params_entry)  != 16);
-    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params)        != 8);
+    BUILD_BUG_ON(sizeof(struct xc_sr_ihdr) != 24);
+    BUILD_BUG_ON(sizeof(struct xc_sr_dhdr) != 16);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rhdr) != 8);
+
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_page_data_header)  != 8);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_info)       != 8);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_p2m_frames) != 8);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_vcpu_hdr)   != 8);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_tsc_info)          != 24);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params_entry)  != 16);
+    BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params)        != 8);
 }
 
 /*
index 7510031d7e6b402d710c00875f1657c8832eed38..a8fb23ef81a45824d9e2aeb1e8c6e043321f5aae 100644 (file)
@@ -4148,14 +4148,6 @@ int libxl__string_parse_json(libxl__gc *gc, const libxl__json_object *o,
 
 int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len);
 
-/*
- * Compile time assertion
- */
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); })
-#else
-#define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
-#endif
 #include "_libxl_types_private.h"
 #include "_libxl_types_internal_private.h"
 
index 99733f61cca249778b53c2c2af38be24518592d8..786183cf74973bad701a998b61ebaa6d7c3a5246 100644 (file)
@@ -16,6 +16,7 @@
 #include "libxl_osdeps.h" /* must come before any other headers */
 #include "libxl_internal.h"
 
+#include <xen-tools/libs.h>
 
 #define IA32_QM_CTR_ERROR_MASK         (0x3ul << 62)