kernel/fork.c
Source file repositories/reference/linux-study-clean/kernel/fork.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/fork.c- Extension
.c- Size
- 85693 bytes
- Lines
- 3408
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/anon_inodes.hlinux/slab.hlinux/sched/autogroup.hlinux/sched/mm.hlinux/sched/user.hlinux/sched/numa_balancing.hlinux/sched/stat.hlinux/sched/task.hlinux/sched/task_stack.hlinux/sched/cputime.hlinux/sched/ext.hlinux/sched/exec_state.hlinux/seq_file.hlinux/rtmutex.hlinux/init.hlinux/unistd.hlinux/module.hlinux/vmalloc.hlinux/completion.hlinux/personality.hlinux/mempolicy.hlinux/sem.hlinux/file.hlinux/fdtable.hlinux/iocontext.hlinux/key.hlinux/kmsan.hlinux/binfmts.hlinux/mman.hlinux/mmu_notifier.hlinux/fs.hlinux/mm.h
Detected Declarations
syscall set_tid_addresssyscall forksyscall vforksyscall clonesyscall clonesyscall clonesyscall clonesyscall clone3syscall unsharestruct vm_stackfunction lockdep_tasklist_lock_is_heldfunction nr_processesfunction arch_release_task_structfunction free_task_structfunction try_release_thread_stack_to_cachefunction thread_stack_free_rcufunction thread_stack_delayed_freefunction free_vm_stack_cachefunction memcg_charge_kernel_stackfunction alloc_thread_stack_nodefunction free_thread_stackfunction thread_stack_free_rcufunction thread_stack_delayed_freefunction alloc_thread_stack_nodefunction free_thread_stackfunction thread_stack_free_rcufunction thread_stack_delayed_freefunction alloc_thread_stack_nodefunction free_thread_stackfunction thread_stack_cache_initfunction account_kernel_stackfunction exit_task_stack_accountfunction release_task_stackfunction put_task_stackfunction free_taskfunction dup_mm_exe_filefunction mm_alloc_pgdfunction mm_free_pgdfunction mm_alloc_idfunction mm_free_idfunction mm_alloc_idfunction mm_free_idfunction do_check_lazy_tlbfunction do_shoot_lazy_tlbfunction cleanup_lazy_tlbsfunction __mmdropfunction mmdrop_async_fnfunction mmdrop_async
Annotated Snippet
SYSCALL_DEFINE1(set_tid_address, int __user *, tidptr)
{
current->clear_child_tid = tidptr;
return task_pid_vnr(current);
}
static void rt_mutex_init_task(struct task_struct *p)
{
raw_spin_lock_init(&p->pi_lock);
#ifdef CONFIG_RT_MUTEXES
p->pi_waiters = RB_ROOT_CACHED;
p->pi_top_task = NULL;
p->pi_blocked_on = NULL;
#endif
}
static inline void init_task_pid_links(struct task_struct *task)
{
enum pid_type type;
for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type)
INIT_HLIST_NODE(&task->pid_links[type]);
}
static inline void
init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
{
if (type == PIDTYPE_PID)
task->thread_pid = pid;
else
task->signal->pids[type] = pid;
}
static inline void rcu_copy_process(struct task_struct *p)
{
#ifdef CONFIG_PREEMPT_RCU
p->rcu_read_lock_nesting = 0;
p->rcu_read_unlock_special.s = 0;
p->rcu_blocked_node = NULL;
INIT_LIST_HEAD(&p->rcu_node_entry);
#endif /* #ifdef CONFIG_PREEMPT_RCU */
#ifdef CONFIG_TASKS_RCU
p->rcu_tasks_holdout = false;
INIT_LIST_HEAD(&p->rcu_tasks_holdout_list);
p->rcu_tasks_idle_cpu = -1;
INIT_LIST_HEAD(&p->rcu_tasks_exit_list);
#endif /* #ifdef CONFIG_TASKS_RCU */
#ifdef CONFIG_TASKS_TRACE_RCU
p->trc_reader_nesting = 0;
#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */
}
/**
* pidfd_prepare - allocate a new pidfd_file and reserve a pidfd
* @pid: the struct pid for which to create a pidfd
* @flags: flags of the new @pidfd
* @ret_file: return the new pidfs file
*
* Allocate a new file that stashes @pid and reserve a new pidfd number in the
* caller's file descriptor table. The pidfd is reserved but not installed yet.
*
* The helper verifies that @pid is still in use, without PIDFD_THREAD the
* task identified by @pid must be a thread-group leader.
*
* If this function returns successfully the caller is responsible to either
* call fd_install() passing the returned pidfd and pidfd file as arguments in
* order to install the pidfd into its file descriptor table or they must use
* put_unused_fd() and fput() on the returned pidfd and pidfd file
* respectively.
*
* This function is useful when a pidfd must already be reserved but there
* might still be points of failure afterwards and the caller wants to ensure
* that no pidfd is leaked into its file descriptor table.
*
* Return: On success, a reserved pidfd is returned from the function and a new
* pidfd file is returned in the last argument to the function. On
* error, a negative error code is returned from the function and the
* last argument remains unchanged.
*/
int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret_file)
{
struct file *pidfs_file;
/*
* PIDFD_STALE is only allowed to be passed if the caller knows
* that @pid is already registered in pidfs and thus
* PIDFD_INFO_EXIT information is guaranteed to be available.
*/
if (!(flags & PIDFD_STALE)) {
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/slab.h`, `linux/sched/autogroup.h`, `linux/sched/mm.h`, `linux/sched/user.h`, `linux/sched/numa_balancing.h`, `linux/sched/stat.h`, `linux/sched/task.h`.
- Detected declarations: `syscall set_tid_address`, `syscall fork`, `syscall vfork`, `syscall clone`, `syscall clone`, `syscall clone`, `syscall clone`, `syscall clone3`, `syscall unshare`, `struct vm_stack`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.