Commit 3cdaf45578b9aa1eb748d0a32678ee5a0180575b

Authored by Jeff Dike
Committed by Linus Torvalds
1 parent 8ca842c4b5

uml: replace clone with fork

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.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 20 additions and 35 deletions Side-by-side Diff

arch/um/os-Linux/start_up.c
... ... @@ -25,7 +25,7 @@
25 25 #include "registers.h"
26 26 #include "skas_ptrace.h"
27 27  
28   -static int ptrace_child(void *arg)
  28 +static int ptrace_child(void)
29 29 {
30 30 int ret;
31 31 int pid = os_getpid(), ppid = getppid();
32 32  
33 33  
34 34  
35 35  
36 36  
... ... @@ -90,31 +90,23 @@
90 90 fflush(stdout);
91 91 }
92 92  
93   -static int start_ptraced_child(void **stack_out)
  93 +static int start_ptraced_child(void)
94 94 {
95   - void *stack;
96   - unsigned long sp;
97 95 int pid, n, status;
98 96  
99   - stack = mmap(NULL, UM_KERN_PAGE_SIZE,
100   - PROT_READ | PROT_WRITE | PROT_EXEC,
101   - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
102   - if (stack == MAP_FAILED)
103   - fatal_perror("check_ptrace : mmap failed");
  97 + pid = fork();
  98 + if (pid == 0)
  99 + ptrace_child();
  100 + else if (pid < 0)
  101 + fatal_perror("start_ptraced_child : fork failed");
104 102  
105   - sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);
106   - pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
107   - if (pid < 0)
108   - fatal_perror("start_ptraced_child : clone failed");
109   -
110 103 CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
111 104 if (n < 0)
112   - fatal_perror("check_ptrace : clone failed");
  105 + fatal_perror("check_ptrace : waitpid failed");
113 106 if (!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP))
114 107 fatal("check_ptrace : expected SIGSTOP, got status = %d",
115 108 status);
116 109  
117   - *stack_out = stack;
118 110 return pid;
119 111 }
120 112  
... ... @@ -124,8 +116,7 @@
124 116 * So only for SYSEMU features we test mustpanic, while normal host features
125 117 * must work anyway!
126 118 */
127   -static int stop_ptraced_child(int pid, void *stack, int exitcode,
128   - int mustexit)
  119 +static int stop_ptraced_child(int pid, int exitcode, int mustexit)
129 120 {
130 121 int status, n, ret = 0;
131 122  
... ... @@ -145,8 +136,6 @@
145 136 ret = -1;
146 137 }
147 138  
148   - if (munmap(stack, UM_KERN_PAGE_SIZE) < 0)
149   - fatal_perror("check_ptrace : munmap failed");
150 139 return ret;
151 140 }
152 141  
153 142  
... ... @@ -198,13 +187,12 @@
198 187  
199 188 static void __init check_sysemu(void)
200 189 {
201   - void *stack;
202 190 unsigned long regs[MAX_REG_NR];
203 191 int pid, n, status, count=0;
204 192  
205 193 non_fatal("Checking syscall emulation patch for ptrace...");
206 194 sysemu_supported = 0;
207   - pid = start_ptraced_child(&stack);
  195 + pid = start_ptraced_child();
208 196  
209 197 if (ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
210 198 goto fail;
... ... @@ -231,7 +219,7 @@
231 219 goto fail;
232 220 }
233 221  
234   - if (stop_ptraced_child(pid, stack, 0, 0) < 0)
  222 + if (stop_ptraced_child(pid, 0, 0) < 0)
235 223 goto fail_stopped;
236 224  
237 225 sysemu_supported = 1;
... ... @@ -239,7 +227,7 @@
239 227 set_using_sysemu(!force_sysemu_disabled);
240 228  
241 229 non_fatal("Checking advanced syscall emulation patch for ptrace...");
242   - pid = start_ptraced_child(&stack);
  230 + pid = start_ptraced_child();
243 231  
244 232 if ((ptrace(PTRACE_OLDSETOPTIONS, pid, 0,
245 233 (void *) PTRACE_O_TRACESYSGOOD) < 0))
... ... @@ -271,7 +259,7 @@
271 259 fatal("check_ptrace : expected SIGTRAP or "
272 260 "(SIGTRAP | 0x80), got status = %d", status);
273 261 }
274   - if (stop_ptraced_child(pid, stack, 0, 0) < 0)
  262 + if (stop_ptraced_child(pid, 0, 0) < 0)
275 263 goto fail_stopped;
276 264  
277 265 sysemu_supported = 2;
278 266  
279 267  
... ... @@ -282,18 +270,17 @@
282 270 return;
283 271  
284 272 fail:
285   - stop_ptraced_child(pid, stack, 1, 0);
  273 + stop_ptraced_child(pid, 1, 0);
286 274 fail_stopped:
287 275 non_fatal("missing\n");
288 276 }
289 277  
290 278 static void __init check_ptrace(void)
291 279 {
292   - void *stack;
293 280 int pid, syscall, n, status;
294 281  
295 282 non_fatal("Checking that ptrace can change system call numbers...");
296   - pid = start_ptraced_child(&stack);
  283 + pid = start_ptraced_child();
297 284  
298 285 if ((ptrace(PTRACE_OLDSETOPTIONS, pid, 0,
299 286 (void *) PTRACE_O_TRACESYSGOOD) < 0))
... ... @@ -323,7 +310,7 @@
323 310 break;
324 311 }
325 312 }
326   - stop_ptraced_child(pid, stack, 0, 1);
  313 + stop_ptraced_child(pid, 0, 1);
327 314 non_fatal("OK\n");
328 315 check_sysemu();
329 316 }
330 317  
... ... @@ -403,11 +390,10 @@
403 390 static inline void check_skas3_ptrace_faultinfo(void)
404 391 {
405 392 struct ptrace_faultinfo fi;
406   - void *stack;
407 393 int pid, n;
408 394  
409 395 non_fatal(" - PTRACE_FAULTINFO...");
410   - pid = start_ptraced_child(&stack);
  396 + pid = start_ptraced_child();
411 397  
412 398 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
413 399 if (n < 0) {
414 400  
... ... @@ -425,13 +411,12 @@
425 411 }
426 412  
427 413 init_registers(pid);
428   - stop_ptraced_child(pid, stack, 1, 1);
  414 + stop_ptraced_child(pid, 1, 1);
429 415 }
430 416  
431 417 static inline void check_skas3_ptrace_ldt(void)
432 418 {
433 419 #ifdef PTRACE_LDT
434   - void *stack;
435 420 int pid, n;
436 421 unsigned char ldtbuf[40];
437 422 struct ptrace_ldt ldt_op = (struct ptrace_ldt) {
... ... @@ -440,7 +425,7 @@
440 425 .bytecount = sizeof(ldtbuf)};
441 426  
442 427 non_fatal(" - PTRACE_LDT...");
443   - pid = start_ptraced_child(&stack);
  428 + pid = start_ptraced_child();
444 429  
445 430 n = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op);
446 431 if (n < 0) {
... ... @@ -458,7 +443,7 @@
458 443 non_fatal("found, but use is disabled\n");
459 444 }
460 445  
461   - stop_ptraced_child(pid, stack, 1, 1);
  446 + stop_ptraced_child(pid, 1, 1);
462 447 #else
463 448 /* PTRACE_LDT might be disabled via cmdline option.
464 449 * We want to override this, else we might use the stub