Commit 6e7e034e authored by Quentin Monnet's avatar Quentin Monnet Committed by Daniel Borkmann
Browse files

tools, bpftool: Poison and replace kernel integer typedefs



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: default avatarQuentin Monnet <quentin@isovalent.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200511161536.29853-2-quentin@isovalent.com
parent 385bbf7b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;

+2 −2
Original line number Diff line number Diff line
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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(); })
+1 −1
Original line number Diff line number Diff line
@@ -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[];
};
+1 −1
Original line number Diff line number Diff line
@@ -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);