Module: wine Branch: master Commit: 3a49b5d77d259170cdc1b2ad42f8f01ecdd112c4 URL: https://gitlab.winehq.org/wine/wine/-/commit/3a49b5d77d259170cdc1b2ad42f8f01...
Author: Alexandre Julliard julliard@winehq.org Date: Fri Sep 9 15:28:14 2022 +0200
ntdll: Add a helper function to allocate process parameters.
---
dlls/ntdll/env.c | 98 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 41 deletions(-)
diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index bb8931a556b..fa00340058b 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -514,6 +514,55 @@ static void append_unicode_string( void **data, const UNICODE_STRING *src, else dst->Buffer = NULL; }
+static RTL_USER_PROCESS_PARAMETERS *alloc_process_params( const UNICODE_STRING *image, + const UNICODE_STRING *dllpath, + const UNICODE_STRING *curdir, + const UNICODE_STRING *cmdline, + const WCHAR *env, + const UNICODE_STRING *title, + const UNICODE_STRING *desktop, + const UNICODE_STRING *shell, + const UNICODE_STRING *runtime ) +{ + RTL_USER_PROCESS_PARAMETERS *params; + SIZE_T size, env_size = 0; + void *ptr; + + if (env) env_size = get_env_length( env ) * sizeof(WCHAR); + + size = (sizeof(RTL_USER_PROCESS_PARAMETERS) + + ROUND_SIZE( image->MaximumLength ) + + ROUND_SIZE( dllpath->MaximumLength ) + + ROUND_SIZE( curdir->MaximumLength ) + + ROUND_SIZE( cmdline->MaximumLength ) + + ROUND_SIZE( title->MaximumLength ) + + ROUND_SIZE( desktop->MaximumLength ) + + ROUND_SIZE( shell->MaximumLength ) + + ROUND_SIZE( runtime->MaximumLength )); + + if (!(ptr = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, size + ROUND_SIZE( env_size ) ))) + return NULL; + + params = ptr; + params->AllocationSize = size; + params->Size = size; + params->Flags = PROCESS_PARAMS_FLAG_NORMALIZED; + params->EnvironmentSize = ROUND_SIZE( env_size ); + /* all other fields are zero */ + + ptr = params + 1; + append_unicode_string( &ptr, curdir, ¶ms->CurrentDirectory.DosPath ); + append_unicode_string( &ptr, dllpath, ¶ms->DllPath ); + append_unicode_string( &ptr, image, ¶ms->ImagePathName ); + append_unicode_string( &ptr, cmdline, ¶ms->CommandLine ); + append_unicode_string( &ptr, title, ¶ms->WindowTitle ); + append_unicode_string( &ptr, desktop, ¶ms->Desktop ); + append_unicode_string( &ptr, shell, ¶ms->ShellInfo ); + append_unicode_string( &ptr, runtime, ¶ms->RuntimeInfo ); + if (env) params->Environment = memcpy( ptr, env, env_size ); + return params; +} +
/****************************************************************************** * RtlCreateProcessParametersEx [NTDLL.@] @@ -532,8 +581,6 @@ NTSTATUS WINAPI RtlCreateProcessParametersEx( RTL_USER_PROCESS_PARAMETERS **resu { UNICODE_STRING curdir; const RTL_USER_PROCESS_PARAMETERS *cur_params; - SIZE_T size, env_size = 0; - void *ptr; NTSTATUS status = STATUS_SUCCESS;
RtlAcquirePebLock(); @@ -556,40 +603,11 @@ NTSTATUS WINAPI RtlCreateProcessParametersEx( RTL_USER_PROCESS_PARAMETERS **resu if (!ShellInfo) ShellInfo = &empty_str; if (!RuntimeInfo) RuntimeInfo = &null_str;
- if (Environment) env_size = get_env_length( Environment ) * sizeof(WCHAR); - - size = (sizeof(RTL_USER_PROCESS_PARAMETERS) - + ROUND_SIZE( ImagePathName->MaximumLength ) - + ROUND_SIZE( DllPath->MaximumLength ) - + ROUND_SIZE( curdir.MaximumLength ) - + ROUND_SIZE( CommandLine->MaximumLength ) - + ROUND_SIZE( WindowTitle->MaximumLength ) - + ROUND_SIZE( Desktop->MaximumLength ) - + ROUND_SIZE( ShellInfo->MaximumLength ) - + ROUND_SIZE( RuntimeInfo->MaximumLength )); - - if ((ptr = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, size + ROUND_SIZE( env_size ) ))) + if ((*result = alloc_process_params( ImagePathName, DllPath, &curdir, CommandLine, + Environment, WindowTitle, Desktop, ShellInfo, RuntimeInfo ))) { - RTL_USER_PROCESS_PARAMETERS *params = ptr; - params->AllocationSize = size; - params->Size = size; - params->Flags = PROCESS_PARAMS_FLAG_NORMALIZED; - params->EnvironmentSize = ROUND_SIZE( env_size ); - if (cur_params) params->ConsoleFlags = cur_params->ConsoleFlags; - /* all other fields are zero */ - - ptr = params + 1; - append_unicode_string( &ptr, &curdir, ¶ms->CurrentDirectory.DosPath ); - append_unicode_string( &ptr, DllPath, ¶ms->DllPath ); - append_unicode_string( &ptr, ImagePathName, ¶ms->ImagePathName ); - append_unicode_string( &ptr, CommandLine, ¶ms->CommandLine ); - append_unicode_string( &ptr, WindowTitle, ¶ms->WindowTitle ); - append_unicode_string( &ptr, Desktop, ¶ms->Desktop ); - append_unicode_string( &ptr, ShellInfo, ¶ms->ShellInfo ); - append_unicode_string( &ptr, RuntimeInfo, ¶ms->RuntimeInfo ); - if (Environment) params->Environment = memcpy( ptr, Environment, env_size ); - *result = params; - if (!(flags & PROCESS_PARAMS_FLAG_NORMALIZED)) RtlDeNormalizeProcessParams( params ); + if (cur_params) (*result)->ConsoleFlags = cur_params->ConsoleFlags; + if (!(flags & PROCESS_PARAMS_FLAG_NORMALIZED)) RtlDeNormalizeProcessParams( *result ); } else status = STATUS_NO_MEMORY;
@@ -646,12 +664,10 @@ void init_user_process_params(void) else env[0] = 0; }
- params->Environment = NULL; /* avoid copying it */ - if (RtlCreateProcessParametersEx( &new_params, ¶ms->ImagePathName, ¶ms->DllPath, - ¶ms->CurrentDirectory.DosPath, - ¶ms->CommandLine, NULL, ¶ms->WindowTitle, ¶ms->Desktop, - ¶ms->ShellInfo, ¶ms->RuntimeInfo, - PROCESS_PARAMS_FLAG_NORMALIZED )) + if (!(new_params = alloc_process_params( ¶ms->ImagePathName, ¶ms->DllPath, + ¶ms->CurrentDirectory.DosPath, ¶ms->CommandLine, + NULL, ¶ms->WindowTitle, ¶ms->Desktop, + ¶ms->ShellInfo, ¶ms->RuntimeInfo ))) return;
new_params->Environment = env;