Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[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.

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

authored by

Jeff Dike and committed by
Linus Torvalds
98fdffcc 36ca1195

+19 -29
+19 -29
arch/um/kernel/process.c
··· 130 130 return(arg.pid); 131 131 } 132 132 133 - static int ptrace_child(void *arg) 133 + static int ptrace_child(void) 134 134 { 135 135 int ret; 136 136 int pid = os_getpid(), ppid = getppid(); ··· 159 159 _exit(ret); 160 160 } 161 161 162 - static int start_ptraced_child(void **stack_out) 162 + static int start_ptraced_child(void) 163 163 { 164 - void *stack; 165 - unsigned long sp; 166 164 int pid, n, status; 167 165 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 + 174 170 if(pid < 0) 175 - panic("check_ptrace : clone failed, errno = %d", errno); 171 + panic("check_ptrace : fork failed, errno = %d", errno); 176 172 CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); 177 173 if(n < 0) 178 174 panic("check_ptrace : wait failed, errno = %d", errno); ··· 176 180 panic("check_ptrace : expected SIGSTOP, got status = %d", 177 181 status); 178 182 179 - *stack_out = stack; 180 183 return(pid); 181 184 } 182 185 ··· 183 188 * just avoid using sysemu, not panic, but only if SYSEMU features are broken. 184 189 * So only for SYSEMU features we test mustpanic, while normal host features 185 190 * must work anyway!*/ 186 - static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic) 191 + static int stop_ptraced_child(int pid, int exitcode, int mustexit) 187 192 { 188 193 int status, n, ret = 0; 189 194 190 195 if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) 191 - panic("check_ptrace : ptrace failed, errno = %d", errno); 196 + panic("stop_ptraced_child : ptrace failed, errno = %d", errno); 192 197 CATCH_EINTR(n = waitpid(pid, &status, 0)); 193 198 if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) { 194 199 int exit_with = WEXITSTATUS(status); ··· 199 204 printk("check_ptrace : child exited with exitcode %d, while " 200 205 "expecting %d; status 0x%x", exit_with, 201 206 exitcode, status); 202 - if (mustpanic) 207 + if (mustexit) 203 208 panic("\n"); 204 209 else 205 210 printk("\n"); 206 211 ret = -1; 207 212 } 208 213 209 - if(munmap(stack, PAGE_SIZE) < 0) 210 - panic("check_ptrace : munmap failed, errno = %d", errno); 211 214 return ret; 212 215 } 213 216 ··· 227 234 228 235 static void __init check_sysemu(void) 229 236 { 230 - void *stack; 231 237 int pid, syscall, n, status, count=0; 232 238 233 239 printk("Checking syscall emulation patch for ptrace..."); 234 240 sysemu_supported = 0; 235 - pid = start_ptraced_child(&stack); 241 + pid = start_ptraced_child(); 236 242 237 243 if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0) 238 244 goto fail; ··· 249 257 panic("check_sysemu : failed to modify system " 250 258 "call return, errno = %d", errno); 251 259 252 - if (stop_ptraced_child(pid, stack, 0, 0) < 0) 260 + if (stop_ptraced_child(pid, 0, 0) < 0) 253 261 goto fail_stopped; 254 262 255 263 sysemu_supported = 1; ··· 257 265 set_using_sysemu(!force_sysemu_disabled); 258 266 259 267 printk("Checking advanced syscall emulation patch for ptrace..."); 260 - pid = start_ptraced_child(&stack); 268 + pid = start_ptraced_child(); 261 269 while(1){ 262 270 count++; 263 271 if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0) ··· 282 290 break; 283 291 } 284 292 } 285 - if (stop_ptraced_child(pid, stack, 0, 0) < 0) 293 + if (stop_ptraced_child(pid, 0, 0) < 0) 286 294 goto fail_stopped; 287 295 288 296 sysemu_supported = 2; ··· 293 301 return; 294 302 295 303 fail: 296 - stop_ptraced_child(pid, stack, 1, 0); 304 + stop_ptraced_child(pid, 1, 0); 297 305 fail_stopped: 298 306 printk("missing\n"); 299 307 } 300 308 301 309 void __init check_ptrace(void) 302 310 { 303 - void *stack; 304 311 int pid, syscall, n, status; 305 312 306 313 printk("Checking that ptrace can change system call numbers..."); 307 - pid = start_ptraced_child(&stack); 314 + pid = start_ptraced_child(); 308 315 309 316 if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0) 310 317 panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno); ··· 330 339 break; 331 340 } 332 341 } 333 - stop_ptraced_child(pid, stack, 0, 1); 342 + stop_ptraced_child(pid, 0, 1); 334 343 printk("OK\n"); 335 344 check_sysemu(); 336 345 } ··· 362 371 static inline int check_skas3_ptrace_support(void) 363 372 { 364 373 struct ptrace_faultinfo fi; 365 - void *stack; 366 374 int pid, n, ret = 1; 367 375 368 376 printf("Checking for the skas3 patch in the host..."); 369 - pid = start_ptraced_child(&stack); 377 + pid = start_ptraced_child(); 370 378 371 379 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); 372 380 if (n < 0) { ··· 380 390 } 381 391 382 392 init_registers(pid); 383 - stop_ptraced_child(pid, stack, 1, 1); 393 + stop_ptraced_child(pid, 1, 1); 384 394 385 395 return(ret); 386 396 }