mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[NTOS:KE/x64] Fix KiConvertToGuiThread
- Do not allocate a new stack, if the thread already has a large one. This prevents the function from freeing a large stack as a normal stack and subsequently leaking system PTEs. - Fix the check for failure of PsConvertToGuiThread (test eax, not rax, for being negative, because by default rax is zero extended from eax, not sign extended). This fixes an infinite loop on failure.
This commit is contained in:
parent
c7fd9983cb
commit
15fbcc19b9
2 changed files with 11 additions and 3 deletions
|
@ -1041,6 +1041,11 @@ FUNC KiConvertToGuiThread
|
||||||
.allocstack 40
|
.allocstack 40
|
||||||
.endprolog
|
.endprolog
|
||||||
|
|
||||||
|
/* Check if we already have a large stack */
|
||||||
|
mov rax, gs:[PcCurrentThread]
|
||||||
|
cmp byte ptr [rax + KTHREAD_LargeStack], 0
|
||||||
|
jnz AlreadyLargeStack
|
||||||
|
|
||||||
// NewStack = (ULONG_PTR)MmCreateKernelStack(TRUE, 0);
|
// NewStack = (ULONG_PTR)MmCreateKernelStack(TRUE, 0);
|
||||||
mov cl, 1
|
mov cl, 1
|
||||||
xor rdx, rdx
|
xor rdx, rdx
|
||||||
|
@ -1050,10 +1055,10 @@ FUNC KiConvertToGuiThread
|
||||||
test rax, rax
|
test rax, rax
|
||||||
jz KiConvertToGuiThreadFailed
|
jz KiConvertToGuiThreadFailed
|
||||||
|
|
||||||
/* OldStack = KeSwitchKernelStack((PVOID)NewStack, (PVOID)(NewStack - KERNEL_STACK_SIZE)); */
|
/* OldStack = KeSwitchKernelStack((PVOID)NewStack, (PVOID)(NewStack - KERNEL_LARGE_STACK_COMMIT )); */
|
||||||
mov rcx, rax
|
mov rcx, rax
|
||||||
mov rdx, rax
|
mov rdx, rax
|
||||||
sub rdx, KERNEL_STACK_SIZE
|
sub rdx, KERNEL_LARGE_STACK_COMMIT
|
||||||
call KeSwitchKernelStack
|
call KeSwitchKernelStack
|
||||||
|
|
||||||
// MmDeleteKernelStack(OldStack, FALSE);
|
// MmDeleteKernelStack(OldStack, FALSE);
|
||||||
|
@ -1061,11 +1066,13 @@ FUNC KiConvertToGuiThread
|
||||||
xor rdx, rdx
|
xor rdx, rdx
|
||||||
call MmDeleteKernelStack
|
call MmDeleteKernelStack
|
||||||
|
|
||||||
|
AlreadyLargeStack:
|
||||||
|
|
||||||
/* Call the worker function */
|
/* Call the worker function */
|
||||||
call PsConvertToGuiThread
|
call PsConvertToGuiThread
|
||||||
|
|
||||||
/* Check for failure */
|
/* Check for failure */
|
||||||
test rax, rax
|
test eax, eax
|
||||||
js KiConvertToGuiThreadFailed
|
js KiConvertToGuiThreadFailed
|
||||||
|
|
||||||
/* Disable interrupts for return */
|
/* Disable interrupts for return */
|
||||||
|
|
|
@ -1047,6 +1047,7 @@ OFFSET(KTHREAD_TrapFrame, KTHREAD, TrapFrame),
|
||||||
OFFSET(KTHREAD_PreviousMode, KTHREAD, PreviousMode),
|
OFFSET(KTHREAD_PreviousMode, KTHREAD, PreviousMode),
|
||||||
OFFSET(KTHREAD_KernelStack, KTHREAD, KernelStack),
|
OFFSET(KTHREAD_KernelStack, KTHREAD, KernelStack),
|
||||||
OFFSET(KTHREAD_UserApcPending, KTHREAD, ApcState.UserApcPending),
|
OFFSET(KTHREAD_UserApcPending, KTHREAD, ApcState.UserApcPending),
|
||||||
|
OFFSET(KTHREAD_LargeStack, KTHREAD, LargeStack),
|
||||||
|
|
||||||
HEADER("KINTERRUPT"),
|
HEADER("KINTERRUPT"),
|
||||||
OFFSET(KINTERRUPT_Type, KINTERRUPT, Type),
|
OFFSET(KINTERRUPT_Type, KINTERRUPT, Type),
|
||||||
|
|
Loading…
Reference in a new issue