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.40 2003/10/12 17:05:45 hbirr 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/kd.h>
36 #include <internal/ke.h>
37 #include <internal/ps.h>
39 #include <internal/debug.h>
41 #include "../../hal/halx86/include/hal.h"
43 /* GLOBALS ******************************************************************/
45 static LIST_ENTRY BugcheckCallbackListHead
= {NULL
,NULL
};
46 static ULONG InBugCheck
;
48 VOID
PsDumpThreads(VOID
);
50 /* FUNCTIONS *****************************************************************/
53 KeInitializeBugCheck(VOID
)
55 InitializeListHead(&BugcheckCallbackListHead
);
63 KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
)
73 KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
74 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
79 InsertTailList(&BugcheckCallbackListHead
, &CallbackRecord
->Entry
);
80 CallbackRecord
->Length
= Length
;
81 CallbackRecord
->Buffer
= Buffer
;
82 CallbackRecord
->Component
= Component
;
83 CallbackRecord
->CallbackRoutine
= CallbackRoutine
;
88 KeBugCheckWithTf(ULONG BugCheckCode
,
89 ULONG BugCheckParameter1
,
90 ULONG BugCheckParameter2
,
91 ULONG BugCheckParameter3
,
92 ULONG BugCheckParameter4
,
95 PRTL_MESSAGE_RESOURCE_ENTRY Message
;
99 /* Make sure we're switching back to the blue screen and print messages on it */
100 HalReleaseDisplayOwnership();
101 if (0 == (KdDebugState
& KD_DEBUG_GDB
))
103 KdDebugState
|= KD_DEBUG_SCREEN
;
107 if (KeGetCurrentIrql() < DISPATCH_LEVEL
)
109 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
111 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
118 Status
= RtlFindMessage((PVOID
)KERNEL_BASE
, //0xC0000000,
119 11, //RT_MESSAGETABLE,
123 if (NT_SUCCESS(Status
))
125 if (Message
->Flags
== 0)
126 DbgPrint(" %s\n", Message
->Text
);
128 DbgPrint(" %S\n", (PWSTR
)Message
->Text
);
132 DbgPrint(" No message text found!\n\n");
137 DbgPrint("Recursive bug check halting now\n");
144 KiDumpTrapFrame(Tf
, BugCheckParameter1
, BugCheckParameter2
);
145 MmDumpToPagingFile(BugCheckCode
, BugCheckParameter1
,
146 BugCheckParameter2
, BugCheckParameter3
,
147 BugCheckParameter4
, Tf
);
149 if (KdDebuggerEnabled
)
166 KeBugCheckEx(ULONG BugCheckCode
,
167 ULONG BugCheckParameter1
,
168 ULONG BugCheckParameter2
,
169 ULONG BugCheckParameter3
,
170 ULONG BugCheckParameter4
)
172 * FUNCTION: Brings the system down in a controlled manner when an
173 * inconsistency that might otherwise cause corruption has been detected
175 * BugCheckCode = Specifies the reason for the bug check
176 * BugCheckParameter[1-4] = Additional information about bug
180 PRTL_MESSAGE_RESOURCE_ENTRY Message
;
184 /* Make sure we're switching back to the blue screen and print messages on it */
185 HalReleaseDisplayOwnership();
186 if (0 == (KdDebugState
& KD_DEBUG_GDB
))
188 KdDebugState
|= KD_DEBUG_SCREEN
;
192 if (KeGetCurrentIrql() < DISPATCH_LEVEL
)
194 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
196 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
203 Status
= RtlFindMessage((PVOID
)KERNEL_BASE
, //0xC0000000,
204 11, //RT_MESSAGETABLE,
208 if (NT_SUCCESS(Status
))
210 if (Message
->Flags
== 0)
211 DbgPrint(" %s\n", Message
->Text
);
213 DbgPrint(" %S\n", (PWSTR
)Message
->Text
);
217 DbgPrint(" No message text found!\n\n");
222 DbgPrint("Recursive bug check halting now\n");
229 if (PsGetCurrentProcess() != NULL
)
231 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId
);
232 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName
);
234 if (PsGetCurrentThread() != NULL
)
236 DbgPrint("Thrd: %x Tid: %x\n",
237 PsGetCurrentThread(),
238 PsGetCurrentThread()->Cid
.UniqueThread
);
240 KeDumpStackFrames((PULONG
)__builtin_frame_address(0));
241 MmDumpToPagingFile(BugCheckCode
, BugCheckParameter1
,
242 BugCheckParameter2
, BugCheckParameter3
,
243 BugCheckParameter4
, NULL
);
245 if (KdDebuggerEnabled
)
262 KeBugCheck(ULONG BugCheckCode
)
264 * FUNCTION: Brings the system down in a controlled manner when an
265 * inconsistency that might otherwise cause corruption has been detected
267 * BugCheckCode = Specifies the reason for the bug check
271 KeBugCheckEx(BugCheckCode
, 0, 0, 0, 0);