crash.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*++
  2. Copyright (c) 2012 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. crash.c
  9. Abstract:
  10. This module implements support for the unfortunate event of a fatal system
  11. error.
  12. Author:
  13. Evan Green 25-Sep-2012
  14. Environment:
  15. Kernel
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. #include <minoca/kernel/kernel.h>
  21. #include <minoca/kernel/kdebug.h>
  22. #include "kep.h"
  23. //
  24. // ---------------------------------------------------------------- Definitions
  25. //
  26. //
  27. // ------------------------------------------------------ Data Type Definitions
  28. //
  29. //
  30. // ----------------------------------------------- Internal Function Prototypes
  31. //
  32. //
  33. // -------------------------------------------------------------------- Globals
  34. //
  35. //
  36. // ------------------------------------------------------------------ Functions
  37. //
  38. KERNEL_API
  39. VOID
  40. KeCrashSystemEx (
  41. ULONG CrashCode,
  42. PCSTR CrashCodeString,
  43. ULONGLONG Parameter1,
  44. ULONGLONG Parameter2,
  45. ULONGLONG Parameter3,
  46. ULONGLONG Parameter4
  47. )
  48. /*++
  49. Routine Description:
  50. This routine officially takes the system down after a fatal system error
  51. has occurred. This function does not return.
  52. Arguments:
  53. CrashCode - Supplies the reason for the system crash.
  54. CrashCodeString - Supplies the string corresponding to the given crash
  55. code. This parameter is generated by the macro, and should not be
  56. filled in directly.
  57. Parameter1 - Supplies an optional parameter regarding the crash.
  58. Parameter2 - Supplies an optional parameter regarding the crash.
  59. Parameter3 - Supplies an optional parameter regarding the crash.
  60. Parameter4 - Supplies an optional parameter regarding the crash.
  61. Return Value:
  62. None. This function does not return.
  63. --*/
  64. {
  65. KSTATUS Status;
  66. KeRaiseRunLevel(RunLevelHigh);
  67. //
  68. // TODO: Freeze all processors before writing crash dump.
  69. //
  70. ArDisableInterrupts();
  71. RtlDebugPrint("\n\n"
  72. "**********************************************************"
  73. "**********************\n"
  74. "* "
  75. " *\n"
  76. "* Fatal System Error "
  77. " *\n"
  78. "* "
  79. " *\n"
  80. "**********************************************************"
  81. "**********************\n\n"
  82. "Error Code: %s (0x%x)\n"
  83. "Parameter1: 0x%08I64x\n"
  84. "Parameter2: 0x%08I64x\n"
  85. "Parameter3: 0x%08I64x\n"
  86. "Parameter4: 0x%08I64x\n\n",
  87. CrashCodeString,
  88. CrashCode,
  89. Parameter1,
  90. Parameter2,
  91. Parameter3,
  92. Parameter4);
  93. KdBreak();
  94. //
  95. // Proceed to attempt writing a crash dump to disk. If this succeeds then
  96. // reset the system.
  97. //
  98. Status = KepWriteCrashDump(CrashCode,
  99. Parameter1,
  100. Parameter2,
  101. Parameter3,
  102. Parameter4);
  103. //
  104. // TODO: Remove the forced failure when crash dumps are finished.
  105. //
  106. Status = STATUS_UNSUCCESSFUL;
  107. if (KSUCCESS(Status)) {
  108. KdDisconnect();
  109. Status = HlResetSystem(SystemResetWarm, NULL, 0);
  110. KdConnect();
  111. RtlDebugPrint("System reset unsuccessful: %d\n", Status);
  112. }
  113. //
  114. // Spin forever.
  115. //
  116. while (TRUE) {
  117. KdBreak();
  118. }
  119. }
  120. //
  121. // --------------------------------------------------------- Internal Functions
  122. //