MCPcopy Create free account
hub / github.com/F-Stack/f-stack / do_fork

Function do_fork

freebsd/kern/kern_fork.c:362–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

360}
361
362static void
363do_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

Callers 1

fork1Function · 0.85

Calls 15

pargs_holdFunction · 0.85
bzeroFunction · 0.85
prison_proc_holdFunction · 0.85
fork_findpidFunction · 0.85
tidhash_addFunction · 0.85
sigacts_allocFunction · 0.85
pdinitFunction · 0.85
fdinitFunction · 0.85
pdshareFunction · 0.85
pdcopyFunction · 0.85
fdcopyFunction · 0.85
fdshareFunction · 0.85

Tested by

no test coverage detected