From ba1495f7c2c3cff3db9ce99600bfc8ddfa365387 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 27 Apr 2020 12:35:39 +0200 Subject: [PATCH] ntdll: Avoid using wine_dll_enum_load_path() from libwine. Signed-off-by: Alexandre Julliard --- dlls/ntdll/env.c | 5 ++--- dlls/ntdll/loader.c | 8 +++----- dlls/ntdll/ntdll_misc.h | 2 ++ dlls/ntdll/server.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index eabebbcc287..71ae48681df 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -38,7 +38,6 @@ #define WIN32_NO_STATUS #include "windef.h" #include "winternl.h" -#include "wine/library.h" #include "wine/debug.h" #include "ntdll_misc.h" #include "winnt.h" @@ -412,10 +411,10 @@ static void set_wow64_environment( WCHAR **env ) set_wine_path_variable( env, winehomedirW, home ); set_wine_path_variable( env, winebuilddirW, build_dir ); set_wine_path_variable( env, wineconfigdirW, config_dir ); - for (i = 0; (p = wine_dll_enum_load_path( i )); i++) + for (i = 0; dll_paths[i]; i++) { NTDLL_swprintf( buf, winedlldirW, i ); - set_wine_path_variable( env, buf, p ); + set_wine_path_variable( env, buf, dll_paths[i] ); } NTDLL_swprintf( buf, winedlldirW, i ); set_wine_path_variable( env, buf, NULL ); diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 4d69e33b098..5ae6b11e00f 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2715,7 +2715,6 @@ static NTSTATUS find_builtin_dll( const WCHAR *name, WINE_MODREF **pwm, void **module, pe_image_info_t *image_info, struct stat *st, char **so_name ) { - const char *path; unsigned int i, pos, len, namelen, maxlen = 0; char *ptr, *file; NTSTATUS status = STATUS_DLL_NOT_FOUND; @@ -2723,8 +2722,7 @@ static NTSTATUS find_builtin_dll( const WCHAR *name, WINE_MODREF **pwm, len = wcslen( name ); if (build_dir) maxlen = strlen(build_dir) + sizeof("/programs/") + len; - for (i = 0; (path = wine_dll_enum_load_path( i )); i++) maxlen = max( maxlen, strlen(path)+1 ); - maxlen += len + sizeof(".so"); + maxlen = max( maxlen, dll_path_maxlen ) + len + sizeof(".so"); if (!(file = RtlAllocateHeap( GetProcessHeap(), 0, maxlen ))) return STATUS_NO_MEMORY; @@ -2763,10 +2761,10 @@ static NTSTATUS find_builtin_dll( const WCHAR *name, WINE_MODREF **pwm, if (status != STATUS_DLL_NOT_FOUND) goto done; } - for (i = 0; (path = wine_dll_enum_load_path( i )); i++) + for (i = 0; dll_paths[i]; i++) { file[pos + len + 1] = 0; - ptr = prepend( file + pos, path, strlen(path) ); + ptr = prepend( file + pos, dll_paths[i], strlen(dll_paths[i]) ); status = open_builtin_file( ptr, pwm, module, image_info, st, so_name ); if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) found_image = TRUE; else if (status != STATUS_DLL_NOT_FOUND) goto done; diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index fc12bf47ef9..2e26d189a1e 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -108,6 +108,8 @@ extern WCHAR **__wine_main_wargv; extern const char *build_dir DECLSPEC_HIDDEN; extern const char *data_dir DECLSPEC_HIDDEN; extern const char *config_dir DECLSPEC_HIDDEN; +extern const char **dll_paths DECLSPEC_HIDDEN; +extern size_t dll_path_maxlen DECLSPEC_HIDDEN; extern timeout_t server_start_time DECLSPEC_HIDDEN; extern unsigned int server_cpus DECLSPEC_HIDDEN; extern BOOL is_wow64 DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index 429a41c397e..bc25e242a77 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -116,6 +116,8 @@ static const enum cpu_type client_cpu = CPU_ARM64; const char *build_dir = NULL; const char *data_dir = NULL; const char *config_dir = NULL; +const char **dll_paths = NULL; +size_t dll_path_maxlen = 0; static const char *server_dir; static const char *bin_dir; @@ -1311,6 +1313,36 @@ static const char *init_config_dir(void) } +/*********************************************************************** + * build_dll_path + */ +static void build_dll_path( const char *dll_dir ) +{ + const char *default_dlldir = DLLDIR; + char *p, *path = getenv( "WINEDLLPATH" ); + int i, count = 0; + + if (path) for (p = path, count = 1; *p; p++) if (*p == ':') count++; + + dll_paths = malloc( (count + 2) * sizeof(*dll_paths) ); + count = 0; + + if (!build_dir && dll_dir) dll_paths[count++] = dll_dir; + + if (path) + { + path = strdup(path); + for (p = strtok( path, ":" ); p; p = strtok( NULL, ":" )) dll_paths[count++] = strdup( p ); + free( path ); + } + + if (!build_dir && !dll_dir) dll_paths[count++] = default_dlldir; + + for (i = 0; i < count; i++) dll_path_maxlen = max( dll_path_maxlen, strlen(dll_paths[i]) ); + dll_paths[count] = NULL; +} + + /*********************************************************************** * init_paths */ @@ -1343,6 +1375,7 @@ void init_paths(void) data_dir = build_path( bin_dir, BIN_TO_DATADIR ); } + build_dll_path( dll_dir ); config_dir = init_config_dir(); }