https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f4d47faeb7407936f1254…
commit f4d47faeb7407936f125490841ea29cc77eb782d
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Mon Jun 7 13:57:32 2021 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Jun 19 12:17:18 2021 +0200
[NTOS:KE] Fix usage of KTHREAD::SwapBusy
---
ntoskrnl/ke/amd64/ctxswitch.S | 8 ++++++++
ntoskrnl/ke/amd64/thrdini.c | 3 +++
sdk/include/asm/ksx.template.h | 1 +
3 files changed, 12 insertions(+)
diff --git a/ntoskrnl/ke/amd64/ctxswitch.S b/ntoskrnl/ke/amd64/ctxswitch.S
index 94c726aa486..17a87e7c023 100644
--- a/ntoskrnl/ke/amd64/ctxswitch.S
+++ b/ntoskrnl/ke/amd64/ctxswitch.S
@@ -149,6 +149,14 @@ PUBLIC KiThreadStartup
.allocstack (6 * 8)
.endprolog
+ /* Wait for SwapBusy */
+.SwapBusySet:
+ cmp byte ptr [r8 + ThSwapBusy], 0
+ je .SwapBusyClear
+ pause
+ jmp .SwapBusySet
+.SwapBusyClear:
+
/* Save WaitIrql as KSWITCH_FRAME::ApcBypass */
mov [rsp + SwApcBypass], cl
diff --git a/ntoskrnl/ke/amd64/thrdini.c b/ntoskrnl/ke/amd64/thrdini.c
index 71d4179843a..044ac7c6396 100644
--- a/ntoskrnl/ke/amd64/thrdini.c
+++ b/ntoskrnl/ke/amd64/thrdini.c
@@ -184,6 +184,9 @@ KiSwapContextResume(
0);
}
+ /* Old thread os no longer busy */
+ OldThread->SwapBusy = FALSE;
+
/* Kernel APCs may be pending */
if (NewThread->ApcState.KernelApcPending)
{
diff --git a/sdk/include/asm/ksx.template.h b/sdk/include/asm/ksx.template.h
index 232ad290dca..9cf895d3fd2 100644
--- a/sdk/include/asm/ksx.template.h
+++ b/sdk/include/asm/ksx.template.h
@@ -762,6 +762,7 @@ OFFSET(ThSystemCallNumber, KTHREAD, SystemCallNumber),
OFFSET(ThTrapFrame, KTHREAD, TrapFrame),
OFFSET(ThApcState, KTHREAD, ApcState),
OFFSET(ThPriority, KTHREAD, Priority), // obsolete
+OFFSET(ThSwapBusy, KTHREAD, SwapBusy),
OFFSET(ThContextSwitches, KTHREAD, ContextSwitches),
OFFSET(ThState, KTHREAD, State),
OFFSET(ThProcess, KTHREAD, Process), // thProcess in native headers