Module: wine Branch: master Commit: a573860062b1117ec97c9e92fb82e1437fa1dd34 URL: https://gitlab.winehq.org/wine/wine/-/commit/a573860062b1117ec97c9e92fb82e14...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Jul 8 23:08:51 2024 +0200
wow64cpu: Simplify the Unix call thunk.
Non-PE builds are no longer supported.
---
dlls/wow64cpu/cpu.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-)
diff --git a/dlls/wow64cpu/cpu.c b/dlls/wow64cpu/cpu.c index c574315ec7d..6c6b2352bb6 100644 --- a/dlls/wow64cpu/cpu.c +++ b/dlls/wow64cpu/cpu.c @@ -43,14 +43,7 @@ struct thunk_32to64 struct thunk_opcodes { struct thunk_32to64 syscall_thunk; - struct - { - BYTE pushl; /* pushl $dispatcher_high */ - DWORD dispatcher_high; - BYTE pushl2; /* pushl $dispatcher_low */ - DWORD dispatcher_low; - struct thunk_32to64 t; - } unix_thunk; + struct thunk_32to64 unix_thunk; }; #include "poppack.h"
@@ -60,6 +53,8 @@ static USHORT cs64_sel; static USHORT ds64_sel; static USHORT fs32_sel;
+void **__wine_unix_call_dispatcher = NULL; + BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, void *reserved ) { if (reason == DLL_PROCESS_ATTACH) LdrDisableThreadCalloutsForDll( inst ); @@ -252,14 +247,14 @@ __ASM_GLOBAL_FUNC( unix_call_32to64, "movl %esi,0xa0(%r13)\n\t" /* context->Esi */ "movl %ebx,0xa4(%r13)\n\t" /* context->Ebx */ "movl %ebp,0xb4(%r13)\n\t" /* context->Ebp */ - "movl 8(%r14),%edx\n\t" + "movl (%r14),%edx\n\t" "movl %edx,0xb8(%r13)\n\t" /* context->Eip */ - "leaq 28(%r14),%rdx\n\t" + "leaq 20(%r14),%rdx\n\t" "movl %edx,0xc4(%r13)\n\t" /* context->Esp */ - "movq 12(%r14),%rcx\n\t" /* handle */ - "movl 20(%r14),%edx\n\t" /* code */ - "movl 24(%r14),%r8d\n\t" /* args */ - "callq *(%r14)\n\t" + "movq 4(%r14),%rcx\n\t" /* handle */ + "movl 12(%r14),%edx\n\t" /* code */ + "movl 16(%r14),%r8d\n\t" /* args */ + "callq *__wine_unix_call_dispatcher(%rip)\n\t" "btrl $0,-4(%r13)\n\t" /* cpu->Flags & WOW64_CPURESERVED_FLAG_RESET_STATE */ "jc .Lsyscall_32to64_return\n\t" "movl 0xb8(%r13),%edx\n\t" /* context->Eip */ @@ -316,6 +311,7 @@ NTSTATUS WINAPI BTCpuProcessInit(void)
LdrGetDllHandle( NULL, 0, &str, &module ); p__wine_unix_call_dispatcher = RtlFindExportedRoutineByName( module, "__wine_unix_call_dispatcher" ); + __wine_unix_call_dispatcher = *p__wine_unix_call_dispatcher;
RtlCaptureContext( &context ); cs64_sel = context.SegCs; @@ -328,15 +324,11 @@ NTSTATUS WINAPI BTCpuProcessInit(void) thunk->syscall_thunk.addr = PtrToUlong( syscall_32to64 ); thunk->syscall_thunk.cs = cs64_sel;
- thunk->unix_thunk.pushl = 0x68; - thunk->unix_thunk.dispatcher_high = (ULONG_PTR)*p__wine_unix_call_dispatcher >> 32; - thunk->unix_thunk.pushl2 = 0x68; - thunk->unix_thunk.dispatcher_low = (ULONG_PTR)*p__wine_unix_call_dispatcher; - thunk->unix_thunk.t.ljmp = 0xff; - thunk->unix_thunk.t.modrm = 0x2d; - thunk->unix_thunk.t.op = PtrToUlong( &thunk->unix_thunk.t.addr ); - thunk->unix_thunk.t.addr = PtrToUlong( unix_call_32to64 ); - thunk->unix_thunk.t.cs = cs64_sel; + thunk->unix_thunk.ljmp = 0xff; + thunk->unix_thunk.modrm = 0x2d; + thunk->unix_thunk.op = PtrToUlong( &thunk->unix_thunk.addr ); + thunk->unix_thunk.addr = PtrToUlong( unix_call_32to64 ); + thunk->unix_thunk.cs = cs64_sel;
NtProtectVirtualMemory( GetCurrentProcess(), (void **)&thunk, &size, PAGE_EXECUTE_READ, &old_prot ); return STATUS_SUCCESS;