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

[Xen-changelog] [xen staging] public: add macro for defining variable length array in public headers



commit c0536ed315b26e93d62bcbc296764d6a35b13ae1
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Sep 3 14:47:18 2019 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Sep 3 14:47:18 2019 +0200

    public: 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.
    
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 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-compat.h        |  2 ++
 xen/include/public/xen.h               |  9 +++++++++
 7 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/xen/include/public/arch-x86/hvm/save.h 
b/xen/include/public/arch-x86/hvm/save.h
index 8344aa471f..bb8fa7c12f 100644
--- a/xen/include/public/arch-x86/hvm/save.h
+++ b/xen/include/public/arch-x86/hvm/save.h
@@ -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_FLEX_ARRAY_DIM];
 };
 
 #define CPU_MSR_CODE  20
diff --git a/xen/include/public/arch-x86/pmu.h 
b/xen/include/public/arch-x86/pmu.h
index 68ebf121d0..c421cb7a4a 100644
--- a/xen/include/public/arch-x86/pmu.h
+++ b/xen/include/public/arch-x86/pmu.h
@@ -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_FLEX_ARRAY_DIM];
 };
 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_FLEX_ARRAY_DIM];
 };
 typedef struct xen_pmu_intel_ctxt xen_pmu_intel_ctxt_t;
 DEFINE_XEN_GUEST_HANDLE(xen_pmu_intel_ctxt_t);
diff --git a/xen/include/public/argo.h b/xen/include/public/argo.h
index cc603d395d..6b645f34e6 100644
--- a/xen/include/public/argo.h
+++ b/xen/include/public/argo.h
@@ -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_FLEX_ARRAY_DIM];
 } 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_FLEX_ARRAY_DIM];
 } xen_argo_ring_data_t;
 
 struct xen_argo_ring_message_header
@@ -148,11 +140,7 @@ struct xen_argo_ring_message_header
     uint32_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_FLEX_ARRAY_DIM];
 };
 
 /*
diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h
index b6faf8350c..aedb71d678 100644
--- a/xen/include/public/physdev.h
+++ b/xen/include/public/physdev.h
@@ -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_FLEX_ARRAY_DIM];
 };
 typedef struct physdev_pci_device_add physdev_pci_device_add_t;
 DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_add_t);
diff --git a/xen/include/public/version.h b/xen/include/public/version.h
index 7063e8ca55..17a81e23cd 100644
--- a/xen/include/public/version.h
+++ b/xen/include/public/version.h
@@ -95,11 +95,8 @@ typedef char xen_commandline_t[1024];
 #define XENVER_build_id 10
 struct 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_FLEX_ARRAY_DIM];
+                             /* OUT: Variable length buffer with build_id. */
 };
 typedef struct xen_build_id xen_build_id_t;
 
diff --git a/xen/include/public/xen-compat.h b/xen/include/public/xen-compat.h
index 6708132394..3f8b467934 100644
--- a/xen/include/public/xen-compat.h
+++ b/xen/include/public/xen-compat.h
@@ -41,4 +41,6 @@
 #error "These header files do not support the requested interface version."
 #endif
 
+#define COMPAT_FLEX_ARRAY_DIM XEN_FLEX_ARRAY_DIM
+
 #endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 0c7b5c3865..cef65c38e7 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -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_FLEX_ARRAY_DIM
+#elif defined(__GNUC__)
+#define XEN_FLEX_ARRAY_DIM  0
+#else
+#define XEN_FLEX_ARRAY_DIM  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
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.