Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\fork.c Create Date:2022-07-28 08:58:37
Last Modify:2020-03-17 11:04:53 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

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  struct file * 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( - EINVAL)
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( - EINVAL)
1850  If clone_flags & Same thread group && Not (clone_flags & set if signal handlers and blocked signals shared ) Then Return ERR_PTR( - EINVAL)
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( - EINVAL)
1867  If clone_flags & set if we want to have the same parent as the cloner && flags & r init: ignore fatal signals Then Return ERR_PTR( - EINVAL)
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( - EINVAL)
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( - EINVAL)
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 = -ENOMEM
1911  p = Replication process and set stack
1912  If Not p Then Go to fork_out
1921  CLONE_CHILD_SETTID: = (clone_flags & set the TID in the child ) ? child_tid : NULL
1925  CLONE_CHILD_CLEARTID: = (clone_flags & clear the TID in the child ) ? child_tid : NULL
1927  ftrace_graph_init_task(p)
1929  Process mutual exclusion lock initialization
1935  retval = -EAGAIN
1936  If atomic_read( & processes) >= task_rlimit(p, RLIMIT_NPROC) Then
1938  If real user ID subscription != 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_creds(p, clone_flags)
1945  If retval < 0 Then Go to bad_fork_free
1953  retval = -EAGAIN
1954  If counter of threads >= unable 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  cgroup_fork(p)
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 = sched_fork(clone_flags, p)
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 = copy_semundo(clone_flags, p)
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 = he namespaces access rules are:* 1. only current task is allowed to change tsk->nsproxy pointer or* any pointer on the nsproxy itself. Current must hold the task_lock* when changing tsk->nsproxy.* 2
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 = anon_inode_getfile("[pidfd]", & pidfd_fops, pid, O_RDWR | O_CLOEXEC)
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 = he 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.* pid_nr_ns() : id seen from the ns specified.
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 >> PAGE_SHIFT 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  group_threadgroup_change_begin - threadgroup exclusion for cgroups*@tsk: target task* Allows cgroup operations to synchronize against threadgroup changes* using a percpu_rw_semaphore.
2175  retval = cgroup_can_fork(p)
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  klp_copy_process(p)
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 = -ENOMEM
2220  Go to bad_fork_cancel_cgroup
2224  If fatal_signal_pending(current process) Then
2225  retval = -EINTR
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  ptrace_init_task - initialize ptrace state for a new child*@child: new child task*@ptrace: true if child should be ptrace'd by parent's tracer* This is called immediately after adding @child to its parent's children* list
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  hese helpers 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  cgroup_post_fork(p)
2283  group_threadgroup_change_end - threadgroup exclusion for cgroups*@tsk: target task* Counterpart of cgroup_threadcgroup_change_begin().
2284  perf_event_fork(p)
2286  trace_task_newtask(p, clone_flags)
2287  uprobe_copy_process(p, clone_flags)
2289  Return p
2291  bad_fork_cancel_cgroup :
2292  spin_unlock( & siglock)
2293  write_unlock_irq( & tasklist_lock)
2294  cgroup_cancel_fork(p)
2295  bad_fork_cgroup_threadgroup_change_end :
2296  group_threadgroup_change_end - threadgroup exclusion for cgroups*@tsk: target task* Counterpart of cgroup_threadcgroup_change_begin().
2297  bad_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)
2302  bad_fork_free_pid :
2303  If pid != init_struct_pid Then free_pid(pid)
2305  bad_fork_cleanup_thread :
2306  exit_thread(p)
2307  bad_fork_cleanup_io :
2308  If io_context Then exit_io_context(p)
2310  bad_fork_cleanup_namespaces :
2311  exit_task_namespaces(p)
2312  bad_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.
2317  bad_fork_cleanup_signal :
2318  If Not (clone_flags & Same thread group) Then free_signal_struct( Signal handlers: )
2320  bad_fork_cleanup_sighand :
2321  __cleanup_sighand(sighand)
2322  bad_fork_cleanup_fs :
2323  exit_fs(p)
2324  bad_fork_cleanup_files :
2325  exit_files(p)
2326  bad_fork_cleanup_semundo :
2327  exit_sem(p)
2328  bad_fork_cleanup_security :
2329  security_task_free(p)
2330  bad_fork_cleanup_audit :
2331  audit_free(p)
2332  bad_fork_cleanup_perf :
2333  perf_event_free_task(p)
2334  bad_fork_cleanup_policy :
2335  lockdep_free_task(p)
2337  mpol_put( Protected by alloc_lock: )
2338  bad_fork_cleanup_threadgroup_lock :
2340  delayacct_tsk_free(p)
2341  bad_fork_cleanup_count :
2342  atomic_dec( & processes)
2343  exit_creds(p)
2344  bad_fork_free :
2345  run state = TASK_DEAD
2346  put_task_stack(p)
2347  delayed_free_task(p)
2348  fork_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