1 // SPDX-License-Identifier: GPL-2.0
5 #include <uapi/linux/bpf.h>
8 * A helper structure used by eBPF C program to describe map attributes to
9 * elf_bpf loader, taken from tools/testing/selftests/bpf/bpf_helpers.h:
13 unsigned int key_size;
14 unsigned int value_size;
15 unsigned int max_entries;
16 unsigned int map_flags;
17 unsigned int inner_map_idx;
18 unsigned int numa_node;
22 * FIXME: this should receive .max_entries as a parameter, as careful
23 * tuning of these limits is needed to avoid hitting limits that
24 * prevents other BPF constructs, such as tracepoint handlers,
25 * to get installed, with cryptic messages from libbpf, etc.
26 * For the current need, 'perf trace --filter-pids', 64 should
27 * be good enough, but this surely needs to be revisited.
29 #define pid_map(name, value_type) \
30 struct bpf_map SEC("maps") name = { \
31 .type = BPF_MAP_TYPE_HASH, \
32 .key_size = sizeof(pid_t), \
33 .value_size = sizeof(value_type), \
37 static int (*bpf_map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags) = (void *)BPF_FUNC_map_update_elem;
38 static void *(*bpf_map_lookup_elem)(struct bpf_map *map, void *key) = (void *)BPF_FUNC_map_lookup_elem;
40 #define SEC(NAME) __attribute__((section(NAME), used))
42 #define probe(function, vars) \
43 SEC(#function "=" #function " " #vars) function
45 #define syscall_enter(name) \
46 SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name
48 #define syscall_exit(name) \
49 SEC("syscalls:sys_exit_" #name) syscall_exit_ ## name
51 #define license(name) \
52 char _license[] SEC("license") = #name; \
53 int _version SEC("version") = LINUX_VERSION_CODE;
55 static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read;
56 static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str;
58 static int (*perf_event_output)(void *, struct bpf_map *, int, void *, unsigned long) = (void *)BPF_FUNC_perf_event_output;
60 #endif /* _PERF_BPF_H */