https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3abb21080d1bdd39ac339…
commit 3abb21080d1bdd39ac33993895bff401d4543135
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Dec 12 21:26:25 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:38:43 2024 +0100
[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-92314…
---
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],
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b15dcb5cf61bf5e72537a…
commit b15dcb5cf61bf5e72537a7b8f66981ebe22967d1
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Dec 7 16:29:02 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:33:53 2024 +0100
[NTOS:KD64] The DbgKdPageInApi, introduced in NT4, has been obsoleted in NT5.
It has been replaced by ExpDebuggerPageIn support in ExpDebuggerWorker().
---
ntoskrnl/kd64/kdapi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/ntoskrnl/kd64/kdapi.c b/ntoskrnl/kd64/kdapi.c
index 089af9c5f86..4baeb4d9c42 100644
--- a/ntoskrnl/kd64/kdapi.c
+++ b/ntoskrnl/kd64/kdapi.c
@@ -1497,8 +1497,9 @@ SendPacket:
case DbgKdPageInApi:
- /* TODO */
- KdpDprintf("Page-In support is unimplemented!\n");
+ /* This API, introduced in NT4, has been obsoleted in NT5. It is
+ * replaced by ExpDebuggerPageIn support in ExpDebuggerWorker(). */
+ KdpDprintf("DbgKdPageInApi is obsolete!\n");
KdpNotSupported(&ManipulateState);
break;
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=da59d797d15a957e14d97…
commit da59d797d15a957e14d97d179f0859b89f4447ca
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Dec 7 16:31:15 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:51 2024 +0100
[NTOS:EX] Minor enhancements to ExpDebuggerWorker()
- Add some DbgPrints.
- Use SAL2 annotations.
---
ntoskrnl/ex/dbgctrl.c | 24 +++++++++++++++---------
ntoskrnl/include/internal/ex.h | 5 ++++-
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/ntoskrnl/ex/dbgctrl.c b/ntoskrnl/ex/dbgctrl.c
index 70280703a31..f3fc6c0b43b 100644
--- a/ntoskrnl/ex/dbgctrl.c
+++ b/ntoskrnl/ex/dbgctrl.c
@@ -49,7 +49,8 @@ ULONG_PTR ExpDebuggerPageIn;
*/
VOID
NTAPI
-ExpDebuggerWorker(IN PVOID Context)
+ExpDebuggerWorker(
+ _In_ PVOID Context)
{
PEPROCESS ProcessToAttach, ProcessToKill;
ULONG_PTR PageInAddress;
@@ -83,11 +84,10 @@ ExpDebuggerWorker(IN PVOID Context)
Process = NULL;
/* Check if we need to attach or kill some process */
- if (ProcessToAttach != NULL || ProcessToKill != NULL)
+ if (ProcessToAttach || ProcessToKill)
{
/* Find the process in the list */
- Process = PsGetNextProcess(Process);
- while (Process)
+ while ((Process = PsGetNextProcess(Process)))
{
/* Is this the process we want to attach to? */
if (Process == ProcessToAttach)
@@ -104,12 +104,16 @@ ExpDebuggerWorker(IN PVOID Context)
ObDereferenceObject(Process);
return;
}
+ }
- /* Get the next process */
- Process = PsGetNextProcess(Process);
+ if (!Process)
+ {
+ DbgPrintEx(DPFLTR_SYSTEM_ID, DPFLTR_ERROR_LEVEL,
+ "EX debug work: Unable to find process %p\n",
+ ProcessToAttach ? ProcessToAttach : ProcessToKill);
}
- /* We either have found a process, or we default to the current process */
+ /* We either have found a process, or we default to the current one */
}
/* If we have an address to page in... */
@@ -122,7 +126,9 @@ ExpDebuggerWorker(IN PVOID Context)
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- DPRINT1("Failed to page in address 0x%p, Status 0x%08lx\n", PageInAddress, _SEH2_GetExceptionCode());
+ DbgPrintEx(DPFLTR_SYSTEM_ID, DPFLTR_ERROR_LEVEL,
+ "EX page in: Failed to page-in address 0x%p, Status 0x%08lx\n",
+ PageInAddress, _SEH2_GetExceptionCode());
}
_SEH2_END;
}
@@ -135,7 +141,7 @@ ExpDebuggerWorker(IN PVOID Context)
{
/* ... we can detach from the process */
KeUnstackDetachProcess(&ApcState);
- /* Dereference the process which was referenced for us by PsGetNextProcess */
+ /* Dereference the process referenced by PsGetNextProcess() */
ObDereferenceObject(Process);
}
}
diff --git a/ntoskrnl/include/internal/ex.h b/ntoskrnl/include/internal/ex.h
index 50dde0cbfc8..4c212972fcb 100644
--- a/ntoskrnl/include/internal/ex.h
+++ b/ntoskrnl/include/internal/ex.h
@@ -70,7 +70,10 @@ extern PEPROCESS ExpDebuggerProcessAttach;
extern PEPROCESS ExpDebuggerProcessKill;
extern ULONG_PTR ExpDebuggerPageIn;
-VOID NTAPI ExpDebuggerWorker(IN PVOID Context);
+VOID
+NTAPI
+ExpDebuggerWorker(
+ _In_ PVOID Context);
#ifdef _WIN64
#define HANDLE_LOW_BITS (PAGE_SHIFT - 4)
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f395f87bb35fbc66c920a…
commit f395f87bb35fbc66c920abf2ea6acb9be9dd49fa
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 21:11:24 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:48 2024 +0100
[NTOS:MM] MiScanMemoryDescriptors(): Use the MiIsMemoryTypeInvisible() and MiIsMemoryTypeFree() helpers.
---
ntoskrnl/mm/ARM3/mminit.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/ntoskrnl/mm/ARM3/mminit.c b/ntoskrnl/mm/ARM3/mminit.c
index bd5ab3caa88..30e17c6edff 100644
--- a/ntoskrnl/mm/ARM3/mminit.c
+++ b/ntoskrnl/mm/ARM3/mminit.c
@@ -421,20 +421,14 @@ MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* Count this descriptor */
MiNumberDescriptors++;
- /* Check if this is invisible memory */
- if ((Descriptor->MemoryType == LoaderFirmwarePermanent) ||
- (Descriptor->MemoryType == LoaderSpecialMemory) ||
- (Descriptor->MemoryType == LoaderHALCachedMemory) ||
- (Descriptor->MemoryType == LoaderBBTMemory))
- {
- /* Skip this descriptor */
+ /* If this is invisible memory, skip this descriptor */
+ if (MiIsMemoryTypeInvisible(Descriptor->MemoryType))
continue;
- }
- /* Check if this is bad memory */
+ /* Check if this isn't bad memory */
if (Descriptor->MemoryType != LoaderBad)
{
- /* Count this in the total of pages */
+ /* Count it in the physical pages */
MmNumberOfPhysicalPages += (PFN_COUNT)Descriptor->PageCount;
}
@@ -454,12 +448,9 @@ MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
}
/* Check if this is free memory */
- if ((Descriptor->MemoryType == LoaderFree) ||
- (Descriptor->MemoryType == LoaderLoadedProgram) ||
- (Descriptor->MemoryType == LoaderFirmwareTemporary) ||
- (Descriptor->MemoryType == LoaderOsloaderStack))
+ if (MiIsMemoryTypeFree(Descriptor->MemoryType))
{
- /* Count it too free pages */
+ /* Count it in the free pages */
MiNumberOfFreePages += Descriptor->PageCount;
/* Check if this is the largest memory descriptor */
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cb0c9a4570b2c563c866d…
commit cb0c9a4570b2c563c866d07d98be1b7729cbbc26
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 20:07:25 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:46 2024 +0100
[NTOS:KD64] KdInitSystem(): Minor code enhancements.
- Move local variables to the code blocks where they are used.
- if-s one-line bodies on their own lines.
- Massage the boot-images symbols loading, using a for-loop.
---
ntoskrnl/kd64/kdinit.c | 71 +++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 39 deletions(-)
diff --git a/ntoskrnl/kd64/kdinit.c b/ntoskrnl/kd64/kdinit.c
index 93f2bd7dfca..99ff187b962 100644
--- a/ntoskrnl/kd64/kdinit.c
+++ b/ntoskrnl/kd64/kdinit.c
@@ -162,21 +162,10 @@ KdInitSystem(
_In_ ULONG BootPhase,
_In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
{
- BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable;
- PSTR CommandLine, DebugLine, DebugOptionStart, DebugOptionEnd;
- STRING ImageName;
+ BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable = FALSE;
PLDR_DATA_TABLE_ENTRY LdrEntry;
- PLIST_ENTRY NextEntry;
- ULONG i, j, Length;
- SIZE_T DebugOptionLength;
+ ULONG i;
SIZE_T MemSizeMBs;
- CHAR NameBuffer[256];
- PWCHAR Name;
-
-#if defined(__GNUC__)
- /* Make gcc happy */
- BlockEnable = FALSE;
-#endif
/* Check if this is Phase 1 */
if (BootPhase)
@@ -187,7 +176,8 @@ KdInitSystem(
}
/* Check if we already initialized once */
- if (KdDebuggerEnabled) return TRUE;
+ if (KdDebuggerEnabled)
+ return TRUE;
/* Set the Debug Routine as the Stub for now */
KiDebugRoutine = KdpStub;
@@ -233,6 +223,8 @@ KdInitSystem(
/* Check if we have a loader block */
if (LoaderBlock)
{
+ PSTR CommandLine, DebugLine;
+
/* Get the image entry */
LdrEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
LDR_DATA_TABLE_ENTRY,
@@ -263,7 +255,7 @@ KdInitSystem(
/* Don't enable KD and don't let it be enabled later */
KdPitchDebugger = TRUE;
}
- else if ((DebugLine = strstr(CommandLine, "DEBUG")) != NULL)
+ else if ((DebugLine = strstr(CommandLine, "DEBUG")))
{
/* Enable KD */
EnableKd = TRUE;
@@ -272,11 +264,14 @@ KdInitSystem(
if (DebugLine[5] == '=')
{
/* Save pointers */
+ PSTR DebugOptionStart, DebugOptionEnd;
DebugOptionStart = DebugOptionEnd = &DebugLine[6];
/* Scan the string for debug options */
for (;;)
{
+ SIZE_T DebugOptionLength;
+
/* Loop until we reach the end of the string */
while (*DebugOptionEnd != ANSI_NULL)
{
@@ -287,7 +282,7 @@ KdInitSystem(
{
/*
* We reached the end of the option or
- * the end of the string, break out
+ * the end of the string, break out.
*/
break;
}
@@ -301,20 +296,19 @@ KdInitSystem(
/* Calculate the length of the current option */
DebugOptionLength = (DebugOptionEnd - DebugOptionStart);
- /*
- * Break out if we reached the last option
- * or if there were no options at all
- */
- if (!DebugOptionLength) break;
+ /*
+ * Break out if we reached the last option
+ * or if there were no options at all.
+ */
+ if (!DebugOptionLength)
+ break;
/* Now check which option this is */
if ((DebugOptionLength == 10) &&
!(strncmp(DebugOptionStart, "AUTOENABLE", 10)))
{
- /*
- * Disable the debugger, but
- * allow it to be reenabled
- */
+ /* Disable the debugger, but
+ * allow to re-enable it later */
DisableKdAfterInit = TRUE;
BlockEnable = FALSE;
KdAutoEnableOnEvent = TRUE;
@@ -335,14 +329,11 @@ KdInitSystem(
}
/*
- * If there are more options then
- * the next character should be a comma
+ * If there are more options then the next character
+ * should be a comma. Break out if it isn't.
*/
if (*DebugOptionEnd != ',')
- {
- /* It isn't, break out */
break;
- }
/* Move on to the next option */
DebugOptionEnd++;
@@ -431,10 +422,16 @@ KdInitSystem(
/* Check if we have a loader block */
if (LoaderBlock)
{
- /* Loop boot images */
- NextEntry = LoaderBlock->LoadOrderListHead.Flink;
- i = 0;
- while ((NextEntry != &LoaderBlock->LoadOrderListHead) && (i < 2))
+ PLIST_ENTRY NextEntry;
+ ULONG j, Length;
+ PWCHAR Name;
+ STRING ImageName;
+ CHAR NameBuffer[256];
+
+ /* Loop over the first two boot images: HAL and kernel */
+ for (NextEntry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
+ NextEntry != &LoaderBlock->LoadOrderListHead && (i < 2);
+ NextEntry = NextEntry->Flink, ++i)
{
/* Get the image entry */
LdrEntry = CONTAINING_RECORD(NextEntry,
@@ -454,15 +451,11 @@ KdInitSystem(
/* Null-terminate */
NameBuffer[j] = ANSI_NULL;
- /* Load symbols for image */
+ /* Load the symbols */
RtlInitString(&ImageName, NameBuffer);
DbgLoadImageSymbols(&ImageName,
LdrEntry->DllBase,
(ULONG_PTR)PsGetCurrentProcessId());
-
- /* Go to the next entry */
- NextEntry = NextEntry->Flink;
- i++;
}
/* Check for incoming break-in and break on symbol load