1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2017 Facebook
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
7 #include <bpf/bpf_core_read.h>
11 int kretprobe2_res = 0;
12 int uprobe_byname_res = 0;
13 int uretprobe_byname_res = 0;
14 int uprobe_byname2_res = 0;
15 int uretprobe_byname2_res = 0;
16 int uprobe_byname3_sleepable_res = 0;
17 int uprobe_byname3_res = 0;
18 int uretprobe_byname3_sleepable_res = 0;
19 int uretprobe_byname3_res = 0;
22 SEC("ksyscall/nanosleep")
23 int BPF_KSYSCALL(handle_kprobe_auto, struct __kernel_timespec *req, struct __kernel_timespec *rem)
29 SEC("kretsyscall/nanosleep")
30 int BPF_KRETPROBE(handle_kretprobe_auto, int ret)
37 int handle_uprobe_ref_ctr(struct pt_regs *ctx)
43 int handle_uretprobe_ref_ctr(struct pt_regs *ctx)
49 int handle_uprobe_byname(struct pt_regs *ctx)
51 uprobe_byname_res = 5;
55 /* use auto-attach format for section definition. */
56 SEC("uretprobe//proc/self/exe:trigger_func2")
57 int handle_uretprobe_byname(struct pt_regs *ctx)
59 uretprobe_byname_res = 6;
64 int BPF_UPROBE(handle_uprobe_byname2, const char *pathname, const char *mode)
66 char mode_buf[2] = {};
68 /* verify fopen mode */
69 bpf_probe_read_user(mode_buf, sizeof(mode_buf), mode);
70 if (mode_buf[0] == 'r' && mode_buf[1] == 0)
71 uprobe_byname2_res = 7;
76 int BPF_URETPROBE(handle_uretprobe_byname2, void *ret)
78 uretprobe_byname2_res = 8;
82 static __always_inline bool verify_sleepable_user_copy(void)
86 bpf_copy_from_user(data, sizeof(data), user_ptr);
87 return bpf_strncmp(data, sizeof(data), "test_data") == 0;
90 SEC("uprobe.s//proc/self/exe:trigger_func3")
91 int handle_uprobe_byname3_sleepable(struct pt_regs *ctx)
93 if (verify_sleepable_user_copy())
94 uprobe_byname3_sleepable_res = 9;
99 * same target as the uprobe.s above to force sleepable and non-sleepable
100 * programs in the same bpf_prog_array
102 SEC("uprobe//proc/self/exe:trigger_func3")
103 int handle_uprobe_byname3(struct pt_regs *ctx)
105 uprobe_byname3_res = 10;
109 SEC("uretprobe.s//proc/self/exe:trigger_func3")
110 int handle_uretprobe_byname3_sleepable(struct pt_regs *ctx)
112 if (verify_sleepable_user_copy())
113 uretprobe_byname3_sleepable_res = 11;
117 SEC("uretprobe//proc/self/exe:trigger_func3")
118 int handle_uretprobe_byname3(struct pt_regs *ctx)
120 uretprobe_byname3_res = 12;
125 char _license[] SEC("license") = "GPL";