History

[PATCH] uml: use fork instead of clone

Convert the boot-time host ptrace testing from clone to fork. They were essentially doing fork anyway. This cleans up the code a bit, and makes valgrind a bit happier about grinding it.

Jeff Dike committed 21 years ago

Commit 98fdffc1 parent 36ca1191 file · +19 −29Browse files

Unified · Split

arch/um/kernel/process.c+19−29
@@ -130,7 +130,7 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack, · 129 unmodified lines
130130 return(arg.pid);
131131 }
132132
133−static int ptrace_child(void *arg)
133+static int ptrace_child(void)
134134 {
135135 int ret;
136136 int pid = os_getpid(), ppid = getppid();
@@ -159,20 +159,16 @@ static int ptrace_child(void *arg) · 22 unmodified lines
159159 _exit(ret);
160160 }
161161
162−static int start_ptraced_child(void **stack_out)
162+static int start_ptraced_child(void)
163163 {
164− void *stack;
165− unsigned long sp;
166164 int pid, n, status;
167165
168− stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
169− MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
170− if(stack == MAP_FAILED)
171− panic("check_ptrace : mmap failed, errno = %d", errno);
172− sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
173− pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
166+ pid = fork();
167+ if(pid == 0)
168+ ptrace_child();
169+
174170 if(pid < 0)
175− panic("check_ptrace : clone failed, errno = %d", errno);
171+ panic("check_ptrace : fork failed, errno = %d", errno);
176172 CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
177173 if(n < 0)
178174 panic("check_ptrace : wait failed, errno = %d", errno);
@@ -180,7 +176,6 @@ static int start_ptraced_child(void **stack_out) · 1 unmodified line
180176 panic("check_ptrace : expected SIGSTOP, got status = %d",
181177 status);
182178
183− *stack_out = stack;
184179 return(pid);
185180 }
186181
@@ -188,12 +183,12 @@ static int start_ptraced_child(void **stack_out) · 1 unmodified line
188183 * just avoid using sysemu, not panic, but only if SYSEMU features are broken.
189184 * So only for SYSEMU features we test mustpanic, while normal host features
190185 * must work anyway!*/
191−static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic)
186+static int stop_ptraced_child(int pid, int exitcode, int mustexit)
192187 {
193188 int status, n, ret = 0;
194189
195190 if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
196− panic("check_ptrace : ptrace failed, errno = %d", errno);
191+ panic("stop_ptraced_child : ptrace failed, errno = %d", errno);
197192 CATCH_EINTR(n = waitpid(pid, &status, 0));
198193 if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
199194 int exit_with = WEXITSTATUS(status);
@@ -204,15 +199,13 @@ static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic) · 4 unmodified lines
204199 printk("check_ptrace : child exited with exitcode %d, while "
205200 "expecting %d; status 0x%x", exit_with,
206201 exitcode, status);
207− if (mustpanic)
202+ if (mustexit)
208203 panic("\n");
209204 else
210205 printk("\n");
211206 ret = -1;
212207 }
213208
214− if(munmap(stack, PAGE_SIZE) < 0)
215− panic("check_ptrace : munmap failed, errno = %d", errno);
216209 return ret;
217210 }
218211
@@ -234,12 +227,11 @@ __uml_setup("nosysemu", nosysemu_cmd_param, · 15 unmodified lines
234227
235228 static void __init check_sysemu(void)
236229 {
237− void *stack;
238230 int pid, syscall, n, status, count=0;
239231
240232 printk("Checking syscall emulation patch for ptrace...");
241233 sysemu_supported = 0;
242− pid = start_ptraced_child(&stack);
234+ pid = start_ptraced_child();
243235
244236 if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
245237 goto fail;
@@ -257,7 +249,7 @@ static void __init check_sysemu(void) · 11 unmodified lines
257249 panic("check_sysemu : failed to modify system "
258250 "call return, errno = %d", errno);
259251
260− if (stop_ptraced_child(pid, stack, 0, 0) < 0)
252+ if (stop_ptraced_child(pid, 0, 0) < 0)
261253 goto fail_stopped;
262254
263255 sysemu_supported = 1;
@@ -265,7 +257,7 @@ static void __init check_sysemu(void) · 1 unmodified line
265257 set_using_sysemu(!force_sysemu_disabled);
266258
267259 printk("Checking advanced syscall emulation patch for ptrace...");
268− pid = start_ptraced_child(&stack);
260+ pid = start_ptraced_child();
269261 while(1){
270262 count++;
271263 if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
@@ -290,7 +282,7 @@ static void __init check_sysemu(void) · 18 unmodified lines
290282 break;
291283 }
292284 }
293− if (stop_ptraced_child(pid, stack, 0, 0) < 0)
285+ if (stop_ptraced_child(pid, 0, 0) < 0)
294286 goto fail_stopped;
295287
296288 sysemu_supported = 2;
@@ -301,18 +293,17 @@ static void __init check_sysemu(void) · 4 unmodified lines
301293 return;
302294
303295 fail:
304− stop_ptraced_child(pid, stack, 1, 0);
296+ stop_ptraced_child(pid, 1, 0);
305297 fail_stopped:
306298 printk("missing\n");
307299 }
308300
309301 void __init check_ptrace(void)
310302 {
311− void *stack;
312303 int pid, syscall, n, status;
313304
314305 printk("Checking that ptrace can change system call numbers...");
315− pid = start_ptraced_child(&stack);
306+ pid = start_ptraced_child();
316307
317308 if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
318309 panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno);
@@ -339,7 +330,7 @@ void __init check_ptrace(void) · 20 unmodified lines
339330 break;
340331 }
341332 }
342− stop_ptraced_child(pid, stack, 0, 1);
333+ stop_ptraced_child(pid, 0, 1);
343334 printk("OK\n");
344335 check_sysemu();
345336 }
@@ -371,11 +362,10 @@ void forward_pending_sigio(int target) · 25 unmodified lines
371362 static inline int check_skas3_ptrace_support(void)
372363 {
373364 struct ptrace_faultinfo fi;
374− void *stack;
375365 int pid, n, ret = 1;
376366
377367 printf("Checking for the skas3 patch in the host...");
378− pid = start_ptraced_child(&stack);
368+ pid = start_ptraced_child();
379369
380370 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
381371 if (n < 0) {
@@ -390,7 +380,7 @@ static inline int check_skas3_ptrace_support(void) · 8 unmodified lines
390380 }
391381
392382 init_registers(pid);
393− stop_ptraced_child(pid, stack, 1, 1);
383+ stop_ptraced_child(pid, 1, 1);
394384
395385 return(ret);
396386 }