ReactOS 0.4.16-dev-125-g798ea90
bug.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for bug.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PVOID NTAPI KiPcToFileHeader (IN PVOID Pc, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry, IN BOOLEAN DriversOnly, OUT PBOOLEAN InKernel)
 
PVOID NTAPI KiRosPcToUserFileHeader (IN PVOID Pc, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry)
 
USHORT NTAPI KeRosCaptureUserStackBackTrace (IN ULONG FramesToSkip, IN ULONG FramesToCapture, OUT PVOID *BackTrace, OUT PULONG BackTraceHash OPTIONAL)
 
VOID FASTCALL KeRosDumpStackFrameArray (IN PULONG_PTR Frames, IN ULONG FrameCount)
 
VOID NTAPI KeRosDumpStackFrames (IN PULONG_PTR Frame OPTIONAL, IN ULONG FrameCount OPTIONAL)
 
VOID NTAPI KiInitializeBugCheck (VOID)
 
BOOLEAN NTAPI KeGetBugMessageText (IN ULONG BugCheckCode, OUT PANSI_STRING OutputString OPTIONAL)
 
VOID NTAPI KiDoBugCheckCallbacks (VOID)
 
VOID NTAPI KiBugCheckDebugBreak (IN ULONG StatusCode)
 
PCHAR NTAPI KeBugCheckUnicodeToAnsi (IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
 
VOID NTAPI KiDumpParameterImages (IN PCHAR Message, IN PULONG_PTR Parameters, IN ULONG ParameterCount, IN PKE_BUGCHECK_UNICODE_TO_ANSI ConversionRoutine)
 
VOID NTAPI KiDisplayBlueScreen (IN ULONG MessageId, IN BOOLEAN IsHardError, IN PCHAR HardErrCaption OPTIONAL, IN PCHAR HardErrMessage OPTIONAL, IN PCHAR Message)
 
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf (IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4, IN PKTRAP_FRAME TrapFrame)
 
BOOLEAN NTAPI KiHandleNmi (VOID)
 
NTSTATUS NTAPI KeInitializeCrashDumpHeader (IN ULONG Type, IN ULONG Flags, OUT PVOID Buffer, IN ULONG BufferSize, OUT ULONG BufferNeeded OPTIONAL)
 
BOOLEAN NTAPI KeDeregisterBugCheckCallback (IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
 
BOOLEAN NTAPI KeDeregisterBugCheckReasonCallback (IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord)
 
BOOLEAN NTAPI KeRegisterBugCheckCallback (IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord, IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Buffer, IN ULONG Length, IN PUCHAR Component)
 
BOOLEAN NTAPI KeRegisterBugCheckReasonCallback (IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord, IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine, IN KBUGCHECK_CALLBACK_REASON Reason, IN PUCHAR Component)
 
PVOID NTAPI KeRegisterNmiCallback (IN PNMI_CALLBACK CallbackRoutine, IN PVOID Context)
 
NTSTATUS NTAPI KeDeregisterNmiCallback (IN PVOID Handle)
 
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx (IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
 
DECLSPEC_NORETURN VOID NTAPI KeBugCheck (ULONG BugCheckCode)
 
VOID NTAPI KeEnterKernelDebugger (VOID)
 

Variables

LIST_ENTRY KeBugcheckCallbackListHead
 
LIST_ENTRY KeBugcheckReasonCallbackListHead
 
KSPIN_LOCK BugCheckCallbackLock
 
ULONG KeBugCheckActive
 
ULONG KeBugCheckOwner
 
LONG KeBugCheckOwnerRecursionCount
 
PMESSAGE_RESOURCE_DATA KiBugCodeMessages
 
ULONG KeBugCheckCount = 1
 
ULONG KiHardwareTrigger
 
PUNICODE_STRING KiBugCheckDriver
 
ULONG_PTR KiBugCheckData [5]
 
PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead = NULL
 
KSPIN_LOCK KiNmiCallbackListLock
 
UNICODE_STRING KeRosProcessorName
 
UNICODE_STRING KeRosBiosDate
 
UNICODE_STRING KeRosBiosVersion
 
UNICODE_STRING KeRosVideoBiosDate
 
UNICODE_STRING KeRosVideoBiosVersion
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file bug.c.

Function Documentation

◆ KeBugCheck()

DECLSPEC_NORETURN VOID NTAPI KeBugCheck ( ULONG  BugCheckCode)

Definition at line 1430 of file bug.c.

1431{
1432 /* Call the internal API */
1433 KeBugCheckWithTf(BugCheckCode, 0, 0, 0, 0, NULL);
1434}
DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4, IN PKTRAP_FRAME TrapFrame)
Definition: bug.c:712
#define NULL
Definition: types.h:112

Referenced by _Success_(), CcInitCacheZeroPage(), CcpDereferenceCache(), CcRosRequestVacb(), CcScheduleReadAhead(), ClassSendStartUnit(), ExeFmtpReadFile(), ExInitSystem(), ExpInitializeExecutive(), ExpInitNls(), FsRtlCreateSectionForDataScan(), HalpInitializeTsc(), i8042KbdInterruptService(), KdbEnterDebuggerException(), KdpCauseBugCheck(), KeDetachProcess(), Kei386EoiHelper(), KeRaiseIrqlToDpcLevel(), KeUnstackDetachProcess(), KeWaitForMultipleObjects(), KfLowerIrql(), KfRaiseIrql(), KiInitializeCpu(), KiSetAffinityThread(), KiThreadStartup(), KiUnexpectedInterrupt(), MiBalancerThread(), MiInitBalancerThread(), MiReadPageFile(), MiRosUnmapViewOfSection(), MiTrimMemoryConsumer(), MmAccessFaultSectionView(), MmAllocSwapPage(), MmCreatePageFileMapping(), MmCreateVirtualMapping(), MmCreateVirtualMappingUnsafeEx(), MmDeleteRmap(), MmFreeSwapPage(), MmInsertRmap(), MmNotPresentFaultSectionView(), MmPageOutPhysicalAddress(), MmpPageOutPhysicalAddress(), MmReleasePageMemoryConsumer(), MmSetDirtyBit(), MmSetPageProtect(), MmSharePageEntrySectionSegment(), MmspPageAlignSegments(), MmUnsharePageEntrySectionSegment(), MmWriteToSwapPage(), MupDereferenceMasterQueryContext(), Phase1InitializationDiscard(), PpInitSystem(), PspDeleteProcess(), PspDeleteThread(), PspSystemThreadStartup(), RawDispatch(), TdiAddressSizeFromType(), USBCCGP_PDOSelectConfiguration(), UserProcessCreate(), VfatReadFileData(), VfatWriteFileData(), and xHalIoAssignDriveLetters().

◆ KeBugCheckEx()

DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx ( IN ULONG  BugCheckCode,
IN ULONG_PTR  BugCheckParameter1,
IN ULONG_PTR  BugCheckParameter2,
IN ULONG_PTR  BugCheckParameter3,
IN ULONG_PTR  BugCheckParameter4 
)

Definition at line 1409 of file bug.c.

1414{
1415 /* Call the internal API */
1416 KeBugCheckWithTf(BugCheckCode,
1417 BugCheckParameter1,
1418 BugCheckParameter2,
1419 BugCheckParameter3,
1420 BugCheckParameter4,
1421 NULL);
1422}

◆ KeBugCheckUnicodeToAnsi()

PCHAR NTAPI KeBugCheckUnicodeToAnsi ( IN PUNICODE_STRING  Unicode,
OUT PCHAR  Ansi,
IN ULONG  Length 
)

Definition at line 518 of file bug.c.

521{
522 PCHAR p;
523 PWCHAR pw;
524 ULONG i;
525
526 /* Set length and normalize it */
527 i = Unicode->Length / sizeof(WCHAR);
528 i = min(i, Length - 1);
529
530 /* Set source and destination, and copy */
531 pw = Unicode->Buffer;
532 p = Ansi;
533 while (i--) *p++ = (CHAR)*pw++;
534
535 /* Null terminate and return */
536 *p = ANSI_NULL;
537 return Ansi;
538}
#define CHAR(Char)
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define min(a, b)
Definition: monoChain.cc:55
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by KeBugCheckWithTf(), KeRosDumpStackFrameArray(), and KiDisplayBlueScreen().

◆ KeBugCheckWithTf()

DECLSPEC_NORETURN VOID NTAPI KeBugCheckWithTf ( IN ULONG  BugCheckCode,
IN ULONG_PTR  BugCheckParameter1,
IN ULONG_PTR  BugCheckParameter2,
IN ULONG_PTR  BugCheckParameter3,
IN ULONG_PTR  BugCheckParameter4,
IN PKTRAP_FRAME  TrapFrame 
)

Definition at line 712 of file bug.c.

718{
719 PKPRCB Prcb = KeGetCurrentPrcb();
721 ULONG MessageId;
722 CHAR AnsiName[128];
723 BOOLEAN IsSystem, IsHardError = FALSE, Reboot = FALSE;
724 PCHAR HardErrCaption = NULL, HardErrMessage = NULL;
725 PVOID Pc = NULL, Memory;
726 PVOID DriverBase;
727 PLDR_DATA_TABLE_ENTRY LdrEntry;
728 PULONG_PTR HardErrorParameters;
730
731 /* Set active bugcheck */
734
735 /* Check if this is power failure simulation */
736 if (BugCheckCode == POWER_FAILURE_SIMULATE)
737 {
738 /* Call the Callbacks and reboot */
741 }
742
743 /* Save the IRQL and set hardware trigger */
746
747 /* Capture the CPU Context */
751
752 /* FIXME: Call the Watchdog if it's registered */
753
754 /* Check which bugcode this is */
755 switch (BugCheckCode)
756 {
757 /* These bug checks already have detailed messages, keep them */
758 case UNEXPECTED_KERNEL_MODE_TRAP:
759 case DRIVER_CORRUPTED_EXPOOL:
760 case ACPI_BIOS_ERROR:
761 case ACPI_BIOS_FATAL_ERROR:
762 case THREAD_STUCK_IN_DEVICE_DRIVER:
763 case DATA_BUS_ERROR:
764 case FAT_FILE_SYSTEM:
765 case NO_MORE_SYSTEM_PTES:
766 case INACCESSIBLE_BOOT_DEVICE:
767
768 /* Keep the same code */
769 MessageId = BugCheckCode;
770 break;
771
772 /* Check if this is a kernel-mode exception */
773 case KERNEL_MODE_EXCEPTION_NOT_HANDLED:
774 case SYSTEM_THREAD_EXCEPTION_NOT_HANDLED:
775 case KMODE_EXCEPTION_NOT_HANDLED:
776
777 /* Use the generic text message */
778 MessageId = KMODE_EXCEPTION_NOT_HANDLED;
779 break;
780
781 /* File-system errors */
782 case NTFS_FILE_SYSTEM:
783
784 /* Use the generic message for FAT */
785 MessageId = FAT_FILE_SYSTEM;
786 break;
787
788 /* Check if this is a coruption of the Mm's Pool */
789 case DRIVER_CORRUPTED_MMPOOL:
790
791 /* Use generic corruption message */
792 MessageId = DRIVER_CORRUPTED_EXPOOL;
793 break;
794
795 /* Check if this is a signature check failure */
797
798 /* Use the generic corruption message */
799 MessageId = BUGCODE_PSS_MESSAGE_SIGNATURE;
800 break;
801
802 /* All other codes */
803 default:
804
805 /* Use the default bugcheck message */
806 MessageId = BUGCODE_PSS_MESSAGE;
807 break;
808 }
809
810 /* Save bugcheck data */
811 KiBugCheckData[0] = BugCheckCode;
812 KiBugCheckData[1] = BugCheckParameter1;
813 KiBugCheckData[2] = BugCheckParameter2;
814 KiBugCheckData[3] = BugCheckParameter3;
815 KiBugCheckData[4] = BugCheckParameter4;
816
817 /* Now check what bugcheck this is */
818 switch (BugCheckCode)
819 {
820 /* Invalid access to R/O memory or Unhandled KM Exception */
821 case KERNEL_MODE_EXCEPTION_NOT_HANDLED:
822 case ATTEMPTED_WRITE_TO_READONLY_MEMORY:
823 case ATTEMPTED_EXECUTE_OF_NOEXECUTE_MEMORY:
824 {
825 /* Check if we have a trap frame */
826 if (!TrapFrame)
827 {
828 /* Use parameter 3 as a trap frame, if it exists */
829 if (BugCheckParameter3) TrapFrame = (PVOID)BugCheckParameter3;
830 }
831
832 /* Check if we got one now and if we need to get the Program Counter */
833 if ((TrapFrame) &&
834 (BugCheckCode != KERNEL_MODE_EXCEPTION_NOT_HANDLED))
835 {
836 /* Get the Program Counter */
837 Pc = (PVOID)KeGetTrapFramePc(TrapFrame);
838 }
839 break;
840 }
841
842 /* Wrong IRQL */
843 case IRQL_NOT_LESS_OR_EQUAL:
844 {
845 /*
846 * The NT kernel has 3 special sections:
847 * MISYSPTE, POOLMI and POOLCODE. The bug check code can
848 * determine in which of these sections this bugcode happened
849 * and provide a more detailed analysis. For now, we don't.
850 */
851
852 /* Program Counter is in parameter 4 */
853 Pc = (PVOID)BugCheckParameter4;
854
855 /* Get the driver base */
856 DriverBase = KiPcToFileHeader(Pc,
857 &LdrEntry,
858 FALSE,
859 &IsSystem);
860 if (IsSystem)
861 {
862 /*
863 * The error happened inside the kernel or HAL.
864 * Get the memory address that was being referenced.
865 */
866 Memory = (PVOID)BugCheckParameter1;
867
868 /* Find to which driver it belongs */
869 DriverBase = KiPcToFileHeader(Memory,
870 &LdrEntry,
871 TRUE,
872 &IsSystem);
873 if (DriverBase)
874 {
875 /* Get the driver name and update the bug code */
876 KiBugCheckDriver = &LdrEntry->BaseDllName;
877 KiBugCheckData[0] = DRIVER_PORTION_MUST_BE_NONPAGED;
878 }
879 else
880 {
881 /* Find the driver that unloaded at this address */
882 KiBugCheckDriver = NULL; // FIXME: ROS can't locate
883
884 /* Check if the cause was an unloaded driver */
886 {
887 /* Update bug check code */
888 KiBugCheckData[0] =
889 SYSTEM_SCAN_AT_RAISED_IRQL_CAUGHT_IMPROPER_DRIVER_UNLOAD;
890 }
891 }
892 }
893 else
894 {
895 /* Update the bug check code */
896 KiBugCheckData[0] = DRIVER_IRQL_NOT_LESS_OR_EQUAL;
897 }
898
899 /* Clear Pc so we don't look it up later */
900 Pc = NULL;
901 break;
902 }
903
904 /* Hard error */
905 case FATAL_UNHANDLED_HARD_ERROR:
906 {
907 /* Copy bug check data from hard error */
908 HardErrorParameters = (PULONG_PTR)BugCheckParameter2;
909 KiBugCheckData[0] = BugCheckParameter1;
910 KiBugCheckData[1] = HardErrorParameters[0];
911 KiBugCheckData[2] = HardErrorParameters[1];
912 KiBugCheckData[3] = HardErrorParameters[2];
913 KiBugCheckData[4] = HardErrorParameters[3];
914
915 /* Remember that this is hard error and set the caption/message */
916 IsHardError = TRUE;
917 HardErrCaption = (PCHAR)BugCheckParameter3;
918 HardErrMessage = (PCHAR)BugCheckParameter4;
919 break;
920 }
921
922 /* Page fault */
923 case PAGE_FAULT_IN_NONPAGED_AREA:
924 {
925 /* Assume no driver */
926 DriverBase = NULL;
927
928 /* Check if we have a trap frame */
929 if (!TrapFrame)
930 {
931 /* We don't, use parameter 3 if possible */
932 if (BugCheckParameter3) TrapFrame = (PVOID)BugCheckParameter3;
933 }
934
935 /* Check if we have a frame now */
936 if (TrapFrame)
937 {
938 /* Get the Program Counter */
939 Pc = (PVOID)KeGetTrapFramePc(TrapFrame);
940 KiBugCheckData[3] = (ULONG_PTR)Pc;
941
942 /* Find out if was in the kernel or drivers */
943 DriverBase = KiPcToFileHeader(Pc,
944 &LdrEntry,
945 FALSE,
946 &IsSystem);
947 }
948 else
949 {
950 /* Can't blame a driver, assume system */
951 IsSystem = TRUE;
952 }
953
954 /* FIXME: Check for session pool in addition to special pool */
955
956 /* Special pool has its own bug check codes */
957 if (MmIsSpecialPoolAddress((PVOID)BugCheckParameter1))
958 {
959 if (MmIsSpecialPoolAddressFree((PVOID)BugCheckParameter1))
960 {
961 KiBugCheckData[0] = IsSystem
962 ? PAGE_FAULT_IN_FREED_SPECIAL_POOL
963 : DRIVER_PAGE_FAULT_IN_FREED_SPECIAL_POOL;
964 }
965 else
966 {
967 KiBugCheckData[0] = IsSystem
968 ? PAGE_FAULT_BEYOND_END_OF_ALLOCATION
969 : DRIVER_PAGE_FAULT_BEYOND_END_OF_ALLOCATION;
970 }
971 }
972 else if (!DriverBase)
973 {
974 /* Find the driver that unloaded at this address */
975 KiBugCheckDriver = NULL; // FIXME: ROS can't locate
976
977 /* Check if the cause was an unloaded driver */
979 {
980 KiBugCheckData[0] =
981 DRIVER_UNLOADED_WITHOUT_CANCELLING_PENDING_OPERATIONS;
982 }
983 }
984 break;
985 }
986
987 /* Check if the driver forgot to unlock pages */
988 case DRIVER_LEFT_LOCKED_PAGES_IN_PROCESS:
989
990 /* Program Counter is in parameter 1 */
991 Pc = (PVOID)BugCheckParameter1;
992 break;
993
994 /* Check if the driver consumed too many PTEs */
995 case DRIVER_USED_EXCESSIVE_PTES:
996
997 /* Loader entry is in parameter 1 */
998 LdrEntry = (PVOID)BugCheckParameter1;
999 KiBugCheckDriver = &LdrEntry->BaseDllName;
1000 break;
1001
1002 /* Check if the driver has a stuck thread */
1003 case THREAD_STUCK_IN_DEVICE_DRIVER:
1004
1005 /* The name is in Parameter 3 */
1006 KiBugCheckDriver = (PVOID)BugCheckParameter3;
1007 break;
1008
1009 /* Anything else */
1010 default:
1011 break;
1012 }
1013
1014 /* Do we have a driver name? */
1015 if (KiBugCheckDriver)
1016 {
1017 /* Convert it to ANSI */
1018 KeBugCheckUnicodeToAnsi(KiBugCheckDriver, AnsiName, sizeof(AnsiName));
1019 }
1020 else
1021 {
1022 /* Do we have a Program Counter? */
1023 if (Pc)
1024 {
1025 /* Dump image name */
1026 KiDumpParameterImages(AnsiName,
1027 (PULONG_PTR)&Pc,
1028 1,
1030 }
1031 }
1032
1033 /* Check if we need to save the context for KD */
1035
1036 /* Check if a debugger is connected */
1037 if ((BugCheckCode != MANUALLY_INITIATED_CRASH) && (KdDebuggerEnabled))
1038 {
1039 /* Crash on the debugger console */
1040 DbgPrint("\n*** Fatal System Error: 0x%08lx\n"
1041 " (0x%p,0x%p,0x%p,0x%p)\n\n",
1042 KiBugCheckData[0],
1043 KiBugCheckData[1],
1044 KiBugCheckData[2],
1045 KiBugCheckData[3],
1046 KiBugCheckData[4]);
1047
1048 /* Check if the debugger isn't currently connected */
1050 {
1051 /* Check if we have a driver to blame */
1052 if (KiBugCheckDriver)
1053 {
1054 /* Dump it */
1055 DbgPrint("Driver at fault: %s.\n", AnsiName);
1056 }
1057
1058 /* Check if this was a hard error */
1059 if (IsHardError)
1060 {
1061 /* Print caption and message */
1062 if (HardErrCaption) DbgPrint(HardErrCaption);
1063 if (HardErrMessage) DbgPrint(HardErrMessage);
1064 }
1065
1066 /* Break in the debugger */
1068 }
1069 }
1070
1071 /* Raise IRQL to HIGH_LEVEL */
1072 _disable();
1074
1075 /* Avoid recursion */
1077 {
1078#ifdef CONFIG_SMP
1079 /* Set CPU that is bug checking now */
1080 KeBugCheckOwner = Prcb->Number;
1081
1082 /* Freeze the other CPUs */
1083 for (ULONG i = 0; i < KeNumberProcessors; i++)
1084 {
1085 if (i != Prcb->Number)
1086 {
1087 /* Send the IPI */
1089 }
1090 }
1091
1092 /* Give the other CPUs one second to catch up */
1094#endif
1095
1096 /* Display the BSOD */
1097 KiDisplayBlueScreen(MessageId,
1098 IsHardError,
1099 HardErrCaption,
1100 HardErrMessage,
1101 AnsiName);
1102
1103 // TODO/FIXME: Run the registered reason-callbacks from
1104 // the KeBugcheckReasonCallbackListHead list with the
1105 // KbCallbackReserved1 reason.
1106
1107 /* Check if the debugger is disabled but we can enable it */
1109 {
1110 /* Enable it */
1112 }
1113 else
1114 {
1115 /* Otherwise, print the last line */
1116 InbvDisplayString("\r\n");
1117 }
1118
1119 /* Save the context */
1121
1122 /* FIXME: Support Triage Dump */
1123
1124 /* FIXME: Write the crash dump */
1125 }
1126 else
1127 {
1128 /* Increase recursion count */
1131 {
1132 /* Break in the debugger */
1134 }
1135 else if (KeBugCheckOwnerRecursionCount > 2)
1136 {
1137 /* Halt execution */
1138 while (TRUE);
1139 }
1140 }
1141
1142 /* Call the Callbacks */
1144
1145 /* FIXME: Call Watchdog if enabled */
1146
1147 /* Check if we have to reboot */
1148 if (Reboot)
1149 {
1150 /* Unload symbols */
1153 }
1154
1155 /* Attempt to break in the debugger (otherwise halt CPU) */
1157
1158 /* Shouldn't get here */
1159 ASSERT(FALSE);
1160 while (TRUE);
1161}
unsigned char BOOLEAN
#define ACPI_BIOS_ERROR(plist)
Definition: acoutput.h:243
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define MAXULONG_PTR
Definition: basetsd.h:103
@ Reboot
Definition: bl.h:891
PVOID NTAPI KiPcToFileHeader(IN PVOID Pc, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry, IN BOOLEAN DriversOnly, OUT PBOOLEAN InKernel)
Definition: bug.c:44
ULONG KeBugCheckOwner
Definition: bug.c:25
PUNICODE_STRING KiBugCheckDriver
Definition: bug.c:30
PCHAR NTAPI KeBugCheckUnicodeToAnsi(IN PUNICODE_STRING Unicode, OUT PCHAR Ansi, IN ULONG Length)
Definition: bug.c:518
VOID NTAPI KiDumpParameterImages(IN PCHAR Message, IN PULONG_PTR Parameters, IN ULONG ParameterCount, IN PKE_BUGCHECK_UNICODE_TO_ANSI ConversionRoutine)
Definition: bug.c:542
LONG KeBugCheckOwnerRecursionCount
Definition: bug.c:26
ULONG KeBugCheckActive
Definition: bug.c:25
VOID NTAPI KiDisplayBlueScreen(IN ULONG MessageId, IN BOOLEAN IsHardError, IN PCHAR HardErrCaption OPTIONAL, IN PCHAR HardErrMessage OPTIONAL, IN PCHAR Message)
Definition: bug.c:612
ULONG_PTR KiBugCheckData[5]
Definition: bug.c:31
VOID NTAPI KiDoBugCheckCallbacks(VOID)
Definition: bug.c:436
VOID NTAPI KiBugCheckDebugBreak(IN ULONG StatusCode)
Definition: bug.c:493
ULONG KeBugCheckCount
Definition: bug.c:28
ULONG KiHardwareTrigger
Definition: bug.c:29
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DbgPrint
Definition: hal.h:12
VOID NTAPI HalReturnToFirmware(_In_ FIRMWARE_REENTRY Action)
Definition: reboot.c:21
BOOLEAN NTAPI InbvDisplayString(_In_ PCHAR String)
Definition: inbv.c:332
void __cdecl _disable(void)
Definition: intrin_arm.h:365
BOOLEAN KdPitchDebugger
Definition: kddata.c:80
NTSTATUS NTAPI KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:1990
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:81
BOOLEAN KdDebuggerEnabled
Definition: kddata.c:82
KDDEBUGGER_DATA64 * KdDebuggerDataBlock
Definition: kdpacket.c:21
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
#define KeStallExecutionProcessor(MicroSeconds)
Definition: precomp.h:27
#define IPI_FREEZE
Definition: ketypes.h:299
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
@ HalRebootRoutine
Definition: haltypes.h:37
#define DBG_STATUS_BUGCHECK_FIRST
Definition: kdtypes.h:41
#define DBG_STATUS_BUGCHECK_SECOND
Definition: kdtypes.h:42
FORCEINLINE KAFFINITY AFFINITY_MASK(ULONG Index)
Definition: kefuncs.h:39
VOID NTAPI DbgUnLoadImageSymbols(_In_ PSTRING Name, _In_ PVOID Base, _In_ ULONG_PTR ProcessId)
NTSYSAPI VOID NTAPI RtlCaptureContext(_Out_ PCONTEXT ContextRecord)
#define KeGetTrapFramePc(TrapFrame)
Definition: ke.h:37
VOID FASTCALL KiIpiSend(KAFFINITY TargetSet, ULONG IpiRequest)
VOID NTAPI KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
Definition: cpu.c:576
BOOLEAN NTAPI MmIsSpecialPoolAddress(IN PVOID P)
BOOLEAN NTAPI MmIsSpecialPoolAddressFree(IN PVOID P)
#define STATUS_SYSTEM_IMAGE_BAD_SIGNATURE
Definition: ntstatus.h:829
ULONG64 SavedContext
Definition: wdbgexts.h:195
USHORT Number
Definition: ketypes.h:643
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:663
UCHAR DebuggerSavedIRQL
Definition: ketypes.h:823
CONTEXT ContextFrame
Definition: ketypes.h:616
Definition: btrfs_drv.h:1876
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
uint32_t * PULONG_PTR
Definition: typedefs.h:65
void * PVOID
Definition: typedefs.h:50
int32_t * PLONG
Definition: typedefs.h:58
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
char CHAR
Definition: xmlstorage.h:175

Referenced by KeBugCheck(), and KeBugCheckEx().

◆ KeDeregisterBugCheckCallback()

BOOLEAN NTAPI KeDeregisterBugCheckCallback ( IN PKBUGCHECK_CALLBACK_RECORD  CallbackRecord)

Definition at line 1205 of file bug.c.

1206{
1207 KIRQL OldIrql;
1209
1210 /* Raise IRQL to High */
1212
1213 /* Check the Current State */
1215 {
1216 /* Reset state and remove from list */
1219 Status = TRUE;
1220 }
1221
1222 /* Lower IRQL and return */
1224 return Status;
1225}
KBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
Status
Definition: gdiplustypes.h:25
@ BufferEmpty
Definition: ketypes.h:319
@ BufferInserted
Definition: ketypes.h:320

Referenced by NdisMDeregisterAdapterShutdownHandler().

◆ KeDeregisterBugCheckReasonCallback()

BOOLEAN NTAPI KeDeregisterBugCheckReasonCallback ( IN PKBUGCHECK_REASON_CALLBACK_RECORD  CallbackRecord)

Definition at line 1232 of file bug.c.

1234{
1235 KIRQL OldIrql;
1237
1238 /* Raise IRQL to High */
1240
1241 /* Check the Current State */
1243 {
1244 /* Reset state and remove from list */
1247 Status = TRUE;
1248 }
1249
1250 /* Lower IRQL and return */
1252 return Status;
1253}

◆ KeDeregisterNmiCallback()

NTSTATUS NTAPI KeDeregisterNmiCallback ( IN PVOID  Handle)

Definition at line 1364 of file bug.c.

1365{
1366 KIRQL OldIrql;
1367 PKNMI_HANDLER_CALLBACK NmiData;
1368 PKNMI_HANDLER_CALLBACK* Previous;
1370
1371 /* Find in the list the NMI callback corresponding to the handle */
1373 Previous = &KiNmiCallbackListHead;
1374 NmiData = *Previous;
1375 while (NmiData)
1376 {
1377 if (NmiData->Handle == Handle)
1378 {
1379 /* The handle is the pointer to the callback itself */
1380 ASSERT(Handle == NmiData);
1381
1382 /* Found it, remove from the list */
1383 *Previous = NmiData->Next;
1384 break;
1385 }
1386
1387 /* Not found; try again */
1388 Previous = &NmiData->Next;
1389 NmiData = *Previous;
1390 }
1392
1393 /* If we have found the entry, free it */
1394 if (NmiData)
1395 {
1396 ExFreePoolWithTag(NmiData, TAG_KNMI);
1397 return STATUS_SUCCESS;
1398 }
1399
1400 return STATUS_INVALID_HANDLE;
1401}
PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead
Definition: bug.c:33
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG Handle
Definition: gdb_input.c:15
FORCEINLINE VOID KiAcquireNmiListLock(OUT PKIRQL OldIrql)
Definition: ke_x.h:1682
FORCEINLINE VOID KiReleaseNmiListLock(IN KIRQL OldIrql)
Definition: ke_x.h:1689
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _KNMI_HANDLER_CALLBACK * Next
Definition: ke.h:80
#define TAG_KNMI
Definition: tag.h:41

◆ KeEnterKernelDebugger()

VOID NTAPI KeEnterKernelDebugger ( VOID  )

Definition at line 1441 of file bug.c.

1442{
1443 /* Disable interrupts */
1445 _disable();
1446
1447 /* Check the bugcheck count */
1449 {
1450 /* There was only one, is the debugger disabled? */
1452 {
1453 /* Enable the debugger */
1454 KdInitSystem(0, NULL);
1455 }
1456 }
1457
1458 /* Break in the debugger */
1460}
BOOLEAN NTAPI KdInitSystem(_In_ ULONG BootPhase, _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:142
#define DBG_STATUS_FATAL
Definition: kdtypes.h:43

Referenced by HalHandleNMI().

◆ KeGetBugMessageText()

BOOLEAN NTAPI KeGetBugMessageText ( IN ULONG  BugCheckCode,
OUT PANSI_STRING OutputString  OPTIONAL 
)

Definition at line 338 of file bug.c.

340{
341 ULONG i;
342 ULONG IdOffset;
343 PMESSAGE_RESOURCE_ENTRY MessageEntry;
344 PCHAR BugCode;
347
348 /* Make sure we're not bugchecking too early */
349 if (!KiBugCodeMessages) return Result;
350
351 /*
352 * Globally protect in SEH as we are trying to access data in
353 * dire situations, and potentially going to patch it (see below).
354 */
356 {
357
358 /*
359 * Make the kernel resource section writable, as we are going to manually
360 * trim the trailing newlines in the bugcheck resource message in place,
361 * when OutputString is NULL and before displaying it on screen.
362 */
364
365 /* Find the message. This code is based on RtlFindMesssage */
366 for (i = 0; i < KiBugCodeMessages->NumberOfBlocks; i++)
367 {
368 /* Check if the ID matches */
369 if ((BugCheckCode >= KiBugCodeMessages->Blocks[i].LowId) &&
370 (BugCheckCode <= KiBugCodeMessages->Blocks[i].HighId))
371 {
372 /* Get offset to entry */
373 MessageEntry = (PMESSAGE_RESOURCE_ENTRY)
375 IdOffset = BugCheckCode - KiBugCodeMessages->Blocks[i].LowId;
376
377 /* Advance in the entries until finding it */
378 while (IdOffset--)
379 {
380 MessageEntry = (PMESSAGE_RESOURCE_ENTRY)
381 ((ULONG_PTR)MessageEntry + MessageEntry->Length);
382 }
383
384 /* Make sure it's not Unicode */
385 ASSERT(!(MessageEntry->Flags & MESSAGE_RESOURCE_UNICODE));
386
387 /* Get the final code */
388 BugCode = (PCHAR)MessageEntry->Text;
389 Length = (USHORT)strlen(BugCode);
390
391 /* Handle trailing newlines */
392 while ((Length > 0) && ((BugCode[Length - 1] == '\n') ||
393 (BugCode[Length - 1] == '\r') ||
394 (BugCode[Length - 1] == ANSI_NULL)))
395 {
396 /* Directly trim the newline in place if we don't return the string */
397 if (!OutputString) BugCode[Length - 1] = ANSI_NULL;
398
399 /* Skip the trailing newline */
400 Length--;
401 }
402
403 /* Check if caller wants an output string */
404 if (OutputString)
405 {
406 /* Return it in the OutputString */
407 OutputString->Buffer = BugCode;
408 OutputString->Length = Length;
409 OutputString->MaximumLength = Length;
410 }
411 else
412 {
413 /* Direct output to screen */
414 InbvDisplayString(BugCode);
415 InbvDisplayString("\r");
416 }
417
418 /* We're done */
419 Result = TRUE;
420 break;
421 }
422 }
423
424 }
426 {
427 }
428 _SEH2_END;
429
430 /* Return the result */
431 return Result;
432}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PMESSAGE_RESOURCE_DATA KiBugCodeMessages
Definition: bug.c:27
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define MESSAGE_RESOURCE_UNICODE
Definition: rtltypes.h:351
struct _MESSAGE_RESOURCE_ENTRY * PMESSAGE_RESOURCE_ENTRY
VOID NTAPI MmMakeKernelResourceSectionWritable(VOID)
Definition: sysldr.c:2362
unsigned short USHORT
Definition: pedump.c:61
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
MESSAGE_RESOURCE_BLOCK Blocks[ANYSIZE_ARRAY]
Definition: rtltypes.h:1912
Definition: rtltypes.h:1896
UCHAR Text[ANYSIZE_ARRAY]
Definition: rtltypes.h:1899
USHORT Flags
Definition: rtltypes.h:1898
USHORT Length
Definition: rtltypes.h:1897
uint32_t ULONG_PTR
Definition: typedefs.h:65
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by KiDisplayBlueScreen().

◆ KeInitializeCrashDumpHeader()

NTSTATUS NTAPI KeInitializeCrashDumpHeader ( IN ULONG  Type,
IN ULONG  Flags,
OUT PVOID  Buffer,
IN ULONG  BufferSize,
OUT ULONG BufferNeeded  OPTIONAL 
)

Definition at line 1190 of file bug.c.

1195{
1197 return STATUS_UNSUCCESSFUL;
1198}
#define UNIMPLEMENTED
Definition: debug.h:118
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ KeRegisterBugCheckCallback()

BOOLEAN NTAPI KeRegisterBugCheckCallback ( IN PKBUGCHECK_CALLBACK_RECORD  CallbackRecord,
IN PKBUGCHECK_CALLBACK_ROUTINE  CallbackRoutine,
IN PVOID  Buffer,
IN ULONG  Length,
IN PUCHAR  Component 
)

Definition at line 1260 of file bug.c.

1265{
1266 KIRQL OldIrql;
1268
1269 /* Raise IRQL to High */
1271
1272 /* Check the Current State first so we don't double-register */
1274 {
1275 /* Set the Callback Settings and insert into the list */
1276 CallbackRecord->Length = Length;
1277 CallbackRecord->Buffer = Buffer;
1282 Status = TRUE;
1283 }
1284
1285 /* Lower IRQL and return */
1287 return Status;
1288}
LIST_ENTRY KeBugcheckCallbackListHead
Definition: bug.c:22
Definition: bufpool.h:45
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ _In_ PFLT_GET_OPERATION_STATUS_CALLBACK CallbackRoutine
Definition: fltkernel.h:1035
PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine
Definition: ketypes.h:311
_In_ ULONG Component
Definition: potypes.h:496

Referenced by NdisMRegisterAdapterShutdownHandler().

◆ KeRegisterBugCheckReasonCallback()

BOOLEAN NTAPI KeRegisterBugCheckReasonCallback ( IN PKBUGCHECK_REASON_CALLBACK_RECORD  CallbackRecord,
IN PKBUGCHECK_REASON_CALLBACK_ROUTINE  CallbackRoutine,
IN KBUGCHECK_CALLBACK_REASON  Reason,
IN PUCHAR  Component 
)

Definition at line 1295 of file bug.c.

1300{
1301 KIRQL OldIrql;
1303
1304 /* Raise IRQL to High */
1306
1307 /* Check the Current State first so we don't double-register */
1309 {
1310 /* Set the Callback Settings and insert into the list */
1317 Status = TRUE;
1318 }
1319
1320 /* Lower IRQL and return */
1322 return Status;
1323}
LIST_ENTRY KeBugcheckReasonCallbackListHead
Definition: bug.c:23
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:47
KBUGCHECK_CALLBACK_REASON Reason
Definition: ketypes.h:314

◆ KeRegisterNmiCallback()

PVOID NTAPI KeRegisterNmiCallback ( IN PNMI_CALLBACK  CallbackRoutine,
IN PVOID  Context 
)

Definition at line 1330 of file bug.c.

1332{
1333 KIRQL OldIrql;
1334 PKNMI_HANDLER_CALLBACK NmiData, Next;
1336
1337 /* Allocate NMI callback data */
1338 NmiData = ExAllocatePoolWithTag(NonPagedPool, sizeof(*NmiData), TAG_KNMI);
1339 if (!NmiData) return NULL;
1340
1341 /* Fill in the information */
1342 NmiData->Callback = CallbackRoutine;
1343 NmiData->Context = Context;
1344 NmiData->Handle = NmiData;
1345
1346 /* Insert it into NMI callback list */
1348 NmiData->Next = KiNmiCallbackListHead;
1350 NmiData,
1351 NmiData->Next);
1352 ASSERT(Next == NmiData->Next);
1354
1355 /* Return the opaque "handle" */
1356 return NmiData->Handle;
1357}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
PNMI_CALLBACK Callback
Definition: ke.h:81

Referenced by DriverEntry().

◆ KeRosCaptureUserStackBackTrace()

USHORT NTAPI KeRosCaptureUserStackBackTrace ( IN ULONG  FramesToSkip,
IN ULONG  FramesToCapture,
OUT PVOID BackTrace,
OUT PULONG BackTraceHash  OPTIONAL 
)

Definition at line 158 of file bug.c.

162{
163 PVOID Frames[2 * 64];
164 ULONG FrameCount;
165 ULONG Hash = 0, i;
166
167 /* Skip a frame for the caller */
168 FramesToSkip++;
169
170 /* Don't go past the limit */
171 if ((FramesToCapture + FramesToSkip) >= 128) return 0;
172
173 /* Do the back trace */
174 FrameCount = RtlWalkFrameChain(Frames, FramesToCapture + FramesToSkip, 1);
175
176 /* Make sure we're not skipping all of them */
177 if (FrameCount <= FramesToSkip) return 0;
178
179 /* Loop all the frames */
180 for (i = 0; i < FramesToCapture; i++)
181 {
182 /* Don't go past the limit */
183 if ((FramesToSkip + i) >= FrameCount) break;
184
185 /* Save this entry and hash it */
186 BackTrace[i] = Frames[FramesToSkip + i];
187 Hash += PtrToUlong(BackTrace[i]);
188 }
189
190 /* Write the hash */
192
193 /* Clear the other entries and return count */
194 RtlFillMemoryUlong(Frames, 128, 0);
195 return (USHORT)i;
196}
ULONG NTAPI RtlWalkFrameChain(OUT PVOID *Callers, IN ULONG Count, IN ULONG Flags)
Definition: libsupp.c:229
static int Hash(const char *)
Definition: reader.c:2257
#define PtrToUlong(u)
Definition: config.h:107
_In_ ULONG FramesToCapture
_In_ ULONG _Out_opt_ PULONG BackTraceHash
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55

Referenced by KeRosDumpStackFrames().

◆ KeRosDumpStackFrameArray()

VOID FASTCALL KeRosDumpStackFrameArray ( IN PULONG_PTR  Frames,
IN ULONG  FrameCount 
)

Definition at line 201 of file bug.c.

203{
204 ULONG i;
205 ULONG_PTR Addr;
206 BOOLEAN InSystem;
207 PVOID p;
208
209 /* GCC complaints that it may be used uninitialized */
210 PLDR_DATA_TABLE_ENTRY LdrEntry = NULL;
211
212 /* Loop them */
213 for (i = 0; i < FrameCount; i++)
214 {
215 /* Get the EIP */
216 Addr = Frames[i];
217 if (!Addr)
218 {
219 break;
220 }
221
222 /* Get the base for this file */
224 {
225 /* We are in kernel */
226 p = KiPcToFileHeader((PVOID)Addr, &LdrEntry, FALSE, &InSystem);
227 }
228 else
229 {
230 /* We are in user land */
231 p = KiRosPcToUserFileHeader((PVOID)Addr, &LdrEntry);
232 }
233 if (p)
234 {
235#ifdef KDBG
236 if (!KdbSymPrintAddress((PVOID)Addr, NULL))
237#endif
238 {
239 CHAR AnsiName[64];
240
241 /* Convert module name to ANSI and print it */
243 AnsiName,
244 sizeof(AnsiName));
245 Addr -= (ULONG_PTR)LdrEntry->DllBase;
246 DbgPrint("<%s: %p>", AnsiName, (PVOID)Addr);
247 }
248 }
249 else
250 {
251 /* Print only the address */
252 DbgPrint("<%p>", (PVOID)Addr);
253 }
254
255 /* Go to the next frame */
256 DbgPrint("\n");
257 }
258}
PVOID NTAPI KiRosPcToUserFileHeader(IN PVOID Pc, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry)
Definition: bug.c:109
BOOLEAN KdbSymPrintAddress(IN PVOID Address, IN PCONTEXT Context)
Print address...
Definition: kdb_symbols.c:149
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
PVOID DllBase
Definition: btrfs_drv.h:1880

Referenced by KeRosDumpStackFrames().

◆ KeRosDumpStackFrames()

VOID NTAPI KeRosDumpStackFrames ( IN PULONG_PTR Frame  OPTIONAL,
IN ULONG FrameCount  OPTIONAL 
)

Definition at line 262 of file bug.c.

264{
265 ULONG_PTR Frames[32];
266 ULONG RealFrameCount;
267
268 /* If the caller didn't ask, assume 32 frames */
269 if (!FrameCount || FrameCount > 32) FrameCount = 32;
270
271 if (Frame)
272 {
273 /* Dump them */
274 KeRosDumpStackFrameArray(Frame, FrameCount);
275 }
276 else
277 {
278 /* Get the current frames (skip the two. One for the dumper, one for the caller) */
279 RealFrameCount = RtlCaptureStackBackTrace(2, FrameCount, (PVOID*)Frames, NULL);
280 DPRINT1("RealFrameCount =%lu\n", RealFrameCount);
281
282 /* Dump them */
283 KeRosDumpStackFrameArray(Frames, RealFrameCount);
284
285 /* Count left for user mode? */
286 if (FrameCount - RealFrameCount > 0)
287 {
288 /* Get the current frames */
289 RealFrameCount = KeRosCaptureUserStackBackTrace(-1, FrameCount - RealFrameCount, (PVOID*)Frames, NULL);
290
291 /* Dump them */
292 KeRosDumpStackFrameArray(Frames, RealFrameCount);
293 }
294 }
295}
#define DPRINT1
Definition: precomp.h:8
VOID FASTCALL KeRosDumpStackFrameArray(IN PULONG_PTR Frames, IN ULONG FrameCount)
Definition: bug.c:201
USHORT NTAPI KeRosCaptureUserStackBackTrace(IN ULONG FramesToSkip, IN ULONG FramesToCapture, OUT PVOID *BackTrace, OUT PULONG BackTraceHash OPTIONAL)
Definition: bug.c:158
NTSYSAPI USHORT NTAPI RtlCaptureStackBackTrace(_In_ ULONG FramesToSkip, _In_ ULONG FramesToCapture, _Out_writes_to_(FramesToCapture, return) PVOID *BackTrace, _Out_opt_ PULONG BackTraceHash)

◆ KiBugCheckDebugBreak()

VOID NTAPI KiBugCheckDebugBreak ( IN ULONG  StatusCode)

Definition at line 493 of file bug.c.

494{
495 /*
496 * Wrap this in SEH so we don't crash if
497 * there is no debugger or if it disconnected
498 */
499DoBreak:
501 {
502 /* Breakpoint */
503 DbgBreakPointWithStatus(StatusCode);
504 }
506 {
507 /* No debugger, halt the CPU */
509 }
510 _SEH2_END;
511
512 /* Break again if this wasn't first try */
513 if (StatusCode != DBG_STATUS_BUGCHECK_FIRST) goto DoBreak;
514}
#define HalHaltSystem
Definition: halfuncs.h:43
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)

Referenced by KeBugCheckWithTf(), and KeEnterKernelDebugger().

◆ KiDisplayBlueScreen()

VOID NTAPI KiDisplayBlueScreen ( IN ULONG  MessageId,
IN BOOLEAN  IsHardError,
IN PCHAR HardErrCaption  OPTIONAL,
IN PCHAR HardErrMessage  OPTIONAL,
IN PCHAR  Message 
)

Definition at line 612 of file bug.c.

617{
618 CHAR AnsiName[107];
619
620 /* Check if bootvid is installed */
622 {
623 /* Acquire ownership and reset the display */
626
627 /* Display blue screen */
633 }
634
635 /* Check if this is a hard error */
636 if (IsHardError)
637 {
638 /* Display caption and message */
639 if (HardErrCaption) InbvDisplayString(HardErrCaption);
640 if (HardErrMessage) InbvDisplayString(HardErrMessage);
641 }
642
643 /* Begin the display */
644 InbvDisplayString("\r\n");
645
646 /* Print out initial message */
647 KeGetBugMessageText(BUGCHECK_MESSAGE_INTRO, NULL);
648 InbvDisplayString("\r\n\r\n");
649
650 /* Check if we have a driver */
652 {
653 /* Print out into to driver name */
654 KeGetBugMessageText(BUGCODE_ID_DRIVER, NULL);
655
656 /* Convert and print out driver name */
657 KeBugCheckUnicodeToAnsi(KiBugCheckDriver, AnsiName, sizeof(AnsiName));
659 InbvDisplayString(AnsiName);
660 InbvDisplayString("\r\n\r\n");
661 }
662
663 /* Check if this is the generic message */
664 if (MessageId == BUGCODE_PSS_MESSAGE)
665 {
666 /* It is, so get the bug code string as well */
668 InbvDisplayString("\r\n\r\n");
669 }
670
671 /* Print second introduction message */
672 KeGetBugMessageText(PSS_MESSAGE_INTRO, NULL);
673 InbvDisplayString("\r\n\r\n");
674
675 /* Get the bug code string */
676 KeGetBugMessageText(MessageId, NULL);
677 InbvDisplayString("\r\n\r\n");
678
679 /* Print message for technical information */
680 KeGetBugMessageText(BUGCHECK_TECH_INFO, NULL);
681
682 /* Show the technical Data */
683 RtlStringCbPrintfA(AnsiName,
684 sizeof(AnsiName),
685 "\r\n\r\n*** STOP: 0x%08lX (0x%p,0x%p,0x%p,0x%p)\r\n\r\n",
691 InbvDisplayString(AnsiName);
692
693 /* Check if we have a driver*/
695 {
696 /* Display technical driver data */
698 }
699 else
700 {
701 /* Dump parameter information */
704 4,
706 }
707}
BOOLEAN NTAPI KeGetBugMessageText(IN ULONG BugCheckCode, OUT PANSI_STRING OutputString OPTIONAL)
Definition: bug.c:338
static const WCHAR Message[]
Definition: register.c:74
VOID NTAPI InbvAcquireDisplayOwnership(VOID)
Definition: inbv.c:290
VOID NTAPI InbvInstallDisplayStringFilter(_In_ INBV_DISPLAY_STRING_FILTER DisplayFilter)
Definition: inbv.c:387
VOID NTAPI InbvSetTextColor(_In_ ULONG Color)
Definition: inbv.c:460
BOOLEAN NTAPI InbvEnableDisplayString(_In_ BOOLEAN Enable)
Definition: inbv.c:370
BOOLEAN NTAPI InbvResetDisplay(VOID)
Definition: inbv.c:431
VOID NTAPI InbvSetScrollRegion(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom)
Definition: inbv.c:448
VOID NTAPI InbvSolidColorFill(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom, _In_ ULONG Color)
Definition: inbv.c:485
BOOLEAN NTAPI InbvIsBootDriverInstalled(VOID)
Definition: inbv.c:396
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
#define SCREEN_WIDTH
Definition: pc98video.c:27
#define SCREEN_HEIGHT
Definition: pc98video.c:28
#define BV_COLOR_BLUE
Definition: display.h:19
#define BV_COLOR_WHITE
Definition: display.h:30

Referenced by KeBugCheckWithTf().

◆ KiDoBugCheckCallbacks()

VOID NTAPI KiDoBugCheckCallbacks ( VOID  )

Definition at line 436 of file bug.c.

437{
438 PKBUGCHECK_CALLBACK_RECORD CurrentRecord;
439 PLIST_ENTRY ListHead, NextEntry, LastEntry;
440 ULONG_PTR Checksum;
441
442 /* First make sure that the list is initialized... it might not be */
443 ListHead = &KeBugcheckCallbackListHead;
444 if ((!ListHead->Flink) || (!ListHead->Blink))
445 return;
446
447 /* Loop the list */
448 LastEntry = ListHead;
449 NextEntry = ListHead->Flink;
450 while (NextEntry != ListHead)
451 {
452 /* Get the reord */
453 CurrentRecord = CONTAINING_RECORD(NextEntry,
455 Entry);
456
457 /* Validate it */
458 // TODO/FIXME: Check whether the memory CurrentRecord points to
459 // is still accessible and valid!
460 if (CurrentRecord->Entry.Blink != LastEntry) return;
461 Checksum = (ULONG_PTR)CurrentRecord->CallbackRoutine;
462 Checksum += (ULONG_PTR)CurrentRecord->Buffer;
463 Checksum += (ULONG_PTR)CurrentRecord->Length;
464 Checksum += (ULONG_PTR)CurrentRecord->Component;
465
466 /* Make sure it's inserted and validated */
467 if ((CurrentRecord->State == BufferInserted) &&
468 (CurrentRecord->Checksum == Checksum))
469 {
470 /* Call the routine */
471 CurrentRecord->State = BufferStarted;
473 {
474 (CurrentRecord->CallbackRoutine)(CurrentRecord->Buffer,
475 CurrentRecord->Length);
476 CurrentRecord->State = BufferFinished;
477 }
479 {
480 CurrentRecord->State = BufferIncomplete;
481 }
482 _SEH2_END;
483 }
484
485 /* Go to the next entry */
486 LastEntry = NextEntry;
487 NextEntry = NextEntry->Flink;
488 }
489}
base of all file and directory entries
Definition: entries.h:83
PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine
Definition: ketypes.h:336
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
@ BufferIncomplete
Definition: ketypes.h:323
@ BufferFinished
Definition: ketypes.h:322
@ BufferStarted
Definition: ketypes.h:321

Referenced by KeBugCheckWithTf().

◆ KiDumpParameterImages()

VOID NTAPI KiDumpParameterImages ( IN PCHAR  Message,
IN PULONG_PTR  Parameters,
IN ULONG  ParameterCount,
IN PKE_BUGCHECK_UNICODE_TO_ANSI  ConversionRoutine 
)

Definition at line 542 of file bug.c.

546{
547 ULONG i;
548 BOOLEAN InSystem;
549 PLDR_DATA_TABLE_ENTRY LdrEntry;
550 PVOID ImageBase;
551 PUNICODE_STRING DriverName;
552 CHAR AnsiName[32];
553 PIMAGE_NT_HEADERS NtHeader;
555 BOOLEAN FirstRun = TRUE;
556
557 /* Loop parameters */
558 for (i = 0; i < ParameterCount; i++)
559 {
560 /* Get the base for this parameter */
561 ImageBase = KiPcToFileHeader((PVOID)Parameters[i],
562 &LdrEntry,
563 FALSE,
564 &InSystem);
565 if (!ImageBase)
566 {
567 /* FIXME: Add code to check for unloaded drivers */
568 DPRINT1("Potentially unloaded driver!\n");
569 continue;
570 }
571 else
572 {
573 /* Get the NT Headers and Timestamp */
574 NtHeader = RtlImageNtHeader(LdrEntry->DllBase);
576
577 /* Convert the driver name */
578 DriverName = &LdrEntry->BaseDllName;
579 ConversionRoutine(&LdrEntry->BaseDllName,
580 AnsiName,
581 sizeof(AnsiName));
582 }
583
584 /* Format driver name */
586 "%s** %12s - Address %p base at %p, DateStamp %08lx\r\n",
587 FirstRun ? "\r\n*":"*",
588 AnsiName,
590 ImageBase,
591 TimeStamp);
592
593 /* Check if we only had one parameter */
594 if (ParameterCount <= 1)
595 {
596 /* Then just save the name */
597 KiBugCheckDriver = DriverName;
598 }
599 else
600 {
601 /* Otherwise, display the message */
603 }
604
605 /* Loop again */
606 FirstRun = FALSE;
607 }
608}
#define RtlImageNtHeader
Definition: compat.h:806
#define sprintf(buf, format,...)
Definition: sprintf.c:55
SECURITY_INTEGER TimeStamp
Definition: sspi.h:78
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

Referenced by KeBugCheckWithTf(), and KiDisplayBlueScreen().

◆ KiHandleNmi()

BOOLEAN NTAPI KiHandleNmi ( VOID  )

Definition at line 1165 of file bug.c.

1166{
1168 PKNMI_HANDLER_CALLBACK NmiData;
1169
1170 /* Parse the list of callbacks */
1171 NmiData = KiNmiCallbackListHead;
1172 while (NmiData)
1173 {
1174 /* Save if this callback has handled it -- all it takes is one */
1175 Handled |= NmiData->Callback(NmiData->Context, Handled);
1176 NmiData = NmiData->Next;
1177 }
1178
1179 /* Has anyone handled this? */
1180 return Handled;
1181}
_In_ BOOLEAN Handled
Definition: ketypes.h:349

Referenced by KiNmiInterruptHandler(), and KiTrap02Handler().

◆ KiInitializeBugCheck()

VOID NTAPI KiInitializeBugCheck ( VOID  )

Definition at line 300 of file bug.c.

301{
303 LDR_RESOURCE_INFO ResourceInfo;
304 PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
306 PLDR_DATA_TABLE_ENTRY LdrEntry;
307
308 /* Get the kernel entry */
311 InLoadOrderLinks);
312
313 /* Cache the Bugcheck Message Strings. Prepare the Lookup Data */
314 ResourceInfo.Type = 11;
315 ResourceInfo.Name = 1;
316 ResourceInfo.Language = 9;
317
318 /* Do the lookup. */
319 Status = LdrFindResource_U(LdrEntry->DllBase,
320 &ResourceInfo,
322 &ResourceDataEntry);
323
324 /* Make sure it worked */
325 if (NT_SUCCESS(Status))
326 {
327 /* Now actually get a pointer to it */
328 Status = LdrAccessResource(LdrEntry->DllBase,
329 ResourceDataEntry,
331 NULL);
333 }
334}
static tBugCheckData BugCheckData
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
NTSTATUS NTAPI LdrAccessResource(_In_ PVOID BaseAddress, _In_ PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry, _Out_opt_ PVOID *Resource, _Out_opt_ PULONG Size)
NTSTATUS NTAPI LdrFindResource_U(_In_ PVOID BaseAddress, _In_ PLDR_RESOURCE_INFO ResourceInfo, _In_ ULONG Level, _Out_ PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry)
#define RESOURCE_DATA_LEVEL
Definition: ldrtypes.h:33
Definition: pedump.c:458
ULONG_PTR Language
Definition: ldrtypes.h:183
ULONG_PTR Name
Definition: ldrtypes.h:182
ULONG_PTR Type
Definition: ldrtypes.h:181
LIST_ENTRY LoadOrderListHead
Definition: arc.h:540

