Alexandre Julliard : ntdll: Add a separate helper to build the main module on Wow64.
Module: wine Branch: master Commit: a1830c03a50ad38ec3f857a2a8b88498d1bf5e54 URL: https://gitlab.winehq.org/wine/wine/-/commit/a1830c03a50ad38ec3f857a2a8b8849... Author: Alexandre Julliard <julliard(a)winehq.org> Date: Sun Oct 8 13:55:45 2023 +0200 ntdll: Add a separate helper to build the main module on Wow64. We can't use the normal routine because the module is 32-bit. --- dlls/ntdll/loader.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 2bf1437623f..e0cfead6893 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2191,11 +2191,16 @@ static NTSTATUS build_module( LPCWSTR load_path, const UNICODE_STRING *nt_name, * * Build the module data for the initially-loaded ntdll. */ -static void build_ntdll_module( HMODULE module ) +static void build_ntdll_module(void) { UNICODE_STRING nt_name = RTL_CONSTANT_STRING( L"\\??\\C:\\windows\\system32\\ntdll.dll" ); + MEMORY_BASIC_INFORMATION meminfo; WINE_MODREF *wm; + void *module; + NtQueryVirtualMemory( GetCurrentProcess(), LdrInitializeThunk, MemoryBasicInformation, + &meminfo, sizeof(meminfo), NULL ); + module = meminfo.AllocationBase; wm = alloc_module( module, &nt_name, TRUE ); assert( wm ); wm->ldr.Flags &= ~LDR_DONT_RESOLVE_REFS; @@ -2724,8 +2729,10 @@ static WINE_MODREF *build_main_module(void) status = RtlDosPathNameToNtPathName_U_WithStatus( params->ImagePathName.Buffer, &nt_name, NULL, NULL ); if (status) goto failed; status = build_module( NULL, &nt_name, &module, &info, NULL, DONT_RESOLVE_DLL_REFERENCES, FALSE, &wm ); + if (status) goto failed; RtlFreeUnicodeString( &nt_name ); - if (!status) return wm; + wm->ldr.LoadCount = -1; + return wm; failed: MESSAGE( "wine: failed to create main module for %s, status %lx\n", debugstr_us(¶ms->ImagePathName), status ); @@ -4055,12 +4062,29 @@ static void load_global_options(void) #ifdef _WIN64 +static void build_wow64_main_module(void) +{ + UNICODE_STRING nt_name; + WINE_MODREF *wm; + RTL_USER_PROCESS_PARAMETERS *params = NtCurrentTeb()->Peb->ProcessParameters; + void *module = NtCurrentTeb()->Peb->ImageBaseAddress; + + RtlDosPathNameToNtPathName_U_WithStatus( params->ImagePathName.Buffer, &nt_name, NULL, NULL ); + wm = alloc_module( module, &nt_name, FALSE ); + assert( wm ); + wm->ldr.LoadCount = -1; + RtlFreeUnicodeString( &nt_name ); +} + static void (WINAPI *pWow64LdrpInitialize)( CONTEXT *ctx ); void (WINAPI *pWow64PrepareForException)( EXCEPTION_RECORD *rec, CONTEXT *context ) = NULL; static void init_wow64( CONTEXT *context ) { + build_wow64_main_module(); + build_ntdll_module(); + if (!imports_fixup_done) { HMODULE wow64; @@ -4219,12 +4243,11 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR init_user_process_params(); load_global_options(); version_init(); - build_ntdll_module( meminfo.AllocationBase ); if (NtCurrentTeb()->WowTebOffset) init_wow64( context ); wm = build_main_module(); - wm->ldr.LoadCount = -1; + build_ntdll_module(); if ((status = load_dll( NULL, L"kernel32.dll", 0, &kernel32, FALSE )) != STATUS_SUCCESS) {
participants (1)
-
Alexandre Julliard