Module: wine Branch: master Commit: d45de318748639cfd1e80a976b39f5e19213990f URL: https://gitlab.winehq.org/wine/wine/-/commit/d45de318748639cfd1e80a976b39f5e...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Nov 22 12:08:19 2022 +0100
ntdll: Always set WINELOADER variable to the current loader name.
---
dlls/ntdll/unix/env.c | 3 +++ dlls/ntdll/unix/loader.c | 48 +++++++++++++++++++++--------------------------- 2 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 5e36f2c2e0d..46c3d97c852 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -354,6 +354,7 @@ static BOOL is_dynamic_env_var( const char *var ) STARTS_WITH( var, "WINEHOMEDIR=" ) || STARTS_WITH( var, "WINEBUILDDIR=" ) || STARTS_WITH( var, "WINECONFIGDIR=" ) || + STARTS_WITH( var, "WINELOADER=" ) || STARTS_WITH( var, "WINEDLLDIR" ) || STARTS_WITH( var, "WINEUNIXCP=" ) || STARTS_WITH( var, "WINEUSERLOCALE=" ) || @@ -1068,6 +1069,7 @@ static void add_system_dll_path_var( WCHAR **env, SIZE_T *pos, SIZE_T *size ) static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size ) { const char *overrides = getenv( "WINEDLLOVERRIDES" ); + const char *wineloader = getenv( "WINELOADER" ); unsigned int i; char str[22];
@@ -1083,6 +1085,7 @@ static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size ) sprintf( str, "WINEDLLDIR%u", i ); append_envW( env, pos, size, str, NULL ); add_system_dll_path_var( env, pos, size ); + append_envA( env, pos, size, "WINELOADER", wineloader ); append_envA( env, pos, size, "WINEUSERNAME", user_name ); append_envA( env, pos, size, "WINEDLLOVERRIDES", overrides ); if (unix_cp.CodePage != CP_UTF8) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 3bb7f056b2a..fa0811ac468 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -378,10 +378,10 @@ static const BOOL use_preloader = TRUE; static const BOOL use_preloader = FALSE; #endif
-static char *argv0; static const char *bin_dir; static const char *dll_dir; static const char *ntdll_dir; +static const char *wineloader; static SIZE_T dll_path_maxlen; static int *p___wine_main_argc; static char ***p___wine_main_argv; @@ -618,8 +618,10 @@ static void set_config_dir(void) static void init_paths( char *argv[] ) { Dl_info info; + char *basename, *env;
- argv0 = strdup( argv[0] ); + if ((basename = strrchr( argv[0], '/' ))) basename++; + else basename = argv[0];
if (!dladdr( init_paths, &info ) || !(ntdll_dir = realpath_dirname( info.dli_fname ))) fatal_error( "cannot get path to ntdll.so\n" ); @@ -639,11 +641,18 @@ static void init_paths( char *argv[] ) free( path ); } #else - bin_dir = realpath_dirname( argv0 ); + bin_dir = realpath_dirname( argv[0] ); #endif if (!bin_dir) bin_dir = build_path( dll_dir, DLL_TO_BINDIR ); data_dir = build_path( bin_dir, BIN_TO_DATADIR ); + wineloader = build_path( bin_dir, basename ); } + else wineloader = build_path( build_path( build_dir, "loader" ), basename ); + + env = malloc( sizeof("WINELOADER=") + strlen(wineloader) ); + strcpy( env, "WINELOADER=" ); + strcat( env, wineloader ); + putenv( env );
set_dll_path(); set_system_dll_path(); @@ -726,8 +735,7 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i WORD machine = pe_info->machine; ULONGLONG res_start = pe_info->base; ULONGLONG res_end = pe_info->base + pe_info->map_size; - const char *loader = argv0; - const char *loader_env = getenv( "WINELOADER" ); + const char *loader = wineloader; char preloader_reserve[64], socket_env[64]; BOOL is_child_64bit;
@@ -738,28 +746,14 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i
if (!is_win64 ^ !is_child_64bit) { - /* remap WINELOADER to the alternate 32/64-bit version if necessary */ - if (loader_env) - { - int len = strlen( loader_env ); - char *env = malloc( sizeof("WINELOADER=") + len + 2 ); + int len = strlen( loader ); + char *env = malloc( len + 2 );
- if (!env) return STATUS_NO_MEMORY; - strcpy( env, "WINELOADER=" ); - strcat( env, loader_env ); - if (is_child_64bit) - { - strcat( env, "64" ); - } - else - { - len += sizeof("WINELOADER=") - 1; - if (!strcmp( env + len - 2, "64" )) env[len - 2] = 0; - } - loader = env; - putenv( env ); - } - else loader = is_child_64bit ? "wine64" : "wine"; + if (!env) return STATUS_NO_MEMORY; + strcpy( env, loader ); + if (is_child_64bit) strcat( env, "64" ); + else if (!strcmp( env + len - 2, "64" )) env[len - 2] = 0; + loader = env; }
signal( SIGPIPE, SIG_DFL ); @@ -2510,7 +2504,7 @@ void __wine_main( int argc, char *argv[], char *envp[] )
memcpy( new_argv + 1, argv, (argc + 1) * sizeof(*argv) ); putenv( noexec ); - loader_exec( argv0, new_argv, current_machine ); + loader_exec( wineloader, new_argv, current_machine ); fatal_error( "could not exec the wine loader\n" ); } }