Referenced by ExpInitializeExecutive().

◆ KiPcToFileHeader()

PVOID NTAPI KiPcToFileHeader ( IN PVOID  Pc,
OUT PLDR_DATA_TABLE_ENTRY LdrEntry,
IN BOOLEAN  DriversOnly,
OUT PBOOLEAN  InKernel 
)

Definition at line 44 of file bug.c.

48{
49 ULONG i = 0;
50 PVOID ImageBase, PcBase = NULL;
52 PLIST_ENTRY ListHead, NextEntry;
53
54 /* Check which list we should use */
57
58 /* Assume no */
59 *InKernel = FALSE;
60
61 /* Set list pointers and make sure it's valid */
62 NextEntry = ListHead->Flink;
63 if (NextEntry)
64 {
65 /* Start loop */
66 while (NextEntry != ListHead)
67 {
68 /* Increase entry */
69 i++;
70
71 /* Check if this is a kernel entry and we only want drivers */
72 if ((i <= 2) && (DriversOnly != FALSE))
73 {
74 /* Skip it */
75 NextEntry = NextEntry->Flink;
76 continue;
77 }
78
79 /* Get the loader entry */
80 Entry = CONTAINING_RECORD(NextEntry,
82 InLoadOrderLinks);
83
84 /* Move to the next entry */
85 NextEntry = NextEntry->Flink;
86 ImageBase = Entry->DllBase;
87
88 /* Check if this is the right one */
89 if (((ULONG_PTR)Pc >= (ULONG_PTR)Entry->DllBase) &&
90 ((ULONG_PTR)Pc < ((ULONG_PTR)Entry->DllBase + Entry->SizeOfImage)))
91 {
92 /* Return this entry */
93 *LdrEntry = Entry;
94 PcBase = ImageBase;
95
96 /* Check if this was a kernel or HAL entry */
97 if (i <= 2) *InKernel = TRUE;
98 break;
99 }
100 }
101 }
102
103 /* Return the base address */
104 return PcBase;
105}
if(dx< 0)
Definition: linetemp.h:194
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:21

