linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools headers UAPI: Sync linux/stddef.h with the kernel sources
@ 2022-10-31  9:30 Yang Jihong
  0 siblings, 0 replies; only message in thread
From: Yang Jihong @ 2022-10-31  9:30 UTC (permalink / raw)
  To: acme, tadeusz.struk, keescook, linux-kernel, pf; +Cc: yangjihong1

commit 036b8f5b8970 ("tools headers uapi: Update linux/in.h copy") modify
tools/include/uapi/linux/in.h, and __DECLARE_FLEX_ARRAY is introduced.
Macro is not defined in tools/include, compilation fails:

    CLNG-BPF [test_maps] bind4_prog.bpf.o
  In file included from progs/bind4_prog.c:7:
  /root/linux-mainline-new/linux/tools/include/uapi/linux/in.h:199:3: error: type name requires a specifier or qualifier
                  __DECLARE_FLEX_ARRAY(__be32, imsf_slist_flex);
                  ^
  /root/linux-mainline-new/linux/tools/include/uapi/linux/in.h:199:32: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
                  __DECLARE_FLEX_ARRAY(__be32, imsf_slist_flex);
                                               ^
  2 errors generated.

Synchronize include/uapi/linux/stddef.h to tools headers directory,
and delete the line "#include <linux/compiler_types.h>":

  # cp ./include/uapi/linux/stddef.h tools/include/uapi/linux/stddef.h
  # sed -i '/#include <linux\/compiler_types.h>/,+1d' tools/include/uapi/linux/stddef.h

And add missed <linux/stddef.h> header in tools/include/uapi/linux/in.h.

Fixes: 036b8f5b8970 (tools headers uapi: Update linux/in.h copy)
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
 tools/include/uapi/linux/in.h     |  1 +
 tools/include/uapi/linux/stddef.h | 45 +++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 tools/include/uapi/linux/stddef.h

diff --git a/tools/include/uapi/linux/in.h b/tools/include/uapi/linux/in.h
index f243ce665f74..79015665daf1 100644
--- a/tools/include/uapi/linux/in.h
+++ b/tools/include/uapi/linux/in.h
@@ -22,6 +22,7 @@
 #include <linux/types.h>
 #include <linux/libc-compat.h>
 #include <linux/socket.h>
+#include <linux/stddef.h>
 
 #if __UAPI_DEF_IN_IPPROTO
 /* Standard well-defined IP protocols.  */
diff --git a/tools/include/uapi/linux/stddef.h b/tools/include/uapi/linux/stddef.h
new file mode 100644
index 000000000000..72bcdf96999f
--- /dev/null
+++ b/tools/include/uapi/linux/stddef.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_STDDEF_H
+#define _UAPI_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
-- 
2.30.GIT


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-31  9:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-31  9:30 [PATCH] tools headers UAPI: Sync linux/stddef.h with the kernel sources Yang Jihong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).