From patchwork Tue Apr 30 11:09:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13648761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5236FC19F53 for ; Tue, 30 Apr 2024 11:09:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714730.1116036 (Exim 4.92) (envelope-from ) id 1s1lMf-0003aA-Qb; Tue, 30 Apr 2024 11:09:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714730.1116036; Tue, 30 Apr 2024 11:09:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1lMf-0003a3-Nx; Tue, 30 Apr 2024 11:09:37 +0000 Received: by outflank-mailman (input) for mailman id 714730; Tue, 30 Apr 2024 11:09:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1lMe-0003Lb-3O for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 11:09:36 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 1fccf056-06e2-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 13:09:34 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CA0A0339; Tue, 30 Apr 2024 04:09:59 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 434D03F73F; Tue, 30 Apr 2024 04:09:32 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1fccf056-06e2-11ef-b4bb-af5377834399 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, nicola.vetrini@bugseng.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 1/2] xen/kernel.h: Import __struct_group from Linux Date: Tue, 30 Apr 2024 12:09:21 +0100 Message-Id: <20240430110922.15052-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430110922.15052-1-luca.fancellu@arm.com> References: <20240430110922.15052-1-luca.fancellu@arm.com> MIME-Version: 1.0 Import __struct_group from Linux, commit 50d7bd38c3aa ("stddef: Introduce struct_group() helper macro"), in order to allow the access through the anonymous structure to the members without having to write also the name, e.g: struct foo { int one; struct { int two; int three, four; } thing; int five; }; would become: struct foo { int one; __struct_group(/* None */, thing, /* None */, int two; int three, four; ); int five; }; Allowing the users of this structure to access the .thing members by using .two/.three/.four on the struct foo. This construct will become useful in order to have some generalized interfaces that shares some common members. Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 50d7bd38c3aa Signed-off-by: Luca Fancellu Reviewed-by: Stefano Stabellini --- xen/include/xen/kernel.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/xen/include/xen/kernel.h b/xen/include/xen/kernel.h index bb6b0f38912d..bc2440b5f96e 100644 --- a/xen/include/xen/kernel.h +++ b/xen/include/xen/kernel.h @@ -54,6 +54,27 @@ typeof_field(type, member) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +/** + * __struct_group() - Create a mirrored named and anonyomous struct + * + * @TAG: The tag name for the named sub-struct (usually empty) + * @NAME: The identifier name of the mirrored sub-struct + * @ATTRS: Any struct attributes (usually empty) + * @MEMBERS: The member declarations for the mirrored structs + * + * Used to create an anonymous union of two structs with identical layout + * and size: one anonymous and one named. The former's members can be used + * normally without sub-struct naming, and the latter can be used to + * reason about the start, end, and size of the group of struct members. + * The named struct can also be explicitly tagged for layer reuse, as well + * as both having struct attributes appended. + */ +#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ + union { \ + struct { MEMBERS } ATTRS; \ + struct TAG { MEMBERS } ATTRS NAME; \ + } ATTRS + /* * Check at compile time that something is of a particular type. * Always evaluates to 1 so you may use it easily in comparisons.