blob: 727d22e34a6e5daf90ab0afb40ab7a309146ab62 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Wang Nan8f9e05f2016-01-11 13:47:57 +00002#include <asm/unistd.h>
Wang Nan1b76c132015-07-01 02:13:51 +00003#include <linux/bpf.h>
Wang Nan8f9e05f2016-01-11 13:47:57 +00004#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. Millerb0c47802017-04-22 12:31:05 -070013# elif defined(__sparc__)
14# define __NR_bpf 349
Daniel Borkmannbad19262017-08-04 14:20:55 +020015# elif defined(__s390__)
16# define __NR_bpf 351
Tiezhu Yange32cb122021-11-25 09:36:07 +080017# elif defined(__mips__) && defined(_ABIO32)
18# define __NR_bpf 4355
19# elif defined(__mips__) && defined(_ABIN32)
20# define __NR_bpf 6319
21# elif defined(__mips__) && defined(_ABI64)
22# define __NR_bpf 5315
David S. Millerb0c47802017-04-22 12:31:05 -070023# else
Wang Nan8f9e05f2016-01-11 13:47:57 +000024# error __NR_bpf not defined. libbpf does not support your arch.
25# endif
26#endif
Wang Nan1b76c132015-07-01 02:13:51 +000027
28int main(void)
29{
30 union bpf_attr attr;
31
Wang Nan8f9e05f2016-01-11 13:47:57 +000032 /* Check fields in attr */
Wang Nan1b76c132015-07-01 02:13:51 +000033 attr.prog_type = BPF_PROG_TYPE_KPROBE;
34 attr.insn_cnt = 0;
35 attr.insns = 0;
36 attr.license = 0;
37 attr.log_buf = 0;
38 attr.log_size = 0;
39 attr.log_level = 0;
40 attr.kern_version = 0;
David S. Millere07b98d2017-05-10 11:38:07 -070041 attr.prog_flags = 0;
Wang Nan1b76c132015-07-01 02:13:51 +000042
Wang Nan8f9e05f2016-01-11 13:47:57 +000043 /*
44 * Test existence of __NR_bpf and BPF_PROG_LOAD.
45 * This call should fail if we run the testcase.
46 */
Florian Fainelli1a714762016-04-24 19:34:54 -070047 return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
Wang Nan1b76c132015-07-01 02:13:51 +000048}