ntdll: Use environ/_NSGetEnviron() directly rather than caching it in main_envp.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57005
This commit is contained in:
Brendan Shanks 2024-07-29 16:54:09 -07:00 committed by Alexandre Julliard
parent 0291c9f9fb
commit 8cb1009e4c
Notes: Alexandre Julliard 2024-07-31 23:44:16 +02:00
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/wine/-/merge_requests/6178
4 changed files with 9 additions and 11 deletions

View file

@ -44,6 +44,10 @@
#ifdef __APPLE__
# include <CoreFoundation/CFLocale.h>
# include <CoreFoundation/CFString.h>
# include <crt_externs.h>
# 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;

View file

@ -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 );

View file

@ -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;

View file

@ -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);
}