mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
tools: add sizeof_field and endof_field macros
* `sizeof_field` returns the size of a specific struct member
* `endof_field` returns the offset to the end of the member within the struct
It will be useful in upcoming layout checks of SMBIOS structs.
Signed-off-by: Petr Beneš <w1benny@gmail.com>
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
master commit: 17e66ca918
master date: 2025-08-27 11:26:33 +0200
This commit is contained in:
1 parent
1541866d47
commit
68f5ecf690
1 file changed
+5
@@ -83,6 +83,11 @@
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif
|
||||
|
||||
#define sizeof_field(type, member) sizeof(((type *)NULL)->member)
|
||||
|
||||
#define endof_field(type, member) \
|
||||
(offsetof(type, member) + sizeof_field(type, member))
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
typeof(((type *)0)->member) *mptr__ = (ptr); \
|
||||
(type *)((char *)mptr__ - offsetof(type, member)); \
|
||||
|
||||