From 390d71b09186c77755e93c31fe24ac10f4ac0dde Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 7 Jul 2021 11:39:41 +0200 Subject: [PATCH] ntdll: Also load the Wow64 ntdll for the main exe target machine. Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/loader.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 4d286099a2c..2fa3a720d5a 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1758,6 +1758,39 @@ static void load_ntdll(void) } +/*********************************************************************** + * load_wow64_ntdll + */ +static void load_wow64_ntdll( USHORT machine ) +{ + static const WCHAR ntdllW[] = {'n','t','d','l','l','.','d','l','l',0}; + SECTION_IMAGE_INFORMATION info; + UNICODE_STRING nt_name; + void *module; + NTSTATUS status; + SIZE_T size; + WCHAR *path = malloc( sizeof("\\??\\C:\\windows\\system32\\ntdll.dll") * sizeof(WCHAR) ); + + wcscpy( path, get_machine_wow64_dir( machine )); + wcscat( path, ntdllW ); + init_unicode_string( &nt_name, path ); + status = find_builtin_dll( &nt_name, &module, &size, &info, machine, FALSE ); + switch (status) + { + case STATUS_IMAGE_NOT_AT_BASE: + relocate_ntdll( module ); + /* fall through */ + case STATUS_SUCCESS: + TRACE("loaded %s at %p\n", debugstr_w(path), module ); + break; + default: + ERR( "failed to load %s error %x\n", debugstr_w(path), status ); + break; + } + free( path ); +} + + /*********************************************************************** * get_image_address */ @@ -1868,6 +1901,7 @@ static void start_main_thread(void) init_thread_stack( teb, is_win64 ? 0x7fffffff : 0, 0, 0 ); NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 ); load_ntdll(); + if (main_image_info.Machine != current_machine) load_wow64_ntdll( main_image_info.Machine ); status = p__wine_set_unix_funcs( NTDLL_UNIXLIB_VERSION, &unix_funcs ); if (status == STATUS_REVISION_MISMATCH) {