From: Luca Fancellu <luca.fancellu@arm.com>
To: xen-devel@lists.xenproject.org
Cc: consulting@bugseng.com, nicola.vetrini@bugseng.com,
Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH 1/2] xen/kernel.h: Import __struct_group from Linux
Date: Tue, 30 Apr 2024 12:09:21 +0100 [thread overview]
Message-ID: <20240430110922.15052-2-luca.fancellu@arm.com> (raw)
In-Reply-To: <20240430110922.15052-1-luca.fancellu@arm.com>
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 <luca.fancellu@arm.com>
---
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.
--
2.34.1
next prev parent reply other threads:[~2024-04-30 11:09 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 11:09 [PATCH 0/2] Fix MISRA regression about flexible array member not at the end Luca Fancellu
2024-04-30 11:09 ` Luca Fancellu [this message]
2024-04-30 11:43 ` [PATCH 1/2] xen/kernel.h: Import __struct_group from Linux Jan Beulich
2024-05-01 6:54 ` Luca Fancellu
2024-05-02 6:09 ` Jan Beulich
2024-05-02 6:23 ` Luca Fancellu
2024-05-02 6:38 ` Jan Beulich
2024-05-02 18:23 ` Stefano Stabellini
2024-04-30 11:09 ` [PATCH 2/2] xen/arm: Fix MISRA regression on R1.1, flexible array member not at the end Luca Fancellu
2024-04-30 11:37 ` Jan Beulich
2024-05-01 6:57 ` Luca Fancellu
2024-05-02 6:14 ` Jan Beulich
2024-05-02 6:33 ` Luca Fancellu
2024-05-02 6:43 ` Jan Beulich
2024-05-02 8:13 ` Luca Fancellu
2024-05-02 9:53 ` Jan Beulich
2024-05-02 10:12 ` Luca Fancellu
2024-05-02 10:30 ` Jan Beulich
2024-05-02 10:42 ` Luca Fancellu
2024-04-30 12:55 ` Nicola Vetrini
2024-05-02 18:35 ` Stefano Stabellini
2024-05-08 16:18 ` Luca Fancellu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240430110922.15052-2-luca.fancellu@arm.com \
--to=luca.fancellu@arm.com \
--cc=andrew.cooper3@citrix.com \
--cc=consulting@bugseng.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=nicola.vetrini@bugseng.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).