Module: wine Branch: master Commit: 0433db1eb1dadcb7e38b659f7863d5d6c88f5395 URL: https://gitlab.winehq.org/wine/wine/-/commit/0433db1eb1dadcb7e38b659f7863d5d...
Author: Alexandre Julliard julliard@winehq.org Date: Tue May 23 13:22:28 2023 +0200
ntdll: Add a helper function to map the main exe module.
---
dlls/ntdll/unix/loader.c | 16 +++++----------- dlls/ntdll/unix/unix_private.h | 2 ++ dlls/ntdll/unix/virtual.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index ba96e1ed851..4f485655fe2 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1663,7 +1663,7 @@ BOOL is_builtin_path( const UNICODE_STRING *path, WORD *machine ) * open_main_image */ static NTSTATUS open_main_image( WCHAR *image, void **module, SECTION_IMAGE_INFORMATION *info, - enum loadorder loadorder ) + enum loadorder loadorder, USHORT machine ) { static const WCHAR soW[] = {'.','s','o',0}; UNICODE_STRING nt_name; @@ -1684,14 +1684,8 @@ static NTSTATUS open_main_image( WCHAR *image, void **module, SECTION_IMAGE_INFO status = open_dll_file( unix_name, &attr, &mapping ); if (!status) { - *module = NULL; - status = NtMapViewOfSection( mapping, NtCurrentProcess(), module, 0, 0, NULL, &size, - ViewShare, 0, PAGE_EXECUTE_READ ); - if (!status) - { - NtQuerySection( mapping, SectionImageInformation, info, sizeof(*info), NULL ); - if (info->u.s.ComPlusNativeReady) info->Machine = native_machine; - } + status = virtual_map_module( mapping, module, &size, info, 0, machine ); + if (!status && info->u.s.ComPlusNativeReady) info->Machine = native_machine; NtClose( mapping ); } else if (status == STATUS_INVALID_IMAGE_NOT_MZ && loadorder != LO_NATIVE) @@ -1732,7 +1726,7 @@ NTSTATUS load_main_exe( const WCHAR *dos_name, const char *unix_name, const WCHA if ((status = unix_to_nt_file_name( unix_name, image ))) goto failed; init_unicode_string( &nt_name, *image ); loadorder = get_load_order( &nt_name ); - status = open_main_image( *image, module, &main_image_info, loadorder ); + status = open_main_image( *image, module, &main_image_info, loadorder, 0 ); if (status != STATUS_DLL_NOT_FOUND) return status; free( *image ); } @@ -1752,7 +1746,7 @@ NTSTATUS load_main_exe( const WCHAR *dos_name, const char *unix_name, const WCHA init_unicode_string( &nt_name, *image ); if (loadorder == LO_INVALID) loadorder = get_load_order( &nt_name );
- status = open_main_image( *image, module, &main_image_info, loadorder ); + status = open_main_image( *image, module, &main_image_info, loadorder, 0 ); if (status != STATUS_DLL_NOT_FOUND) return status;
/* if path is in system dir, we can load the builtin even if the file itself doesn't exist */ diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index e21fd780cf4..1b9ec243945 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -223,6 +223,8 @@ extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN; extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info, BOOL wow64 ) DECLSPEC_HIDDEN; extern NTSTATUS virtual_map_builtin_module( HANDLE mapping, void **module, SIZE_T *size, SECTION_IMAGE_INFORMATION *info, ULONG_PTR limit, WORD machine, BOOL prefer_native ) DECLSPEC_HIDDEN; +extern NTSTATUS virtual_map_module( HANDLE mapping, void **module, SIZE_T *size, SECTION_IMAGE_INFORMATION *info, + ULONG_PTR limit, USHORT machine ) DECLSPEC_HIDDEN; extern NTSTATUS virtual_create_builtin_view( void *module, const UNICODE_STRING *nt_name, pe_image_info_t *info, void *so_handle ) DECLSPEC_HIDDEN; extern TEB *virtual_alloc_first_teb(void) DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 873800bb42f..9ebede0b159 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -3073,6 +3073,42 @@ NTSTATUS virtual_map_builtin_module( HANDLE mapping, void **module, SIZE_T *size }
+/*********************************************************************** + * virtual_map_module + */ +NTSTATUS virtual_map_module( HANDLE mapping, void **module, SIZE_T *size, SECTION_IMAGE_INFORMATION *info, + ULONG_PTR limit, USHORT machine ) +{ + unsigned int status; + mem_size_t full_size; + unsigned int sec_flags; + HANDLE shared_file; + pe_image_info_t *image_info = NULL; + ACCESS_MASK access = SECTION_MAP_READ | SECTION_MAP_EXECUTE; + WCHAR *filename; + + if ((status = get_mapping_info( mapping, access, &sec_flags, &full_size, &shared_file, &image_info ))) + return status; + + if (!image_info) return STATUS_INVALID_PARAMETER; + + *module = NULL; + *size = 0; + filename = (WCHAR *)(image_info + 1); + + /* check if we can replace that mapping with the builtin */ + status = load_builtin( image_info, filename, machine, module, size, limit ); + if (status == STATUS_IMAGE_ALREADY_LOADED) + status = virtual_map_image( mapping, access, module, size, shared_file, limit, 0, + machine, image_info, filename, FALSE ); + + virtual_fill_image_information( image_info, info ); + if (shared_file) NtClose( shared_file ); + free( image_info ); + return status; +} + + /*********************************************************************** * virtual_create_builtin_view */