| 360 | } |
| 361 | |
| 362 | static void |
| 363 | do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *td2, |
| 364 | struct vmspace *vm2, struct file *fp_procdesc) |
| 365 | { |
| 366 | struct proc *p1, *pptr; |
| 367 | struct filedesc *fd; |
| 368 | struct filedesc_to_leader *fdtol; |
| 369 | struct pwddesc *pd; |
| 370 | struct sigacts *newsigacts; |
| 371 | |
| 372 | p1 = td->td_proc; |
| 373 | |
| 374 | PROC_LOCK(p1); |
| 375 | bcopy(&p1->p_startcopy, &p2->p_startcopy, |
| 376 | __rangeof(struct proc, p_startcopy, p_endcopy)); |
| 377 | pargs_hold(p2->p_args); |
| 378 | PROC_UNLOCK(p1); |
| 379 | |
| 380 | bzero(&p2->p_startzero, |
| 381 | __rangeof(struct proc, p_startzero, p_endzero)); |
| 382 | |
| 383 | /* Tell the prison that we exist. */ |
| 384 | prison_proc_hold(p2->p_ucred->cr_prison); |
| 385 | |
| 386 | p2->p_state = PRS_NEW; /* protect against others */ |
| 387 | p2->p_pid = fork_findpid(fr->fr_flags); |
| 388 | AUDIT_ARG_PID(p2->p_pid); |
| 389 | |
| 390 | sx_xlock(&allproc_lock); |
| 391 | LIST_INSERT_HEAD(&allproc, p2, p_list); |
| 392 | allproc_gen++; |
| 393 | sx_xunlock(&allproc_lock); |
| 394 | |
| 395 | sx_xlock(PIDHASHLOCK(p2->p_pid)); |
| 396 | LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash); |
| 397 | sx_xunlock(PIDHASHLOCK(p2->p_pid)); |
| 398 | |
| 399 | tidhash_add(td2); |
| 400 | |
| 401 | /* |
| 402 | * Malloc things while we don't hold any locks. |
| 403 | */ |
| 404 | if (fr->fr_flags & RFSIGSHARE) |
| 405 | newsigacts = NULL; |
| 406 | else |
| 407 | newsigacts = sigacts_alloc(); |
| 408 | |
| 409 | /* |
| 410 | * Copy filedesc. |
| 411 | */ |
| 412 | if (fr->fr_flags & RFCFDG) { |
| 413 | pd = pdinit(p1->p_pd, false); |
| 414 | fd = fdinit(p1->p_fd, false, NULL); |
| 415 | fdtol = NULL; |
| 416 | } else if (fr->fr_flags & RFFDG) { |
| 417 | if (fr->fr_flags2 & FR2_SHARE_PATHS) |
| 418 | pd = pdshare(p1->p_pd); |
| 419 | else |
no test coverage detected