From 40673153b4c8e6f6e5637c640a68764619237a28 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 31 Aug 2021 11:31:41 +0200 Subject: [PATCH] wow64: Patch the Wow64Transition pointer in all loaded modules. Signed-off-by: Alexandre Julliard --- dlls/wow64/syscall.c | 23 ++++++++++++++++------- dlls/wow64/virtual.c | 6 ++++++ dlls/wow64/wow64_private.h | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dlls/wow64/syscall.c b/dlls/wow64/syscall.c index feda6bf348c..087bf1aa3ad 100644 --- a/dlls/wow64/syscall.c +++ b/dlls/wow64/syscall.c @@ -334,6 +334,17 @@ static DWORD get_syscall_num( const BYTE *syscall ) } +/********************************************************************** + * init_image_mapping + */ +void init_image_mapping( HMODULE module ) +{ + void **ptr = RtlFindExportedRoutineByName( module, "Wow64Transition" ); + + if (ptr) *ptr = pBTCpuGetBopCode(); +} + + /********************************************************************** * init_syscall_table */ @@ -440,7 +451,6 @@ static HMODULE load_cpu_dll(void) */ static DWORD WINAPI process_init( RTL_RUN_ONCE *once, void *param, void **context ) { - void **pWow64Transition, **p__wine_syscall_dispatcher; HMODULE module; UNICODE_STRING str; @@ -454,18 +464,17 @@ static DWORD WINAPI process_init( RTL_RUN_ONCE *once, void *param, void **contex LdrGetDllHandle( NULL, 0, &str, &module ); GET_PTR( LdrSystemDllInitBlock ); - module = (HMODULE)(ULONG_PTR)pLdrSystemDllInitBlock->ntdll_handle; - GET_PTR( Wow64Transition ); - GET_PTR( __wine_syscall_dispatcher ); - init_syscall_table( module, 0, &ntdll_syscall_table ); - module = load_cpu_dll(); GET_PTR( BTCpuGetBopCode ); GET_PTR( BTCpuProcessInit ); GET_PTR( BTCpuSimulate ); pBTCpuProcessInit(); - *pWow64Transition = *p__wine_syscall_dispatcher = pBTCpuGetBopCode(); + + module = (HMODULE)(ULONG_PTR)pLdrSystemDllInitBlock->ntdll_handle; + init_image_mapping( module ); + init_syscall_table( module, 0, &ntdll_syscall_table ); + *(void **)RtlFindExportedRoutineByName( module, "__wine_syscall_dispatcher" ) = pBTCpuGetBopCode(); init_file_redirects(); return TRUE; diff --git a/dlls/wow64/virtual.c b/dlls/wow64/virtual.c index b4aabb13c7d..e5759609974 100644 --- a/dlls/wow64/virtual.c +++ b/dlls/wow64/virtual.c @@ -257,6 +257,12 @@ NTSTATUS WINAPI wow64_NtMapViewOfSection( UINT *args ) commit, offset, size_32to64( &size, size32 ), inherit, alloc, protect ); if (NT_SUCCESS(status)) { + SECTION_IMAGE_INFORMATION info; + + if (!NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL )) + { + if (info.Machine == current_machine) init_image_mapping( addr ); + } put_addr( addr32, addr ); put_size( size32, size ); } diff --git a/dlls/wow64/wow64_private.h b/dlls/wow64/wow64_private.h index 370ae76a0c4..1a9d05eaf43 100644 --- a/dlls/wow64/wow64_private.h +++ b/dlls/wow64/wow64_private.h @@ -32,6 +32,7 @@ void * WINAPI Wow64AllocateTemp( SIZE_T size ); void WINAPI Wow64ApcRoutine( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3, CONTEXT *context ); void WINAPI Wow64PassExceptionToGuest( EXCEPTION_POINTERS *ptrs ); +extern void init_image_mapping( HMODULE module ) DECLSPEC_HIDDEN; extern void init_file_redirects(void) DECLSPEC_HIDDEN; extern BOOL get_file_redirect( OBJECT_ATTRIBUTES *attr ) DECLSPEC_HIDDEN;