FreeBSD kernel kern code
kern_fork.c File Reference
#include <sys/cdefs.h>
#include "opt_ktrace.h"
#include "opt_kstack_pages.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bitstring.h>
#include <sys/sysproto.h>
#include <sys/eventhandler.h>
#include <sys/fcntl.h>
#include <sys/filedesc.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/sysctl.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/msan.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/procdesc.h>
#include <sys/ptrace.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/syscall.h>
#include <sys/vmmeter.h>
#include <sys/vnode.h>
#include <sys/acct.h>
#include <sys/ktr.h>
#include <sys/ktrace.h>
#include <sys/unistd.h>
#include <sys/sdt.h>
#include <sys/sx.h>
#include <sys/sysent.h>
#include <sys/signalvar.h>
#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_extern.h>
#include <vm/uma.h>
Include dependency graph for kern_fork.c:

Go to the source code of this file.

Data Structures

struct  fork_args
 

Functions

 __FBSDID ("$FreeBSD$")
 
 SDT_PROVIDER_DECLARE (proc)
 
 SDT_PROBE_DEFINE3 (proc,,, create, "struct proc *", "struct proc *", "int")
 
int sys_fork (struct thread *td, struct fork_args *uap)
 
int sys_pdfork (struct thread *td, struct pdfork_args *uap)
 
int sys_vfork (struct thread *td, struct vfork_args *uap)
 
int sys_rfork (struct thread *td, struct rfork_args *uap)
 
 SYSCTL_INT (_kern, OID_AUTO, lastpid, CTLFLAG_RD, &lastpid, 0, "Last used PID")
 
static int sysctl_kern_randompid (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, OID_AUTO, randompid, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, 0, sysctl_kern_randompid, "I", "Random PID modulus. Special values: 0: disable, 1: choose random value")
 
static int fork_findpid (int flags)
 
static int fork_norfproc (struct thread *td, int flags)
 
static void do_fork (struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *td2, struct vmspace *vm2, struct file *fp_procdesc)
 
void fork_rfppwait (struct thread *td)
 
int fork1 (struct thread *td, struct fork_req *fr)
 
void fork_exit (void(*callout)(void *, struct trapframe *), void *arg, struct trapframe *frame)
 
void fork_return (struct thread *td, struct trapframe *frame)
 

Variables

int __exclusive_cache_line nprocs = 1
 
int lastpid = 0
 
static int randompid = 0
 
bitstr_t proc_id_pidmap
 
bitstr_t proc_id_grpidmap
 
bitstr_t proc_id_sessidmap
 
bitstr_t proc_id_reapmap
 

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ do_fork()

static void do_fork ( struct thread *  td,
struct fork_req *  fr,
struct proc *  p2,
struct thread *  td2,
struct vmspace *  vm2,
struct file *  fp_procdesc 
)
static

◆ fork1()

int fork1 ( struct thread *  td,
struct fork_req *  fr 
)

◆ fork_exit()

void fork_exit ( void(*)(void *, struct trapframe *)  callout,
void *  arg,
struct trapframe *  frame 
)

Definition at line 1068 of file kern_fork.c.

References Giant, kmsan_mark(), kthread_exit(), printf(), sched_fork_exit(), and thread_stash().

Here is the call graph for this function:

◆ fork_findpid()

static int fork_findpid ( int  flags)
static

Definition at line 257 of file kern_fork.c.

References flags, lastpid, pid_max, proc_id_grpidmap, proc_id_pidmap, proc_id_reapmap, proc_id_sessidmap, procid_lock, randompid, and result.

Referenced by do_fork().

Here is the caller graph for this function:

◆ fork_norfproc()

static int fork_norfproc ( struct thread *  td,
int  flags 
)
static

Definition at line 308 of file kern_fork.c.

References fdescfree(), fdinit(), fdunshare(), flags, pdescfree(), pdinit(), pdunshare(), thread_single(), and thread_single_end().

Referenced by fork1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fork_return()

void fork_return ( struct thread *  td,
struct trapframe *  frame 
)

Definition at line 1126 of file kern_fork.c.

References exit1(), prison_isalive(), ptracestop(), and userret().

Here is the call graph for this function:

◆ fork_rfppwait()

void fork_rfppwait ( struct thread *  td)

Definition at line 808 of file kern_fork.c.

References hz, ptracestop(), thread_suspend_check(), and thread_suspend_check_needed().

Referenced by ast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SDT_PROBE_DEFINE3()

SDT_PROBE_DEFINE3 ( proc  ,
create  ,
"struct proc *"  ,
"struct proc *"  ,
"int"   
)

◆ SDT_PROVIDER_DECLARE()

SDT_PROVIDER_DECLARE ( proc  )

◆ sys_fork()

int sys_fork ( struct thread *  td,
struct fork_args uap 
)

Definition at line 104 of file kern_fork.c.

References fork1().

Here is the call graph for this function:

◆ sys_pdfork()

int sys_pdfork ( struct thread *  td,
struct pdfork_args *  uap 
)

Definition at line 122 of file kern_fork.c.

References fd, and fork1().

Here is the call graph for this function:

◆ sys_rfork()

int sys_rfork ( struct thread *  td,
struct rfork_args *  uap 
)

Definition at line 166 of file kern_fork.c.

References fork1().

Here is the call graph for this function:

◆ sys_vfork()

int sys_vfork ( struct thread *  td,
struct vfork_args *  uap 
)

Definition at line 149 of file kern_fork.c.

References fork1().

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
lastpid  ,
CTLFLAG_RD  ,
lastpid,
,
"Last used PID"   
)

◆ sysctl_kern_randompid()

static int sysctl_kern_randompid ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 211 of file kern_fork.c.

References allproc_lock, pid_max, randompid, sysctl_handle_int(), and sysctl_wire_old_buffer().

Here is the call graph for this function:

◆ SYSCTL_PROC()

SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
randompid  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_randompid  ,
"I"  ,
"Random PID modulus. Special values: 0:  disable,
1:choose random value  
)

Variable Documentation

◆ lastpid

int lastpid = 0

Definition at line 196 of file kern_fork.c.

Referenced by fork_findpid().

◆ nprocs

int __exclusive_cache_line nprocs = 1

Definition at line 195 of file kern_fork.c.

Referenced by fork1(), and proc_reap().

◆ proc_id_grpidmap

bitstr_t proc_id_grpidmap
extern

Referenced by fork_findpid().

◆ proc_id_pidmap

bitstr_t proc_id_pidmap
extern

Referenced by fork_findpid().

◆ proc_id_reapmap

bitstr_t proc_id_reapmap
extern

Referenced by fork_findpid().

◆ proc_id_sessidmap

bitstr_t proc_id_sessidmap
extern

Referenced by fork_findpid().

◆ randompid

int randompid = 0
static

Definition at line 208 of file kern_fork.c.

Referenced by fork_findpid(), and sysctl_kern_randompid().