https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a011d19ed2ae2345fbfcd429590e1bec9194fa6e

commit a011d19ed2ae2345fbfcd429590e1bec9194fa6e
Author:     Timo Kreuzer <[email protected]>
AuthorDate: Mon Jun 7 10:23:01 2021 +0200
Commit:     Timo Kreuzer <[email protected]>
CommitDate: Sat Jun 19 12:17:18 2021 +0200

    [NTOS:KE] Fix some locking issues
---
 ntoskrnl/include/internal/ke_x.h | 2 ++
 ntoskrnl/ke/amd64/stubs.c        | 4 ++++
 ntoskrnl/ke/dpc.c                | 1 +
 ntoskrnl/ke/procobj.c            | 3 +++
 4 files changed, 10 insertions(+)

diff --git a/ntoskrnl/include/internal/ke_x.h b/ntoskrnl/include/internal/ke_x.h
index 5bd084d0e14..7a00fba8f9c 100644
--- a/ntoskrnl/include/internal/ke_x.h
+++ b/ntoskrnl/include/internal/ke_x.h
@@ -1347,6 +1347,8 @@ KxUnwaitThreadForEvent(IN PKEVENT Event,
 // This routine must be entered with the PRCB lock held and it will exit
 // with the PRCB lock released!
 //
+_Requires_lock_held_(Prcb->PrcbLock)
+_Releases_lock_(Prcb->PrcbLock)
 FORCEINLINE
 VOID
 KxQueueReadyThread(IN PKTHREAD Thread,
diff --git a/ntoskrnl/ke/amd64/stubs.c b/ntoskrnl/ke/amd64/stubs.c
index 2f7c2c5ef2c..21d9b20b920 100644
--- a/ntoskrnl/ke/amd64/stubs.c
+++ b/ntoskrnl/ke/amd64/stubs.c
@@ -26,6 +26,7 @@ NTSTATUS
 KiConvertToGuiThread(
     VOID);
 
+_Requires_lock_not_held_(Prcb->PrcbLock)
 VOID
 NTAPI
 KiDpcInterruptHandler(VOID)
@@ -61,6 +62,9 @@ KiDpcInterruptHandler(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/dpc.c b/ntoskrnl/ke/dpc.c
index 07c64303fe5..5ef845ffbdf 100644
--- a/ntoskrnl/ke/dpc.c
+++ b/ntoskrnl/ke/dpc.c
@@ -460,6 +460,7 @@ KiTimerListExpire(IN PLIST_ENTRY ExpiredListHead,
     }
 }
 
+_Requires_lock_not_held_(Prcb->PrcbLock)
 VOID
 NTAPI
 KiQuantumEnd(VOID)
diff --git a/ntoskrnl/ke/procobj.c b/ntoskrnl/ke/procobj.c
index f2095545a13..1d639ea6e71 100644
--- a/ntoskrnl/ke/procobj.c
+++ b/ntoskrnl/ke/procobj.c
@@ -367,6 +367,9 @@ KeSetPriorityAndQuantumProcess(IN PKPROCESS Process,
     /* Lock the process */
     KiAcquireProcessLockRaiseToSynch(Process, &ProcessLock);
 
+    /* Acquire the dispatcher lock */
+    KiAcquireDispatcherLockAtSynchLevel();
+
     /* Check if we are modifying the quantum too */
     if (Quantum) Process->QuantumReset = Quantum;
 

Reply via email to