Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

stddef: Introduce TRAILING_OVERLAP() helper macro

Add new TRAILING_OVERLAP() helper macro to create a union between
a flexible-array member (FAM) and a set of members that would
otherwise follow it. This overlays the trailing members onto the
FAM while preserving the original memory layout.

Co-developed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/aFG8gEwKXAWWIvX0@kspp
Signed-off-by: Kees Cook <kees@kernel.org>

authored by

Gustavo A. R. Silva and committed by
Kees Cook
29bb79e9 4bfbc269

+20
+20
include/linux/stddef.h
··· 93 93 #define DECLARE_FLEX_ARRAY(TYPE, NAME) \ 94 94 __DECLARE_FLEX_ARRAY(TYPE, NAME) 95 95 96 + /** 97 + * TRAILING_OVERLAP() - Overlap a flexible-array member with trailing members. 98 + * 99 + * Creates a union between a flexible-array member (FAM) in a struct and a set 100 + * of additional members that would otherwise follow it. 101 + * 102 + * @TYPE: Flexible structure type name, including "struct" keyword. 103 + * @NAME: Name for a variable to define. 104 + * @FAM: The flexible-array member within @TYPE 105 + * @MEMBERS: Trailing overlapping members. 106 + */ 107 + #define TRAILING_OVERLAP(TYPE, NAME, FAM, MEMBERS) \ 108 + union { \ 109 + TYPE NAME; \ 110 + struct { \ 111 + unsigned char __offset_to_##FAM[offsetof(TYPE, FAM)]; \ 112 + MEMBERS \ 113 + }; \ 114 + } 115 + 96 116 #endif