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