xref: /linux/tools/testing/selftests/bpf/progs/uprobe_multi_session_single.c (revision fcc79e1714e8c2b8e216dc3149812edd37884eef)
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 __u64 uprobe_session_result[3] = {};
12 int pid = 0;
13 
14 static int uprobe_multi_check(void *ctx, int idx)
15 {
16 	if (bpf_get_current_pid_tgid() >> 32 != pid)
17 		return 1;
18 
19 	uprobe_session_result[idx]++;
20 
21 	/* only consumer 1 executes return probe */
22 	if (idx == 0 || idx == 2)
23 		return 1;
24 
25 	return 0;
26 }
27 
28 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
29 int uprobe_0(struct pt_regs *ctx)
30 {
31 	return uprobe_multi_check(ctx, 0);
32 }
33 
34 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
35 int uprobe_1(struct pt_regs *ctx)
36 {
37 	return uprobe_multi_check(ctx, 1);
38 }
39 
40 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
41 int uprobe_2(struct pt_regs *ctx)
42 {
43 	return uprobe_multi_check(ctx, 2);
44 }
45