0001
0002
0003
0004 #include "vmlinux.h"
0005 #include <asm/unistd.h>
0006 #include <bpf/bpf_helpers.h>
0007 #include <bpf/bpf_tracing.h>
0008 #include <bpf/bpf_core_read.h>
0009
0010 #define MY_TV_NSEC 1337
0011
0012 bool tp_called = false;
0013 bool raw_tp_called = false;
0014 bool tp_btf_called = false;
0015 bool kprobe_called = false;
0016 bool fentry_called = false;
0017
0018 SEC("tp/syscalls/sys_enter_nanosleep")
0019 int handle__tp(struct trace_event_raw_sys_enter *args)
0020 {
0021 struct __kernel_timespec *ts;
0022 long tv_nsec;
0023
0024 if (args->id != __NR_nanosleep)
0025 return 0;
0026
0027 ts = (void *)args->args[0];
0028 if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
0029 tv_nsec != MY_TV_NSEC)
0030 return 0;
0031
0032 tp_called = true;
0033 return 0;
0034 }
0035
0036 SEC("raw_tp/sys_enter")
0037 int BPF_PROG(handle__raw_tp, struct pt_regs *regs, long id)
0038 {
0039 struct __kernel_timespec *ts;
0040 long tv_nsec;
0041
0042 if (id != __NR_nanosleep)
0043 return 0;
0044
0045 ts = (void *)PT_REGS_PARM1_CORE(regs);
0046 if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
0047 tv_nsec != MY_TV_NSEC)
0048 return 0;
0049
0050 raw_tp_called = true;
0051 return 0;
0052 }
0053
0054 SEC("tp_btf/sys_enter")
0055 int BPF_PROG(handle__tp_btf, struct pt_regs *regs, long id)
0056 {
0057 struct __kernel_timespec *ts;
0058 long tv_nsec;
0059
0060 if (id != __NR_nanosleep)
0061 return 0;
0062
0063 ts = (void *)PT_REGS_PARM1_CORE(regs);
0064 if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
0065 tv_nsec != MY_TV_NSEC)
0066 return 0;
0067
0068 tp_btf_called = true;
0069 return 0;
0070 }
0071
0072 SEC("kprobe/hrtimer_start_range_ns")
0073 int BPF_KPROBE(handle__kprobe, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
0074 const enum hrtimer_mode mode)
0075 {
0076 if (tim == MY_TV_NSEC)
0077 kprobe_called = true;
0078 return 0;
0079 }
0080
0081 SEC("fentry/hrtimer_start_range_ns")
0082 int BPF_PROG(handle__fentry, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
0083 const enum hrtimer_mode mode)
0084 {
0085 if (tim == MY_TV_NSEC)
0086 fentry_called = true;
0087 return 0;
0088 }
0089
0090 char _license[] SEC("license") = "GPL";