1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
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
;
24 if (args
->id
!= __NR_nanosleep
)
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
)
36 SEC("raw_tp/sys_enter")
37 int BPF_PROG(handle__raw_tp
, struct pt_regs
*regs
, long id
)
39 struct __kernel_timespec
*ts
;
42 if (id
!= __NR_nanosleep
)
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
)
54 SEC("tp_btf/sys_enter")
55 int BPF_PROG(handle__tp_btf
, struct pt_regs
*regs
, long id
)
57 struct __kernel_timespec
*ts
;
60 if (id
!= __NR_nanosleep
)
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
)
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
)
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
)
90 char _license
[] SEC("license") = "GPL";