summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2021-03-18 04:48:05 +0300
committerAlexei Starovoitov <ast@kernel.org>2021-03-18 04:48:05 +0300
commit6b28276512fdfc010e25c833973328e51a56eafb (patch)
tree589d69ed389703a6940e66dbe1ed61a3811f3407
parent97a19caf1b1f6a9d4f620a9d51405a1973bd4641 (diff)
parentc53a3355eb2976fc4eb4d42862db0eea205045a1 (diff)
downloadlinux-6b28276512fdfc010e25c833973328e51a56eafb.tar.xz
Merge branch 'Provide NULL and KERNEL_VERSION macros in bpf_helpers.h'
Andrii Nakryiko says: ==================== Provide NULL and KERNEL_VERSION macros in bpf_helpers.h. Patch #2 removes such custom NULL definition from one of the selftests. v2->v3: - instead of vmlinux.h, do this in bpf_helpers.h; - added KERNEL_VERSION, which comes up periodically as well; - I dropped strict compilation patches for now, because we run into new warnings (e.g., not checking read() result) in kernel-patches CI, which I can't even reproduce locally. Also -Wdiscarded-qualifiers pragma for jit_disasm.c is not supported by Clang, it needs to be -Wincompatible-pointer-types-discards-qualifiers for Clang; we don't have to deal with that in this patch set; v1->v2: - fix few typos and wrong copy/paste; - fix #pragma push -> pop. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--tools/lib/bpf/bpf_helpers.h16
-rw-r--r--tools/testing/selftests/bpf/progs/skb_pkt_end.c1
2 files changed, 15 insertions, 2 deletions
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index 53ff81c49dbd..cc2e51c64a54 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -40,8 +40,22 @@
#define __weak __attribute__((weak))
#endif
+/* When utilizing vmlinux.h with BPF CO-RE, user BPF programs can't include
+ * any system-level headers (such as stddef.h, linux/version.h, etc), and
+ * commonly-used macros like NULL and KERNEL_VERSION aren't available through
+ * vmlinux.h. This just adds unnecessary hurdles and forces users to re-define
+ * them on their own. So as a convenience, provide such definitions here.
+ */
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#ifndef KERNEL_VERSION
+#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c))
+#endif
+
/*
- * Helper macro to manipulate data structures
+ * Helper macros to manipulate data structures
*/
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER)
diff --git a/tools/testing/selftests/bpf/progs/skb_pkt_end.c b/tools/testing/selftests/bpf/progs/skb_pkt_end.c
index cf6823f42e80..7f2eaa2f89f8 100644
--- a/tools/testing/selftests/bpf/progs/skb_pkt_end.c
+++ b/tools/testing/selftests/bpf/progs/skb_pkt_end.c
@@ -4,7 +4,6 @@
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_helpers.h>
-#define NULL 0
#define INLINE __always_inline
#define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)