Module: wine Branch: master Commit: c29f6504747c3a80135085a7ae9ac470d2950c09 URL: https://source.winehq.org/git/wine.git/?a=commit;h=c29f6504747c3a80135085a7a...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Aug 10 16:55:21 2021 +0200
ntdll: Load the Unix dll at the same time as the PE one, but don't map it yet.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/unix/loader.c | 17 +++++++++-------- dlls/ntdll/unix/unix_private.h | 3 ++- dlls/ntdll/unix/virtual.c | 33 ++++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 5f1cbda51a9..f5135a19f40 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1121,21 +1121,17 @@ static NTSTATUS CDECL init_unix_lib( void *module, DWORD reason, const void *ptr
if (!entry) { - if (!name) return STATUS_DLL_NOT_FOUND; - if (!(handle = dlopen( name, RTLD_NOW ))) return STATUS_DLL_NOT_FOUND; + if (!name || !handle) return STATUS_DLL_NOT_FOUND;
if (!(nt = dlsym( handle, "__wine_spec_nt_header" )) || !(entry = dlsym( handle, "__wine_init_unix_lib" ))) - { - dlclose( handle ); - set_builtin_unix_info( module, NULL, NULL, NULL ); return STATUS_INVALID_IMAGE_FORMAT; - } + TRACE( "loaded %s for %p\n", debugstr_a(name), module ); unix_module = (void *)((nt->OptionalHeader.ImageBase + 0xffff) & ~0xffff); map_so_dll( nt, unix_module ); fixup_ntdll_imports( name, unix_module ); - set_builtin_unix_info( module, NULL, handle, entry ); + set_builtin_unix_entry( module, entry ); } init_func = entry; return init_func( module, reason, ptr_in, ptr_out ); @@ -1417,8 +1413,13 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T done: if (status >= 0 && ext) { + void *handle; + strcpy( ext, ".so" ); - set_builtin_unix_info( *module, ptr, NULL, NULL ); + if ((handle = dlopen( ptr, RTLD_NOW ))) + { + if (set_builtin_unix_handle( *module, ptr, handle )) dlclose( handle ); + } } free( file ); return status; diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 7d89d99d120..0fce580b120 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -231,7 +231,8 @@ extern void virtual_fill_image_information( const pe_image_info_t *pe_info, SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN; extern void *get_builtin_so_handle( void *module ) DECLSPEC_HIDDEN; extern NTSTATUS get_builtin_unix_info( void *module, const char **name, void **handle, void **entry ) DECLSPEC_HIDDEN; -extern NTSTATUS set_builtin_unix_info( void *module, const char *name, void *handle, void *entry ) DECLSPEC_HIDDEN; +extern NTSTATUS set_builtin_unix_handle( void *module, const char *name, void *handle ) DECLSPEC_HIDDEN; +extern NTSTATUS set_builtin_unix_entry( void *module, void *entry ) DECLSPEC_HIDDEN;
extern NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) DECLSPEC_HIDDEN; extern void *get_native_context( CONTEXT *context ) DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 63b322a0c68..ee1f331d778 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -682,9 +682,9 @@ NTSTATUS get_builtin_unix_info( void *module, const char **name, void **handle,
/*********************************************************************** - * set_builtin_unix_info + * set_builtin_unix_handle */ -NTSTATUS set_builtin_unix_info( void *module, const char *name, void *handle, void *entry ) +NTSTATUS set_builtin_unix_handle( void *module, const char *name, void *handle ) { sigset_t sigset; NTSTATUS status = STATUS_DLL_NOT_FOUND; @@ -696,10 +696,8 @@ NTSTATUS set_builtin_unix_info( void *module, const char *name, void *handle, vo if (builtin->module != module) continue; if (!builtin->unix_handle) { - free( builtin->unix_name ); - builtin->unix_name = name ? strdup( name ) : NULL; + builtin->unix_name = strdup( name ); builtin->unix_handle = handle; - builtin->unix_entry = entry; status = STATUS_SUCCESS; } else status = STATUS_IMAGE_ALREADY_LOADED; @@ -710,6 +708,31 @@ NTSTATUS set_builtin_unix_info( void *module, const char *name, void *handle, vo }
+/*********************************************************************** + * set_builtin_unix_entry + */ +NTSTATUS set_builtin_unix_entry( void *module, void *entry ) +{ + sigset_t sigset; + NTSTATUS status = STATUS_DLL_NOT_FOUND; + struct builtin_module *builtin; + + server_enter_uninterrupted_section( &virtual_mutex, &sigset ); + LIST_FOR_EACH_ENTRY( builtin, &builtin_modules, struct builtin_module, entry ) + { + if (builtin->module != module) continue; + if (builtin->unix_handle) + { + builtin->unix_entry = entry; + status = STATUS_SUCCESS; + } + break; + } + server_leave_uninterrupted_section( &virtual_mutex, &sigset ); + return status; +} + + /*********************************************************************** * free_ranges_lower_bound *