summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/test_task_pt_regs.c
blob: 6c059f1cfa1bb27b84b7162f93786d2c4a9334d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-License-Identifier: GPL-2.0

#include <linux/ptrace.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

struct pt_regs current_regs = {};
struct pt_regs ctx_regs = {};
int uprobe_res = 0;

SEC("uprobe/trigger_func")
int handle_uprobe(struct pt_regs *ctx)
{
	struct task_struct *current;
	struct pt_regs *regs;

	current = bpf_get_current_task_btf();
	regs = (struct pt_regs *) bpf_task_pt_regs(current);
	__builtin_memcpy(&current_regs, regs, sizeof(*regs));
	__builtin_memcpy(&ctx_regs, ctx, sizeof(*ctx));

	/* Prove that uprobe was run */
	uprobe_res = 1;

	return 0;
}

char _license[] SEC("license") = "GPL";