1*4dc78e53SAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2*4dc78e53SAndroid Build Coastguard Worker #ifndef _LINUX_STDDEF_H 3*4dc78e53SAndroid Build Coastguard Worker #define _LINUX_STDDEF_H 4*4dc78e53SAndroid Build Coastguard Worker 5*4dc78e53SAndroid Build Coastguard Worker 6*4dc78e53SAndroid Build Coastguard Worker 7*4dc78e53SAndroid Build Coastguard Worker #ifndef __always_inline 8*4dc78e53SAndroid Build Coastguard Worker #define __always_inline __inline__ 9*4dc78e53SAndroid Build Coastguard Worker #endif 10*4dc78e53SAndroid Build Coastguard Worker 11*4dc78e53SAndroid Build Coastguard Worker /** 12*4dc78e53SAndroid Build Coastguard Worker * __struct_group() - Create a mirrored named and anonyomous struct 13*4dc78e53SAndroid Build Coastguard Worker * 14*4dc78e53SAndroid Build Coastguard Worker * @TAG: The tag name for the named sub-struct (usually empty) 15*4dc78e53SAndroid Build Coastguard Worker * @NAME: The identifier name of the mirrored sub-struct 16*4dc78e53SAndroid Build Coastguard Worker * @ATTRS: Any struct attributes (usually empty) 17*4dc78e53SAndroid Build Coastguard Worker * @MEMBERS: The member declarations for the mirrored structs 18*4dc78e53SAndroid Build Coastguard Worker * 19*4dc78e53SAndroid Build Coastguard Worker * Used to create an anonymous union of two structs with identical layout 20*4dc78e53SAndroid Build Coastguard Worker * and size: one anonymous and one named. The former's members can be used 21*4dc78e53SAndroid Build Coastguard Worker * normally without sub-struct naming, and the latter can be used to 22*4dc78e53SAndroid Build Coastguard Worker * reason about the start, end, and size of the group of struct members. 23*4dc78e53SAndroid Build Coastguard Worker * The named struct can also be explicitly tagged for layer reuse, as well 24*4dc78e53SAndroid Build Coastguard Worker * as both having struct attributes appended. 25*4dc78e53SAndroid Build Coastguard Worker */ 26*4dc78e53SAndroid Build Coastguard Worker #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ 27*4dc78e53SAndroid Build Coastguard Worker union { \ 28*4dc78e53SAndroid Build Coastguard Worker struct { MEMBERS } ATTRS; \ 29*4dc78e53SAndroid Build Coastguard Worker struct TAG { MEMBERS } ATTRS NAME; \ 30*4dc78e53SAndroid Build Coastguard Worker } 31*4dc78e53SAndroid Build Coastguard Worker 32*4dc78e53SAndroid Build Coastguard Worker /** 33*4dc78e53SAndroid Build Coastguard Worker * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union 34*4dc78e53SAndroid Build Coastguard Worker * 35*4dc78e53SAndroid Build Coastguard Worker * @TYPE: The type of each flexible array element 36*4dc78e53SAndroid Build Coastguard Worker * @NAME: The name of the flexible array member 37*4dc78e53SAndroid Build Coastguard Worker * 38*4dc78e53SAndroid Build Coastguard Worker * In order to have a flexible array member in a union or alone in a 39*4dc78e53SAndroid Build Coastguard Worker * struct, it needs to be wrapped in an anonymous struct with at least 1 40*4dc78e53SAndroid Build Coastguard Worker * named member, but that member can be empty. 41*4dc78e53SAndroid Build Coastguard Worker */ 42*4dc78e53SAndroid Build Coastguard Worker #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ 43*4dc78e53SAndroid Build Coastguard Worker struct { \ 44*4dc78e53SAndroid Build Coastguard Worker struct { } __empty_ ## NAME; \ 45*4dc78e53SAndroid Build Coastguard Worker TYPE NAME[]; \ 46*4dc78e53SAndroid Build Coastguard Worker } 47*4dc78e53SAndroid Build Coastguard Worker #endif 48