This commit was manufactured by cvs2svn to create tag
[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 int netdump_mode = 0;
41 EXPORT_SYMBOL_GPL(netdump_mode);
42
43 /**
44  *      panic - halt the system
45  *      @fmt: The text string to print
46  *
47  *      Display a message, then perform cleanups. Functions in the panic
48  *      notifier list are called after the filesystem cache is flushed (when possible).
49  *
50  *      This function never returns.
51  */
52  
53 NORET_TYPE void panic(const char * fmt, ...)
54 {
55         static char buf[1024];
56         va_list args;
57 #if defined(CONFIG_ARCH_S390)
58         unsigned long caller = (unsigned long) __builtin_return_address(0);
59 #endif
60
61         bust_spinlocks(1);
62         va_start(args, fmt);
63         vsnprintf(buf, sizeof(buf), fmt, args);
64         va_end(args);
65         printk(KERN_EMERG "Kernel panic: %s\n",buf);
66         if (netdump_func)
67                 BUG();
68         if (in_interrupt())
69                 printk(KERN_EMERG "In interrupt handler - not syncing\n");
70         else if (!current->pid)
71                 printk(KERN_EMERG "In idle task - not syncing\n");
72         else
73                 sys_sync();
74         bust_spinlocks(0);
75
76 #ifdef CONFIG_SMP
77         smp_send_stop();
78 #endif
79
80        notifier_call_chain(&panic_notifier_list, 0, buf);
81
82         if (panic_timeout > 0)
83         {
84                 int i;
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; i++) {
91                         touch_nmi_watchdog();
92                         mdelay(1000);
93                 }
94                 /*
95                  *      Should we run the reboot notifier. For the moment Im
96                  *      choosing not too. It might crash, be corrupt or do
97                  *      more harm than good for other reasons.
98                  */
99                 machine_restart(NULL);
100         }
101 #ifdef __sparc__
102         {
103                 extern int stop_a_enabled;
104                 /* Make sure the user can actually press L1-A */
105                 stop_a_enabled = 1;
106                 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
107         }
108 #endif
109 #if defined(CONFIG_ARCH_S390)
110         disabled_wait(caller);
111 #endif
112         local_irq_enable();
113         for (;;)
114                 ;
115 }
116
117 EXPORT_SYMBOL(panic);
118
119 /**
120  *      print_tainted - return a string to represent the kernel taint state.
121  *
122  *  'P' - Proprietary module has been loaded.
123  *  'F' - Module has been forcibly loaded.
124  *  'S' - SMP with CPUs not designed for SMP.
125  *
126  *      The string is overwritten by the next call to print_taint().
127  */
128  
129 const char *print_tainted(void)
130 {
131         static char buf[20];
132         if (tainted) {
133                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c",
134                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
135                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
136                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
137         }
138         else
139                 snprintf(buf, sizeof(buf), "Not tainted");
140         return(buf);
141 }