stddef.h: Introduce sizeof_field()
The size of fields within a structure is needed in a few places in the kernel already, and will be needed for the usercopy whitelisting when declaring whitelist regions within structures. This creates a dedicated macro and redefines offsetofend() to use it. Existing usage, ignoring the 1200+ lustre assert uses: $ git grep -E 'sizeof\(\(\((struct )?[a-zA-Z_]+ \*\)0\)->' | \ grep -v staging/lustre | wc -l 65 Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
parent
c758868624
commit
4229a47017
@ -19,6 +19,14 @@ enum {
|
|||||||
#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
|
#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sizeof_field(TYPE, MEMBER)
|
||||||
|
*
|
||||||
|
* @TYPE: The structure containing the field of interest
|
||||||
|
* @MEMBER: The field to return the size of
|
||||||
|
*/
|
||||||
|
#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* offsetofend(TYPE, MEMBER)
|
* offsetofend(TYPE, MEMBER)
|
||||||
*
|
*
|
||||||
@ -26,6 +34,6 @@ enum {
|
|||||||
* @MEMBER: The member within the structure to get the end offset of
|
* @MEMBER: The member within the structure to get the end offset of
|
||||||
*/
|
*/
|
||||||
#define offsetofend(TYPE, MEMBER) \
|
#define offsetofend(TYPE, MEMBER) \
|
||||||
(offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))
|
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user