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