[NTOS:KE/x64] Move setting the thread's trap frame to KiSystemCallEntry64

This is needed, because KiSystemCallHandler can be called multiple times for the same syscall entry, which would mess up the linkage. This replaces a previous hack and makes things cleaner.
This commit is contained in:
Timo Kreuzer 2024-03-25 15:57:34 +02:00
parent fc6bf61e4c
commit 1538712c0b
2 changed files with 9 additions and 10 deletions

View file

@ -817,6 +817,15 @@ PUBLIC KiSystemCallEntry64
stmxcsr [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_MxCsr] stmxcsr [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_MxCsr]
ldmxcsr gs:[PcMxCsr] ldmxcsr gs:[PcMxCsr]
/* Get the current thread and the trap frame */
mov rax, gs:[PcCurrentThread]
mov rcx, [rax + ThTrapFrame]
/* Save the old trap frame */
lea rdx, [rsp + MAX_SYSCALL_PARAM_SIZE]
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_TrapFrame], rcx
mov [rax + ThTrapFrame], rdx
#if DBG #if DBG
/* Check IRQL */ /* Check IRQL */
mov rax, cr8 mov rax, cr8
@ -1077,12 +1086,6 @@ AlreadyLargeStack:
/* Disable interrupts for return */ /* Disable interrupts for return */
cli cli
// FIXME: should just do the trap frame switch in KiSystemCallHandler64
/* Restore old trap frame */
mov rcx, gs:[PcCurrentThread]
mov rdx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_TrapFrame]
mov [rcx + KTHREAD_TrapFrame], rdx
// Restore register parameters // Restore register parameters
mov rcx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rip] mov rcx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rip]
mov rdx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rdx] mov rdx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rdx]

View file

@ -116,10 +116,6 @@ KiSystemCallHandler(
/* Set previous mode */ /* Set previous mode */
Thread->PreviousMode = TrapFrame->PreviousMode = UserMode; Thread->PreviousMode = TrapFrame->PreviousMode = UserMode;
/* Save the old trap frame and set the new */
TrapFrame->TrapFrame = (ULONG64)Thread->TrapFrame;
Thread->TrapFrame = TrapFrame;
/* We don't have an exception frame yet */ /* We don't have an exception frame yet */
TrapFrame->ExceptionFrame = 0; TrapFrame->ExceptionFrame = 0;