WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_vmlinux.c
blobe9dfa0313d1bb24ce88f9a76767473572d1bd05e
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
4 #include "vmlinux.h"
5 #include <asm/unistd.h>
6 #include <bpf/bpf_helpers.h>
7 #include <bpf/bpf_tracing.h>
8 #include <bpf/bpf_core_read.h>
10 #define MY_TV_NSEC 1337
12 bool tp_called = false;
13 bool raw_tp_called = false;
14 bool tp_btf_called = false;
15 bool kprobe_called = false;
16 bool fentry_called = false;
18 SEC("tp/syscalls/sys_enter_nanosleep")
19 int handle__tp(struct trace_event_raw_sys_enter *args)
21 struct __kernel_timespec *ts;
22 long tv_nsec;
24 if (args->id != __NR_nanosleep)
25 return 0;
27 ts = (void *)args->args[0];
28 if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
29 tv_nsec != MY_TV_NSEC)
30 return 0;
32 tp_called = true;
33 return 0;
36 SEC("raw_tp/sys_enter")
37 int BPF_PROG(handle__raw_tp, struct pt_regs *regs, long id)
39 struct __kernel_timespec *ts;
40 long tv_nsec;
42 if (id != __NR_nanosleep)
43 return 0;
45 ts = (void *)PT_REGS_PARM1_CORE(regs);
46 if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
47 tv_nsec != MY_TV_NSEC)
48 return 0;
50 raw_tp_called = true;
51 return 0;
54 SEC("tp_btf/sys_enter")
55 int BPF_PROG(handle__tp_btf, struct pt_regs *regs, long id)
57 struct __kernel_timespec *ts;
58 long tv_nsec;
60 if (id != __NR_nanosleep)
61 return 0;
63 ts = (void *)PT_REGS_PARM1_CORE(regs);
64 if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
65 tv_nsec != MY_TV_NSEC)
66 return 0;
68 tp_btf_called = true;
69 return 0;
72 SEC("kprobe/hrtimer_start_range_ns")
73 int BPF_KPROBE(handle__kprobe, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
74 const enum hrtimer_mode mode)
76 if (tim == MY_TV_NSEC)
77 kprobe_called = true;
78 return 0;
81 SEC("fentry/hrtimer_start_range_ns")
82 int BPF_PROG(handle__fentry, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
83 const enum hrtimer_mode mode)
85 if (tim == MY_TV_NSEC)
86 fentry_called = true;
87 return 0;
90 char _license[] SEC("license") = "GPL";