test-bpf.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <asm/unistd.h>
  3. #include <linux/bpf.h>
  4. #include <unistd.h>
  5. #ifndef __NR_bpf
  6. # if defined(__i386__)
  7. # define __NR_bpf 357
  8. # elif defined(__x86_64__)
  9. # define __NR_bpf 321
  10. # elif defined(__aarch64__)
  11. # define __NR_bpf 280
  12. # elif defined(__sparc__)
  13. # define __NR_bpf 349
  14. # elif defined(__s390__)
  15. # define __NR_bpf 351
  16. # elif defined(__mips__) && defined(_ABIO32)
  17. # define __NR_bpf 4355
  18. # elif defined(__mips__) && defined(_ABIN32)
  19. # define __NR_bpf 6319
  20. # elif defined(__mips__) && defined(_ABI64)
  21. # define __NR_bpf 5315
  22. # else
  23. # error __NR_bpf not defined. libbpf does not support your arch.
  24. # endif
  25. #endif
  26. int main(void)
  27. {
  28. union bpf_attr attr;
  29. /* Check fields in attr */
  30. attr.prog_type = BPF_PROG_TYPE_KPROBE;
  31. attr.insn_cnt = 0;
  32. attr.insns = 0;
  33. attr.license = 0;
  34. attr.log_buf = 0;
  35. attr.log_size = 0;
  36. attr.log_level = 0;
  37. attr.kern_version = 0;
  38. attr.prog_flags = 0;
  39. /*
  40. * Test existence of __NR_bpf and BPF_PROG_LOAD.
  41. * This call should fail if we run the testcase.
  42. */
  43. return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)) == 0;
  44. }