3 * Copyright (C) 1998, 1999, 2000, 2001, 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: bug.c,v 1.45 2004/08/15 16:39:05 chorns Exp $
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/ke/bug.c
23 * PURPOSE: Graceful system shutdown if a bug is detected
24 * PROGRAMMER: David Welch (welch@cwcom.net)
25 * PORTABILITY: Unchecked
28 * Phillip Susi: 12/8/99: Minor fix
31 /* INCLUDES *****************************************************************/
34 #include <ntos/bootvid.h>
35 #include <internal/debug.h>
36 #include "../../hal/halx86/include/hal.h"
38 /* GLOBALS ******************************************************************/
40 static LIST_ENTRY BugcheckCallbackListHead
= {NULL
,NULL
};
41 static ULONG InBugCheck
;
43 VOID
PsDumpThreads(VOID
);
45 /* FUNCTIONS *****************************************************************/
48 KeInitializeBugCheck(VOID
)
50 InitializeListHead(&BugcheckCallbackListHead
);
58 KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
)
68 KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
69 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
74 InsertTailList(&BugcheckCallbackListHead
, &CallbackRecord
->Entry
);
75 CallbackRecord
->Length
= Length
;
76 CallbackRecord
->Buffer
= Buffer
;
77 CallbackRecord
->Component
= Component
;
78 CallbackRecord
->CallbackRoutine
= CallbackRoutine
;
83 KeBugCheckWithTf(ULONG BugCheckCode
,
84 ULONG BugCheckParameter1
,
85 ULONG BugCheckParameter2
,
86 ULONG BugCheckParameter3
,
87 ULONG BugCheckParameter4
,
90 PRTL_MESSAGE_RESOURCE_ENTRY Message
;
94 /* Make sure we're switching back to the blue screen and print messages on it */
95 HalReleaseDisplayOwnership();
96 if (0 == (KdDebugState
& KD_DEBUG_GDB
))
98 KdDebugState
|= KD_DEBUG_SCREEN
;
101 Ke386DisableInterrupts();
102 DebugLogDumpMessages();
104 if (KeGetCurrentIrql() < DISPATCH_LEVEL
)
106 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
108 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
115 Status
= RtlFindMessage((PVOID
)KERNEL_BASE
, //0xC0000000,
116 11, //RT_MESSAGETABLE,
120 if (NT_SUCCESS(Status
))
122 if (Message
->Flags
== 0)
123 DbgPrint(" %s\n", Message
->Text
);
125 DbgPrint(" %S\n", (PWSTR
)Message
->Text
);
129 DbgPrint(" No message text found!\n\n");
134 DbgPrint("Recursive bug check halting now\n");
135 Ke386HaltProcessor();
140 KiDumpTrapFrame(Tf
, BugCheckParameter1
, BugCheckParameter2
);
144 #if defined(__GNUC__)
145 KeDumpStackFrames((PULONG
)__builtin_frame_address(0));
146 #elif defined(_MSC_VER)
148 __asm call KeDumpStackFrames
151 #error Unknown compiler for inline assembler
154 MmDumpToPagingFile(BugCheckCode
, BugCheckParameter1
,
155 BugCheckParameter2
, BugCheckParameter3
,
156 BugCheckParameter4
, Tf
);
158 if (KdDebuggerEnabled
)
160 Ke386EnableInterrupts();
161 DbgBreakPointNoBugCheck();
162 Ke386DisableInterrupts();
167 Ke386HaltProcessor();
175 KeBugCheckEx(ULONG BugCheckCode
,
176 ULONG BugCheckParameter1
,
177 ULONG BugCheckParameter2
,
178 ULONG BugCheckParameter3
,
179 ULONG BugCheckParameter4
)
181 * FUNCTION: Brings the system down in a controlled manner when an
182 * inconsistency that might otherwise cause corruption has been detected
184 * BugCheckCode = Specifies the reason for the bug check
185 * BugCheckParameter[1-4] = Additional information about bug
189 KeBugCheckWithTf(BugCheckCode
, BugCheckParameter1
, BugCheckParameter2
,
190 BugCheckParameter3
, BugCheckParameter4
, NULL
);
197 KeBugCheck(ULONG BugCheckCode
)
199 * FUNCTION: Brings the system down in a controlled manner when an
200 * inconsistency that might otherwise cause corruption has been detected
202 * BugCheckCode = Specifies the reason for the bug check
206 KeBugCheckEx(BugCheckCode
, 0, 0, 0, 0);