Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | #ifndef _PERF_BPF_H |
| 3 | #define _PERF_BPF_H |
| 4 | |
| 5 | #include <uapi/linux/bpf.h> |
| 6 | |
| 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 | |
| 21 | #define SEC(NAME) __attribute__((section(NAME), used)) |
| 22 | |
| 23 | #define probe(function, vars) \ |
| 24 | SEC(#function "=" #function " " #vars) function |
| 25 | |
| 26 | #define syscall_enter(name) \ |
| 27 | SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name |
| 28 | |
| 29 | #define license(name) \ |
| 30 | char _license[] SEC("license") = #name; \ |
| 31 | int _version SEC("version") = LINUX_VERSION_CODE; |
| 32 | |
| 33 | static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read; |
| 34 | static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str; |
| 35 | |
| 36 | #endif /* _PERF_BPF_H */ |