4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/module.h>
9 #include <linux/utsname.h>
10 #include <linux/mman.h>
11 #include <linux/smp_lock.h>
12 #include <linux/notifier.h>
13 #include <linux/reboot.h>
14 #include <linux/prctl.h>
15 #include <linux/highuid.h>
17 #include <linux/resource.h>
18 #include <linux/kernel.h>
19 #include <linux/kexec.h>
20 #include <linux/workqueue.h>
21 #include <linux/capability.h>
22 #include <linux/device.h>
23 #include <linux/key.h>
24 #include <linux/times.h>
25 #include <linux/posix-timers.h>
26 #include <linux/security.h>
27 #include <linux/dcookies.h>
28 #include <linux/suspend.h>
29 #include <linux/tty.h>
30 #include <linux/signal.h>
31 #include <linux/cn_proc.h>
32 #include <linux/getcpu.h>
33 #include <linux/task_io_accounting_ops.h>
34 #include <linux/seccomp.h>
35 #include <linux/cpu.h>
36 #include <linux/ptrace.h>
38 #include <linux/compat.h>
39 #include <linux/syscalls.h>
40 #include <linux/kprobes.h>
41 #include <linux/user_namespace.h>
43 #include <asm/uaccess.h>
45 #include <asm/unistd.h>
47 extern asmlinkage
long (*original_reboot
)(int magic1
, int magic2
, unsigned int cmd
, void __user
*arg
);
50 static struct notifier_block dummy_notifier_reboot
= {
51 .notifier_call
= NULL
,
56 BLOCKING_NOTIFIER_HEAD(notifier_head
);
60 void kernel_restart_prepare(char *cmd
)
62 void (*original_kernel_restart_prepare
)(char *) = (void (*)(char *))KERNEL_RESTART_PREPARE
;
63 return original_kernel_restart_prepare(cmd
);
65 register_reboot_notifier(&dummy_notifier_reboot
);
66 notifier_head
.head
=dummy_notifier_reboot
.next
;
67 unregister_reboot_notifier(&dummy_notifier_reboot
);
69 blocking_notifier_call_chain(¬ifier_head
, SYS_RESTART
, cmd
);
70 system_state
= SYSTEM_RESTART
;
77 * Reboot system call: for obvious reasons only root may call it,
78 * and even root needs to set up some magic numbers in the registers
79 * so that some mistake won't make this reboot the whole machine.
80 * You can also set the meaning of the ctrl-alt-del-key here.
82 * reboot doesn't sync: do that yourself before calling this.
84 asmlinkage
long reboot(int magic1
, int magic2
, unsigned int cmd
, void __user
*arg
)
87 if(cmd
==LINUX_REBOOT_CMD_KEXEC
) {
88 /* We only trust the superuser with rebooting the system. */
89 if (!capable(CAP_SYS_BOOT
))
92 /* For safety, we require "magic" arguments. */
93 if (magic1
!= LINUX_REBOOT_MAGIC1
||
94 (magic2
!= LINUX_REBOOT_MAGIC2
&&
95 magic2
!= LINUX_REBOOT_MAGIC2A
&&
96 magic2
!= LINUX_REBOOT_MAGIC2B
&&
97 magic2
!= LINUX_REBOOT_MAGIC2C
))
101 ret
= kernel_kexec();
105 return original_reboot(magic1
, magic2
, cmd
, arg
);