Referenced by KeBugCheckWithTf(), KeRosDumpStackFrameArray(), KiDumpParameterImages(), and RtlPcToFileHeader().

◆ KiRosPcToUserFileHeader()

PVOID NTAPI KiRosPcToUserFileHeader ( IN PVOID  Pc,
OUT PLDR_DATA_TABLE_ENTRY LdrEntry 
)

Definition at line 109 of file bug.c.

111{
112 PVOID ImageBase, PcBase = NULL;
114 PLIST_ENTRY ListHead, NextEntry;
115
116 /*
117 * We know this is valid because we should only be called after a
118 * succesfull address from RtlWalkFrameChain for UserMode, which
119 * validates everything for us.
120 */
121 ListHead = &KeGetCurrentThread()->
122 Teb->ProcessEnvironmentBlock->Ldr->InLoadOrderModuleList;
123
124 /* Set list pointers and make sure it's valid */
125 NextEntry = ListHead->Flink;
126 if (NextEntry)
127 {
128 /* Start loop */
129 while (NextEntry != ListHead)
130 {
131 /* Get the loader entry */
132 Entry = CONTAINING_RECORD(NextEntry,
134 InLoadOrderLinks);
135
136 /* Move to the next entry */
137 NextEntry = NextEntry->Flink;
138 ImageBase = Entry->DllBase;
139
140 /* Check if this is the right one */
141 if (((ULONG_PTR)Pc >= (ULONG_PTR)Entry->DllBase) &&
142 ((ULONG_PTR)Pc < ((ULONG_PTR)Entry->DllBase + Entry->SizeOfImage)))
143 {
144 /* Return this entry */
145 *LdrEntry = Entry;
146 PcBase = ImageBase;
147 break;
148 }
149 }
150 }
151
152 /* Return the base address */
153 return PcBase;
154}
#define KeGetCurrentThread
Definition: hal.h:55

