4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * This function is used through-out the kernel (including mm and fs)
9 * to indicate a major problem.
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/notifier.h>
17 #include <linux/init.h>
18 #include <linux/sysrq.h>
19 #include <linux/interrupt.h>
20 #include <linux/nmi.h>
21 #include <linux/kexec.h>
27 EXPORT_SYMBOL(panic_timeout);
29 struct notifier_block *panic_notifier_list;
31 EXPORT_SYMBOL(panic_notifier_list);
33 static int __init panic_setup(char *str)
35 panic_timeout = simple_strtoul(str, NULL, 0);
38 __setup("panic=", panic_setup);
40 static long no_blink(long time)
45 /* Returns how long it waited in ms */
46 long (*panic_blink)(long time);
47 EXPORT_SYMBOL(panic_blink);
50 * panic - halt the system
51 * @fmt: The text string to print
53 * Display a message, then perform cleanups.
55 * This function never returns.
58 NORET_TYPE void panic(const char * fmt, ...)
61 static char buf[1024];
63 #if defined(CONFIG_S390)
64 unsigned long caller = (unsigned long) __builtin_return_address(0);
68 * It's possible to come here directly from a panic-assertion and not
69 * have preempt disabled. Some functions called from here want
70 * preempt to be disabled. No point enabling it later though...
76 vsnprintf(buf, sizeof(buf), fmt, args);
78 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
82 * If we have crashed and we have a crash kernel loaded let it handle
84 * Do we want to call this before we try to display a message?
90 * Note smp_send_stop is the usual smp shutdown function, which
91 * unfortunately means it may not be hardened to work in a panic
97 notifier_call_chain(&panic_notifier_list, 0, buf);
100 panic_blink = no_blink;
102 if (panic_timeout > 0) {
104 * Delay timeout seconds before rebooting the machine.
105 * We can't use the "normal" timers since we just panicked..
107 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
108 for (i = 0; i < panic_timeout*1000; ) {
109 touch_nmi_watchdog();
114 /* This will not be a clean reboot, with everything
115 * shutting down. But if there is a chance of
116 * rebooting the system it will be rebooted.
122 extern int stop_a_enabled;
123 /* Make sure the user can actually press Stop-A (L1-A) */
125 printk(KERN_EMERG "Press Stop-A (L1-A) to return to the boot prom\n");
128 #if defined(CONFIG_S390)
129 disabled_wait(caller);
133 touch_softlockup_watchdog();
140 EXPORT_SYMBOL(panic);
143 * print_tainted - return a string to represent the kernel taint state.
145 * 'P' - Proprietary module has been loaded.
146 * 'F' - Module has been forcibly loaded.
147 * 'S' - SMP with CPUs not designed for SMP.
148 * 'R' - User forced a module unload.
149 * 'M' - Machine had a machine check experience.
150 * 'B' - System has hit bad_page.
152 * The string is overwritten by the next call to print_taint().
155 const char *print_tainted(void)
159 snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
160 tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
161 tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
162 tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
163 tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
164 tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
165 tainted & TAINT_BAD_PAGE ? 'B' : ' ');
168 snprintf(buf, sizeof(buf), "Not tainted");
172 void add_taint(unsigned flag)
176 EXPORT_SYMBOL(add_taint);