Function report

linux kernel

5.5.9

Brick

Source Code:kernel\fork.c Create Date:2020-03-23 17:37:37
Last Modify:2020-03-17 11:04:53 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload PLEAChinese

Name:Create a new process

Proto:static __latent_entropy struct task_struct *copy_process(struct pid *pid, int trace, int node, struct kernel_clone_args *args)

Type:struct task_struct

Parameter:

TypeParameterName
struct pid *pid
inttrace
intnode
struct kernel_clone_args *args
1830  pidfd = -1
1833  pidfile = NULL
1834  clone_flags = flags
1840  If (clone_flags & (New mount namespace group | set if fs info shared between processes )) == (New mount namespace group | set if fs info shared between processes ) Then Return ERR_PTR( - Invalid argument)
1843  If (clone_flags & (New user namespace | set if fs info shared between processes )) == (New user namespace | set if fs info shared between processes ) Then Return ERR_PTR( - Invalid argument)
1850  If clone_flags & Same thread group && Not (clone_flags & set if signal handlers and blocked signals shared ) Then Return ERR_PTR( - Invalid argument)
1858  If clone_flags & set if signal handlers and blocked signals shared && Not (clone_flags & set if VM shared between processes ) Then Return ERR_PTR( - Invalid argument)
1867  If clone_flags & set if we want to have the same parent as the cloner && flags & for init: ignore fatal signals Then Return ERR_PTR( - Invalid argument)
1875  If clone_flags & Same thread group Then
1876  If clone_flags & (New user namespace | New pid namespace ) || task_active_pid_ns(current process) != pid_ns_for_children Then Return ERR_PTR( - Invalid argument)
1882  If clone_flags & set if a pidfd should be placed in parent Then
1888  If clone_flags & (Unused, ignored | Same thread group) Then Return ERR_PTR( - Invalid argument)
1898  sigemptyset( & signal)
1899  INIT_HLIST_NODE( & node)
1901  spin_lock_irq( & siglock)
1902  If Not (clone_flags & Same thread group) Then hlist_add_head( & node, & multiprocess)
1904  recalc_sigpending()
1905  spin_unlock_irq( & siglock)
1906  retval = -ERESTARTNOINTR
1907  If signal_pending(current process) Then Go to fork_out
1910  retval = -Out of memory
1911  p = Replication process and set stack
1912  If Not p Then Go to fork_out
1921  CLONE_CHILD_SETTID: = If clone_flags & set the TID in the child Then child_tid Else NULL
1925  CLONE_CHILD_CLEARTID: = If clone_flags & clear the TID in the child Then child_tid Else NULL
1927  ftrace_graph_init_task(p)
1929  Process mutual exclusion lock initialization
1935  retval = -Try again
1936  If atomic_read( & processes) >= task_rlimit(p, RLIMIT_NPROC) Then
1938  If user != INIT_USER && Not Check operation authority && Not Check operation authority Then Go to bad_fork_free
1942  flags &= ~set_user() noticed that RLIMIT_NPROC was exceeded
1944  retval = Copy a certificate
1945  If retval < 0 Then Go to bad_fork_free
1953  retval = -Try again
1954  If counter of threads >= tunable limit on nr_threads Then Go to bad_fork_cleanup_count
1957  Initialization delay record
1958  Per task flags (PF_*), defined further below: &= ~( Used super-user privileges | I'm a workqueue worker | I am an IDLE thread )
1959  Per task flags (PF_*), defined further below: |= Forked but didn't exec
1960  Initialization list head
1961  Initialization list head
1962  rcu_copy_process(p)
1963  vfork_done = NULL
1964  Process spin lock initialization( & Protection against (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, mempolicy: )
1966  Initialization signal transmission
1968  utime = stime = gtime = 0
1972  prev_cputime_init( & prev_cputime)
1981  memset( & rss_stat, 0, size of rss_stat )
1984  default_timer_slack_ns = timer_slack_ns
1990  Process I/O accounting initialization
1991  clear integrals
1993  posix_cputimers_init( & Empty if CONFIG_POSIX_CPUTIMERS=n )
1995  io_context = NULL
1996  audit_set_context(p, NULL)
1997  initialize cgroup related fields during copy_process()
1999  Protected by alloc_lock: = mpol_dup( Protected by alloc_lock: )
2000  If IS_ERR( Protected by alloc_lock: ) Then
2001  retval = PTR_ERR( Protected by alloc_lock: )
2002  Protected by alloc_lock: = NULL
2003  Go to bad_fork_cleanup_threadgroup_lock
2027  pagefault_disabled = 0
2042  retval = fork()/clone()-time setup:
2043  If retval Then Go to bad_fork_cleanup_policy
2046  retval = perf_event_init_task(p)
2047  If retval Then Go to bad_fork_cleanup_policy
2049  retval = audit_alloc(p)
2050  If retval Then Go to bad_fork_cleanup_perf
2053  shm_init_task(p)
2054  retval = security_task_alloc(p, clone_flags)
2055  If retval Then Go to bad_fork_cleanup_audit
2057  retval = If CLONE_SYSVSEM is set, establish sharing of SEM_UNDO state between * parent and child tasks.
2058  If retval Then Go to bad_fork_cleanup_security
2060  retval = copy_files(clone_flags, p)
2061  If retval Then Go to bad_fork_cleanup_semundo
2063  retval = copy_fs(clone_flags, p)
2064  If retval Then Go to bad_fork_cleanup_files
2066  retval = copy_sighand(clone_flags, p)
2067  If retval Then Go to bad_fork_cleanup_fs
2069  retval = copy_signal(clone_flags, p)
2070  If retval Then Go to bad_fork_cleanup_sighand
2072  retval = copy_mm(clone_flags, p)
2073  If retval Then Go to bad_fork_cleanup_signal
2075  retval = This now handles copy for nsproxy and all namespaces therein
2076  If retval Then Go to bad_fork_cleanup_mm
2078  retval = copy_io(clone_flags, p)
2079  If retval Then Go to bad_fork_cleanup_namespaces
2081  retval = Architectures that haven't opted into copy_thread_tls get the tls argument * via pt_regs, so ignore the tls argument passed via C
2083  If retval Then Go to bad_fork_cleanup_io
2086  stackleak_task_init(p)
2088  If pid != init_struct_pid Then
2089  pid = alloc_pid(pid_ns_for_children, set_tid, Number of elements in *set_tid )
2091  If IS_ERR(pid) Then
2092  retval = PTR_ERR(pid)
2102  If clone_flags & set if a pidfd should be placed in parent Then
2103  retval = get_unused_fd_flags(O_RDWR | O_CLOEXEC)
2104  If retval < 0 Then Go to bad_fork_free_pid
2107  pidfd = retval
2109  pidfile = creates a new file instance by hooking it up to an * anonymous inode, and a dentry that describe the "class" * of the file
2111  If IS_ERR(pidfile) Then
2113  retval = PTR_ERR(pidfile)
2114  Go to bad_fork_free_pid
2116  get_pid(pid)
2118  retval = Write a simple value into user space(pidfd, pidfd)
2119  If retval Then Go to bad_fork_put_pidfd
2124  Stack plugging: = NULL
2126  futex_init_task(p)
2131  If (clone_flags & (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_reset(p)
2138  user_disable_single_step(p)
2139  clear_tsk_thread_flag(p, syscall trace active )
2141  clear_tsk_thread_flag(p, syscall emulation active )
2143  clear_tsk_latency_tracing(p)
2146  process id = the helpers to get the pid's id seen from different namespaces * pid_nr() : global id, i.e. the id seen from the init namespace; * pid_vnr() : virtual id, i.e. the id seen from the pid namespace of * current
2147  If clone_flags & Same thread group Then
2148  exit signal = -1
2149  group_leader = group_leader
2150  thread group id = tgid
2151  Else
2152  If clone_flags & set if we want to have the same parent as the cloner Then exit signal = exit_signal
2154  Else exit signal = exit_signal
2156  group_leader = p
2157  thread group id = process id
2160  * When (nr_dirtied >= nr_dirtied_pause), it's time to call * balance_dirty_pages() for a dirty throttling pause: = 0
2161  nr_dirtied_pause = 128 >> determines the page size - 10
2162  Start of a write-and-pause period: = 0
2164  The signal sent when the parent dies = 0
2165  Initialization list head
2166  task_works = NULL
2168  threadgroup exclusion for cgroups
2175  retval = called on a new task before the process is exposed
2176  If retval Then Go to bad_fork_cgroup_threadgroup_change_end
2187  Monotonic time in nsecs: = ktime_get_ns()
2188  Boot based time in nsecs: = ktime_get_boottime_ns()
2194  write_lock_irq( & tasklist_lock)
2197  If clone_flags & (set if we want to have the same parent as the cloner | Same thread group) Then
2198  Real parent process: = real_parent
2199  Thread group tracking: = parent_exec_id
2200  Else
2201  Real parent process: = current process
2202  Thread group tracking: = self_exec_id
2205  Called from copy_process() during fork
2207  spin_lock( & siglock)
2213  copy_seccomp(p)
2215  rseq_fork(p, clone_flags)
2218  If Value for the false possibility is greater at compile time(!(pid_allocated & PIDNS_ADDING)) Then
2219  retval = -Out of memory
2220  Go to bad_fork_cancel_cgroup
2224  If fatal_signal_pending(current process) Then
2225  retval = -Interrupted system call
2226  Go to bad_fork_cancel_cgroup
2230  If pidfile Then fd_install(pidfd, pidfile)
2233  init_task_pid_links(p)
2234  If Value is more likely to compile time(process id) Then
2235  initialize ptrace state for a new child
2237  init_task_pid(p, PIDTYPE_PID, pid)
2238  If thread_group_leader(p) Then
2247  signal = signal
2262  Else
2263  nr_threads++
2264  atomic_inc( & live)
2272  must be called with the tasklist_lock write-held.
2273  counter of threads++
2275  Handle normal Linux uptimes++
2276  hlist_del_init( & node)
2277  spin_unlock( & siglock)
2278  syscall_tracepoint_update(p)
2279  write_unlock_irq( & tasklist_lock)
2281  proc_fork_connector(p)
2282  called on a new task after adding it to the task list
2283  threadgroup exclusion for cgroups
2284  perf_event_fork(p)
2286  trace_task_newtask(p, clone_flags)
2287  Called in context of a new clone/fork from copy_process.
2289  Return p
2291bad_fork_cancel_cgroup:
2292  spin_unlock( & siglock)
2293  write_unlock_irq( & tasklist_lock)
2294  called if a fork failed after cgroup_can_fork()
2295bad_fork_cgroup_threadgroup_change_end:
2296  threadgroup exclusion for cgroups
2297bad_fork_put_pidfd:
2298  If clone_flags & set if a pidfd should be placed in parent Then
2299  fput(pidfile)
2300  put_unused_fd(pidfd)
2302bad_fork_free_pid:
2303  If pid != init_struct_pid Then free_pid(pid)
2305bad_fork_cleanup_thread:
2306  exit_thread(p)
2307bad_fork_cleanup_io:
2308  If io_context Then Called by the exiting task
2310bad_fork_cleanup_namespaces:
2311  exit_task_namespaces(p)
2312bad_fork_cleanup_mm:
2313  If mm Then
2314  mm_clear_owner(mm, p)
2315  Decrement the use count and release all resources for an mm.
2317bad_fork_cleanup_signal:
2318  If Not (clone_flags & Same thread group) Then free_signal_struct( Signal handlers: )
2320bad_fork_cleanup_sighand:
2321  __cleanup_sighand(sighand)
2322bad_fork_cleanup_fs:
2323  exit_fs(p)
2324bad_fork_cleanup_files:
2325  exit_files(p)
2326bad_fork_cleanup_semundo:
2327  add semadj values to semaphores, free undo structures
2328bad_fork_cleanup_security:
2329  security_task_free(p)
2330bad_fork_cleanup_audit:
2331  audit_free(p)
2332bad_fork_cleanup_perf:
2333  perf_event_free_task(p)
2334bad_fork_cleanup_policy:
2335  lockdep_free_task(p)
2337  mpol_put( Protected by alloc_lock: )
2338bad_fork_cleanup_threadgroup_lock:
2340  delayacct_tsk_free(p)
2341bad_fork_cleanup_count:
2342  atomic_dec( & processes)
2343  Clean up a task's credentials when it exits
2344bad_fork_free:
2345  run state = TASK_DEAD
2346  put_task_stack(p)
2347  delayed_free_task(p)
2348fork_out:
2349  spin_lock_irq( & siglock)
2350  hlist_del_init( & node)
2351  spin_unlock_irq( & siglock)
2352  Return ERR_PTR(retval)
Caller
NameDescribe
fork_idle
_do_forkfork routine