1576d47bbSDaniel Xu // SPDX-License-Identifier: GPL-2.0
2576d47bbSDaniel Xu 
33a029e1fSJean-Philippe Brucker #include "vmlinux.h"
4576d47bbSDaniel Xu #include <bpf/bpf_helpers.h>
5576d47bbSDaniel Xu #include <bpf/bpf_tracing.h>
6576d47bbSDaniel Xu 
73a029e1fSJean-Philippe Brucker #define PT_REGS_SIZE sizeof(struct pt_regs)
83a029e1fSJean-Philippe Brucker 
93a029e1fSJean-Philippe Brucker /*
103a029e1fSJean-Philippe Brucker  * The kernel struct pt_regs isn't exported in its entirety to userspace.
113a029e1fSJean-Philippe Brucker  * Pass it as an array to task_pt_regs.c
123a029e1fSJean-Philippe Brucker  */
133a029e1fSJean-Philippe Brucker char current_regs[PT_REGS_SIZE] = {};
143a029e1fSJean-Philippe Brucker char ctx_regs[PT_REGS_SIZE] = {};
15576d47bbSDaniel Xu int uprobe_res = 0;
16576d47bbSDaniel Xu 
17*39f8dc43SAlan Maguire SEC("uprobe")
handle_uprobe(struct pt_regs * ctx)18576d47bbSDaniel Xu int handle_uprobe(struct pt_regs *ctx)
19576d47bbSDaniel Xu {
20576d47bbSDaniel Xu 	struct task_struct *current;
21576d47bbSDaniel Xu 	struct pt_regs *regs;
22576d47bbSDaniel Xu 
23576d47bbSDaniel Xu 	current = bpf_get_current_task_btf();
24576d47bbSDaniel Xu 	regs = (struct pt_regs *) bpf_task_pt_regs(current);
253a029e1fSJean-Philippe Brucker 	if (bpf_probe_read_kernel(current_regs, PT_REGS_SIZE, regs))
263a029e1fSJean-Philippe Brucker 		return 0;
273a029e1fSJean-Philippe Brucker 	if (bpf_probe_read_kernel(ctx_regs, PT_REGS_SIZE, ctx))
283a029e1fSJean-Philippe Brucker 		return 0;
29576d47bbSDaniel Xu 
30576d47bbSDaniel Xu 	/* Prove that uprobe was run */
31576d47bbSDaniel Xu 	uprobe_res = 1;
32576d47bbSDaniel Xu 
33576d47bbSDaniel Xu 	return 0;
34576d47bbSDaniel Xu }
35576d47bbSDaniel Xu 
36576d47bbSDaniel Xu char _license[] SEC("license") = "GPL";
37