summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
diff options
context:
space:
mode:
authorAlan Maguire <alan.maguire@oracle.com>2022-03-30 16:26:40 +0100
committerAndrii Nakryiko <andrii@kernel.org>2022-04-03 19:56:01 -0700
commit579c3196b21800538e0cfd512a05619ee80fb19a (patch)
treed7a5856aa921c106e1faf8f8c33cba8450292298 /tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
parentba7499bc9d52f7ea93301a48c05caa370c68b213 (diff)
selftests/bpf: Add tests for uprobe auto-attach via skeleton
tests that verify auto-attach works for function entry/return for local functions in program and library functions in a library. Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/1648654000-21758-6-git-send-email-alan.maguire@oracle.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c')
-rw-r--r--tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
new file mode 100644
index 000000000000..b442fb5ef54b
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2022, Oracle and/or its affiliates. */
+
+#include <linux/ptrace.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+int uprobe_byname_res = 0;
+int uretprobe_byname_res = 0;
+int uprobe_byname2_res = 0;
+int uretprobe_byname2_res = 0;
+
+/* This program cannot auto-attach, but that should not stop other
+ * programs from attaching.
+ */
+SEC("uprobe")
+int handle_uprobe_noautoattach(struct pt_regs *ctx)
+{
+ return 0;
+}
+
+SEC("uprobe//proc/self/exe:autoattach_trigger_func")
+int handle_uprobe_byname(struct pt_regs *ctx)
+{
+ uprobe_byname_res = 1;
+ return 0;
+}
+
+SEC("uretprobe//proc/self/exe:autoattach_trigger_func")
+int handle_uretprobe_byname(struct pt_regs *ctx)
+{
+ uretprobe_byname_res = 2;
+ return 0;
+}
+
+
+SEC("uprobe/libc.so.6:malloc")
+int handle_uprobe_byname2(struct pt_regs *ctx)
+{
+ uprobe_byname2_res = 3;
+ return 0;
+}
+
+SEC("uretprobe/libc.so.6:free")
+int handle_uretprobe_byname2(struct pt_regs *ctx)
+{
+ uretprobe_byname2_res = 4;
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";