ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / kernel / panic.c
1 /*
2  *  linux/kernel/panic.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
6
7 /*
8  * This function is used through-out the kernel (including mm and fs)
9  * to indicate a major problem.
10  */
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/syscalls.h>
20 #include <linux/interrupt.h>
21 #include <linux/nmi.h>
22
23 int panic_timeout;
24 int panic_on_oops;
25 int tainted;
26
27 EXPORT_SYMBOL(panic_timeout);
28
29 struct notifier_block *panic_notifier_list;
30
31 EXPORT_SYMBOL(panic_notifier_list);
32
33 static int __init panic_setup(char *str)
34 {
35         panic_timeout = simple_strtoul(str, NULL, 0);
36         return 1;
37 }
38 __setup("panic=", panic_setup);
39
40 /**
41  *      panic - halt the system
42  *      @fmt: The text string to print
43  *
44  *      Display a message, then perform cleanups. Functions in the panic
45  *      notifier list are called after the filesystem cache is flushed (when possible).
46  *
47  *      This function never returns.
48  */
49  
50 NORET_TYPE void panic(const char * fmt, ...)
51 {
52         static char buf[1024];
53         va_list args;
54 #if defined(CONFIG_ARCH_S390)
55         unsigned long caller = (unsigned long) __builtin_return_address(0);
56 #endif
57
58         bust_spinlocks(1);
59         va_start(args, fmt);
60         vsnprintf(buf, sizeof(buf), fmt, args);
61         va_end(args);
62         printk(KERN_EMERG "Kernel panic: %s\n",buf);
63         if (in_interrupt())
64                 printk(KERN_EMERG "In interrupt handler - not syncing\n");
65         else if (!current->pid)
66                 printk(KERN_EMERG "In idle task - not syncing\n");
67         else
68                 sys_sync();
69         bust_spinlocks(0);
70
71 #ifdef CONFIG_SMP
72         smp_send_stop();
73 #endif
74
75        notifier_call_chain(&panic_notifier_list, 0, buf);
76
77         if (panic_timeout > 0)
78         {
79                 int i;
80                 /*
81                  * Delay timeout seconds before rebooting the machine. 
82                  * We can't use the "normal" timers since we just panicked..
83                  */
84                 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
85                 for (i = 0; i < panic_timeout; i++) {
86                         touch_nmi_watchdog();
87                         mdelay(1000);
88                 }
89                 /*
90                  *      Should we run the reboot notifier. For the moment Im
91                  *      choosing not too. It might crash, be corrupt or do
92                  *      more harm than good for other reasons.
93                  */
94                 machine_restart(NULL);
95         }
96 #ifdef __sparc__
97         {
98                 extern int stop_a_enabled;
99                 /* Make sure the user can actually press L1-A */
100                 stop_a_enabled = 1;
101                 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
102         }
103 #endif
104 #if defined(CONFIG_ARCH_S390)
105         disabled_wait(caller);
106 #endif
107         local_irq_enable();
108         for (;;)
109                 ;
110 }
111
112 EXPORT_SYMBOL(panic);
113
114 /**
115  *      print_tainted - return a string to represent the kernel taint state.
116  *
117  *  'P' - Proprietary module has been loaded.
118  *  'F' - Module has been forcibly loaded.
119  *  'S' - SMP with CPUs not designed for SMP.
120  *
121  *      The string is overwritten by the next call to print_taint().
122  */
123  
124 const char *print_tainted(void)
125 {
126         static char buf[20];
127         if (tainted) {
128                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c",
129                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
130                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
131                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
132         }
133         else
134                 snprintf(buf, sizeof(buf), "Not tainted");
135         return(buf);
136 }