xen: add macro for defining variable length array in public headers
PATCH 1/1 xen: add macro for defining variable length array in public headers
Several public headers of the hypervisor contain structures with variable length arrays. In order to be usable with different compilers those definitions are depending on the compiler type and the standard supported by the compiler.
In order to avoid open coding the different variants in each header add a common macro for that purpose in xen.h.
This at once corrects most of the definitions which miss one case leading to not defining the array at all.
--- xen/include/public/arch-x86/hvm/save.h | 8 +------- xen/include/public/arch-x86/pmu.h | 12 ++---------- xen/include/public/argo.h | 18 +++--------------- xen/include/public/physdev.h | 6 +----- xen/include/public/version.h | 7 ++----- xen/include/public/xen.h | 9 +++++++++ 6 files changed, 18 insertions(+), 42 deletions(-)
xen/include/public/arch-x86/hvm/save.h +1 -7
@@ -632,13 +632,7 @@ struct hvm_msr {uint32_t index;uint32_t _rsvd;uint64_t val; -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L - } msr[]; -#elif defined(__GNUC__) - } msr[0]; -#else - } msr[1 /* variable size */ ]; -#endif + } msr[__XEN_VARLEN_ARRAY_SIZE]; };#define CPU_MSR_CODE 20
xen/include/public/arch-x86/pmu.h +2 -10
@@ -35,11 +35,7 @@ struct xen_pmu_amd_ctxt {uint32_t ctrls;/* Counter MSRs */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -uint64_t regs[]; -#elif defined(__GNUC__) -uint64_t regs[0 ]; -#endif +uint64_t regs[__XEN_VARLEN_ARRAY_SIZE]; };typedef struct xen_pmu_amd_ctxt xen_pmu_amd_ctxt_t ;DEFINE_XEN_GUEST_HANDLE (xen_pmu_amd_ctxt_t);
@@ -71,11 +67,7 @@ struct xen_pmu_intel_ctxt {uint64_t debugctl;/* Fixed and architectural counter MSRs */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -uint64_t regs[]; -#elif defined(__GNUC__) -uint64_t regs[0 ]; -#endif +uint64_t regs[__XEN_VARLEN_ARRAY_SIZE]; };typedef struct xen_pmu_intel_ctxt xen_pmu_intel_ctxt_t ;DEFINE_XEN_GUEST_HANDLE (xen_pmu_intel_ctxt_t);
xen/include/public/argo.h +3 -15
@@ -82,11 +82,7 @@ typedef struct xen_argo_ring* multiple of the message slot size. */ uint8_t reserved[56 ]; -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -uint8_t ring[]; -#elif defined(__GNUC__) -uint8_t ring[0 ]; -#endif +uint8_t ring[__XEN_VARLEN_ARRAY_SIZE]; } xen_argo_ring_t; typedef struct xen_argo_register_ring
@@ -136,11 +132,7 @@ typedef struct xen_argo_ring_data {uint32_t nent;uint32_t pad; -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -struct xen_argo_ring_data_ent data[]; -#elif defined(__GNUC__) -struct xen_argo_ring_data_ent data[0 ]; -#endif +struct xen_argo_ring_data_ent data[__XEN_VARLEN_ARRAY_SIZE]; } xen_argo_ring_data_t;struct xen_argo_ring_message_header
@@ -148,11 +140,7 @@ struct xen_argo_ring_message_headeruint32_t len;struct xen_argo_addr source;uint32_t message_type; -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -uint8_t data[]; -#elif defined(__GNUC__) -uint8_t data[0 ]; -#endif +uint8_t data[__XEN_VARLEN_ARRAY_SIZE]; };/*
xen/include/public/physdev.h +1 -5
@@ -300,11 +300,7 @@ struct physdev_pci_device_add {* First element ([0]) is PXM domain associated with the device (if * XEN_PCI_DEV_PXM is set) */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -uint32_t optarr[]; -#elif defined(__GNUC__) -uint32_t optarr[0 ]; -#endif +uint32_t optarr[__XEN_VARLEN_ARRAY_SIZE]; };typedef struct physdev_pci_device_add physdev_pci_device_add_t ;DEFINE_XEN_GUEST_HANDLE (physdev_pci_device_add_t);
xen/include/public/version.h +2 -5
@@ -95,11 +95,8 @@ typedef char xen_commandline_t[1024];#define XENVER_build_id 10struct xen_build_id {uint32_t len;/* IN: size of buf[]. */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L -unsigned char buf[]; -#elif defined(__GNUC__) -unsigned char buf[1 ];/* OUT: Variable length buffer with build_id. */ -#endif +unsigned char buf[__XEN_VARLEN_ARRAY_SIZE]; +/* OUT: Variable length buffer with build_id. */ };typedef struct xen_build_id xen_build_id_t ;
xen/include/public/xen.h +9 -0
@@ -53,6 +53,15 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);DEFINE_XEN_GUEST_HANDLE (xen_ulong_t); +/* Define a variable length array (depends on compiler). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L +#define __XEN_VARLEN_ARRAY_SIZE +#elif defined(__GNUC__) +#define __XEN_VARLEN_ARRAY_SIZE 0 +#else +#define __XEN_VARLEN_ARRAY_SIZE 1/* variable size */ +#endif +/* Turn a plain number into a C unsigned (long (long)) constant. */ #define __xen_mk_uint (x) x ## U#define __xen_mk_ulong (x) x ## UL
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Juergen Gross
xen/include/public/xen.h +0
-0@@ -53,6 +53,15 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);
xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(uint64_t); · line 63
Quoted 10 lines
xen/include/public/xen.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_ulong_t); +/* Define a variable length array (depends on compiler). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L +#define __XEN_VARLEN_ARRAY_SIZE +#elif defined(__GNUC__) +#define __XEN_VARLEN_ARRAY_SIZE 0 +#else +#define __XEN_VARLEN_ARRAY_SIZE 1/* variable size */ +#endif
To be in line with the intentions, the C90 standard, and io/ring.h I'd suggest to use FLEX instead of VARLEN. Furthermore, especially in a public header, two double leading underscores need to go away.
And then, with FLEX in the name, SIZE isn't really appropriate anymore. Therefore I see three possible names: XEN_FLEXIBLE_ARRAY, XEN_FLEX_ARRAY_DIMENSION (possibly just _DIM at its end), or XEN_FLEX_ARRAY_DESIGNATOR.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/include/public/xen.h +0
-0@@ -53,6 +53,15 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(uint64_t); · line 63
Quoted 10 lines
xen/include/public/xen.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_ulong_t); +/* Define a variable length array (depends on compiler). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L +#define __XEN_VARLEN_ARRAY_SIZE +#elif defined(__GNUC__) +#define __XEN_VARLEN_ARRAY_SIZE 0 +#else +#define __XEN_VARLEN_ARRAY_SIZE 1/* variable size */ +#endif To be in line with the intentions, the C90 standard, and
io/ring.hI'd suggest to use FLEX instead of VARLEN. Furthermore, especially in a public header, two double leading underscores need to go away.
Quoted 4 lines
And then, with FLEX in the name, SIZE isn't really appropriate anymore. Therefore I see three possible names:
XEN_FLEXIBLE_ARRAY,XEN_FLEX_ARRAY_DIMENSION(possibly just_DIMat its end), orXEN_FLEX_ARRAY_DESIGNATOR.
Okay to the "FLEX" part, but the "XEN_" prefix is not working due to compat header generation (that will result in COMPAT_ prefix in the compat headers).
So any other ideas for a sensible prefix?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines · Juergen Gross
Quoted 20 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/include/public/xen.h +0
-0@@ -53,6 +53,15 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(uint64_t); · line 63
Quoted 10 lines
xen/include/public/xen.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_ulong_t); +/* Define a variable length array (depends on compiler). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L +#define __XEN_VARLEN_ARRAY_SIZE +#elif defined(__GNUC__) +#define __XEN_VARLEN_ARRAY_SIZE 0 +#else +#define __XEN_VARLEN_ARRAY_SIZE 1/* variable size */ +#endif To be in line with the intentions, the C90 standard, and
io/ring.hI'd suggest to use FLEX instead of VARLEN. Furthermore, especially in a public header, two double leading underscores need to go away.Quoted 4 lines
And then, with FLEX in the name, SIZE isn't really appropriate anymore. Therefore I see three possible names:
XEN_FLEXIBLE_ARRAY,XEN_FLEX_ARRAY_DIMENSION(possibly just_DIMat its end), orXEN_FLEX_ARRAY_DESIGNATOR.
Quoted 5 lines
Okay to the "FLEX" part, but the "
XEN_" prefix is not working due to compat header generation (that will result inCOMPAT_prefix in the compat headers).So any other ideas for a sensible prefix?
Hmm, ugly. Perhaps all lower case then? Or have
#define COMPAT_FLEX_... XEN_FLEX_...
somewhere?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Juergen Gross
Quoted 24 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/include/public/xen.h +0
-0@@ -53,6 +53,15 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(uint64_t); · line 63
Quoted 10 lines
xen/include/public/xen.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_ulong_t); +/* Define a variable length array (depends on compiler). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L +#define __XEN_VARLEN_ARRAY_SIZE +#elif defined(__GNUC__) +#define __XEN_VARLEN_ARRAY_SIZE 0 +#else +#define __XEN_VARLEN_ARRAY_SIZE 1/* variable size */ +#endif To be in line with the intentions, the C90 standard, and
io/ring.hI'd suggest to use FLEX instead of VARLEN. Furthermore, especially in a public header, two double leading underscores need to go away.And then, with FLEX in the name, SIZE isn't really appropriate anymore. Therefore I see three possible names:
XEN_FLEXIBLE_ARRAY,XEN_FLEX_ARRAY_DIMENSION(possibly just_DIMat its end), orXEN_FLEX_ARRAY_DESIGNATOR.
Quoted 7 lines
Quoted 5 lines
Okay to the "FLEX" part, but the "
XEN_" prefix is not working due to compat header generation (that will result inCOMPAT_prefix in the compat headers).So any other ideas for a sensible prefix?
Hmm, ugly. Perhaps all lower case then? Or have
xen_ and Xen_ are being converted, too.
Quoted 4 lines
#define
COMPAT_FLEX_...XEN_FLEX_...somewhere?
Seems as if doing that in include/public/xen-compat.h is working.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 32 lines · Juergen Gross
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Juergen Gross
Quoted 20 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/include/public/xen.h +0
-0@@ -53,6 +53,15 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(uint64_t); · line 63
Quoted 10 lines
xen/include/public/xen.h +8
-0DEFINE_XEN_GUEST_HANDLE (xen_ulong_t); +/* Define a variable length array (depends on compiler). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=199901L +#define __XEN_VARLEN_ARRAY_SIZE +#elif defined(__GNUC__) +#define __XEN_VARLEN_ARRAY_SIZE 0 +#else +#define __XEN_VARLEN_ARRAY_SIZE 1/* variable size */ +#endif To be in line with the intentions, the C90 standard, and
io/ring.hI'd suggest to use FLEX instead of VARLEN. Furthermore, especially in a public header, two double leading underscores need to go away.Quoted 4 lines
And then, with FLEX in the name, SIZE isn't really appropriate anymore. Therefore I see three possible names:
XEN_FLEXIBLE_ARRAY,XEN_FLEX_ARRAY_DIMENSION(possibly just_DIMat its end), orXEN_FLEX_ARRAY_DESIGNATOR.Okay to the "FLEX" part, but the "
XEN_" prefix is not working due to compat header generation (that will result inCOMPAT_prefix in the compat headers).
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
So any other ideas for a sensible prefix?
Hmm, ugly. Perhaps all lower case then? Or have
xen_andXen_are being converted, too.
For Xen_ I agree, but for xen_ I only see
[ r"(struct|union|enum)\s+(xen_?)?(\w)", r"\1 compat_\3" ],
and
[ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ],
, neither of which should match your #define. But perhaps I'm missing something.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel