From patchwork Fri Aug 30 08:32:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11123421 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BF6414F7 for ; Fri, 30 Aug 2019 08:34:24 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F7C32397E for ; Fri, 30 Aug 2019 08:34:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F7C32397E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i3cKd-0007Am-UJ; Fri, 30 Aug 2019 08:32:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i3cKd-0007Ac-Ca for xen-devel@lists.xenproject.org; Fri, 30 Aug 2019 08:32:31 +0000 X-Inumbo-ID: b38bfcda-cb00-11e9-b95f-bc764e2007e4 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b38bfcda-cb00-11e9-b95f-bc764e2007e4; Fri, 30 Aug 2019 08:32:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D3992AF47; Fri, 30 Aug 2019 08:32:27 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 30 Aug 2019 10:32:25 +0200 Message-Id: <20190830083225.10397-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Subject: [Xen-devel] [PATCH] xen: add macro for defining variable length array in public headers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Christopher Clark , Tim Deegan , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 --- 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(-) diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/arch-x86/hvm/save.h index 8344aa471f..7cb6952ab8 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_VARLEN_ARRAY_SIZE]; }; #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..6c3b8cd4b6 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_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); diff --git a/xen/include/public/argo.h b/xen/include/public/argo.h index cc603d395d..696b227137 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_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_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_VARLEN_ARRAY_SIZE]; }; /* diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h index b6faf8350c..c20c4451d3 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_VARLEN_ARRAY_SIZE]; }; 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..4cdab53872 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_VARLEN_ARRAY_SIZE]; + /* OUT: Variable length buffer with build_id. */ }; typedef struct xen_build_id xen_build_id_t; diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index 0c7b5c3865..7b31f68043 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_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