Function Report

Linux Kernel (v4.4)

Source File:kernel\fork.c Create Date:2016-01-14 10:16:55
Last Modify:2016-01-11 07:01:32 Copyright©Brick
home page Tree
Annotate the kernelChinese

Function Name:copy_process

Function:static struct task_struct * copy_process(unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size, int *child_tidptr, struct pid *pid, int trace, unsigned long tls)

Return Type:static struct task_struct *

Parameter:

Type Parameter NameRemarks
unsigned long clone_flagsflags of clone
unsigned long stack_startstart of stack
unsigned long stack_sizesize of stack
int * child_tidptr
struct pid * pid
int trace
unsigned long tls

Function description:Create a new process

1253  *cgrp_ss_priv[CGROUP_CANFORK_COUNT] = {}
1255  If (flags of clone & (New mount namespace group | set if fs info shared between processes)) == (New mount namespace group | set if fs info shared between processes) then Returning ERR_PTR( -Invalid argument)
1258  If (flags of clone & (New user namespace | set if fs info shared between processes)) == (New user namespace | set if fs info shared between processes) then Returning ERR_PTR( -Invalid argument)
1265  If flags of clone & Same thread group && !(flags of clone & set if signal handlers and blocked signals shared) then Returning ERR_PTR( -Invalid argument)
1273  If flags of clone & set if signal handlers and blocked signals shared && !(flags of clone & set if VM shared between processes) then Returning ERR_PTR( -Invalid argument)
1283  If flags of clone & set if we want to have the same parent as the cloner && current process-> signal handlers->signal flags & Ignore the fatal signal when initialization then Returning ERR_PTR( -Invalid argument)
1290  If flags of clone & Same thread group then
1293  If flags of clone & (New user namespace | New pid namespace) || task_active_pid_ns(current process) != current process-> namespaces->pid_ns_for_children then Returning ERR_PTR( -Invalid argument)
1297  Create a security task
1298  If result of Create a security task then Go to fork_out
1301  result of Create a security task = -Out of memory
1302  p = Replication process and set stack
1303  If !p then Go to fork_out
1306  Debug stack for newly created tasks
1308  Process mutual exclusion lock initialization
1314  retval = -Try again
1316  If read atomic variable >= limit on task then
1318  If real user ID subscription != INIT_USER && !Check operation authority && !Check operation authority then Go to bad_fork_free
1321  current process-> per process flags, defined below &= ^set_user noticed that RLIMIT_NPROC was exceeded
1323  Copy a certificate
1324  If result of Copy a certificate < 0 then Go to bad_fork_free
1332  result of Copy a certificate = -Try again
1333  If counter of threads >= tunable limit on nr_threads then Go to bad_fork_cleanup_count
1336  Initialization delay record
1337  per process flags, defined below &= ^(used super-user privileges | I'm a workqueue worker)
1338  per process flags, defined below |= forked but didn't exec
1339  Initialization list head
1340  Initialization list head
1341  Process RCU lock initialization
1342  for vfork() = NULL
1343  Process spin lock initialization
1345  Initialization signal transmission
1347  utime = stime = gtime = 0
1348  utimescaled = stimescaled = 0
1349  prev_cputime_init( &prev_cputime)
1358  set the &rss_stat to 0
1361  default_timer_slack_ns = current process->time slack values
1363  Process I/O accounting initialization
1364  clear integrals
1366  Initialize POSIX timer handling for a single task.
1368  monotonic time in nsec = ktime_get_ns()
1369  boot based time in nsec = ktime_get_boot_ns()
1370  io_context = NULL
1371  audit_context = NULL
1372  mark the beginning of changes to a threadgroup
1373  initialize cgroup related fields during copy_process
1375  Protected by alloc_lock = mpol_dup( Protected by alloc_lock)
1376  If IS_ERR( Protected by alloc_lock) then
1377  PTR_ERR( Protected by alloc_lock)
1378  Protected by alloc_lock = NULL
1379  Go to bad_fork_cleanup_threadgroup_lock
1383  cpuset_mem_spread_rotor = NUMA_NO_NODE
1384  cpuset_slab_spread_rotor = NUMA_NO_NODE
1385  seqcount_init
1403  pagefault_disabled = 0
1406  lockdep_depth = 0
1407  curr_chain_key = 0
1408  lockdep_recursion = 0
1412  mutex deadlock detection = NULL
1420  fork()/clone()-time setup:
1421  If result of fork()/clone()-time setup: then Go to bad_fork_cleanup_policy
1424  Initialize the perf_event context in task_struct
1425  If result of Initialize the perf_event context in task_struct then Go to bad_fork_cleanup_policy
1427  allocate an audit context block for a task
1428  If result of allocate an audit context block for a task then Go to bad_fork_cleanup_perf
1431  shm_init_task
1432  If CLONE_SYSVSEM is set, establish sharing of SEM_UNDO state between parent and child tasks.
1433  If result of If CLONE_SYSVSEM is set, establish sharing of SEM_UNDO state between parent and child tasks. then Go to bad_fork_cleanup_audit
1435  copy_files(flags of clone, p)
1436  If result of copy_files(flags of clone, p) then Go to bad_fork_cleanup_semundo
1438  copy_fs(flags of clone, p)
1439  If result of copy_fs(flags of clone, p) then Go to bad_fork_cleanup_files
1441  copy_sighand(flags of clone, p)
1442  If result of copy_sighand(flags of clone, p) then Go to bad_fork_cleanup_fs
1444  copy_signal(flags of clone, p)
1445  If result of copy_signal(flags of clone, p) then Go to bad_fork_cleanup_sighand
1447  copy_mm(flags of clone, p)
1448  If result of copy_mm(flags of clone, p) then Go to bad_fork_cleanup_signal
1450  This now handles copy for nsproxy and all namespaces therein
1451  If result of This now handles copy for nsproxy and all namespaces therein then Go to bad_fork_cleanup_mm
1453  copy_io(flags of clone, p)
1454  If result of copy_io(flags of clone, p) then Go to bad_fork_cleanup_namespaces
1456  Architectures that haven't opted into copy_thread_tls get the tls argument via pt_regs, so ignore the tls argument passed via C.
1457  If result of Architectures that haven't opted into copy_thread_tls get the tls argument via pt_regs, so ignore the tls argument passed via C. then Go to bad_fork_cleanup_io
1460  If pid != &init_struct_pid then
1461  pid = alloc_pid(pid_ns_for_children)
1462  If IS_ERR(pid) then
1463  PTR_ERR(pid)
1464  Go to bad_fork_cleanup_io
1468  CLONE_CHILD_SETTID = if flags of clone & set the TID in the child then child_tidptr else NULL
1472  CLONE_CHILD_CLEARTID = if flags of clone & clear the TID in the child then child_tidptr else NULL
1474  stack plugging = NULL
1477  robust_list = NULL
1479  compat_robust_list = NULL
1481  Initialization list head
1482  pi_state_cache = NULL
1487  If (flags of clone & (set if VM shared between processes | set if the parent wants the child to wake it up on mm_release)) == set if VM shared between processes then sas_ss_sp = sas_ss_size = 0
1494  user_disable_single_step(p)
1495  clear_tsk_thread_flag(p, syscall trace active)
1497  clear_tsk_thread_flag(p, syscall emulation active)
1499  clear_all_latency_tracing(p)
1502  process id = the helpers to get the pid's id seen from different namespaces
1503  If flags of clone & Same thread group then
1504  exit signal = -1
1505  threadgroup leader = current process-> threadgroup leader
1506  thread group id = current process->thread group id
1507  Else
1508  If flags of clone & set if we want to have the same parent as the cloner then exit signal = current process-> threadgroup leader->exit signal
1510  Else exit signal = flags of clone & signal mask to be sent at exit
1512  threadgroup leader = p
1513  thread group id = process id
1516  when(nr_dirtied>= nr_dirtied_pause), it's time to call balance_dirty_pages() for some dirty throttling pause = 0
1517  nr_dirtied_pause = 128 >> determines the page size - 10
1518  start of a write-and-pause period = 0
1520  The signal sent when the parent dies = 0
1521  Initialization list head
1522  task_works = NULL
1530  called on a new task before the process is exposed
1531  If result of called on a new task before the process is exposed then Go to bad_fork_free_pid
1538  write_lock_irq
1541  If flags of clone & (set if we want to have the same parent as the cloner | Same thread group) then
1542  real parent process = current process-> real parent process
1543  Thread group tracking = current process-> Thread group tracking
1544  Else
1545  real parent process = current process
1546  Thread group tracking = current process->self_exec_id
1549  spin_lock( &current process->sighand->siglock)
1555  copy_seccomp(p)
1565  recalc_sigpending()
1566  If signal_pending(current process) then
1567  spin_unlock( &current process->sighand->siglock)
1568  write_unlock_irq
1569  result of called on a new task before the process is exposed = -ERESTARTNOINTR
1570  Go to bad_fork_cancel_cgroup
1573  If Value is more likely to compile time then
1574  initialize ptrace state for a new child
1576  init_task_pid(p, PIDTYPE_PID, pid)
1577  If thread_group_leader(p) then
1586  leader_pid = pid
1593  Else
1602  must be called with the tasklist_lock write-held.
1603  counter of threads++
1606  Handle normal Linux uptimes.++
1607  spin_unlock( &current process->sighand->siglock)
1608  syscall_tracepoint_update(p)
1609  write_unlock_irq
1611  proc_fork_connector(p)
1612  called on a new task after adding it to the task list
1613  mark the end of changes to a threadgroup
1614  perf_event_fork(p)
1616  trace_task_newtask(p, flags of clone)
1617  Called in context of a new clone/fork from copy_process.
1619  Returning p
1621  bad_fork_cancel_cgroup
1622  called if a fork failed after cgroup_can_fork()
1623  bad_fork_free_pid
1624  If pid != &init_struct_pid then free_pid(pid)
1626  bad_fork_cleanup_io
1627  If io_context then Called by the exiting task
1629  bad_fork_cleanup_namespaces
1630  exit_task_namespaces(p)
1631  bad_fork_cleanup_mm
1632  If mm then Decrement the use count and release all resources for an mm.
1634  bad_fork_cleanup_signal
1635  If !(flags of clone & Same thread group) then free_signal_struct( signal handlers)
1637  bad_fork_cleanup_sighand
1638  __cleanup_sighand(sighand)
1639  bad_fork_cleanup_fs
1640  exit_fs(p)
1641  bad_fork_cleanup_files
1642  exit_files(p)
1643  bad_fork_cleanup_semundo
1644  add semadj values to semaphores, free undo structures.
1645  bad_fork_cleanup_audit
1646  audit_free(p)
1647  bad_fork_cleanup_perf
1648  Free an unexposed, unused context as created by inheritance by perf_event_init_task below, used by fork() in case of fail.
1649  bad_fork_cleanup_policy
1651  mpol_put( Protected by alloc_lock)
1652  bad_fork_cleanup_threadgroup_lock
1654  mark the end of changes to a threadgroup
1655  Free tsk->delays. Called from bad fork and __put_task_struct where there's no risk of tsk->delays being accessed elsewhere
1656  bad_fork_cleanup_count
1657  decrement atomic variable
1658  Clean up a task's credentials when it exits
1659  bad_fork_free
1660  free_task(p)
1661  fork_out
1662  Returning ERR_PTR(retval)
Caller
Function NameFunction description
fork_idle
_do_forkfork routine