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.36 2003/08/22 14:49:54 gvg 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 * The bug check may have happened while the bootscreen image was displayed.
100 * If this happened, switch back to text mode.
102 if (InbvIsBootDriverInstalled())
104 InbvEnableBootDriver(FALSE
);
107 /* Make sure we're switching back to the blue screen and print messages on it */
108 HalReleaseDisplayOwnership();
109 if (0 == (KdDebugState
& KD_DEBUG_GDB
))
111 KdDebugState
|= KD_DEBUG_SCREEN
;
115 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
122 Status
= RtlFindMessage((PVOID
)KERNEL_BASE
, //0xC0000000,
123 11, //RT_MESSAGETABLE,
127 if (NT_SUCCESS(Status
))
129 if (Message
->Flags
== 0)
130 DbgPrint(" %s\n", Message
->Text
);
132 DbgPrint(" %S\n", (PWSTR
)Message
->Text
);
136 DbgPrint(" No message text found!\n\n");
141 DbgPrint("Recursive bug check halting now\n");
148 KiDumpTrapFrame(Tf
, BugCheckParameter1
, BugCheckParameter2
);
149 MmDumpToPagingFile(BugCheckCode
, BugCheckParameter1
,
150 BugCheckParameter2
, BugCheckParameter3
,
151 BugCheckParameter4
, Tf
);
153 if (KdDebuggerEnabled
)
170 KeBugCheckEx(ULONG BugCheckCode
,
171 ULONG BugCheckParameter1
,
172 ULONG BugCheckParameter2
,
173 ULONG BugCheckParameter3
,
174 ULONG BugCheckParameter4
)
176 * FUNCTION: Brings the system down in a controlled manner when an
177 * inconsistency that might otherwise cause corruption has been detected
179 * BugCheckCode = Specifies the reason for the bug check
180 * BugCheckParameter[1-4] = Additional information about bug
184 PRTL_MESSAGE_RESOURCE_ENTRY Message
;
188 * The bug check may have happened while the bootscreen image was displayed.
189 * If this happened, switch back to text mode.
191 if (InbvIsBootDriverInstalled())
193 InbvEnableBootDriver(FALSE
);
196 /* Make sure we're switching back to the blue screen and print messages on it */
197 HalReleaseDisplayOwnership();
198 KdDebugState
|= KD_DEBUG_SCREEN
;
201 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
208 Status
= RtlFindMessage((PVOID
)KERNEL_BASE
, //0xC0000000,
209 11, //RT_MESSAGETABLE,
213 if (NT_SUCCESS(Status
))
215 if (Message
->Flags
== 0)
216 DbgPrint(" %s\n", Message
->Text
);
218 DbgPrint(" %S\n", (PWSTR
)Message
->Text
);
222 DbgPrint(" No message text found!\n\n");
227 DbgPrint("Recursive bug check halting now\n");
234 if (PsGetCurrentProcess() != NULL
)
236 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId
);
237 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName
);
239 if (PsGetCurrentThread() != NULL
)
241 DbgPrint("Thrd: %x Tid: %x\n",
242 PsGetCurrentThread(),
243 PsGetCurrentThread()->Cid
.UniqueThread
);
245 KeDumpStackFrames((PULONG
)__builtin_frame_address(0));
246 MmDumpToPagingFile(BugCheckCode
, BugCheckParameter1
,
247 BugCheckParameter2
, BugCheckParameter3
,
248 BugCheckParameter4
, NULL
);
250 if (KdDebuggerEnabled
)
267 KeBugCheck(ULONG BugCheckCode
)
269 * FUNCTION: Brings the system down in a controlled manner when an
270 * inconsistency that might otherwise cause corruption has been detected
272 * BugCheckCode = Specifies the reason for the bug check
276 KeBugCheckEx(BugCheckCode
, 0, 0, 0, 0);