Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2#include <vmlinux.h>
3#include <bpf/bpf_helpers.h>
4#include <bpf/bpf_tracing.h>
5#include <stdbool.h>
6
7char _license[] SEC("license") = "GPL";
8
9int pid = 0;
10
11__u64 test_uprobe_1_result = 0;
12__u64 test_uprobe_2_result = 0;
13__u64 test_uprobe_3_result = 0;
14
15static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result)
16{
17 __u64 *cookie;
18
19 if (bpf_get_current_pid_tgid() >> 32 != pid)
20 return 1;
21
22 cookie = bpf_session_cookie(ctx);
23
24 if (bpf_session_is_return(ctx))
25 *result = *cookie == val ? val : 0;
26 else
27 *cookie = val;
28 return 0;
29}
30
31SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
32int uprobe_1(struct pt_regs *ctx)
33{
34 return check_cookie(ctx, 1, &test_uprobe_1_result);
35}
36
37SEC("uprobe.session//proc/self/exe:uprobe_multi_func_2")
38int uprobe_2(struct pt_regs *ctx)
39{
40 return check_cookie(ctx, 2, &test_uprobe_2_result);
41}
42
43SEC("uprobe.session//proc/self/exe:uprobe_multi_func_3")
44int uprobe_3(struct pt_regs *ctx)
45{
46 return check_cookie(ctx, 3, &test_uprobe_3_result);
47}