tools, bpftool: Poison and replace kernel integer typedefs
authorQuentin Monnet <quentin@isovalent.com>
Mon, 11 May 2020 16:15:33 +0000 (17:15 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 11 May 2020 19:20:46 +0000 (21:20 +0200)
Replace the use of kernel-only integer typedefs (u8, u32, etc.) by their
user space counterpart (__u8, __u32, etc.).

Similarly to what libbpf does, poison the typedefs to avoid introducing
them again in the future.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200511161536.29853-2-quentin@isovalent.com
tools/bpf/bpftool/btf_dumper.c
tools/bpf/bpftool/cfg.c
tools/bpf/bpftool/main.h
tools/bpf/bpftool/map_perf_ring.c
tools/bpf/bpftool/prog.c

index 497807b..ede162f 100644 (file)
@@ -271,8 +271,8 @@ static void btf_int128_print(json_writer_t *jw, const void *data,
        }
 }
 
-static void btf_int128_shift(__u64 *print_num, u16 left_shift_bits,
-                            u16 right_shift_bits)
+static void btf_int128_shift(__u64 *print_num, __u16 left_shift_bits,
+                            __u16 right_shift_bits)
 {
        __u64 upper_num, lower_num;
 
index 3e21f99..1951219 100644 (file)
@@ -157,7 +157,7 @@ static bool cfg_partition_funcs(struct cfg *cfg, struct bpf_insn *cur,
        return false;
 }
 
-static bool is_jmp_insn(u8 code)
+static bool is_jmp_insn(__u8 code)
 {
        return BPF_CLASS(code) == BPF_JMP || BPF_CLASS(code) == BPF_JMP32;
 }
@@ -176,7 +176,7 @@ static bool func_partition_bb_head(struct func_node *func)
 
        for (; cur <= end; cur++) {
                if (is_jmp_insn(cur->code)) {
-                       u8 opcode = BPF_OP(cur->code);
+                       __u8 opcode = BPF_OP(cur->code);
 
                        if (opcode == BPF_EXIT || opcode == BPF_CALL)
                                continue;
index a41cefa..f89ac70 100644 (file)
@@ -18,6 +18,9 @@
 
 #include "json_writer.h"
 
+/* Make sure we do not use kernel-only integer typedefs */
+#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
+
 #define ptr_to_u64(ptr)        ((__u64)(unsigned long)(ptr))
 
 #define NEXT_ARG()     ({ argc--; argv++; if (argc < 0) usage(); })
index d9b29c1..825f29f 100644 (file)
@@ -39,7 +39,7 @@ struct event_ring_info {
 
 struct perf_event_sample {
        struct perf_event_header header;
-       u64 time;
+       __u64 time;
        __u32 size;
        unsigned char data[];
 };
index f6a5974..b6e5ba5 100644 (file)
@@ -238,7 +238,7 @@ exit_free:
        return fd;
 }
 
-static void show_prog_maps(int fd, u32 num_maps)
+static void show_prog_maps(int fd, __u32 num_maps)
 {
        struct bpf_prog_info info = {};
        __u32 len = sizeof(info);