kernel32: Move Unicode argv initialization to ntdll.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-10-22 10:16:58 +02:00
parent 075741b681
commit ee56be3fcd
2 changed files with 51 additions and 52 deletions

View File

@ -835,45 +835,28 @@ static void set_wow64_environment(void)
} }
/*********************************************************************** /***********************************************************************
* set_library_wargv * set_library_argv
* *
* Set the Wine library Unicode argv global variables. * Set the Wine library argv global variables.
*/ */
static void set_library_wargv( char **argv ) static void set_library_argv( WCHAR **wargv )
{ {
int argc; int argc;
char *q; char *p, **argv;
WCHAR *p;
WCHAR **wargv;
DWORD total = 0; DWORD total = 0;
for (argc = 0; argv[argc]; argc++)
total += MultiByteToWideChar( CP_UNIXCP, 0, argv[argc], -1, NULL, 0 );
wargv = RtlAllocateHeap( GetProcessHeap(), 0,
total * sizeof(WCHAR) + (argc + 1) * sizeof(*wargv) );
p = (WCHAR *)(wargv + argc + 1);
for (argc = 0; argv[argc]; argc++)
{
DWORD reslen = MultiByteToWideChar( CP_UNIXCP, 0, argv[argc], -1, p, total );
wargv[argc] = p;
p += reslen;
total -= reslen;
}
wargv[argc] = NULL;
/* convert argv back from Unicode since it has to be in the Ansi codepage not the Unix one */ /* convert argv back from Unicode since it has to be in the Ansi codepage not the Unix one */
for (argc = 0; wargv[argc]; argc++) for (argc = 0; wargv[argc]; argc++)
total += WideCharToMultiByte( CP_ACP, 0, wargv[argc], -1, NULL, 0, NULL, NULL ); total += WideCharToMultiByte( CP_ACP, 0, wargv[argc], -1, NULL, 0, NULL, NULL );
argv = RtlAllocateHeap( GetProcessHeap(), 0, total + (argc + 1) * sizeof(*argv) ); argv = RtlAllocateHeap( GetProcessHeap(), 0, total + (argc + 1) * sizeof(*argv) );
q = (char *)(argv + argc + 1); p = (char *)(argv + argc + 1);
for (argc = 0; wargv[argc]; argc++) for (argc = 0; wargv[argc]; argc++)
{ {
DWORD reslen = WideCharToMultiByte( CP_ACP, 0, wargv[argc], -1, q, total, NULL, NULL ); DWORD reslen = WideCharToMultiByte( CP_ACP, 0, wargv[argc], -1, p, total, NULL, NULL );
argv[argc] = q; argv[argc] = p;
q += reslen; p += reslen;
total -= reslen; total -= reslen;
} }
argv[argc] = NULL; argv[argc] = NULL;
@ -884,30 +867,6 @@ static void set_library_wargv( char **argv )
} }
/***********************************************************************
* update_library_argv0
*
* Update the argv[0] global variable with the binary we have found.
*/
static void update_library_argv0( const WCHAR *argv0 )
{
DWORD len = strlenW( argv0 );
if (len > strlenW( __wine_main_wargv[0] ))
{
__wine_main_wargv[0] = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
}
strcpyW( __wine_main_wargv[0], argv0 );
len = WideCharToMultiByte( CP_ACP, 0, argv0, -1, NULL, 0, NULL, NULL );
if (len > strlen( __wine_main_argv[0] ) + 1)
{
__wine_main_argv[0] = RtlAllocateHeap( GetProcessHeap(), 0, len );
}
WideCharToMultiByte( CP_ACP, 0, argv0, -1, __wine_main_argv[0], len, NULL, NULL );
}
/*********************************************************************** /***********************************************************************
* build_command_line * build_command_line
* *
@ -1232,13 +1191,10 @@ void * CDECL __wine_kernel_init(void)
} }
init_windows_dirs(); init_windows_dirs();
set_library_wargv( __wine_main_argv );
boot_events[0] = boot_events[1] = 0; boot_events[0] = boot_events[1] = 0;
if (!peb->ProcessParameters->WindowTitle.Buffer) if (!peb->ProcessParameters->WindowTitle.Buffer)
{ {
update_library_argv0( main_exe_name );
if (!build_command_line( __wine_main_wargv )) goto error; if (!build_command_line( __wine_main_wargv )) goto error;
start_wineboot( boot_events ); start_wineboot( boot_events );
} }
@ -1269,6 +1225,7 @@ void * CDECL __wine_kernel_init(void)
set_additional_environment(); set_additional_environment();
} }
set_wow64_environment(); set_wow64_environment();
set_library_argv( __wine_main_wargv );
if (!(peb->ImageBaseAddress = LoadLibraryExW( main_exe_name, 0, DONT_RESOLVE_DLL_REFERENCES ))) if (!(peb->ImageBaseAddress = LoadLibraryExW( main_exe_name, 0, DONT_RESOLVE_DLL_REFERENCES )))
{ {

View File

@ -513,6 +513,45 @@ failed:
} }
/***********************************************************************
* set_library_wargv
*
* Set the Wine library Unicode argv global variables.
*/
static void set_library_wargv( char **argv, const UNICODE_STRING *image )
{
int argc;
WCHAR *p, **wargv;
DWORD total = 0;
if (image) total += 1 + image->Length / sizeof(WCHAR);
for (argc = (image != NULL); argv[argc]; argc++)
total += ntdll_umbstowcs( 0, argv[argc], strlen(argv[argc]) + 1, NULL, 0 );
wargv = RtlAllocateHeap( GetProcessHeap(), 0,
total * sizeof(WCHAR) + (argc + 1) * sizeof(*wargv) );
p = (WCHAR *)(wargv + argc + 1);
if (image)
{
strcpyW( p, image->Buffer );
wargv[0] = p;
p += 1 + image->Length / sizeof(WCHAR);
total -= 1 + image->Length / sizeof(WCHAR);
}
for (argc = (image != NULL); argv[argc]; argc++)
{
DWORD reslen = ntdll_umbstowcs( 0, argv[argc], strlen(argv[argc]) + 1, p, total );
wargv[argc] = p;
p += reslen;
total -= reslen;
}
wargv[argc] = NULL;
__wine_main_argc = argc;
__wine_main_wargv = wargv;
}
/****************************************************************************** /******************************************************************************
* NtQuerySystemEnvironmentValue [NTDLL.@] * NtQuerySystemEnvironmentValue [NTDLL.@]
*/ */
@ -1034,6 +1073,7 @@ void init_user_process_params( SIZE_T data_size )
params->Environment = build_initial_environment( __wine_get_main_environment() ); params->Environment = build_initial_environment( __wine_get_main_environment() );
get_current_directory( &params->CurrentDirectory.DosPath ); get_current_directory( &params->CurrentDirectory.DosPath );
get_image_path( __wine_main_argv[0], &params->ImagePathName ); get_image_path( __wine_main_argv[0], &params->ImagePathName );
set_library_wargv( __wine_main_argv, &params->ImagePathName );
if (isatty(0) || isatty(1) || isatty(2)) if (isatty(0) || isatty(1) || isatty(2))
params->ConsoleHandle = (HANDLE)2; /* see kernel32/kernel_private.h */ params->ConsoleHandle = (HANDLE)2; /* see kernel32/kernel_private.h */
@ -1103,6 +1143,8 @@ void init_user_process_params( SIZE_T data_size )
else params->Environment[0] = 0; else params->Environment[0] = 0;
} }
set_library_wargv( __wine_main_argv, NULL );
done: done:
RtlFreeHeap( GetProcessHeap(), 0, info ); RtlFreeHeap( GetProcessHeap(), 0, info );
if (RtlSetCurrentDirectory_U( &params->CurrentDirectory.DosPath )) if (RtlSetCurrentDirectory_U( &params->CurrentDirectory.DosPath ))