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.
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 *****************************************************************/
33 #include <ddk/ntddk.h>
34 #include <internal/ke.h>
35 #include <internal/ps.h>
37 #include <internal/debug.h>
39 /* GLOBALS ******************************************************************/
41 static LIST_ENTRY BugcheckCallbackListHead = {NULL,NULL};
42 static ULONG InBugCheck;
44 VOID PsDumpThreads(VOID);
46 /* FUNCTIONS *****************************************************************/
49 KeInitializeBugCheck(VOID)
51 InitializeListHead(&BugcheckCallbackListHead);
56 KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
63 KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
64 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
69 InsertTailList(&BugcheckCallbackListHead, &CallbackRecord->Entry);
70 CallbackRecord->Length = Length;
71 CallbackRecord->Buffer = Buffer;
72 CallbackRecord->Component = Component;
73 CallbackRecord->CallbackRoutine = CallbackRoutine;
78 KeBugCheckWithTf(ULONG BugCheckCode,
79 ULONG BugCheckParameter1,
80 ULONG BugCheckParameter2,
81 ULONG BugCheckParameter3,
82 ULONG BugCheckParameter4,
85 PRTL_MESSAGE_RESOURCE_ENTRY Message;
89 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
96 Status = RtlFindMessage((PVOID)KERNEL_BASE, //0xC0000000,
97 11, //RT_MESSAGETABLE,
101 if (NT_SUCCESS(Status))
103 if (Message->Flags == 0)
104 DbgPrint(" %s\n", Message->Text);
106 DbgPrint(" %S\n", (PWSTR)Message->Text);
110 DbgPrint(" No message text found!\n\n");
115 DbgPrint("Recursive bug check halting now\n");
122 KiDumpTrapFrame(Tf, BugCheckParameter1, BugCheckParameter2);
123 MmDumpToPagingFile(BugCheckCode, BugCheckParameter1,
124 BugCheckParameter2, BugCheckParameter3,
125 BugCheckParameter4, Tf);
127 if (KdDebuggerEnabled)
141 KeBugCheckEx(ULONG BugCheckCode,
142 ULONG BugCheckParameter1,
143 ULONG BugCheckParameter2,
144 ULONG BugCheckParameter3,
145 ULONG BugCheckParameter4)
147 * FUNCTION: Brings the system down in a controlled manner when an
148 * inconsistency that might otherwise cause corruption has been detected
150 * BugCheckCode = Specifies the reason for the bug check
151 * BugCheckParameter[1-4] = Additional information about bug
155 PRTL_MESSAGE_RESOURCE_ENTRY Message;
159 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
166 Status = RtlFindMessage((PVOID)KERNEL_BASE, //0xC0000000,
167 11, //RT_MESSAGETABLE,
171 if (NT_SUCCESS(Status))
173 if (Message->Flags == 0)
174 DbgPrint(" %s\n", Message->Text);
176 DbgPrint(" %S\n", (PWSTR)Message->Text);
180 DbgPrint(" No message text found!\n\n");
185 DbgPrint("Recursive bug check halting now\n");
192 if (PsGetCurrentProcess() != NULL)
194 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId);
195 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName);
197 if (PsGetCurrentThread() != NULL)
199 DbgPrint("Thrd: %x Tid: %x\n",
200 PsGetCurrentThread(),
201 PsGetCurrentThread()->Cid.UniqueThread);
203 KeDumpStackFrames((PULONG)__builtin_frame_address(0));
204 MmDumpToPagingFile(BugCheckCode, BugCheckParameter1,
205 BugCheckParameter2, BugCheckParameter3,
206 BugCheckParameter4, NULL);
208 if (KdDebuggerEnabled)
222 KeBugCheck(ULONG BugCheckCode)
224 * FUNCTION: Brings the system down in a controlled manner when an
225 * inconsistency that might otherwise cause corruption has been detected
227 * BugCheckCode = Specifies the reason for the bug check
231 KeBugCheckEx(BugCheckCode, 0, 0, 0, 0);