linux-old/kernel/panic.c
<<
>>
Prefs
   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/sched.h>
  13#include <linux/delay.h>
  14#include <linux/reboot.h>
  15#include <linux/notifier.h>
  16#include <linux/init.h>
  17#include <linux/sysrq.h>
  18#include <linux/interrupt.h>
  19#include <linux/console.h>
  20
  21asmlinkage void sys_sync(void); /* it's really int */
  22
  23int panic_timeout;
  24
  25struct notifier_block *panic_notifier_list;
  26
  27static int __init panic_setup(char *str)
  28{
  29        panic_timeout = simple_strtoul(str, NULL, 0);
  30        return 1;
  31}
  32
  33__setup("panic=", panic_setup);
  34
  35int machine_paniced; 
  36
  37/**
  38 *      panic - halt the system
  39 *      @fmt: The text string to print
  40 *
  41 *      Display a message, then perform cleanups. Functions in the panic
  42 *      notifier list are called after the filesystem cache is flushed (when possible).
  43 *
  44 *      This function never returns.
  45 */
  46 
  47NORET_TYPE void panic(const char * fmt, ...)
  48{
  49        static char buf[1024];
  50        va_list args;
  51#if defined(CONFIG_ARCH_S390)
  52        unsigned long caller = (unsigned long) __builtin_return_address(0);
  53#endif
  54
  55#ifdef CONFIG_VT
  56        disable_console_blank();
  57#endif
  58        machine_paniced = 1;
  59        
  60        bust_spinlocks(1);
  61        va_start(args, fmt);
  62        vsnprintf(buf, sizeof(buf), fmt, args);
  63        va_end(args);
  64        printk(KERN_EMERG "Kernel panic: %s\n",buf);
  65        if (in_interrupt())
  66                printk(KERN_EMERG "In interrupt handler - not syncing\n");
  67        else if (!current->pid)
  68                printk(KERN_EMERG "In idle task - not syncing\n");
  69        else
  70                sys_sync();
  71        bust_spinlocks(0);
  72
  73#ifdef CONFIG_SMP
  74        smp_send_stop();
  75#endif
  76
  77        notifier_call_chain(&panic_notifier_list, 0, NULL);
  78
  79        if (panic_timeout > 0)
  80        {
  81                /*
  82                 * Delay timeout seconds before rebooting the machine. 
  83                 * We can't use the "normal" timers since we just panicked..
  84                 */
  85                printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
  86                mdelay(panic_timeout*1000);
  87                /*
  88                 *      Should we run the reboot notifier. For the moment Im
  89                 *      choosing not too. It might crash, be corrupt or do
  90                 *      more harm than good for other reasons.
  91                 */
  92                machine_restart(NULL);
  93        }
  94#ifdef __sparc__
  95        {
  96                extern int stop_a_enabled;
  97                /* Make sure the user can actually press L1-A */
  98                stop_a_enabled = 1;
  99                printk("Press L1-A to return to the boot prom\n");
 100        }
 101#endif
 102#if defined(CONFIG_ARCH_S390)
 103        disabled_wait(caller);
 104#endif
 105        sti();
 106        for(;;) {
 107#if defined(CONFIG_X86) && defined(CONFIG_VT) 
 108                extern void panic_blink(void);
 109                panic_blink(); 
 110#endif
 111                CHECK_EMERGENCY_SYNC
 112        }
 113}
 114
 115/**
 116 *      print_tainted - return a string to represent the kernel taint state.
 117 *
 118 *      The string is overwritten by the next call to print_taint().
 119 */
 120 
 121const char *print_tainted()
 122{
 123        static char buf[20];
 124        if (tainted) {
 125                snprintf(buf, sizeof(buf), "Tainted: %c%c",
 126                        tainted & 1 ? 'P' : 'G',
 127                        tainted & 2 ? 'F' : ' ');
 128        }
 129        else
 130                snprintf(buf, sizeof(buf), "Not tainted");
 131        return(buf);
 132}
 133
 134int tainted = 0;
 135
 136/*
 137 * A BUG() call in an inline function in a header should be avoided,
 138 * because it can seriously bloat the kernel.  So here we have
 139 * helper functions.
 140 * We lose the BUG()-time file-and-line info this way, but it's
 141 * usually not very useful from an inline anyway.  The backtrace
 142 * tells us what we want to know.
 143 */
 144
 145void __out_of_line_bug(int line)
 146{
 147        printk("kernel BUG in header file at line %d\n", line);
 148
 149        BUG();
 150
 151        /* Satisfy __attribute__((noreturn)) */
 152        for ( ; ; )
 153                ;
 154}
 155
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.