vserver 1.9.5.x5
[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/interrupt.h>
20 #include <linux/nmi.h>
21
22 int panic_timeout;
23 int panic_on_oops;
24 int tainted;
25
26 EXPORT_SYMBOL(panic_timeout);
27
28 struct notifier_block *panic_notifier_list;
29
30 EXPORT_SYMBOL(panic_notifier_list);
31
32 static int __init panic_setup(char *str)
33 {
34         panic_timeout = simple_strtoul(str, NULL, 0);
35         return 1;
36 }
37 __setup("panic=", panic_setup);
38
39 static long no_blink(long time)
40 {
41         return 0;
42 }
43
44 /* Returns how long it waited in ms */
45 long (*panic_blink)(long time);
46 EXPORT_SYMBOL(panic_blink);
47
48 /**
49  *      panic - halt the system
50  *      @fmt: The text string to print
51  *
52  *      Display a message, then perform cleanups. Functions in the panic
53  *      notifier list are called after the filesystem cache is flushed (when possible).
54  *
55  *      This function never returns.
56  */
57  
58 NORET_TYPE void panic(const char * fmt, ...)
59 {
60         long i;
61         static char buf[1024];
62         va_list args;
63 #if defined(CONFIG_ARCH_S390)
64         unsigned long caller = (unsigned long) __builtin_return_address(0);
65 #endif
66
67         bust_spinlocks(1);
68         va_start(args, fmt);
69         vsnprintf(buf, sizeof(buf), fmt, args);
70         va_end(args);
71         printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
72         bust_spinlocks(0);
73
74 #ifdef CONFIG_SMP
75         smp_send_stop();
76 #endif
77
78         notifier_call_chain(&panic_notifier_list, 0, buf);
79
80         if (!panic_blink)
81                 panic_blink = no_blink;
82
83         if (panic_timeout > 0)
84         {
85                 /*
86                  * Delay timeout seconds before rebooting the machine. 
87                  * We can't use the "normal" timers since we just panicked..
88                  */
89                 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
90                 for (i = 0; i < panic_timeout*1000; ) {
91                         touch_nmi_watchdog();
92                         i += panic_blink(i);
93                         mdelay(1);
94                         i++;
95                 }
96                 /*
97                  *      Should we run the reboot notifier. For the moment Im
98                  *      choosing not too. It might crash, be corrupt or do
99                  *      more harm than good for other reasons.
100                  */
101                 machine_restart(NULL);
102         }
103 #ifdef __sparc__
104         {
105                 extern int stop_a_enabled;
106                 /* Make sure the user can actually press L1-A */
107                 stop_a_enabled = 1;
108                 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
109         }
110 #endif
111 #if defined(CONFIG_ARCH_S390)
112         disabled_wait(caller);
113 #endif
114         local_irq_enable();
115         for (i = 0;;) {
116                 i += panic_blink(i);
117                 mdelay(1);
118                 i++;
119         }
120 }
121
122 EXPORT_SYMBOL(panic);
123
124 /**
125  *      print_tainted - return a string to represent the kernel taint state.
126  *
127  *  'P' - Proprietary module has been loaded.
128  *  'F' - Module has been forcibly loaded.
129  *  'S' - SMP with CPUs not designed for SMP.
130  *  'R' - User forced a module unload.
131  *  'M' - Machine had a machine check experience.
132  *  'B' - System has hit bad_page.
133  *
134  *      The string is overwritten by the next call to print_taint().
135  */
136  
137 const char *print_tainted(void)
138 {
139         static char buf[20];
140         if (tainted) {
141                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
142                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
143                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
144                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
145                         tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
146                         tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
147                         tainted & TAINT_BAD_PAGE ? 'B' : ' ');
148         }
149         else
150                 snprintf(buf, sizeof(buf), "Not tainted");
151         return(buf);
152 }
153
154 void add_taint(unsigned flag)
155 {
156         tainted |= flag;
157 }
158 EXPORT_SYMBOL(add_taint);