From 03b4cf354448b568c42585d70ae7887089963217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 6 Dec 2024 21:23:19 +0100 Subject: [PATCH] **** WIP HAL Set correct IRQL for interrupt handlers (see Timo's branch/PR for updated fix) **** --- hal/halx86/apic/apic.c | 11 +++++++++++ hal/halx86/apic/rtctimer.c | 2 +- ntoskrnl/ke/profobj.c | 7 +++++++ ntoskrnl/ke/time.c | 9 +++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/hal/halx86/apic/apic.c b/hal/halx86/apic/apic.c index d98288b81e5..de072c9fb67 100644 --- a/hal/halx86/apic/apic.c +++ b/hal/halx86/apic/apic.c @@ -743,6 +743,16 @@ HalDisableSystemInterrupt( IOApicWrite(IOAPIC_REDTBL + 2 * Index, ReDirReg.Long0); } +/* + * FIXME: Left enabled, until the non-x86 HAL uses the kernel's + * KeInitializeInterrupt(), KeConnectInterrupt() (or its HAL version) + * so that, when the interrupt handlers are invoked, they already + * are running with the correct IRQL, instead of being enforced with + * HalBeginSystemInterrupt() and cleaned up with HalEndSystemInterrupt(). + * + * This code was originally #ifndef _M_AMD64 by commit f085f50747 (r53631). + */ +// #ifndef _M_AMD64 BOOLEAN NTAPI HalBeginSystemInterrupt( @@ -821,6 +831,7 @@ HalEndSystemInterrupt( /* Restore the old IRQL */ ApicLowerIrql(OldIrql); } +// #endif /* !_M_AMD64 */ /* IRQL MANAGEMENT ************************************************************/ diff --git a/hal/halx86/apic/rtctimer.c b/hal/halx86/apic/rtctimer.c index 2f603077cda..21bcd95b673 100644 --- a/hal/halx86/apic/rtctimer.c +++ b/hal/halx86/apic/rtctimer.c @@ -219,7 +219,7 @@ HalpClockIpiHandler(IN PKTRAP_FRAME TrapFrame) return; } - /* Call the kernel to update runtimes */ + /* Call the kernel to update runtime */ KeUpdateRunTime(TrapFrame, Irql); /* End the interrupt */ diff --git a/ntoskrnl/ke/profobj.c b/ntoskrnl/ke/profobj.c index 7c2b213e893..d294e69c05d 100644 --- a/ntoskrnl/ke/profobj.c +++ b/ntoskrnl/ke/profobj.c @@ -356,6 +356,13 @@ KeProfileInterruptWithSource(IN PKTRAP_FRAME TrapFrame, { PKPROCESS Process = KeGetCurrentThread()->ApcState.Process; + { + KIRQL CurrIrql = KeGetCurrentIrql(); + if (CurrIrql < PROFILE_LEVEL) + KdDbgPortPrintf("%s() running at IRQL %d\n", __FUNCTION__, CurrIrql); + } + // ASSERT(KeGetCurrentIrql() == PROFILE_LEVEL); + /* We have to parse 2 lists. Per-Process and System-Wide */ KiParseProfileList(TrapFrame, Source, &Process->ProfileListHead); KiParseProfileList(TrapFrame, Source, &KiProfileListHead); diff --git a/ntoskrnl/ke/time.c b/ntoskrnl/ke/time.c index cb10259bb65..6e8e27813f9 100644 --- a/ntoskrnl/ke/time.c +++ b/ntoskrnl/ke/time.c @@ -59,6 +59,8 @@ KiCheckForTimerExpiration( } } +extern void KdDbgPortPrintf(PCSTR Format, ...); + VOID FASTCALL KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame, @@ -69,6 +71,13 @@ KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame, ULARGE_INTEGER CurrentTime, InterruptTime; LONG OldTickOffset; + { + KIRQL CurrIrql = KeGetCurrentIrql(); + if (CurrIrql < CLOCK_LEVEL) + KdDbgPortPrintf("%s() CurrIrql %d ; PrevIrql %d\n", __FUNCTION__, CurrIrql, Irql); + } + // ASSERT(KeGetCurrentIrql() == CLOCK_LEVEL); // CLOCK2_LEVEL + /* Check if this tick is being skipped */ if (Prcb->SkipTick) {