From 8cb1009e4c2a77f313ceb4d6f7309f215f9c7224 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Mon, 29 Jul 2024 16:54:09 -0700 Subject: [PATCH] ntdll: Use environ/_NSGetEnviron() directly rather than caching it in main_envp. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57005 --- dlls/ntdll/unix/env.c | 9 ++++++--- dlls/ntdll/unix/loader.c | 4 +--- dlls/ntdll/unix/unix_private.h | 1 - loader/main.c | 6 ++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 36949b905fb..f95bf737f56 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -44,6 +44,10 @@ #ifdef __APPLE__ # include # include +# include +# define environ (*_NSGetEnviron()) +#else + extern char **environ; #endif #include "ntstatus.h" @@ -70,7 +74,6 @@ static const WCHAR bootstrapW[] = {'W','I','N','E','B','O','O','T','S','T','R',' int main_argc = 0; char **main_argv = NULL; -char **main_envp = NULL; WCHAR **main_wargv = NULL; static LCID user_lcid, system_lcid; @@ -931,12 +934,12 @@ static WCHAR *get_initial_environment( SIZE_T *pos, SIZE_T *size ) /* estimate needed size */ *size = 1; - for (e = main_envp; *e; e++) *size += strlen(*e) + 1; + for (e = environ; *e; e++) *size += strlen(*e) + 1; env = malloc( *size * sizeof(WCHAR) ); ptr = env; end = env + *size - 1; - for (e = main_envp; *e && ptr < end; e++) + for (e = environ; *e && ptr < end; e++) { char *str = *e; diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 1267469bf37..b7dfb5b3528 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1953,7 +1953,6 @@ static jstring wine_init_jni( JNIEnv *env, jobject obj, jobjectArray cmdline, jo main_argc = argc; main_argv = argv; - main_envp = environ; init_paths( argv ); virtual_init(); @@ -2149,11 +2148,10 @@ static void check_command_line( int argc, char *argv[] ) * * Main entry point called by the wine loader. */ -DECLSPEC_EXPORT void __wine_main( int argc, char *argv[], char *envp[] ) +DECLSPEC_EXPORT void __wine_main( int argc, char *argv[] ) { main_argc = argc; main_argv = argv; - main_envp = envp; init_paths( argv ); diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 91267f66e76..ee5630e76f1 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -172,7 +172,6 @@ extern SIZE_T startup_info_size; extern BOOL is_prefix_bootstrap; extern int main_argc; extern char **main_argv; -extern char **main_envp; extern WCHAR **main_wargv; extern const WCHAR system_dir[]; extern unsigned int supported_machines_count; diff --git a/loader/main.c b/loader/main.c index e5de4750015..ecb51efa136 100644 --- a/loader/main.c +++ b/loader/main.c @@ -37,8 +37,6 @@ #include "main.h" -extern char **environ; - #if defined(__APPLE__) && defined(__x86_64__) && !defined(HAVE_WINE_PRELOADER) /* Not using the preloader on x86_64: @@ -260,8 +258,8 @@ int main( int argc, char *argv[] ) if ((handle = load_ntdll( argv[0] ))) { - void (*init_func)(int, char **, char **) = dlsym( handle, "__wine_main" ); - if (init_func) init_func( argc, argv, environ ); + void (*init_func)(int, char **) = dlsym( handle, "__wine_main" ); + if (init_func) init_func( argc, argv ); fprintf( stderr, "wine: __wine_main function not found in ntdll.so\n" ); exit(1); }