diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h new file mode 100644 index 0000000..d90dca3 --- /dev/null +++ b/include/uapi/linux/stddef.h @@ -0,0 +1,79 @@ +/* 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 + +/* Not all C++ standards support type declarations inside an anonymous union */ +#ifndef __cplusplus +#define __struct_group_tag(TAG) TAG +#else +#define __struct_group_tag(TAG) +#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 (C only), + * as well as both having struct attributes appended. + */ +#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ + union { \ + struct { MEMBERS } ATTRS; \ + struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \ + } ATTRS + +#ifdef __cplusplus +/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */ +#define __DECLARE_FLEX_ARRAY(T, member) \ + T member[0] +#else +/** + * __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 + +#ifndef __counted_by +#define __counted_by(m) +#endif + +#ifndef __counted_by_le +#define __counted_by_le(m) +#endif + +#ifndef __counted_by_be +#define __counted_by_be(m) +#endif + +#ifdef __KERNEL__ +#define __kernel_nonstring __nonstring +#else +#define __kernel_nonstring +#endif + +#endif /* _LINUX_STDDEF_H */ diff --git a/scripts/sync-kernel.sh b/scripts/sync-kernel.sh index bfce983..cbd96bd 100755 --- a/scripts/sync-kernel.sh +++ b/scripts/sync-kernel.sh @@ -40,17 +40,18 @@ declare -A PATH_MAP PATH_MAP=( \ [tools/lib/bpf]=src \ [include/uapi/linux/bpf_common.h]=include/uapi/linux/bpf_common.h \ - [include/uapi/linux/bpf.h]=include/uapi/linux/bpf.h \ - [include/uapi/linux/btf.h]=include/uapi/linux/btf.h \ - [include/uapi/linux/fcntl.h]=include/uapi/linux/fcntl.h \ - [include/uapi/linux/openat2.h]=include/uapi/linux/openat2.h \ - [include/uapi/linux/if_link.h]=include/uapi/linux/if_link.h \ + [include/uapi/linux/bpf.h]=include/uapi/linux/bpf.h \ + [include/uapi/linux/btf.h]=include/uapi/linux/btf.h \ + [include/uapi/linux/fcntl.h]=include/uapi/linux/fcntl.h \ + [include/uapi/linux/openat2.h]=include/uapi/linux/openat2.h \ + [include/uapi/linux/if_link.h]=include/uapi/linux/if_link.h \ [include/uapi/linux/if_xdp.h]=include/uapi/linux/if_xdp.h \ [include/uapi/linux/netdev.h]=include/uapi/linux/netdev.h \ - [include/uapi/linux/netlink.h]=include/uapi/linux/netlink.h \ - [include/uapi/linux/pkt_cls.h]=include/uapi/linux/pkt_cls.h \ - [include/uapi/linux/pkt_sched.h]=include/uapi/linux/pkt_sched.h \ + [include/uapi/linux/netlink.h]=include/uapi/linux/netlink.h \ + [include/uapi/linux/pkt_cls.h]=include/uapi/linux/pkt_cls.h \ + [include/uapi/linux/pkt_sched.h]=include/uapi/linux/pkt_sched.h \ [include/uapi/linux/perf_event.h]=include/uapi/linux/perf_event.h \ + [include/uapi/linux/stddef.h]=include/uapi/linux/stddef.h \ [Documentation/bpf/libbpf]=docs \ ) @@ -63,7 +64,7 @@ LIBBPF_TREE_FILTER="mkdir -p __libbpf/include/uapi/linux __libbpf/include/tools for p in "${!PATH_MAP[@]}"; do LIBBPF_TREE_FILTER+="git mv -kf ${p} __libbpf/${PATH_MAP[${p}]} && "$'\\\n' done -LIBBPF_TREE_FILTER+="find __libbpf/include/uapi/linux -type f -exec sed -i 's/_UAPI\(__\?LINUX\)/\1/' {} + && "$'\\\n' +LIBBPF_TREE_FILTER+="find __libbpf/include/uapi/linux -type f -exec sed -i -e 's/_UAPI\(__\?LINUX\)/\1/g' -e 's@^#include @@' + && "$'\\\n' LIBBPF_TREE_FILTER+="git rm --ignore-unmatch -f __libbpf/src/{Makefile,Build,test_libbpf.c,.gitignore} >/dev/null" cd_to()