Reactos

[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)

+10 -50
+1 -2
dll/win32/kernel32/CMakeLists.txt
··· 99 99 client/i386/thread.S) 100 100 elseif(ARCH STREQUAL "amd64") 101 101 list(APPEND ASM_SOURCE 102 - client/amd64/fiber.S 103 - client/amd64/thread.S) 102 + client/amd64/fiber.S) 104 103 elseif(ARCH STREQUAL "arm") 105 104 list(APPEND ASM_SOURCE 106 105 client/arm/fiber.S
-38
dll/win32/kernel32/client/amd64/thread.S
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: dll/win32/kernel32/client/amd64/thread.S 5 - * PURPOSE: Thread Start Thunks 6 - * PROGRAMMER: Alex Ionescu (alex@relsoft.net) 7 - */ 8 - 9 - #include <asm.inc> 10 - .code64 11 - 12 - EXTERN BaseThreadStartup:PROC 13 - EXTERN BaseProcessStartup:PROC 14 - 15 - PUBLIC BaseThreadStartupThunk 16 - PUBLIC BaseProcessStartThunk 17 - 18 - BaseThreadStartupThunk: 19 - 20 - /* Start out fresh */ 21 - xor rbp, rbp 22 - 23 - push rbx /* lpParameter */ 24 - push rax /* lpStartAddress */ 25 - push 0 /* Return RIP */ 26 - jmp BaseThreadStartup 27 - 28 - BaseProcessStartThunk: 29 - 30 - /* Start out fresh */ 31 - xor rbp, rbp 32 - 33 - push rax /* lpStartAddress */ 34 - push 0 /* Return RIP */ 35 - jmp BaseProcessStartup 36 - 37 - END 38 - /* EOF */
+9 -10
dll/win32/kernel32/client/utils.c
··· 580 580 581 581 #elif defined(_M_AMD64) 582 582 DPRINT("BaseInitializeContext: %p\n", Context); 583 + ASSERT(((ULONG_PTR)StackAddress & 15) == 0); 584 + 585 + RtlZeroMemory(Context, sizeof(*Context)); 583 586 584 587 /* Setup the Initial Win32 Thread Context */ 585 - Context->Rax = (ULONG_PTR)StartAddress; 586 - Context->Rbx = (ULONG_PTR)Parameter; 587 - Context->Rsp = (ULONG_PTR)StackAddress; 588 - /* The other registers are undefined */ 588 + Context->Rcx = (ULONG_PTR)StartAddress; 589 + Context->Rdx = (ULONG_PTR)Parameter; 590 + Context->Rsp = (ULONG_PTR)StackAddress - 5 * sizeof(PVOID); 589 591 590 592 /* Setup the Segments */ 591 593 Context->SegGs = KGDT64_R3_DATA | RPL_MASK; ··· 596 598 Context->SegFs = KGDT64_R3_CMTEB | RPL_MASK; 597 599 598 600 /* Set the EFLAGS */ 599 - Context->EFlags = 0x3000; /* IOPL 3 */ 601 + Context->EFlags = 0x3000 | EFLAGS_INTERRUPT_MASK; /* IOPL 3 */ 600 602 601 603 if (ContextType == 1) /* For Threads */ 602 604 { 603 - Context->Rip = (ULONG_PTR)BaseThreadStartupThunk; 605 + Context->Rip = (ULONG_PTR)BaseThreadStartup; 604 606 } 605 607 else if (ContextType == 2) /* For Fibers */ 606 608 { ··· 608 610 } 609 611 else /* For first thread in a Process */ 610 612 { 611 - Context->Rip = (ULONG_PTR)BaseProcessStartThunk; 613 + Context->Rip = (ULONG_PTR)BaseProcessStartup; 612 614 } 613 615 614 616 /* Set the Context Flags */ 615 617 Context->ContextFlags = CONTEXT_FULL; 616 - 617 - /* Give it some room for the Parameter */ 618 - Context->Rsp -= sizeof(PVOID); 619 618 #elif defined(_M_ARM) 620 619 DPRINT("BaseInitializeContext: %p\n", Context); 621 620