aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
diff options
context:
space:
mode:
authorHengqi Chen <hengqi.chen@gmail.com>2022-02-07 22:31:34 +0800
committerAndrii Nakryiko <andrii@kernel.org>2022-02-08 21:45:06 -0800
commitc28748233b4736bd31b3d3c3011d42054cc738f5 (patch)
tree67f2081ee7aa77a5add2eb541a8e87293b504f18 /tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
parentlibbpf: Add BPF_KPROBE_SYSCALL macro (diff)
downloadlinux-dev-c28748233b4736bd31b3d3c3011d42054cc738f5.tar.xz
linux-dev-c28748233b4736bd31b3d3c3011d42054cc738f5.zip
selftests/bpf: Test BPF_KPROBE_SYSCALL macro
Add tests for the newly added BPF_KPROBE_SYSCALL macro. Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20220207143134.2977852-3-hengqi.chen@gmail.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/bpf_syscall_macro.c')
-rw-r--r--tools/testing/selftests/bpf/progs/bpf_syscall_macro.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c b/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
index 496e54d0ac22..05838ed9b89c 100644
--- a/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
+++ b/tools/testing/selftests/bpf/progs/bpf_syscall_macro.c
@@ -21,6 +21,12 @@ unsigned long arg4_core_cx = 0;
unsigned long arg4_core = 0;
unsigned long arg5_core = 0;
+int option_syscall = 0;
+unsigned long arg2_syscall = 0;
+unsigned long arg3_syscall = 0;
+unsigned long arg4_syscall = 0;
+unsigned long arg5_syscall = 0;
+
const volatile pid_t filter_pid = 0;
SEC("kprobe/" SYS_PREFIX "sys_prctl")
@@ -58,4 +64,21 @@ int BPF_KPROBE(handle_sys_prctl)
return 0;
}
+SEC("kprobe/" SYS_PREFIX "sys_prctl")
+int BPF_KPROBE_SYSCALL(prctl_enter, int option, unsigned long arg2,
+ unsigned long arg3, unsigned long arg4, unsigned long arg5)
+{
+ pid_t pid = bpf_get_current_pid_tgid() >> 32;
+
+ if (pid != filter_pid)
+ return 0;
+
+ option_syscall = option;
+ arg2_syscall = arg2;
+ arg3_syscall = arg3;
+ arg4_syscall = arg4;
+ arg5_syscall = arg5;
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";