panic.c 3.4 KB

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