https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6cf426345b425e9328ebd…
commit 6cf426345b425e9328ebd0b481f955b994dc0cd8
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 22:53:10 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Tue Dec 3 22:14:02 2024 +0100
[NTOS:KD64] Use KdpDprintf() instead of DbgPrint() for the debugger banner DPRINTs (#7540)
Override DbgPrint(), used by the debugger banner DPRINTs,
because KdInitSystem() can be called under the debugger lock
by KdEnableDebugger(WithLock)().
In this case, when DbgPrint() (re-)enters the debugger via an
interrupt and acquires the debugger lock, a deadlock occurs.
---
ntoskrnl/kd64/kdinit.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/ntoskrnl/kd64/kdinit.c b/ntoskrnl/kd64/kdinit.c
index a49655ff6cb..93f2bd7dfca 100644
--- a/ntoskrnl/kd64/kdinit.c
+++ b/ntoskrnl/kd64/kdinit.c
@@ -11,9 +11,18 @@
#include <ntoskrnl.h>
#include <reactos/buildno.h>
+
#define NDEBUG
#include <debug.h>
+/*
+ * Override DbgPrint(), used by the debugger banner DPRINTs below,
+ * because KdInitSystem() can be called under the debugger lock by
+ * KdEnableDebugger(WithLock)().
+ */
+#define DbgPrint(fmt, ...) (KdpDprintf(fmt, ##__VA_ARGS__), 0)
+#define DbgPrintEx(cmpid, lvl, fmt, ...) (KdpDprintf(fmt, ##__VA_ARGS__), 0)
+
/* UTILITY FUNCTIONS *********************************************************/
/*
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1a02d3306b1a827dd3a05…
commit 1a02d3306b1a827dd3a059a68cdb7846dee391ad
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 21:26:03 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Tue Dec 3 22:13:57 2024 +0100
[NTOS:KD64] Fix usage of the debugging banner code, based on when KdInitSystem() is called (#7540)
- The debugging banner helpers *CANNOT* be in the INIT section, because
it is possible for KdInitSystem() to enable the debugger **MUCH LATER**
after boot time. (Reverts part of commit f239ca0f0 (r72922).)
This can happen in two situations:
* When the debugger is in CRASHDEBUG mode, i.e. initialized at boot
time but not immediately enabled, and a BSOD happens later that
enables the debugger with a `KdInitSystem(0, NULL)` call.
* When the debugger was possibly manually disabled with a
KdDisableDebugger() call, then later re-enabled with a
KdEnableDebugger() call.
- In the same cases as described above, the KeLoaderBlock is freed after
boot time. Thus, KdpGetMemorySizeInMBs() cannot use it and enumerate
the MemoryDescriptors to evaluate the number of physical memory pages
available on the system. Instead, we can use what the memory manager
has already computed, since the latter is already initialized by now.
These two fixes avoid (invisible) crashes when (re-)enabling
the debugger at non-boot run time.
---
ntoskrnl/kd64/kdinit.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/ntoskrnl/kd64/kdinit.c b/ntoskrnl/kd64/kdinit.c
index 917061995fe..a49655ff6cb 100644
--- a/ntoskrnl/kd64/kdinit.c
+++ b/ntoskrnl/kd64/kdinit.c
@@ -23,17 +23,27 @@
*
* Strongly inspired by:
* mm\ARM3\mminit.c : MiScanMemoryDescriptors(...)
- *
- * See also: kd\kdio.c
*/
-static CODE_SEG("INIT")
+static
SIZE_T
-KdpGetMemorySizeInMBs(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
+KdpGetMemorySizeInMBs(
+ _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PLIST_ENTRY ListEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Descriptor;
SIZE_T NumberOfPhysicalPages = 0;
+ /*
+ * If no loader block is present (e.g. the debugger is initialized only
+ * much later after boot), just use the already-initialized Mm-computed
+ * number of physical pages. Otherwise do the evaluation ourselves.
+ */
+ if (!LoaderBlock)
+ {
+ NumberOfPhysicalPages = MmNumberOfPhysicalPages;
+ goto ReturnSize;
+ }
+
/* Loop the memory descriptors */
for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
ListEntry != &LoaderBlock->MemoryDescriptorListHead;
@@ -62,12 +72,12 @@ KdpGetMemorySizeInMBs(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
}
}
+ReturnSize:
/* Round size up. Assumed to better match actual physical RAM size */
return ALIGN_UP_BY(NumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
}
-/* See also: kd\kdio.c */
-static CODE_SEG("INIT")
+static
VOID
KdpPrintBanner(IN SIZE_T MemSizeMBs)
{
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=76d35dde1d7ba3c5785a9…
commit 76d35dde1d7ba3c5785a90897fd01001eb301bba
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 19:42:06 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Tue Dec 3 19:29:12 2024 +0100
[NTOS:KD64] KdInitSystem(): Poll for break-in on symbol load *ONLY* at boot-time (#7539)
I.e. when LoaderBlock != NULL and we have loaded the initial hal and
ntoskrnl symbols. KdBreakAfterSymbolLoad is then checked for when the
other boot symbols have been loaded by ex/init.c!ExpLoadBootSymbols(),
invoked by ExpInitializeExecutive().
---
ntoskrnl/kd64/kdinit.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/ntoskrnl/kd64/kdinit.c b/ntoskrnl/kd64/kdinit.c
index 4f49b48ef28..917061995fe 100644
--- a/ntoskrnl/kd64/kdinit.c
+++ b/ntoskrnl/kd64/kdinit.c
@@ -208,7 +208,7 @@ KdInitSystem(
KdVersionBlock.Unused[0] = 0;
/* Link us in the KPCR */
- KeGetPcr()->KdVersionBlock = &KdVersionBlock;
+ KeGetPcr()->KdVersionBlock = &KdVersionBlock;
}
/* Check if we have a loader block */
@@ -445,10 +445,11 @@ KdInitSystem(
NextEntry = NextEntry->Flink;
i++;
}
- }
- /* Check for incoming breakin and break on symbol load if we have it */
- KdBreakAfterSymbolLoad = KdPollBreakIn();
+ /* Check for incoming break-in and break on symbol load
+ * if requested, see ex/init.c!ExpLoadBootSymbols() */
+ KdBreakAfterSymbolLoad = KdPollBreakIn();
+ }
}
else
{
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=61feb649d188f6a998477…
commit 61feb649d188f6a998477240cfe27712e5e72ac6
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Fri Nov 22 16:19:41 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Tue Dec 3 19:02:21 2024 +0100
[NTOS:KD64] kdx86.c: Fix Dr7 check to verify whether debugger disabling is allowed (#7538)
Don't check the whole Dr7 value, but only the first 8 bits that
correspond to the local/global enable breakpoints.
We cannot check the whole value because some of the Dr7 bits are
reserved always set to 1 (bit 10), or describe other debug state.
References:
- https://en.wikipedia.org/wiki/X86_debug_register#DR7_-_Debug_control
- Intel® 64 and IA-32 Architectures Software Developer’s Manual,
Volume 3 (3A, 3B, 3C, & 3D): System Programming Guide
https://www.intel.com/content/www/us/en/developer/articles/technical/intel-…
Section "19.2.4 Debug Control Register (DR7)" (pgs. 644-646)
---
ntoskrnl/kd64/i386/kdx86.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/ntoskrnl/kd64/i386/kdx86.c b/ntoskrnl/kd64/i386/kdx86.c
index a70eb464103..843f6e88b0d 100644
--- a/ntoskrnl/kd64/i386/kdx86.c
+++ b/ntoskrnl/kd64/i386/kdx86.c
@@ -426,23 +426,19 @@ NTSTATUS
NTAPI
KdpAllowDisable(VOID)
{
- LONG i;
- ULONG Dr7;
+ ULONG i;
/* Loop every processor */
for (i = 0; i < KeNumberProcessors; i++)
{
- /* Get its DR7 */
- Dr7 = KiProcessorBlock[i]->ProcessorState.SpecialRegisters.KernelDr7;
+ PKPROCESSOR_STATE ProcessorState = &KiProcessorBlock[i]->ProcessorState;
- /* Check if any processor breakpoints are active */
- if (Dr7 != 0)
- {
- /* We can't allow running without a debugger then */
+ /* If any processor breakpoints are active,
+ * we can't allow running without a debugger */
+ if (ProcessorState->SpecialRegisters.KernelDr7 & 0xFF)
return STATUS_ACCESS_DENIED;
- }
}
- /* No processor breakpoints; allow disabling the debugger */
+ /* No processor breakpoints, allow disabling the debugger */
return STATUS_SUCCESS;
}