xref: /linux-6.15/include/uapi/linux/stddef.h (revision 3407caa6)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
255037ed7STadeusz Struk #ifndef _UAPI_LINUX_STDDEF_H
355037ed7STadeusz Struk #define _UAPI_LINUX_STDDEF_H
455037ed7STadeusz Struk 
5d1515582SWill Deacon #include <linux/compiler_types.h>
6283d7573SDenys Vlasenko 
7283d7573SDenys Vlasenko #ifndef __always_inline
8283d7573SDenys Vlasenko #define __always_inline inline
9283d7573SDenys Vlasenko #endif
1050d7bd38SKees Cook 
11724c6ce3SAlexander Lobakin /* Not all C++ standards support type declarations inside an anonymous union */
12724c6ce3SAlexander Lobakin #ifndef __cplusplus
13724c6ce3SAlexander Lobakin #define __struct_group_tag(TAG)		TAG
14724c6ce3SAlexander Lobakin #else
15724c6ce3SAlexander Lobakin #define __struct_group_tag(TAG)
16724c6ce3SAlexander Lobakin #endif
17724c6ce3SAlexander Lobakin 
1850d7bd38SKees Cook /**
1950d7bd38SKees Cook  * __struct_group() - Create a mirrored named and anonyomous struct
2050d7bd38SKees Cook  *
2150d7bd38SKees Cook  * @TAG: The tag name for the named sub-struct (usually empty)
2250d7bd38SKees Cook  * @NAME: The identifier name of the mirrored sub-struct
2350d7bd38SKees Cook  * @ATTRS: Any struct attributes (usually empty)
2450d7bd38SKees Cook  * @MEMBERS: The member declarations for the mirrored structs
2550d7bd38SKees Cook  *
2650d7bd38SKees Cook  * Used to create an anonymous union of two structs with identical layout
2750d7bd38SKees Cook  * and size: one anonymous and one named. The former's members can be used
2850d7bd38SKees Cook  * normally without sub-struct naming, and the latter can be used to
2950d7bd38SKees Cook  * reason about the start, end, and size of the group of struct members.
30724c6ce3SAlexander Lobakin  * The named struct can also be explicitly tagged for layer reuse (C only),
31724c6ce3SAlexander Lobakin  * as well as both having struct attributes appended.
3250d7bd38SKees Cook  */
3350d7bd38SKees Cook #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
3450d7bd38SKees Cook 	union { \
3550d7bd38SKees Cook 		struct { MEMBERS } ATTRS; \
36724c6ce3SAlexander Lobakin 		struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \
374e86f32aSDmitry Antipov 	} ATTRS
383080ea55SKees Cook 
3932a4ec21SAlexey Dobriyan #ifdef __cplusplus
4032a4ec21SAlexey Dobriyan /* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */
4132a4ec21SAlexey Dobriyan #define __DECLARE_FLEX_ARRAY(T, member)	\
4232a4ec21SAlexey Dobriyan 	T member[0]
4332a4ec21SAlexey Dobriyan #else
443080ea55SKees Cook /**
453080ea55SKees Cook  * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
463080ea55SKees Cook  *
473080ea55SKees Cook  * @TYPE: The type of each flexible array element
483080ea55SKees Cook  * @NAME: The name of the flexible array member
493080ea55SKees Cook  *
503080ea55SKees Cook  * In order to have a flexible array member in a union or alone in a
513080ea55SKees Cook  * struct, it needs to be wrapped in an anonymous struct with at least 1
523080ea55SKees Cook  * named member, but that member can be empty.
533080ea55SKees Cook  */
543080ea55SKees Cook #define __DECLARE_FLEX_ARRAY(TYPE, NAME)	\
553080ea55SKees Cook 	struct { \
563080ea55SKees Cook 		struct { } __empty_ ## NAME; \
573080ea55SKees Cook 		TYPE NAME[]; \
583080ea55SKees Cook 	}
5932a4ec21SAlexey Dobriyan #endif
60c8248fafSKees Cook 
61c8248fafSKees Cook #ifndef __counted_by
62c8248fafSKees Cook #define __counted_by(m)
63c8248fafSKees Cook #endif
64531108ecSAlexey Dobriyan 
656d305cbeSErick Archer #ifndef __counted_by_le
666d305cbeSErick Archer #define __counted_by_le(m)
676d305cbeSErick Archer #endif
686d305cbeSErick Archer 
696d305cbeSErick Archer #ifndef __counted_by_be
706d305cbeSErick Archer #define __counted_by_be(m)
716d305cbeSErick Archer #endif
726d305cbeSErick Archer 
73*3407caa6SKees Cook #ifdef __KERNEL__
74*3407caa6SKees Cook #define __kernel_nonstring	__nonstring
75*3407caa6SKees Cook #else
76*3407caa6SKees Cook #define __kernel_nonstring
77*3407caa6SKees Cook #endif
78*3407caa6SKees Cook 
79531108ecSAlexey Dobriyan #endif /* _UAPI_LINUX_STDDEF_H */
80