3 * Copyright (C) 1998, 1999, 2000, 2001 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.17 2001/03/16 23:04:59 dwelch 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 *****************************************************************/
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
)
62 KeRegisterBugCheckCallback (PKBUGCHECK_CALLBACK_RECORD CallbackRecord
,
63 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
,
68 InsertTailList(&BugcheckCallbackListHead
, &CallbackRecord
->Entry
);
69 CallbackRecord
->Length
= Length
;
70 CallbackRecord
->Buffer
= Buffer
;
71 CallbackRecord
->Component
= Component
;
72 CallbackRecord
->CallbackRoutine
= CallbackRoutine
;
77 KeBugCheckEx (ULONG BugCheckCode
,
78 ULONG BugCheckParameter1
,
79 ULONG BugCheckParameter2
,
80 ULONG BugCheckParameter3
,
81 ULONG BugCheckParameter4
)
83 * FUNCTION: Brings the system down in a controlled manner when an
84 * inconsistency that might otherwise cause corruption has been detected
86 * BugCheckCode = Specifies the reason for the bug check
87 * BugCheckParameter[1-4] = Additional information about bug
91 /* PJS: disable interrupts first, then do the rest */
93 DbgPrint("Bug detected (code %x param %x %x %x %x)\n",BugCheckCode
,
94 BugCheckParameter1
,BugCheckParameter2
,BugCheckParameter3
,
96 if (PsGetCurrentProcess() != NULL
)
98 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId
);
99 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName
);
101 if (PsGetCurrentThread() != NULL
)
103 DbgPrint("Thrd: %x Tid: %x\n",
104 PsGetCurrentThread(),
105 PsGetCurrentThread()->Cid
.UniqueThread
);
108 KeDumpStackFrames(&((&BugCheckCode
)[-1]),64);
113 /* PJS: use HLT instruction, rather than busy wait */
122 KeBugCheck (ULONG BugCheckCode
)
124 * FUNCTION: Brings the system down in a controlled manner when an
125 * inconsistency that might otherwise cause corruption has been detected
127 * BugCheckCode = Specifies the reason for the bug check
132 DbgPrint("Bug detected (code %x)\n", BugCheckCode
);
135 DbgPrint("Recursive bug check halting now\n");
139 if (PsGetCurrentProcess() != NULL
)
141 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId
);
142 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName
);
144 if (PsGetCurrentThread() != NULL
)
146 DbgPrint("Thrd: %x Tid: %x\n",
147 PsGetCurrentThread(),
148 PsGetCurrentThread()->Cid
.UniqueThread
);
151 KeDumpStackFrames(&((&BugCheckCode
)[-1]), 80);