kernel/sys.c
Source file repositories/reference/linux-study-clean/kernel/sys.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sys.c- Extension
.c- Size
- 74540 bytes
- Lines
- 3075
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/mm.hlinux/mm_inline.hlinux/utsname.hlinux/mman.hlinux/reboot.hlinux/prctl.hlinux/highuid.hlinux/fs.hlinux/kmod.hlinux/ksm.hlinux/perf_event.hlinux/resource.hlinux/kernel.hlinux/workqueue.hlinux/capability.hlinux/device.hlinux/key.hlinux/times.hlinux/posix-timers.hlinux/security.hlinux/random.hlinux/suspend.hlinux/tty.hlinux/signal.hlinux/cn_proc.hlinux/task_io_accounting_ops.hlinux/seccomp.hlinux/cpu.hlinux/personality.hlinux/ptrace.hlinux/fs_struct.h
Detected Declarations
syscall setprioritysyscall getprioritysyscall setregidsyscall setgidsyscall setreuidsyscall setuidsyscall setresuidsyscall getresuidsyscall setresgidsyscall getresgidsyscall setfsuidsyscall setfsgidsyscall getpidsyscall gettidsyscall getppidsyscall getuidsyscall geteuidsyscall getgidsyscall getegidsyscall timessyscall setpgidsyscall getpgidsyscall getpgrpsyscall getsidsyscall setsidsyscall newunamesyscall unamesyscall oldunamesyscall sethostnamesyscall gethostnamesyscall setdomainnamesyscall getrlimitsyscall old_getrlimitsyscall prlimit64syscall setrlimitsyscall getrusagesyscall umasksyscall prctlsyscall getcpusyscall sysinfostruct compat_sysinfofunction init_overflow_sysctlfunction set_one_prio_permfunction set_one_priofunction do_each_pid_threadfunction for_each_process_threadfunction do_each_pid_threadfunction for_each_process_thread
Annotated Snippet
SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
{
struct task_struct *g, *p;
struct user_struct *user;
const struct cred *cred = current_cred();
int error = -EINVAL;
struct pid *pgrp;
kuid_t uid;
if (which > PRIO_USER || which < PRIO_PROCESS)
goto out;
/* normalize: avoid signed division (rounding problems) */
error = -ESRCH;
if (niceval < MIN_NICE)
niceval = MIN_NICE;
if (niceval > MAX_NICE)
niceval = MAX_NICE;
rcu_read_lock();
switch (which) {
case PRIO_PROCESS:
if (who)
p = find_task_by_vpid(who);
else
p = current;
if (p)
error = set_one_prio(p, niceval, error);
break;
case PRIO_PGRP:
if (who)
pgrp = find_vpid(who);
else
pgrp = task_pgrp(current);
read_lock(&tasklist_lock);
do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
error = set_one_prio(p, niceval, error);
} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
read_unlock(&tasklist_lock);
break;
case PRIO_USER:
uid = make_kuid(cred->user_ns, who);
user = cred->user;
if (!who)
uid = cred->uid;
else if (!uid_eq(uid, cred->uid)) {
user = find_user(uid);
if (!user)
goto out_unlock; /* No processes for this user */
}
for_each_process_thread(g, p) {
if (uid_eq(task_uid(p), uid) && task_pid_vnr(p))
error = set_one_prio(p, niceval, error);
}
if (!uid_eq(uid, cred->uid))
free_uid(user); /* For find_user() */
break;
}
out_unlock:
rcu_read_unlock();
out:
return error;
}
/*
* Ugh. To avoid negative return values, "getpriority()" will
* not return the normal nice-value, but a negated value that
* has been offset by 20 (ie it returns 40..1 instead of -20..19)
* to stay compatible.
*/
SYSCALL_DEFINE2(getpriority, int, which, int, who)
{
struct task_struct *g, *p;
struct user_struct *user;
const struct cred *cred = current_cred();
long niceval, retval = -ESRCH;
struct pid *pgrp;
kuid_t uid;
if (which > PRIO_USER || which < PRIO_PROCESS)
return -EINVAL;
rcu_read_lock();
switch (which) {
case PRIO_PROCESS:
if (who)
p = find_task_by_vpid(who);
else
p = current;
if (p) {
Annotation
- Immediate include surface: `linux/export.h`, `linux/mm.h`, `linux/mm_inline.h`, `linux/utsname.h`, `linux/mman.h`, `linux/reboot.h`, `linux/prctl.h`, `linux/highuid.h`.
- Detected declarations: `syscall setpriority`, `syscall getpriority`, `syscall setregid`, `syscall setgid`, `syscall setreuid`, `syscall setuid`, `syscall setresuid`, `syscall getresuid`, `syscall setresgid`, `syscall getresgid`.
- 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.