test-bpf.c 737 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <asm/unistd.h>
  2. #include <linux/bpf.h>
  3. #include <unistd.h>
  4. #ifndef __NR_bpf
  5. # if defined(__i386__)
  6. # define __NR_bpf 357
  7. # elif defined(__x86_64__)
  8. # define __NR_bpf 321
  9. # elif defined(__aarch64__)
  10. # define __NR_bpf 280
  11. # error __NR_bpf not defined. libbpf does not support your arch.
  12. # endif
  13. #endif
  14. int main(void)
  15. {
  16. union bpf_attr attr;
  17. /* Check fields in attr */
  18. attr.prog_type = BPF_PROG_TYPE_KPROBE;
  19. attr.insn_cnt = 0;
  20. attr.insns = 0;
  21. attr.license = 0;
  22. attr.log_buf = 0;
  23. attr.log_size = 0;
  24. attr.log_level = 0;
  25. attr.kern_version = 0;
  26. /*
  27. * Test existence of __NR_bpf and BPF_PROG_LOAD.
  28. * This call should fail if we run the testcase.
  29. */
  30. return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
  31. }