https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ab528ac6ae105b19d4575…
commit ab528ac6ae105b19d457587dc680d8016720bc3d
Author: Oleg Dubinskiy <oleg.dubinskij30(a)gmail.com>
AuthorDate: Sat Jan 20 15:58:39 2024 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Jan 20 15:58:39 2024 +0100
[NTOS:KE] Acquire PRCB lock before marking thread ready for execution in dispatch
interrupt routine (#6387)
Fixed in x86 and ARM (this was already done in x64).
This is needed because thread preparation routine KxQueueReadyThread()
releases PRCB lock, but does not acquire it, so that the locking must
always be done outside the function, same as in all its other usage cases.
This fixes an assert from release PRCB routine, when booting x86 ReactOS
in SMP mode, because it attempts to release the lock when it is not
actually acquired.
Addendum to commit a011d19ed.
+ Add an assert in KxQueueReadyThread() to ensure the PRCB lock is actually acquired.
---
ntoskrnl/include/internal/ke_x.h | 1 +
ntoskrnl/ke/arm/thrdini.c | 3 +++
ntoskrnl/ke/i386/thrdini.c | 3 +++
3 files changed, 7 insertions(+)
diff --git a/ntoskrnl/include/internal/ke_x.h b/ntoskrnl/include/internal/ke_x.h
index 70fa05e1d12..fcf3edb2786 100644
--- a/ntoskrnl/include/internal/ke_x.h
+++ b/ntoskrnl/include/internal/ke_x.h
@@ -1359,6 +1359,7 @@ KxQueueReadyThread(IN PKTHREAD Thread,
/* Sanity checks */
ASSERT(Prcb == KeGetCurrentPrcb());
+ ASSERT(Prcb->PrcbLock != 0);
ASSERT(Thread->State == Running);
ASSERT(Thread->NextProcessor == Prcb->Number);
diff --git a/ntoskrnl/ke/arm/thrdini.c b/ntoskrnl/ke/arm/thrdini.c
index 190b73f926c..c32b39c392d 100644
--- a/ntoskrnl/ke/arm/thrdini.c
+++ b/ntoskrnl/ke/arm/thrdini.c
@@ -334,6 +334,9 @@ KiDispatchInterrupt(VOID)
}
else if (Prcb->NextThread)
{
+ /* Acquire the PRCB lock */
+ KiAcquirePrcbLock(Prcb);
+
/* Capture current thread data */
OldThread = Prcb->CurrentThread;
NewThread = Prcb->NextThread;
diff --git a/ntoskrnl/ke/i386/thrdini.c b/ntoskrnl/ke/i386/thrdini.c
index 3214f560872..91e8ad3931f 100644
--- a/ntoskrnl/ke/i386/thrdini.c
+++ b/ntoskrnl/ke/i386/thrdini.c
@@ -495,6 +495,9 @@ KiDispatchInterrupt(VOID)
}
else if (Prcb->NextThread)
{
+ /* Acquire the PRCB lock */
+ KiAcquirePrcbLock(Prcb);
+
/* Capture current thread data */
OldThread = Prcb->CurrentThread;
NewThread = Prcb->NextThread;