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 #include "bpf_misc.h" 7 8 char _license[] SEC("license") = "GPL"; 9 10 int pid = 0; 11 12 int idx_entry = 0; 13 int idx_return = 0; 14 15 __u64 test_uprobe_cookie_entry[6]; 16 __u64 test_uprobe_cookie_return[3]; 17 18 static int check_cookie(struct pt_regs *ctx) 19 { 20 __u64 *cookie = bpf_session_cookie(ctx); 21 22 if (bpf_session_is_return(ctx)) { 23 if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return)) 24 return 1; 25 test_uprobe_cookie_return[idx_return++] = *cookie; 26 return 0; 27 } 28 29 if (idx_entry >= ARRAY_SIZE(test_uprobe_cookie_entry)) 30 return 1; 31 *cookie = test_uprobe_cookie_entry[idx_entry]; 32 return idx_entry++ % 2; 33 } 34 35 36 SEC("uprobe.session//proc/self/exe:uprobe_session_recursive") 37 int uprobe_recursive(struct pt_regs *ctx) 38 { 39 if (bpf_get_current_pid_tgid() >> 32 != pid) 40 return 1; 41 42 return check_cookie(ctx); 43 } 44