diff options
author | Daniel Xu <dxu@dxuuu.xyz> | 2021-08-24 04:43:50 +0200 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-08-25 19:37:05 +0200 |
commit | 576d47bb1a926fe8162253e0bca28e9bede8cf48 (patch) | |
tree | e5b1620463dac99be057e44cb7803dc7a512eada /tools/testing/selftests/bpf/progs | |
parent | bpf: Add bpf_task_pt_regs() helper (diff) | |
download | linux-576d47bb1a926fe8162253e0bca28e9bede8cf48.tar.xz linux-576d47bb1a926fe8162253e0bca28e9bede8cf48.zip |
bpf: selftests: Add bpf_task_pt_regs() selftest
This test retrieves the uprobe's pt_regs in two different ways and
compares the contents in an arch-agnostic way.
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/5581eb8800f6625ec8813fe21e9dce1fbdef4937.1629772842.git.dxu@dxuuu.xyz
Diffstat (limited to 'tools/testing/selftests/bpf/progs')
-rw-r--r-- | tools/testing/selftests/bpf/progs/test_task_pt_regs.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_task_pt_regs.c b/tools/testing/selftests/bpf/progs/test_task_pt_regs.c new file mode 100644 index 000000000000..6c059f1cfa1b --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_task_pt_regs.c @@ -0,0 +1,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(¤t_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"; |