2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 15:20:36 -07:00
|
|
|
#ifndef _LINUX_STDDEF_H
|
|
|
|
|
#define _LINUX_STDDEF_H
|
|
|
|
|
|
2012-10-13 10:46:48 +01:00
|
|
|
#include <uapi/linux/stddef.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2012-03-21 14:08:24 +01:00
|
|
|
#undef NULL
|
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
|
|
2006-09-30 23:27:11 -07:00
|
|
|
enum {
|
|
|
|
|
false = 0,
|
|
|
|
|
true = 1
|
|
|
|
|
};
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
#undef offsetof
|
2022-03-23 16:05:41 -07:00
|
|
|
#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
|
2015-03-09 15:52:17 +01:00
|
|
|
|
2018-01-10 12:53:20 -08:00
|
|
|
/**
|
2021-08-19 13:42:43 -07:00
|
|
|
* sizeof_field() - Report the size of a struct field in bytes
|
2018-01-10 12:53:20 -08:00
|
|
|
*
|
|
|
|
|
* @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))
|
|
|
|
|
|
2015-03-09 15:52:17 +01:00
|
|
|
/**
|
2021-08-19 13:42:43 -07:00
|
|
|
* offsetofend() - Report the offset of a struct field within the struct
|
2015-03-09 15:52:17 +01:00
|
|
|
*
|
|
|
|
|
* @TYPE: The type of the structure
|
|
|
|
|
* @MEMBER: The member within the structure to get the end offset of
|
|
|
|
|
*/
|
|
|
|
|
#define offsetofend(TYPE, MEMBER) \
|
2018-01-10 12:53:20 -08:00
|
|
|
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
|
2015-06-25 15:01:16 -07:00
|
|
|
|
2021-05-17 20:01:15 -07:00
|
|
|
/**
|
|
|
|
|
* struct_group() - Wrap a set of declarations in a mirrored struct
|
|
|
|
|
*
|
|
|
|
|
* @NAME: The identifier name of the mirrored sub-struct
|
|
|
|
|
* @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 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.
|
|
|
|
|
*/
|
|
|
|
|
#define struct_group(NAME, MEMBERS...) \
|
|
|
|
|
__struct_group(/* no tag */, NAME, /* no attrs */, MEMBERS)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* struct_group_attr() - Create a struct_group() with trailing attributes
|
|
|
|
|
*
|
|
|
|
|
* @NAME: The identifier name of the mirrored sub-struct
|
|
|
|
|
* @ATTRS: Any struct attributes to apply
|
|
|
|
|
* @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 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. Includes structure attributes argument.
|
|
|
|
|
*/
|
|
|
|
|
#define struct_group_attr(NAME, ATTRS, MEMBERS...) \
|
|
|
|
|
__struct_group(/* no tag */, NAME, ATTRS, MEMBERS)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* struct_group_tagged() - Create a struct_group with a reusable tag
|
|
|
|
|
*
|
|
|
|
|
* @TAG: The tag name for the named sub-struct
|
|
|
|
|
* @NAME: The identifier name of the mirrored sub-struct
|
|
|
|
|
* @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 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. Includes struct tag argument for the named copy,
|
|
|
|
|
* so the specified layout can be reused later.
|
|
|
|
|
*/
|
|
|
|
|
#define struct_group_tagged(TAG, NAME, MEMBERS...) \
|
|
|
|
|
__struct_group(TAG, NAME, /* no attrs */, MEMBERS)
|
|
|
|
|
|
2021-08-09 11:21:23 -07:00
|
|
|
/**
|
|
|
|
|
* DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
|
|
|
|
|
*
|
|
|
|
|
* @TYPE: The type of each flexible array element
|
|
|
|
|
* @NAME: The name of the flexible array member
|
|
|
|
|
*
|
|
|
|
|
* In order to have a flexible array member in a union or alone in a
|
|
|
|
|
* struct, it needs to be wrapped in an anonymous struct with at least 1
|
|
|
|
|
* named member, but that member can be empty.
|
|
|
|
|
*/
|
|
|
|
|
#define DECLARE_FLEX_ARRAY(TYPE, NAME) \
|
|
|
|
|
__DECLARE_FLEX_ARRAY(TYPE, NAME)
|
|
|
|
|
|
2015-06-25 15:01:16 -07:00
|
|
|
#endif
|