kernel/pid.c
Source file repositories/reference/linux-study-clean/kernel/pid.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/pid.c- Extension
.c- Size
- 24460 bytes
- Lines
- 975
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/export.hlinux/slab.hlinux/init.hlinux/rculist.hlinux/memblock.hlinux/pid_namespace.hlinux/init_task.hlinux/syscalls.hlinux/proc_ns.hlinux/refcount.hlinux/anon_inodes.hlinux/sched/signal.hlinux/sched/task.hlinux/idr.hlinux/pidfs.hnet/sock.huapi/linux/pidfd.h
Detected Declarations
syscall pidfd_opensyscall pidfd_getfdfunction put_pidfunction delayed_put_pidfunction free_pidfunction free_pidsfunction disable_pid_allocationfunction attach_pidfunction __change_pidfunction detach_pidfunction change_pidfunction exchange_tidsfunction transfer_pidfunction rcu_read_lockfunction pid_nr_nsfunction pid_vnrfunction __task_pid_nr_nsfunction pidfd_get_taskfunction pidfd_createfunction sys_pidfd_openfunction set_is_seenfunction pid_table_root_permissionsfunction pid_table_root_set_ownershipfunction proc_do_cad_pidfunction register_pidns_sysctlsfunction unregister_pidns_sysctlsfunction pid_idr_initfunction pid_namespace_sysctl_initfunction pidfd_getfdfunction sys_pidfd_getfdmodule init pid_namespace_sysctl_initexport init_pid_nsexport put_pidexport find_pid_nsexport find_vpidexport pid_taskexport get_task_pidexport get_pid_taskexport find_get_pidexport pid_nr_nsexport pid_vnrexport __task_pid_nr_nsexport task_active_pid_nsexport find_ge_pid
Annotated Snippet
SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
{
int fd;
struct pid *p;
if (flags & ~(PIDFD_NONBLOCK | PIDFD_THREAD))
return -EINVAL;
if (pid <= 0)
return -EINVAL;
p = find_get_pid(pid);
if (!p)
return -ESRCH;
fd = pidfd_create(p, flags);
put_pid(p);
return fd;
}
#ifdef CONFIG_SYSCTL
static struct ctl_table_set *pid_table_root_lookup(struct ctl_table_root *root)
{
return &task_active_pid_ns(current)->set;
}
static int set_is_seen(struct ctl_table_set *set)
{
return &task_active_pid_ns(current)->set == set;
}
static int pid_table_root_permissions(struct ctl_table_header *head,
const struct ctl_table *table)
{
struct pid_namespace *pidns =
container_of(head->set, struct pid_namespace, set);
int mode = table->mode;
if (ns_capable_noaudit(pidns->user_ns, CAP_SYS_ADMIN) ||
uid_eq(current_euid(), make_kuid(pidns->user_ns, 0)))
mode = (mode & S_IRWXU) >> 6;
else if (in_egroup_p(make_kgid(pidns->user_ns, 0)))
mode = (mode & S_IRWXG) >> 3;
else
mode = mode & S_IROTH;
return (mode << 6) | (mode << 3) | mode;
}
static void pid_table_root_set_ownership(struct ctl_table_header *head,
kuid_t *uid, kgid_t *gid)
{
struct pid_namespace *pidns =
container_of(head->set, struct pid_namespace, set);
kuid_t ns_root_uid;
kgid_t ns_root_gid;
ns_root_uid = make_kuid(pidns->user_ns, 0);
if (uid_valid(ns_root_uid))
*uid = ns_root_uid;
ns_root_gid = make_kgid(pidns->user_ns, 0);
if (gid_valid(ns_root_gid))
*gid = ns_root_gid;
}
static struct ctl_table_root pid_table_root = {
.lookup = pid_table_root_lookup,
.permissions = pid_table_root_permissions,
.set_ownership = pid_table_root_set_ownership,
};
static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos)
{
struct pid *new_pid;
pid_t tmp_pid;
int r;
struct ctl_table tmp_table = *table;
tmp_pid = pid_vnr(cad_pid);
tmp_table.data = &tmp_pid;
r = proc_dointvec(&tmp_table, write, buffer, lenp, ppos);
if (r || !write)
return r;
new_pid = find_get_pid(tmp_pid);
if (!new_pid)
return -ESRCH;
Annotation
- Immediate include surface: `linux/mm.h`, `linux/export.h`, `linux/slab.h`, `linux/init.h`, `linux/rculist.h`, `linux/memblock.h`, `linux/pid_namespace.h`, `linux/init_task.h`.
- Detected declarations: `syscall pidfd_open`, `syscall pidfd_getfd`, `function put_pid`, `function delayed_put_pid`, `function free_pid`, `function free_pids`, `function disable_pid_allocation`, `function attach_pid`, `function __change_pid`, `function detach_pid`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- 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.