@@ -40,6 +40,7 @@ struct child {
40
40
int pid ;
41
41
int tid ;
42
42
pthread_t thread ;
43
+ char stack [65536 ];
43
44
};
44
45
45
46
static void release_child (struct child * child )
@@ -69,41 +70,56 @@ static void kick_child(struct child *child)
69
70
fflush (NULL );
70
71
}
71
72
72
- static int spawn_child ( struct child * child )
73
+ static int child_func ( void * arg )
73
74
{
75
+ struct child * child = arg ;
74
76
int err , c ;
75
77
78
+ close (child -> go [1 ]);
79
+
80
+ /* wait for parent's kick */
81
+ err = read (child -> go [0 ], & c , 1 );
82
+ if (err != 1 )
83
+ exit (err );
84
+
85
+ uprobe_multi_func_1 ();
86
+ uprobe_multi_func_2 ();
87
+ uprobe_multi_func_3 ();
88
+ usdt_trigger ();
89
+
90
+ exit (errno );
91
+ }
92
+
93
+ static int spawn_child_flag (struct child * child , bool clone_vm )
94
+ {
76
95
/* pipe to notify child to execute the trigger functions */
77
96
if (pipe (child -> go ))
78
97
return -1 ;
79
98
80
- child -> pid = child -> tid = fork ();
99
+ if (clone_vm ) {
100
+ child -> pid = child -> tid = clone (child_func , child -> stack + sizeof (child -> stack )/2 ,
101
+ CLONE_VM |SIGCHLD , child );
102
+ } else {
103
+ child -> pid = child -> tid = fork ();
104
+ }
81
105
if (child -> pid < 0 ) {
82
106
release_child (child );
83
107
errno = EINVAL ;
84
108
return -1 ;
85
109
}
86
110
87
- /* child */
88
- if (child -> pid == 0 ) {
89
- close (child -> go [1 ]);
90
-
91
- /* wait for parent's kick */
92
- err = read (child -> go [0 ], & c , 1 );
93
- if (err != 1 )
94
- exit (err );
95
-
96
- uprobe_multi_func_1 ();
97
- uprobe_multi_func_2 ();
98
- uprobe_multi_func_3 ();
99
- usdt_trigger ();
100
-
101
- exit (errno );
102
- }
111
+ /* fork-ed child */
112
+ if (!clone_vm && child -> pid == 0 )
113
+ child_func (child );
103
114
104
115
return 0 ;
105
116
}
106
117
118
+ static int spawn_child (struct child * child )
119
+ {
120
+ return spawn_child_flag (child , false);
121
+ }
122
+
107
123
static void * child_thread (void * ctx )
108
124
{
109
125
struct child * child = ctx ;
@@ -948,7 +964,7 @@ static struct bpf_program *uprobe_multi_program(struct uprobe_multi_pid_filter *
948
964
949
965
#define TASKS 3
950
966
951
- static void run_pid_filter (struct uprobe_multi_pid_filter * skel , bool retprobe )
967
+ static void run_pid_filter (struct uprobe_multi_pid_filter * skel , bool clone_vm , bool retprobe )
952
968
{
953
969
LIBBPF_OPTS (bpf_uprobe_multi_opts , opts , .retprobe = retprobe );
954
970
struct bpf_link * link [TASKS ] = {};
@@ -958,7 +974,7 @@ static void run_pid_filter(struct uprobe_multi_pid_filter *skel, bool retprobe)
958
974
memset (skel -> bss -> test , 0 , sizeof (skel -> bss -> test ));
959
975
960
976
for (i = 0 ; i < TASKS ; i ++ ) {
961
- if (!ASSERT_OK (spawn_child (& child [i ]), "spawn_child" ))
977
+ if (!ASSERT_OK (spawn_child_flag (& child [i ], clone_vm ), "spawn_child" ))
962
978
goto cleanup ;
963
979
skel -> bss -> pids [i ] = child [i ].pid ;
964
980
}
@@ -986,16 +1002,16 @@ static void run_pid_filter(struct uprobe_multi_pid_filter *skel, bool retprobe)
986
1002
release_child (& child [i ]);
987
1003
}
988
1004
989
- static void test_pid_filter_process (void )
1005
+ static void test_pid_filter_process (bool clone_vm )
990
1006
{
991
1007
struct uprobe_multi_pid_filter * skel ;
992
1008
993
1009
skel = uprobe_multi_pid_filter__open_and_load ();
994
1010
if (!ASSERT_OK_PTR (skel , "uprobe_multi_pid_filter__open_and_load" ))
995
1011
return ;
996
1012
997
- run_pid_filter (skel , false);
998
- run_pid_filter (skel , true);
1013
+ run_pid_filter (skel , clone_vm , false);
1014
+ run_pid_filter (skel , clone_vm , true);
999
1015
1000
1016
uprobe_multi_pid_filter__destroy (skel );
1001
1017
}
@@ -1093,5 +1109,7 @@ void test_uprobe_multi_test(void)
1093
1109
if (test__start_subtest ("consumers" ))
1094
1110
test_consumers ();
1095
1111
if (test__start_subtest ("filter_fork" ))
1096
- test_pid_filter_process ();
1112
+ test_pid_filter_process (false);
1113
+ if (test__start_subtest ("filter_clone_vm" ))
1114
+ test_pid_filter_process (true);
1097
1115
}
0 commit comments