bpf.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: GPL-2.0
  2. #ifndef _PERF_BPF_H
  3. #define _PERF_BPF_H
  4. #include <uapi/linux/bpf.h>
  5. /*
  6. * A helper structure used by eBPF C program to describe map attributes to
  7. * elf_bpf loader, taken from tools/testing/selftests/bpf/bpf_helpers.h:
  8. */
  9. struct bpf_map {
  10. unsigned int type;
  11. unsigned int key_size;
  12. unsigned int value_size;
  13. unsigned int max_entries;
  14. unsigned int map_flags;
  15. unsigned int inner_map_idx;
  16. unsigned int numa_node;
  17. };
  18. #define SEC(NAME) __attribute__((section(NAME), used))
  19. #define probe(function, vars) \
  20. SEC(#function "=" #function " " #vars) function
  21. #define syscall_enter(name) \
  22. SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name
  23. #define license(name) \
  24. char _license[] SEC("license") = #name; \
  25. int _version SEC("version") = LINUX_VERSION_CODE;
  26. static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read;
  27. static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str;
  28. #endif /* _PERF_BPF_H */