Module: wine Branch: master Commit: 7406583e5ba62d08cc2a5a677b7f4e6341d5fcf6 URL: https://gitlab.winehq.org/wine/wine/-/commit/7406583e5ba62d08cc2a5a677b7f4e6...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Feb 14 13:05:09 2023 +0100
ntdll: Store the unixlib handle at ntdll load time.
---
dlls/ntdll/loader.c | 2 -- dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/unix/loader.c | 18 ++++++++++++++---- dlls/ntdll/unix/unix_private.h | 1 - dlls/ntdll/unix/virtual.c | 22 +--------------------- 5 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 60ff36f4211..e47beb461f9 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -4120,8 +4120,6 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR
NtQueryVirtualMemory( GetCurrentProcess(), LdrInitializeThunk, MemoryBasicInformation, &meminfo, sizeof(meminfo), NULL ); - NtQueryVirtualMemory( GetCurrentProcess(), meminfo.AllocationBase, MemoryWineUnixFuncs, - &__wine_unixlib_handle, sizeof(__wine_unixlib_handle), NULL );
peb->LdrData = &ldr; peb->FastPebLock = &peb_lock; diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index b8c23c57283..537d244c216 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1698,6 +1698,7 @@ @ stdcall __wine_ctrl_routine(ptr) @ extern -private __wine_syscall_dispatcher @ extern -private __wine_unix_call_dispatcher +@ extern -private __wine_unixlib_handle @ extern -arch=arm64 __wine_current_teb
# Debugging diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 65934acfc36..dd0c294ea92 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -117,7 +117,6 @@ void (WINAPI *p__wine_ctrl_routine)(void*); SYSTEM_DLL_INIT_BLOCK *pLdrSystemDllInitBlock = NULL;
static void *p__wine_syscall_dispatcher; -static void **p__wine_unix_call_dispatcher;
static void * const syscalls[] = { @@ -398,7 +397,6 @@ const char **dll_paths = NULL; const char **system_dll_paths = NULL; const char *user_name = NULL; SECTION_IMAGE_INFORMATION main_image_info = { NULL }; -HMODULE ntdll_module = 0; static const IMAGE_EXPORT_DIRECTORY *ntdll_exports;
/* adjust an array of pointers to make them into RVAs */ @@ -1037,6 +1035,9 @@ static const void *get_module_data_dir( HMODULE module, ULONG dir, ULONG *size )
static void load_ntdll_functions( HMODULE module ) { + void **p__wine_unix_call_dispatcher; + unixlib_handle_t *p__wine_unixlib_handle; + ntdll_exports = get_module_data_dir( module, IMAGE_FILE_EXPORT_DIRECTORY, NULL ); assert( ntdll_exports );
@@ -1055,6 +1056,9 @@ static void load_ntdll_functions( HMODULE module ) GET_FUNC( __wine_ctrl_routine ); GET_FUNC( __wine_syscall_dispatcher ); GET_FUNC( __wine_unix_call_dispatcher ); + GET_FUNC( __wine_unixlib_handle ); + *p__wine_unix_call_dispatcher = __wine_unix_call_dispatcher; + *p__wine_unixlib_handle = (UINT_PTR)__wine_unix_call_funcs; #ifdef __aarch64__ { void **p__wine_current_teb; @@ -1087,6 +1091,14 @@ static void load_ntdll_wow64_functions( HMODULE module )
p__wine_ctrl_routine = (void *)find_named_export( module, exports, "__wine_ctrl_routine" );
+#ifdef _WIN64 + { + unixlib_handle_t *p__wine_unixlib_handle = (void *)find_named_export( module, exports, + "__wine_unixlib_handle" ); + *p__wine_unixlib_handle = (UINT_PTR)__wine_unix_call_wow64_funcs; + } +#endif + /* also set the 32-bit LdrSystemDllInitBlock */ memcpy( (void *)(ULONG_PTR)pLdrSystemDllInitBlock->pLdrSystemDllInitBlock, pLdrSystemDllInitBlock, sizeof(*pLdrSystemDllInitBlock) ); @@ -1905,7 +1917,6 @@ static void load_ntdll(void) else if (status) fatal_error( "failed to load %s error %x\n", name, status ); free( name ); load_ntdll_functions( module ); - ntdll_module = module; }
@@ -2099,7 +2110,6 @@ static void start_main_thread(void) if (main_image_info.Machine != current_machine) load_wow64_ntdll( main_image_info.Machine ); load_apiset_dll(); ntdll_init_syscalls( 0, &syscall_table, p__wine_syscall_dispatcher ); - *p__wine_unix_call_dispatcher = __wine_unix_call_dispatcher; server_init_process_done(); }
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 8821cd78491..6c196436cc7 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -41,7 +41,6 @@ static const WORD current_machine = IMAGE_FILE_MACHINE_ARMNT; static const WORD current_machine = IMAGE_FILE_MACHINE_ARM64; #endif extern WORD native_machine DECLSPEC_HIDDEN; -extern HMODULE ntdll_module DECLSPEC_HIDDEN;
extern const unixlib_entry_t __wine_unix_call_funcs[] DECLSPEC_HIDDEN; extern const unixlib_entry_t __wine_unix_call_wow64_funcs[] DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index d4afb8cc2ad..b1267ff0db5 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -640,35 +640,15 @@ void *get_builtin_so_handle( void *module ) */ static NTSTATUS get_builtin_unix_funcs( void *module, BOOL wow, const void **funcs ) { - const char *p, *ptr_name = wow ? "__wine_unix_call_wow64_funcs" : "__wine_unix_call_funcs"; + const char *ptr_name = wow ? "__wine_unix_call_wow64_funcs" : "__wine_unix_call_funcs"; sigset_t sigset; NTSTATUS status = STATUS_DLL_NOT_FOUND; struct builtin_module *builtin;
- if (module == ntdll_module) - { -#ifdef _WIN64 - *funcs = wow ? __wine_unix_call_wow64_funcs : __wine_unix_call_funcs; -#else - *funcs = __wine_unix_call_funcs; -#endif - return STATUS_SUCCESS; - } - 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_path && (p = strrchr( builtin->unix_path, '/' )) && !strcmp( p, "/ntdll.so" )) - { -#ifdef _WIN64 - *funcs = wow ? __wine_unix_call_wow64_funcs : __wine_unix_call_funcs; -#else - *funcs = __wine_unix_call_funcs; -#endif - status = STATUS_SUCCESS; - break; - } if (builtin->unix_path && !builtin->unix_handle) builtin->unix_handle = dlopen( builtin->unix_path, RTLD_NOW ); if (builtin->unix_handle)