1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2017 Facebook
3 
4 #include <linux/ptrace.h>
5 #include <linux/bpf.h>
6 #include <bpf/bpf_helpers.h>
7 #include <bpf/bpf_tracing.h>
8 
9 int kprobe_res = 0;
10 int kretprobe_res = 0;
11 int uprobe_res = 0;
12 int uretprobe_res = 0;
13 
14 SEC("kprobe/sys_nanosleep")
handle_kprobe(struct pt_regs * ctx)15 int handle_kprobe(struct pt_regs *ctx)
16 {
17 	kprobe_res = 1;
18 	return 0;
19 }
20 
21 SEC("kretprobe/sys_nanosleep")
BPF_KRETPROBE(handle_kretprobe)22 int BPF_KRETPROBE(handle_kretprobe)
23 {
24 	kretprobe_res = 2;
25 	return 0;
26 }
27 
28 SEC("uprobe/trigger_func")
handle_uprobe(struct pt_regs * ctx)29 int handle_uprobe(struct pt_regs *ctx)
30 {
31 	uprobe_res = 3;
32 	return 0;
33 }
34 
35 SEC("uretprobe/trigger_func")
handle_uretprobe(struct pt_regs * ctx)36 int handle_uretprobe(struct pt_regs *ctx)
37 {
38 	uretprobe_res = 4;
39 	return 0;
40 }
41 
42 char _license[] SEC("license") = "GPL";
43