mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 14:23:38 +00:00
170 lines
5.9 KiB
Diff
170 lines
5.9 KiB
Diff
--- a/include/linux/stddef.h
|
|
+++ b/include/linux/stddef.h
|
|
@@ -35,5 +35,66 @@
|
|
*/
|
|
#define offsetofend(TYPE, MEMBER) \
|
|
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
|
|
+
|
|
+/**
|
|
+ * 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)
|
|
+
|
|
+/**
|
|
+ * 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)
|
|
|
|
#endif
|
|
--- a/dev/null
|
|
+++ b/tools/include/uapi/linux/stddef.h
|
|
@@ -0,0 +1,47 @@
|
|
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
|
+#ifndef _LINUX_STDDEF_H
|
|
+#define _LINUX_STDDEF_H
|
|
+
|
|
+
|
|
+
|
|
+#ifndef __always_inline
|
|
+#define __always_inline __inline__
|
|
+#endif
|
|
+
|
|
+/**
|
|
+ * __struct_group() - Create a mirrored named and anonyomous struct
|
|
+ *
|
|
+ * @TAG: The tag name for the named sub-struct (usually empty)
|
|
+ * @NAME: The identifier name of the mirrored sub-struct
|
|
+ * @ATTRS: Any struct attributes (usually empty)
|
|
+ * @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's members 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.
|
|
+ * The named struct can also be explicitly tagged for layer reuse, as well
|
|
+ * as both having struct attributes appended.
|
|
+ */
|
|
+#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
|
|
+ union { \
|
|
+ struct { MEMBERS } ATTRS; \
|
|
+ struct TAG { MEMBERS } ATTRS NAME; \
|
|
+ }
|
|
+
|
|
+/**
|
|
+ * __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) \
|
|
+ struct { \
|
|
+ struct { } __empty_ ## NAME; \
|
|
+ TYPE NAME[]; \
|
|
+ }
|
|
+#endif
|
|
--- a/dev/null
|
|
+++ b/include/uapi/linux/stddef.h
|
|
@@ -0,0 +1,47 @@
|
|
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
|
+#ifndef _UAPI_LINUX_STDDEF_H
|
|
+#define _UAPI_LINUX_STDDEF_H
|
|
+
|
|
+#include <linux/compiler_types.h>
|
|
+
|
|
+#ifndef __always_inline
|
|
+#define __always_inline inline
|
|
+#endif
|
|
+
|
|
+/**
|
|
+ * __struct_group() - Create a mirrored named and anonyomous struct
|
|
+ *
|
|
+ * @TAG: The tag name for the named sub-struct (usually empty)
|
|
+ * @NAME: The identifier name of the mirrored sub-struct
|
|
+ * @ATTRS: Any struct attributes (usually empty)
|
|
+ * @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's members 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.
|
|
+ * The named struct can also be explicitly tagged for layer reuse, as well
|
|
+ * as both having struct attributes appended.
|
|
+ */
|
|
+#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
|
|
+ union { \
|
|
+ struct { MEMBERS } ATTRS; \
|
|
+ struct TAG { MEMBERS } ATTRS NAME; \
|
|
+ }
|
|
+
|
|
+/**
|
|
+ * __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) \
|
|
+ struct { \
|
|
+ struct { } __empty_ ## NAME; \
|
|
+ TYPE NAME[]; \
|
|
+ }
|
|
+#endif
|