https://git.reactos.org/?p=reactos.git;a=commitdiff;h=91948dea80126028a05e3ee83f9857d06ed5370f
commit 91948dea80126028a05e3ee83f9857d06ed5370f Author: Timo Kreuzer <timo.kreu...@reactos.org> AuthorDate: Thu Dec 12 14:44:05 2024 +0200 Commit: Timo Kreuzer <timo.kreu...@reactos.org> CommitDate: Mon Dec 16 16:18:45 2024 +0200 [NTOS:KE/x64] Fix handling of PCR::UserRsp This is a temporary helper for the system call entry point to store the user mode stack, before switching to the kernel mode stack. Initially it was copied to the trap frame inside KiSystemCallHandler. This has been moved to the system call entry point, but some remnants remained. The problem is that KiSystemCallHandler can be called twice in a system call (when the call is the first GUI call and the stack needs to be extended). In that scenario, when the thread was preempted, a new v [...] --- ntoskrnl/ke/amd64/traphandler.c | 5 ++--- ntoskrnl/ke/amd64/usercall.c | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ntoskrnl/ke/amd64/traphandler.c b/ntoskrnl/ke/amd64/traphandler.c index dc72d08fc63..ef2cb4d7dae 100644 --- a/ntoskrnl/ke/amd64/traphandler.c +++ b/ntoskrnl/ke/amd64/traphandler.c @@ -159,9 +159,8 @@ KiSystemCallHandler( /* We don't have an exception frame yet */ TrapFrame->ExceptionFrame = 0; - /* Before enabling interrupts get the user rsp from the KPCR */ - UserRsp = __readgsqword(FIELD_OFFSET(KIPCR, UserRsp)); - TrapFrame->Rsp = UserRsp; + /* Get the user Stack pointer */ + UserRsp = TrapFrame->Rsp; /* Enable interrupts */ _enable(); diff --git a/ntoskrnl/ke/amd64/usercall.c b/ntoskrnl/ke/amd64/usercall.c index 9bcc81384b4..81f7a81fdfc 100644 --- a/ntoskrnl/ke/amd64/usercall.c +++ b/ntoskrnl/ke/amd64/usercall.c @@ -318,9 +318,6 @@ KeUserModeCallback( /* Restore stack and return */ *UserStackPointer = OldStack; -#ifdef _M_AMD64 // could probably move the update to TrapFrame->Rsp from the C handler to the asm code - __writegsqword(FIELD_OFFSET(KIPCR, UserRsp), OldStack); -#endif return CallbackStatus; }