blob: 52b6d87fe822c2d22449f0e40951545da40c25fd [file] [log] [blame]
Arnaldo Carvalho de Melodd8e4ea2018-05-04 12:23:29 -03001// SPDX-License-Identifier: GPL-2.0
2#ifndef _PERF_BPF_H
3#define _PERF_BPF_H
Arnaldo Carvalho de Melo822c2622018-08-01 10:50:51 -03004
5#include <uapi/linux/bpf.h>
6
Arnaldo Carvalho de Melo7402e542018-08-06 09:02:26 -03007/*
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 */
11struct 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 Melodd8e4ea2018-05-04 12:23:29 -030021#define SEC(NAME) __attribute__((section(NAME), used))
Arnaldo Carvalho de Melo1f477302018-05-04 15:18:31 -030022
Arnaldo Carvalho de Melod8fc7642018-05-04 15:59:16 -030023#define probe(function, vars) \
24 SEC(#function "=" #function " " #vars) function
25
Arnaldo Carvalho de Melodda9ac92018-08-03 16:28:35 -030026#define syscall_enter(name) \
27 SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name
28
Arnaldo Carvalho de Melo664b6a92018-08-30 08:48:44 -030029#define syscall_exit(name) \
30 SEC("syscalls:sys_exit_" #name) syscall_exit_ ## name
31
Arnaldo Carvalho de Melo1f477302018-05-04 15:18:31 -030032#define license(name) \
33char _license[] SEC("license") = #name; \
34int _version SEC("version") = LINUX_VERSION_CODE;
35
Arnaldo Carvalho de Melo8fa25f32018-08-07 15:10:19 -030036static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read;
37static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str;
38
Arnaldo Carvalho de Melodd8e4ea2018-05-04 12:23:29 -030039#endif /* _PERF_BPF_H */