]> xenbits.xensource.com Git - xen.git/commitdiff
tools/libxc: Introduce ARRAY_SIZE() and replace handrolled examples
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 10 Jun 2014 14:07:59 +0000 (15:07 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 10 Jun 2014 15:04:03 +0000 (16:04 +0100)
xen-hptool and xen-mfndump include xc_private.h.  This is bad, but not trivial
to fix, so they gain a protective #undef and a stern comment.

MiniOS leaks ARRAY_SIZE into the libxc namespace as part of a stubdom build.
Therefore, xc_private.h gains an #ifndef until MiniOS is fixed.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxc/xc_dom_arm.c
tools/libxc/xc_dom_x86.c
tools/libxc/xc_minios.c
tools/libxc/xc_private.h
tools/misc/xen-hptool.c
tools/misc/xen-mfndump.c

index 75f836399a21f34688ef6e44c475db75476f1ad5..cc64363a97ae47072485c08ca605356902ecd3e6 100644 (file)
@@ -230,7 +230,7 @@ static int set_mode(xc_interface *xch, domid_t domid, char *guest_type)
 
     domctl.domain = domid;
     domctl.cmd    = XEN_DOMCTL_set_address_size;
-    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
+    for ( i = 0; i < ARRAY_SIZE(types); i++ )
         if ( !strcmp(types[i].guest, guest_type) )
             domctl.u.address_size.size = types[i].size;
     if ( domctl.u.address_size.size == 0 )
index e034d62373c7a080864d1aefaa6a06412653c9af..bf06fe49c25939e33cdff6d062dac9c152c9971f 100644 (file)
@@ -716,7 +716,7 @@ static int x86_compat(xc_interface *xch, domid_t domid, char *guest_type)
     memset(&domctl, 0, sizeof(domctl));
     domctl.domain = domid;
     domctl.cmd    = XEN_DOMCTL_set_address_size;
-    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
+    for ( i = 0; i < ARRAY_SIZE(types); i++ )
         if ( !strcmp(types[i].guest, guest_type) )
             domctl.u.address_size.size = types[i].size;
     if ( domctl.u.address_size.size == 0 )
@@ -887,7 +887,7 @@ int arch_setup_bootlate(struct xc_dom_image *dom)
     xen_pfn_t shinfo;
     int i, rc;
 
-    for ( i = 0; i < sizeof(types) / sizeof(types[0]); i++ )
+    for ( i = 0; i < ARRAY_SIZE(types); i++ )
         if ( !strcmp(types[i].guest, dom->guest_type) )
             pgd_type = types[i].pgd_type;
 
index e621417cf332688e05682be8e52f8d588b4a041a..e7036843eaf92701a00a9af7fe58d495edaa9709 100644 (file)
@@ -87,7 +87,7 @@ static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
     int i, ret;
 
     call.op = hypercall->op;
-    for (i = 0; i < sizeof(hypercall->arg) / sizeof(*hypercall->arg); i++)
+    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
        call.args[i] = hypercall->arg[i];
 
     ret = HYPERVISOR_multicall(&call, 1);
index 12476ec4ffc0fae48c34aad719ab4db43738c74c..4447cec1e5910de8280790d7ca67112424e48a07 100644 (file)
 #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]))
+#endif
+
 /*
 ** Define max dirty page cache to permit during save/restore -- need to balance 
 ** keeping cache usage down with CPU impact of invalidating too often.
index d0e8e902839a450bdf6837c153d813eac2305f31..113460316d5652e5fdb23fee3022af49c1e7a677 100644 (file)
@@ -4,6 +4,7 @@
 #include <xenstore.h>
 #include <unistd.h>
 
+#undef ARRAY_SIZE /* We shouldn't be including xc_private.h */
 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
 
 static xc_interface *xch;
index 1af3bd8060ad2b61c9c166c8d2a5d13b5de9faa9..0761f6e37b5ca82fa72f51b35f244d30a5196204 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "xg_save_restore.h"
 
+#undef ARRAY_SIZE /* We shouldn't be including xc_private.h */
 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
 
 static xc_interface *xch;