Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Wang Nan | 8f9e05f | 2016-01-11 13:47:57 +0000 | [diff] [blame] | 2 | #include <asm/unistd.h> |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 3 | #include <linux/bpf.h> |
Wang Nan | 8f9e05f | 2016-01-11 13:47:57 +0000 | [diff] [blame] | 4 | #include <unistd.h> |
| 5 | |
| 6 | #ifndef __NR_bpf |
| 7 | # if defined(__i386__) |
| 8 | # define __NR_bpf 357 |
| 9 | # elif defined(__x86_64__) |
| 10 | # define __NR_bpf 321 |
| 11 | # elif defined(__aarch64__) |
| 12 | # define __NR_bpf 280 |
David S. Miller | b0c4780 | 2017-04-22 12:31:05 -0700 | [diff] [blame] | 13 | # elif defined(__sparc__) |
| 14 | # define __NR_bpf 349 |
Daniel Borkmann | bad1926 | 2017-08-04 14:20:55 +0200 | [diff] [blame] | 15 | # elif defined(__s390__) |
| 16 | # define __NR_bpf 351 |
David S. Miller | b0c4780 | 2017-04-22 12:31:05 -0700 | [diff] [blame] | 17 | # else |
Wang Nan | 8f9e05f | 2016-01-11 13:47:57 +0000 | [diff] [blame] | 18 | # error __NR_bpf not defined. libbpf does not support your arch. |
| 19 | # endif |
| 20 | #endif |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 21 | |
| 22 | int main(void) |
| 23 | { |
| 24 | union bpf_attr attr; |
| 25 | |
Wang Nan | 8f9e05f | 2016-01-11 13:47:57 +0000 | [diff] [blame] | 26 | /* Check fields in attr */ |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 27 | attr.prog_type = BPF_PROG_TYPE_KPROBE; |
| 28 | attr.insn_cnt = 0; |
| 29 | attr.insns = 0; |
| 30 | attr.license = 0; |
| 31 | attr.log_buf = 0; |
| 32 | attr.log_size = 0; |
| 33 | attr.log_level = 0; |
| 34 | attr.kern_version = 0; |
David S. Miller | e07b98d | 2017-05-10 11:38:07 -0700 | [diff] [blame] | 35 | attr.prog_flags = 0; |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 36 | |
Wang Nan | 8f9e05f | 2016-01-11 13:47:57 +0000 | [diff] [blame] | 37 | /* |
| 38 | * Test existence of __NR_bpf and BPF_PROG_LOAD. |
| 39 | * This call should fail if we run the testcase. |
| 40 | */ |
Florian Fainelli | 1a71476 | 2016-04-24 19:34:54 -0700 | [diff] [blame] | 41 | return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)); |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 42 | } |