https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8df1bd612a38e8f75e80c…
commit 8df1bd612a38e8f75e80c7e347ab344df09a4cd3
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Mon Feb 12 19:14:15 2018 +0100
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Nov 7 18:33:02 2020 +0100
[KERNEL32] Fix register initialization in BaseInitializeContext
Get rid of BaseThreadStartupThunk and BaseProcessStartThunk asm wrappers and go to the
C functions directly (home space is allocated on the stack by the kernel)
---
dll/win32/kernel32/CMakeLists.txt | 3 +--
dll/win32/kernel32/client/amd64/thread.S | 38 --------------------------------
dll/win32/kernel32/client/utils.c | 19 ++++++++--------
3 files changed, 10 insertions(+), 50 deletions(-)
diff --git a/dll/win32/kernel32/CMakeLists.txt b/dll/win32/kernel32/CMakeLists.txt
index 7d31686837d..4f4eddc4f8f 100644
--- a/dll/win32/kernel32/CMakeLists.txt
+++ b/dll/win32/kernel32/CMakeLists.txt
@@ -99,8 +99,7 @@ if(ARCH STREQUAL "i386")
client/i386/thread.S)
elseif(ARCH STREQUAL "amd64")
list(APPEND ASM_SOURCE
- client/amd64/fiber.S
- client/amd64/thread.S)
+ client/amd64/fiber.S)
elseif(ARCH STREQUAL "arm")
list(APPEND ASM_SOURCE
client/arm/fiber.S
diff --git a/dll/win32/kernel32/client/amd64/thread.S
b/dll/win32/kernel32/client/amd64/thread.S
deleted file mode 100644
index 575789ef17f..00000000000
--- a/dll/win32/kernel32/client/amd64/thread.S
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: dll/win32/kernel32/client/amd64/thread.S
- * PURPOSE: Thread Start Thunks
- * PROGRAMMER: Alex Ionescu (alex(a)relsoft.net)
- */
-
-#include <asm.inc>
-.code64
-
-EXTERN BaseThreadStartup:PROC
-EXTERN BaseProcessStartup:PROC
-
-PUBLIC BaseThreadStartupThunk
-PUBLIC BaseProcessStartThunk
-
-BaseThreadStartupThunk:
-
- /* Start out fresh */
- xor rbp, rbp
-
- push rbx /* lpParameter */
- push rax /* lpStartAddress */
- push 0 /* Return RIP */
- jmp BaseThreadStartup
-
-BaseProcessStartThunk:
-
- /* Start out fresh */
- xor rbp, rbp
-
- push rax /* lpStartAddress */
- push 0 /* Return RIP */
- jmp BaseProcessStartup
-
-END
-/* EOF */
diff --git a/dll/win32/kernel32/client/utils.c b/dll/win32/kernel32/client/utils.c
index 6e3a3368ad5..c10d2d45004 100644
--- a/dll/win32/kernel32/client/utils.c
+++ b/dll/win32/kernel32/client/utils.c
@@ -580,12 +580,14 @@ BaseInitializeContext(IN PCONTEXT Context,
#elif defined(_M_AMD64)
DPRINT("BaseInitializeContext: %p\n", Context);
+ ASSERT(((ULONG_PTR)StackAddress & 15) == 0);
+
+ RtlZeroMemory(Context, sizeof(*Context));
/* Setup the Initial Win32 Thread Context */
- Context->Rax = (ULONG_PTR)StartAddress;
- Context->Rbx = (ULONG_PTR)Parameter;
- Context->Rsp = (ULONG_PTR)StackAddress;
- /* The other registers are undefined */
+ Context->Rcx = (ULONG_PTR)StartAddress;
+ Context->Rdx = (ULONG_PTR)Parameter;
+ Context->Rsp = (ULONG_PTR)StackAddress - 5 * sizeof(PVOID);
/* Setup the Segments */
Context->SegGs = KGDT64_R3_DATA | RPL_MASK;
@@ -596,11 +598,11 @@ BaseInitializeContext(IN PCONTEXT Context,
Context->SegFs = KGDT64_R3_CMTEB | RPL_MASK;
/* Set the EFLAGS */
- Context->EFlags = 0x3000; /* IOPL 3 */
+ Context->EFlags = 0x3000 | EFLAGS_INTERRUPT_MASK; /* IOPL 3 */
if (ContextType == 1) /* For Threads */
{
- Context->Rip = (ULONG_PTR)BaseThreadStartupThunk;
+ Context->Rip = (ULONG_PTR)BaseThreadStartup;
}
else if (ContextType == 2) /* For Fibers */
{
@@ -608,14 +610,11 @@ BaseInitializeContext(IN PCONTEXT Context,
}
else /* For first thread in a Process */
{
- Context->Rip = (ULONG_PTR)BaseProcessStartThunk;
+ Context->Rip = (ULONG_PTR)BaseProcessStartup;
}
/* Set the Context Flags */
Context->ContextFlags = CONTEXT_FULL;
-
- /* Give it some room for the Parameter */
- Context->Rsp -= sizeof(PVOID);
#elif defined(_M_ARM)
DPRINT("BaseInitializeContext: %p\n", Context);