1// SPDX-License-Identifier: GPL-2.0
2
3#include "vmlinux.h"
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6
7#define PT_REGS_SIZE sizeof(struct pt_regs)
8
9/*
10 * The kernel struct pt_regs isn't exported in its entirety to userspace.
11 * Pass it as an array to task_pt_regs.c
12 */
13char current_regs[PT_REGS_SIZE] = {};
14char ctx_regs[PT_REGS_SIZE] = {};
15int uprobe_res = 0;
16
17SEC("uprobe")
18int handle_uprobe(struct pt_regs *ctx)
19{
20 struct task_struct *current;
21 struct pt_regs *regs;
22
23 current = bpf_get_current_task_btf();
24 regs = (struct pt_regs *) bpf_task_pt_regs(current);
25 if (bpf_probe_read_kernel(current_regs, PT_REGS_SIZE, regs))
26 return 0;
27 if (bpf_probe_read_kernel(ctx_regs, PT_REGS_SIZE, ctx))
28 return 0;
29
30 /* Prove that uprobe was run */
31 uprobe_res = 1;
32
33 return 0;
34}
35
36char _license[] SEC("license") = "GPL";
37

source code of linux/tools/testing/selftests/bpf/progs/test_task_pt_regs.c