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