https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3aaee3562910cd0611356…
commit 3aaee3562910cd06113569cace4eb155ee2a6050
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Mon Feb 5 01:23:30 2018 +0100
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Sep 20 23:08:17 2020 +0200
[NTOS:KE] Save and restore previous mode in KiZwSystemService and fix restoring the
trap frame
---
ntoskrnl/ke/amd64/trap.S | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/ntoskrnl/ke/amd64/trap.S b/ntoskrnl/ke/amd64/trap.S
index 15f816f756b..3bcaa1684bf 100644
--- a/ntoskrnl/ke/amd64/trap.S
+++ b/ntoskrnl/ke/amd64/trap.S
@@ -835,6 +835,10 @@ FUNC KiZwSystemService
/* Get current thread */
mov r11, gs:[PcCurrentThread]
+ /* Save PreviousMode in the trap frame */
+ mov dil, byte ptr [r11 + KTHREAD_PreviousMode]
+ mov byte ptr [rbp + KTRAP_FRAME_PreviousMode], dil
+
/* Save the old trap frame in TrapFrame.Rdx */
mov rdi, [r11 + KTHREAD_TrapFrame]
mov [rbp + KTRAP_FRAME_Rdx], rdi
@@ -865,9 +869,13 @@ FUNC KiZwSystemService
/* Restore the old trap frame */
mov r11, gs:[PcCurrentThread]
- mov rsi, [rsp + KTRAP_FRAME_Rdx]
+ mov rsi, [rbp + KTRAP_FRAME_Rdx]
mov [r11 + KTHREAD_TrapFrame], rsi
+ /* Restore PreviousMode from the trap frame */
+ mov dil, byte ptr [rbp + KTRAP_FRAME_PreviousMode]
+ mov byte ptr [r11 + KTHREAD_PreviousMode], dil
+
/* Restore rdi and rsi */
mov rsi, [rbp + KTRAP_FRAME_Rsi]
mov rdi, [rbp + KTRAP_FRAME_Rdi]