File tree 2 files changed +90
-0
lines changed
tools/testing/selftests/bpf 2 files changed +90
-0
lines changed Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ /* Copyright (c) 2022, Oracle and/or its affiliates. */
3
+
4
+ #include <test_progs.h>
5
+ #include "test_uprobe_autoattach.skel.h"
6
+
7
+ /* uprobe attach point */
8
+ static void autoattach_trigger_func (void )
9
+ {
10
+ asm volatile ("" );
11
+ }
12
+
13
+ void test_uprobe_autoattach (void )
14
+ {
15
+ struct test_uprobe_autoattach * skel ;
16
+ char * mem ;
17
+
18
+ skel = test_uprobe_autoattach__open_and_load ();
19
+ if (!ASSERT_OK_PTR (skel , "skel_open" ))
20
+ return ;
21
+
22
+ if (!ASSERT_OK (test_uprobe_autoattach__attach (skel ), "skel_attach" ))
23
+ goto cleanup ;
24
+
25
+ /* trigger & validate uprobe & uretprobe */
26
+ autoattach_trigger_func ();
27
+
28
+ /* trigger & validate shared library u[ret]probes attached by name */
29
+ mem = malloc (1 );
30
+ free (mem );
31
+
32
+ ASSERT_EQ (skel -> bss -> uprobe_byname_res , 1 , "check_uprobe_byname_res" );
33
+ ASSERT_EQ (skel -> bss -> uretprobe_byname_res , 2 , "check_uretprobe_byname_res" );
34
+ ASSERT_EQ (skel -> bss -> uprobe_byname2_res , 3 , "check_uprobe_byname2_res" );
35
+ ASSERT_EQ (skel -> bss -> uretprobe_byname2_res , 4 , "check_uretprobe_byname2_res" );
36
+ cleanup :
37
+ test_uprobe_autoattach__destroy (skel );
38
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ /* Copyright (c) 2022, Oracle and/or its affiliates. */
3
+
4
+ #include <linux/ptrace.h>
5
+ #include <linux/bpf.h>
6
+ #include <bpf/bpf_helpers.h>
7
+ #include <bpf/bpf_tracing.h>
8
+
9
+ int uprobe_byname_res = 0 ;
10
+ int uretprobe_byname_res = 0 ;
11
+ int uprobe_byname2_res = 0 ;
12
+ int uretprobe_byname2_res = 0 ;
13
+
14
+ /* This program cannot auto-attach, but that should not stop other
15
+ * programs from attaching.
16
+ */
17
+ SEC ("uprobe" )
18
+ int handle_uprobe_noautoattach (struct pt_regs * ctx )
19
+ {
20
+ return 0 ;
21
+ }
22
+
23
+ SEC ("uprobe//proc/self/exe:autoattach_trigger_func" )
24
+ int handle_uprobe_byname (struct pt_regs * ctx )
25
+ {
26
+ uprobe_byname_res = 1 ;
27
+ return 0 ;
28
+ }
29
+
30
+ SEC ("uretprobe//proc/self/exe:autoattach_trigger_func" )
31
+ int handle_uretprobe_byname (struct pt_regs * ctx )
32
+ {
33
+ uretprobe_byname_res = 2 ;
34
+ return 0 ;
35
+ }
36
+
37
+
38
+ SEC ("uprobe/libc.so.6:malloc" )
39
+ int handle_uprobe_byname2 (struct pt_regs * ctx )
40
+ {
41
+ uprobe_byname2_res = 3 ;
42
+ return 0 ;
43
+ }
44
+
45
+ SEC ("uretprobe/libc.so.6:free" )
46
+ int handle_uretprobe_byname2 (struct pt_regs * ctx )
47
+ {
48
+ uretprobe_byname2_res = 4 ;
49
+ return 0 ;
50
+ }
51
+
52
+ char _license [] SEC ("license" ) = "GPL" ;
You can’t perform that action at this time.
0 commit comments