Referenced by KeRosDumpStackFrameArray().

Variable Documentation

◆ BugCheckCallbackLock

KSPIN_LOCK BugCheckCallbackLock

Definition at line 24 of file bug.c.

Referenced by KiInitializeKernel(), and KiInitSystem().

◆ KeBugCheckActive

ULONG KeBugCheckActive

Definition at line 25 of file bug.c.

Referenced by KeBugCheckWithTf().

◆ KeBugcheckCallbackListHead

LIST_ENTRY KeBugcheckCallbackListHead

◆ KeBugCheckCount

ULONG KeBugCheckCount = 1

Definition at line 28 of file bug.c.

Referenced by KeBugCheckWithTf(), and KeEnterKernelDebugger().

◆ KeBugCheckOwner

ULONG KeBugCheckOwner

Definition at line 25 of file bug.c.

Referenced by KeBugCheckWithTf().

◆ KeBugCheckOwnerRecursionCount

LONG KeBugCheckOwnerRecursionCount

Definition at line 26 of file bug.c.

Referenced by KeBugCheckWithTf().

◆ KeBugcheckReasonCallbackListHead

LIST_ENTRY KeBugcheckReasonCallbackListHead

Definition at line 23 of file bug.c.

Referenced by KeRegisterBugCheckReasonCallback().

