From 8aac5c4c872ce06d1868a6066ecab4fa0e357575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20S=C5=82abo=C5=84?= Date: Thu, 18 Jun 2026 23:44:48 +0200 Subject: [PATCH] [NTOS:KE][AMD64] Move KD initialization after HalInitializeProcessor call (#9177) This is needed for PCI debugging devices whose KD modules depend on the functions registered in HalpRegisterKdSupportFunctions(). Also it's consistent with what x86 does, and also what Win7 x64 does (the KdInitSystem is invoked after the HalInitializeProcessor call). Necessary for PR #9156 on AMD64. CORE-20385 --- ntoskrnl/ke/amd64/kiinit.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ntoskrnl/ke/amd64/kiinit.c b/ntoskrnl/ke/amd64/kiinit.c index 632634dc5af..b0ca6dd8b67 100644 --- a/ntoskrnl/ke/amd64/kiinit.c +++ b/ntoskrnl/ke/amd64/kiinit.c @@ -536,17 +536,8 @@ KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Setup the IDT */ KeInitExceptions(); - - /* Initialize debugging system */ - KdInitSystem(0, KeLoaderBlock); - - /* Check for break-in */ - if (KdPollBreakIn()) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C); } - DPRINT1("Pcr = %p, Gdt = %p, Idt = %p, Tss = %p\n", - Pcr, Pcr->GdtBase, Pcr->IdtBase, Pcr->TssBase); - /* Acquire lock */ while (InterlockedBitTestAndSet64((PLONG64)&KiFreezeExecutionLock, 0)) { @@ -563,6 +554,18 @@ KiSystemStartup(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Release lock */ InterlockedAnd64((PLONG64)&KiFreezeExecutionLock, 0); + if (Cpu == 0) + { + /* Initialize debugging system */ + KdInitSystem(0, KeLoaderBlock); + + /* Check for break-in */ + if (KdPollBreakIn()) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C); + } + + DPRINT1("Pcr = %p, Gdt = %p, Idt = %p, Tss = %p\n", + Pcr, Pcr->GdtBase, Pcr->IdtBase, Pcr->TssBase); + /* Raise to HIGH_LEVEL */ KfRaiseIrql(HIGH_LEVEL);