From 3dadd980bfbb2fb05a1a695decd06a429ddda97c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 5 Nov 2019 12:39:23 +0100 Subject: [PATCH] ntdll: Directly allocate the final process parameters structure. Signed-off-by: Alexandre Julliard --- dlls/ntdll/env.c | 71 ++++++++++++----------------------------- dlls/ntdll/loader.c | 1 - dlls/ntdll/ntdll_misc.h | 1 - 3 files changed, 21 insertions(+), 52 deletions(-) diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index 7a6c8c4dae0..87ab9bef62a 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -1357,19 +1357,31 @@ void init_user_process_params( SIZE_T data_size ) if (!data_size) { - if (RtlCreateProcessParametersEx( ¶ms, &null_str, &null_str, &empty_str, &null_str, NULL, - &null_str, &null_str, &null_str, &null_str, + RTL_USER_PROCESS_PARAMETERS initial_params = {0}; + WCHAR *env, curdir_buffer[MAX_PATH]; + + NtCurrentTeb()->Peb->ProcessParameters = &initial_params; + initial_params.Environment = build_initial_environment( __wine_get_main_environment() ); + 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 ); + build_command_line( __wine_main_wargv, &cmdline ); + LdrGetDllPath( initial_params.ImagePathName.Buffer, 0, &load_path, &dummy ); + RtlInitUnicodeString( &dllpath, load_path ); + + env = initial_params.Environment; + initial_params.Environment = NULL; /* avoid copying it */ + if (RtlCreateProcessParametersEx( ¶ms, &initial_params.ImagePathName, &dllpath, &curdir, + &cmdline, NULL, &initial_params.ImagePathName, NULL, NULL, NULL, PROCESS_PARAMS_FLAG_NORMALIZED )) return; + params->Environment = env; NtCurrentTeb()->Peb->ProcessParameters = params; - params->Environment = build_initial_environment( __wine_get_main_environment() ); - get_current_directory( ¶ms->CurrentDirectory.DosPath ); - get_image_path( __wine_main_argv[0], ¶ms->ImagePathName ); - set_library_wargv( __wine_main_argv, ¶ms->ImagePathName ); - build_command_line( __wine_main_wargv, ¶ms->CommandLine ); - LdrGetDllPath( params->ImagePathName.Buffer, 0, &load_path, &dummy ); - RtlCreateUnicodeString( ¶ms->DllPath, load_path ); + RtlFreeUnicodeString( &cmdline ); RtlReleasePath( load_path ); if (isatty(0) || isatty(1) || isatty(2)) @@ -1455,44 +1467,3 @@ done: } set_wow64_environment( ¶ms->Environment ); } - - -/*********************************************************************** - * update_user_process_params - * - * Rebuild the RTL_USER_PROCESS_PARAMETERS structure once we have initialized all the fields. - */ -void update_user_process_params( const UNICODE_STRING *image ) -{ - RTL_USER_PROCESS_PARAMETERS *params, *cur_params = NtCurrentTeb()->Peb->ProcessParameters; - UNICODE_STRING title = cur_params->WindowTitle; - WCHAR *env = cur_params->Environment; - - cur_params->Environment = NULL; /* avoid copying it */ - if (!title.Buffer) title = *image; - if (RtlCreateProcessParametersEx( ¶ms, image, &cur_params->DllPath, NULL, - &cur_params->CommandLine, NULL, &title, &cur_params->Desktop, - &cur_params->ShellInfo, &cur_params->RuntimeInfo, - PROCESS_PARAMS_FLAG_NORMALIZED )) - return; - - params->DebugFlags = cur_params->DebugFlags; - params->ConsoleHandle = cur_params->ConsoleHandle; - params->ConsoleFlags = cur_params->ConsoleFlags; - params->hStdInput = cur_params->hStdInput; - params->hStdOutput = cur_params->hStdOutput; - params->hStdError = cur_params->hStdError; - params->dwX = cur_params->dwX; - params->dwY = cur_params->dwY; - params->dwXSize = cur_params->dwXSize; - params->dwYSize = cur_params->dwYSize; - params->dwXCountChars = cur_params->dwXCountChars; - params->dwYCountChars = cur_params->dwYCountChars; - params->dwFillAttribute = cur_params->dwFillAttribute; - params->dwFlags = cur_params->dwFlags; - params->wShowWindow = cur_params->wShowWindow; - params->Environment = env; - - RtlFreeHeap( GetProcessHeap(), 0, cur_params ); - NtCurrentTeb()->Peb->ProcessParameters = params; -} diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 55b341ff3aa..cc7bf6900b2 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -4268,7 +4268,6 @@ void __wine_process_init(void) } NtCurrentTeb()->Peb->LoaderLock = &loader_section; - update_user_process_params( &wm->ldr.FullDllName ); version_init( wm->ldr.FullDllName.Buffer ); virtual_set_large_address_space(); diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index c3f7eca61e6..e2280dea84a 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -86,7 +86,6 @@ extern void virtual_init_threading(void) DECLSPEC_HIDDEN; extern void fill_cpu_info(void) DECLSPEC_HIDDEN; extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN; extern void init_user_process_params( SIZE_T data_size ) DECLSPEC_HIDDEN; -extern void update_user_process_params( const UNICODE_STRING *image ) DECLSPEC_HIDDEN; /* server support */ extern timeout_t server_start_time DECLSPEC_HIDDEN;