Arnaldo Carvalho de Melo | dd8e4ea | 2018-05-04 12:23:29 -0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | #ifndef _PERF_BPF_H |
| 3 | #define _PERF_BPF_H |
Arnaldo Carvalho de Melo | 822c262 | 2018-08-01 10:50:51 -0300 | [diff] [blame] | 4 | |
| 5 | #include <uapi/linux/bpf.h> |
| 6 | |
Arnaldo Carvalho de Melo | 7402e54 | 2018-08-06 09:02:26 -0300 | [diff] [blame] | 7 | /* |
| 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: |
| 10 | */ |
| 11 | struct bpf_map { |
| 12 | unsigned int type; |
| 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; |
| 19 | }; |
| 20 | |
Arnaldo Carvalho de Melo | dd8e4ea | 2018-05-04 12:23:29 -0300 | [diff] [blame] | 21 | #define SEC(NAME) __attribute__((section(NAME), used)) |
Arnaldo Carvalho de Melo | 1f47730 | 2018-05-04 15:18:31 -0300 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | d8fc764 | 2018-05-04 15:59:16 -0300 | [diff] [blame] | 23 | #define probe(function, vars) \ |
| 24 | SEC(#function "=" #function " " #vars) function |
| 25 | |
Arnaldo Carvalho de Melo | dda9ac9 | 2018-08-03 16:28:35 -0300 | [diff] [blame] | 26 | #define syscall_enter(name) \ |
| 27 | SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name |
| 28 | |
Arnaldo Carvalho de Melo | 664b6a9 | 2018-08-30 08:48:44 -0300 | [diff] [blame] | 29 | #define syscall_exit(name) \ |
| 30 | SEC("syscalls:sys_exit_" #name) syscall_exit_ ## name |
| 31 | |
Arnaldo Carvalho de Melo | 1f47730 | 2018-05-04 15:18:31 -0300 | [diff] [blame] | 32 | #define license(name) \ |
| 33 | char _license[] SEC("license") = #name; \ |
| 34 | int _version SEC("version") = LINUX_VERSION_CODE; |
| 35 | |
Arnaldo Carvalho de Melo | 8fa25f3 | 2018-08-07 15:10:19 -0300 | [diff] [blame] | 36 | static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read; |
| 37 | static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str; |
| 38 | |
Arnaldo Carvalho de Melo | dd8e4ea | 2018-05-04 12:23:29 -0300 | [diff] [blame] | 39 | #endif /* _PERF_BPF_H */ |