From 3abb21080d1bdd39ac33993895bff401d4543135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 12 Dec 2024 21:26:25 +0100 Subject: [PATCH] [NTOS:KE/EX] Add minimal EMS (headless) support for bugcheck. In particular, the HeadlessGlobals->InBugCheck flag MUST be set prior to displaying the blue-screen, because the HDL global lock function would trigger a (nested) BSoD otherwise. Regarding the unimplemented HeadlessCmdSendBlueScreenData: it sends to the management console an XML description of the bugcheck. An example can be seen in this issue report: https://github.com/cloud-hypervisor/cloud-hypervisor/issues/3168 For more information, please consult: https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/windowsserver2003emssacxml.doc --- ntoskrnl/ex/hdlsterm.c | 10 ++++++++++ ntoskrnl/ke/bug.c | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ntoskrnl/ex/hdlsterm.c b/ntoskrnl/ex/hdlsterm.c index b4fd7b949f6..bfed212d91d 100644 --- a/ntoskrnl/ex/hdlsterm.c +++ b/ntoskrnl/ex/hdlsterm.c @@ -450,8 +450,15 @@ HdlspDispatch(IN HEADLESS_CMD Command, case HeadlessCmdGetLine: break; + case HeadlessCmdStartBugCheck: + { + HeadlessGlobals->InBugCheck = TRUE; + HeadlessGlobals->ProcessingCmd = FALSE; + Status = STATUS_SUCCESS; break; + } + case HeadlessCmdDoBugCheckProcessing: break; @@ -518,7 +525,10 @@ HdlspDispatch(IN HEADLESS_CMD Command, } case HeadlessCmdSendBlueScreenData: + // TODO: Send XML description of bugcheck. + // InputBuffer points to the BugCheckCode. break; + case HeadlessCmdQueryGUID: break; diff --git a/ntoskrnl/ke/bug.c b/ntoskrnl/ke/bug.c index 1bf6e7cafbd..297de556fe4 100644 --- a/ntoskrnl/ke/bug.c +++ b/ntoskrnl/ke/bug.c @@ -615,8 +615,20 @@ KiDisplayBlueScreen(IN ULONG MessageId, IN PCHAR HardErrMessage OPTIONAL, IN PCHAR Message) { + ULONG BugCheckCode = (ULONG)KiBugCheckData[0]; + BOOLEAN Enable = TRUE; CHAR AnsiName[107]; + /* Enable headless support for bugcheck */ + HeadlessDispatch(HeadlessCmdStartBugCheck, + NULL, 0, NULL, NULL); + HeadlessDispatch(HeadlessCmdEnableTerminal, + &Enable, sizeof(Enable), + NULL, NULL); + HeadlessDispatch(HeadlessCmdSendBlueScreenData, + &BugCheckCode, sizeof(BugCheckCode), + NULL, NULL); + /* Check if bootvid is installed */ if (InbvIsBootDriverInstalled()) { @@ -664,7 +676,7 @@ KiDisplayBlueScreen(IN ULONG MessageId, if (MessageId == BUGCODE_PSS_MESSAGE) { /* It is, so get the bug code string as well */ - KeGetBugMessageText((ULONG)KiBugCheckData[0], NULL); + KeGetBugMessageText(BugCheckCode, NULL); InbvDisplayString("\r\n\r\n"); } @@ -683,7 +695,7 @@ KiDisplayBlueScreen(IN ULONG MessageId, RtlStringCbPrintfA(AnsiName, sizeof(AnsiName), "\r\n\r\n*** STOP: 0x%08lX (0x%p,0x%p,0x%p,0x%p)\r\n\r\n", - (ULONG)KiBugCheckData[0], + BugCheckCode, (PVOID)KiBugCheckData[1], (PVOID)KiBugCheckData[2], (PVOID)KiBugCheckData[3],