kernel/reboot.c
Source file repositories/reference/linux-study-clean/kernel/reboot.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/reboot.c- Extension
.c- Size
- 35816 bytes
- Lines
- 1420
- 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.
- 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/atomic.hlinux/ctype.hlinux/export.hlinux/kexec.hlinux/kmod.hlinux/kmsg_dump.hlinux/reboot.hlinux/suspend.hlinux/syscalls.hlinux/syscore_ops.hlinux/uaccess.h
Detected Declarations
syscall rebootstruct sys_off_handlerfunction emergency_restartfunction kernel_restart_preparefunction register_reboot_notifierfunction unregister_reboot_notifierfunction devm_unregister_reboot_notifierfunction devm_register_reboot_notifierfunction register_restart_handlerfunction unregister_restart_handlerfunction do_kernel_restartfunction migrate_to_reboot_cpufunction do_kernel_restart_preparefunction kernel_restartfunction kernel_shutdown_preparefunction kernel_haltfunction sys_off_notifyfunction free_sys_off_handlerfunction chainfunction unregister_sys_off_handlerfunction devm_unregister_sys_off_handlerfunction devm_register_sys_off_handlerfunction devm_register_power_off_handlerfunction devm_register_restart_handlerfunction platform_power_off_notifyfunction register_platform_power_offfunction unregister_platform_power_offfunction legacy_pm_power_offfunction do_kernel_power_off_preparefunction do_kernel_power_offfunction kernel_can_power_offfunction kernel_power_offfunction deferred_cadfunction ctrl_alt_delfunction run_cmdfunction __orderly_rebootfunction __orderly_powerofffunction poweroff_work_funcfunction orderly_powerofffunction reboot_work_funcfunction orderly_rebootfunction hw_failure_emergency_action_funcfunction hw_failure_emergency_schedulefunction __hw_protection_triggerfunction hw_protection_action_parsefunction hw_protection_setupfunction hw_protection_showfunction hw_protection_store
Annotated Snippet
SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
void __user *, arg)
{
struct pid_namespace *pid_ns = task_active_pid_ns(current);
char buffer[256];
int ret = 0;
/* We only trust the superuser with rebooting the system. */
if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT))
return -EPERM;
/* For safety, we require "magic" arguments. */
if (magic1 != LINUX_REBOOT_MAGIC1 ||
(magic2 != LINUX_REBOOT_MAGIC2 &&
magic2 != LINUX_REBOOT_MAGIC2A &&
magic2 != LINUX_REBOOT_MAGIC2B &&
magic2 != LINUX_REBOOT_MAGIC2C))
return -EINVAL;
/*
* If pid namespaces are enabled and the current task is in a child
* pid_namespace, the command is handled by reboot_pid_ns() which will
* call do_exit().
*/
ret = reboot_pid_ns(pid_ns, cmd);
if (ret)
return ret;
/* Instead of trying to make the power_off code look like
* halt when pm_power_off is not set do it the easy way.
*/
if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off()) {
poweroff_fallback_to_halt = true;
cmd = LINUX_REBOOT_CMD_HALT;
}
mutex_lock(&system_transition_mutex);
switch (cmd) {
case LINUX_REBOOT_CMD_RESTART:
kernel_restart(NULL);
break;
case LINUX_REBOOT_CMD_CAD_ON:
C_A_D = 1;
break;
case LINUX_REBOOT_CMD_CAD_OFF:
C_A_D = 0;
break;
case LINUX_REBOOT_CMD_HALT:
kernel_halt();
do_exit(0);
case LINUX_REBOOT_CMD_POWER_OFF:
kernel_power_off();
do_exit(0);
break;
case LINUX_REBOOT_CMD_RESTART2:
ret = strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1);
if (ret < 0) {
ret = -EFAULT;
break;
}
buffer[sizeof(buffer) - 1] = '\0';
kernel_restart(buffer);
break;
#ifdef CONFIG_KEXEC_CORE
case LINUX_REBOOT_CMD_KEXEC:
ret = kernel_kexec();
break;
#endif
#ifdef CONFIG_HIBERNATION
case LINUX_REBOOT_CMD_SW_SUSPEND:
ret = hibernate();
break;
#endif
default:
ret = -EINVAL;
break;
}
mutex_unlock(&system_transition_mutex);
return ret;
}
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/ctype.h`, `linux/export.h`, `linux/kexec.h`, `linux/kmod.h`, `linux/kmsg_dump.h`, `linux/reboot.h`, `linux/suspend.h`.
- Detected declarations: `syscall reboot`, `struct sys_off_handler`, `function emergency_restart`, `function kernel_restart_prepare`, `function register_reboot_notifier`, `function unregister_reboot_notifier`, `function devm_unregister_reboot_notifier`, `function devm_register_reboot_notifier`, `function register_restart_handler`, `function unregister_restart_handler`.
- 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.