]> Git Repo - linux.git/blob - tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c
Linux 6.14-rc3
[linux.git] / tools / testing / selftests / bpf / progs / uprobe_multi_session_recursive.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
5 #include <stdbool.h>
6 #include "bpf_kfuncs.h"
7 #include "bpf_misc.h"
8
9 char _license[] SEC("license") = "GPL";
10
11 int pid = 0;
12
13 int idx_entry = 0;
14 int idx_return = 0;
15
16 __u64 test_uprobe_cookie_entry[6];
17 __u64 test_uprobe_cookie_return[3];
18
19 static int check_cookie(void)
20 {
21         __u64 *cookie = bpf_session_cookie();
22
23         if (bpf_session_is_return()) {
24                 if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return))
25                         return 1;
26                 test_uprobe_cookie_return[idx_return++] = *cookie;
27                 return 0;
28         }
29
30         if (idx_entry >= ARRAY_SIZE(test_uprobe_cookie_entry))
31                 return 1;
32         *cookie = test_uprobe_cookie_entry[idx_entry];
33         return idx_entry++ % 2;
34 }
35
36
37 SEC("uprobe.session//proc/self/exe:uprobe_session_recursive")
38 int uprobe_recursive(struct pt_regs *ctx)
39 {
40         if (bpf_get_current_pid_tgid() >> 32 != pid)
41                 return 1;
42
43         return check_cookie();
44 }
This page took 0.034397 seconds and 4 git commands to generate.