◆ KeRosBiosDate

UNICODE_STRING KeRosBiosDate

Definition at line 37 of file bug.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KeRosBiosVersion

UNICODE_STRING KeRosBiosVersion

Definition at line 37 of file bug.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KeRosProcessorName

UNICODE_STRING KeRosProcessorName

Definition at line 37 of file bug.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KeRosVideoBiosDate

UNICODE_STRING KeRosVideoBiosDate

Definition at line 38 of file bug.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KeRosVideoBiosVersion

UNICODE_STRING KeRosVideoBiosVersion

Definition at line 38 of file bug.c.

Referenced by CmpInitializeMachineDependentConfiguration().

◆ KiBugCheckData

◆ KiBugCheckDriver

PUNICODE_STRING KiBugCheckDriver

Definition at line 30 of file bug.c.

Referenced by KeBugCheckWithTf(), KiDisplayBlueScreen(), and KiDumpParameterImages().

◆ KiBugCodeMessages

PMESSAGE_RESOURCE_DATA KiBugCodeMessages

Definition at line 27 of file bug.c.

Referenced by KeGetBugMessageText(), and KiInitializeBugCheck().

◆ KiHardwareTrigger

ULONG KiHardwareTrigger

Definition at line 29 of file bug.c.

Referenced by KeBugCheckWithTf(), and KeEnterKernelDebugger().

◆ KiNmiCallbackListHead

PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead = NULL

Definition at line 33 of file bug.c.

Referenced by KeDeregisterNmiCallback(), KeRegisterNmiCallback(), and KiHandleNmi().

◆ KiNmiCallbackListLock

KSPIN_LOCK KiNmiCallbackListLock

Definition at line 34 of file bug.c.

Referenced by KiAcquireNmiListLock(), and KiReleaseNmiListLock().