Skip to content

Commit

Permalink
ntdll: Use environ/_NSGetEnviron() directly rather than caching it in…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpippy authored and julliard committed Jul 31, 2024
1 parent 0291c9f commit 8cb1009
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
9 changes: 6 additions & 3 deletions dlls/ntdll/unix/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions dlls/ntdll/unix/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );

Expand Down
1 change: 0 additions & 1 deletion dlls/ntdll/unix/unix_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions loader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8cb1009

Please sign in to comment.