Commit 45a63e5b authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Store main() arguments in the Unix library.

parent 50134cce
......@@ -61,13 +61,6 @@ static inline SIZE_T get_env_length( const WCHAR *env )
return end + 1 - env;
}
#ifdef __APPLE__
extern char **__wine_get_main_environment(void);
#else
extern char **__wine_main_environ;
static char **__wine_get_main_environment(void) { return __wine_main_environ; }
#endif
/***********************************************************************
* is_special_env_var
......@@ -779,8 +772,6 @@ static void set_library_wargv( char **argv, const UNICODE_STRING *image )
total -= reslen;
}
wargv[argc] = NULL;
__wine_main_argc = argc;
__wine_main_wargv = wargv;
}
......@@ -1465,6 +1456,10 @@ void init_user_process_params( SIZE_T data_size )
startup_info_t *info = NULL;
RTL_USER_PROCESS_PARAMETERS *params = NULL;
UNICODE_STRING curdir, dllpath, imagepath, cmdline, title, desktop, shellinfo, runtime;
int argc;
char **argv, **envp;
unix_funcs->get_main_args( &argc, &argv, &envp );
if (!data_size)
{
......@@ -1472,13 +1467,13 @@ void init_user_process_params( SIZE_T data_size )
WCHAR *env, curdir_buffer[MAX_PATH];
NtCurrentTeb()->Peb->ProcessParameters = &initial_params;
initial_params.Environment = build_initial_environment( __wine_get_main_environment() );
initial_params.Environment = build_initial_environment( envp );
curdir.Buffer = curdir_buffer;
curdir.MaximumLength = sizeof(curdir_buffer);
get_current_directory( &curdir );
initial_params.CurrentDirectory.DosPath = curdir;
get_image_path( __wine_main_argv[0], &initial_params.ImagePathName );
set_library_wargv( __wine_main_argv, &initial_params.ImagePathName );
get_image_path( argv[0], &initial_params.ImagePathName );
set_library_wargv( argv, &initial_params.ImagePathName );
build_command_line( __wine_main_wargv, &cmdline );
LdrGetDllPath( initial_params.ImagePathName.Buffer, 0, &load_path, &dummy );
RtlInitUnicodeString( &dllpath, load_path );
......@@ -1566,7 +1561,7 @@ void init_user_process_params( SIZE_T data_size )
else params->Environment[0] = 0;
}
set_library_wargv( __wine_main_argv, NULL );
set_library_wargv( argv, NULL );
done:
RtlFreeHeap( GetProcessHeap(), 0, info );
......
......@@ -1324,11 +1324,12 @@ static void call_tls_callbacks( HMODULE module, UINT reason )
static void call_constructors( WINE_MODREF *wm )
{
#ifdef HAVE_DLINFO
extern char **__wine_main_environ;
struct link_map *map;
void (*init_func)(int, char **, char **) = NULL;
void (**init_array)(int, char **, char **) = NULL;
ULONG_PTR i, init_arraysz = 0;
int argc;
char **argv, **envp;
#ifdef _WIN64
const Elf64_Dyn *dyn;
#else
......@@ -1351,11 +1352,12 @@ static void call_constructors( WINE_MODREF *wm )
TRACE( "%s: got init_func %p init_array %p %lu\n", debugstr_us( &wm->ldr.BaseDllName ),
init_func, init_array, init_arraysz );
if (init_func) init_func( __wine_main_argc, __wine_main_argv, __wine_main_environ );
unix_funcs->get_main_args( &argc, &argv, &envp );
if (init_func) init_func( argc, argv, envp );
if (init_array)
for (i = 0; i < init_arraysz / sizeof(*init_array); i++)
init_array[i]( __wine_main_argc, __wine_main_argv, __wine_main_environ );
for (i = 0; i < init_arraysz / sizeof(*init_array); i++) init_array[i]( argc, argv, envp );
#endif
}
......
......@@ -65,6 +65,14 @@ WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
extern IMAGE_NT_HEADERS __wine_spec_nt_header;
extern void CDECL __wine_set_unix_funcs( int version, const struct unix_funcs *funcs );
extern int __wine_main_argc;
extern char **__wine_main_argv;
extern char **__wine_main_environ;
static int main_argc;
static char **main_argv;
static char **main_envp;
static inline void *get_rva( const IMAGE_NT_HEADERS *nt, ULONG_PTR addr )
{
return (BYTE *)nt + addr;
......@@ -151,6 +159,19 @@ void CDECL get_host_version( const char **sysname, const char **release )
/*************************************************************************
* get_main_args
*
* Return the initial arguments.
*/
static void CDECL get_main_args( int *argc, char **argv[], char **envp[] )
{
*argc = main_argc;
*argv = main_argv;
*envp = main_envp;
}
/*************************************************************************
* map_so_dll
*
* Map a builtin dll in memory and fixup RVAs.
......@@ -428,6 +449,7 @@ static HMODULE load_ntdll(void)
*/
static struct unix_funcs unix_funcs =
{
get_main_args,
get_version,
get_build_id,
get_host_version,
......@@ -684,9 +706,6 @@ static void check_command_line( int argc, char *argv[] )
*/
void __wine_main( int argc, char *argv[], char *envp[] )
{
extern int __wine_main_argc;
extern char **__wine_main_argv;
extern char **__wine_main_environ;
HMODULE module;
wine_init_argv0_path( argv[0] );
......@@ -705,9 +724,9 @@ void __wine_main( int argc, char *argv[], char *envp[] )
}
}
__wine_main_argc = argc;
__wine_main_argv = argv;
__wine_main_environ = envp;
__wine_main_argc = main_argc = argc;
__wine_main_argv = main_argv = argv;
__wine_main_environ = main_envp = envp;
virtual_init();
module = load_ntdll();
......@@ -734,6 +753,15 @@ NTSTATUS __cdecl __wine_init_unix_lib( HMODULE module, const void *ptr_in, void
{
const IMAGE_NT_HEADERS *nt = ptr_in;
#ifdef __APPLE__
extern char **__wine_get_main_environment(void);
main_envp = __wine_get_main_environment();
#else
main_envp = __wine_main_environ;
#endif
main_argc = __wine_main_argc;
main_argv = __wine_main_argv;
map_so_dll( nt, module );
fixup_ntdll_imports( &__wine_spec_nt_header, module );
*(struct unix_funcs **)ptr_out = &unix_funcs;
......
......@@ -24,11 +24,12 @@
#include "wine/debug.h"
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 3
#define NTDLL_UNIXLIB_VERSION 4
struct unix_funcs
{
/* environment functions */
void (CDECL *get_main_args)( int *argc, char **argv[], char **envp[] );
const char * (CDECL *get_version)(void);
const char * (CDECL *get_build_id)(void);
void (CDECL *get_host_version)( const char **sysname, const char **release );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment