Commit f51cd0a1 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use the process parameters directly in exec_process().

parent 52e9badd
......@@ -70,6 +70,7 @@ const WCHAR system_dir[] = {'C',':','\\','w','i','n','d','o','w','s','\\',
const WCHAR syswow64_dir[] = {'C',':','\\','w','i','n','d','o','w','s','\\',
's','y','s','w','o','w','6','4','\\',0};
static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
BOOL is_wow64 = FALSE;
/* system search path */
......@@ -3931,6 +3932,29 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
/***********************************************************************
* restart_winevdm
*/
static void restart_winevdm( RTL_USER_PROCESS_PARAMETERS *params )
{
DWORD len;
WCHAR *appname, *cmdline;
len = wcslen(system_dir) + wcslen(L"winevdm.exe") + 1;
appname = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) );
wcscpy( appname, (is_win64 || is_wow64) ? syswow64_dir : system_dir );
wcscat( appname, L"winevdm.exe" );
len += 16 + wcslen(params->ImagePathName.Buffer) + wcslen(params->CommandLine.Buffer);
cmdline = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) );
swprintf( cmdline, len, L"%s --app-name \"%s\" %s",
appname, params->ImagePathName.Buffer, params->CommandLine.Buffer );
RtlInitUnicodeString( &params->ImagePathName, appname );
RtlInitUnicodeString( &params->CommandLine, cmdline );
}
/***********************************************************************
* process_init
*/
static void process_init(void)
......@@ -4024,21 +4048,33 @@ static void process_init(void)
}
else
{
status = restart_process( params, status );
switch (status)
{
case STATUS_INVALID_IMAGE_WIN_64:
ERR( "%s 64-bit application not supported in 32-bit prefix\n",
debugstr_us(&params->ImagePathName) );
case STATUS_INVALID_IMAGE_NOT_MZ:
{
WCHAR *p = wcsrchr( params->ImagePathName.Buffer, '.' );
if (p && (!wcsicmp( p, L".com" ) || !wcsicmp( p, L".pif" )))
{
restart_winevdm( params );
status = STATUS_INVALID_IMAGE_WIN_16;
}
status = unix_funcs->exec_process( status );
break;
}
case STATUS_INVALID_IMAGE_WIN_16:
case STATUS_INVALID_IMAGE_NE_FORMAT:
case STATUS_INVALID_IMAGE_PROTECT:
ERR( "%s 16-bit application not supported on this system\n",
debugstr_us(&params->ImagePathName) );
restart_winevdm( params );
status = unix_funcs->exec_process( status );
break;
case STATUS_CONFLICTING_ADDRESSES:
case STATUS_NO_MEMORY:
case STATUS_INVALID_IMAGE_FORMAT:
ERR( "%s not supported on this system\n", debugstr_us(&params->ImagePathName) );
status = unix_funcs->exec_process( status );
break;
case STATUS_INVALID_IMAGE_WIN_64:
ERR( "%s 64-bit application not supported in 32-bit prefix\n",
debugstr_us(&params->ImagePathName) );
break;
case STATUS_DLL_NOT_FOUND:
ERR( "%s not found\n", debugstr_us(&params->ImagePathName) );
......
......@@ -64,7 +64,6 @@ extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN;
extern void init_unix_codepage(void) DECLSPEC_HIDDEN;
extern void init_locale( HMODULE module ) DECLSPEC_HIDDEN;
extern void init_user_process_params(void) DECLSPEC_HIDDEN;
extern NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) DECLSPEC_HIDDEN;
extern void CDECL DECLSPEC_NORETURN signal_start_thread( CONTEXT *ctx ) DECLSPEC_HIDDEN;
/* server support */
......
......@@ -38,12 +38,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(process);
static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
/*
* Process object
*/
/******************************************************************************
* RtlGetCurrentPeb [NTDLL.@]
......@@ -54,56 +48,6 @@ PEB * WINAPI RtlGetCurrentPeb(void)
return NtCurrentTeb()->Peb;
}
/***********************************************************************
* restart_process
*/
NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status )
{
static const WCHAR argsW[] = {'%','s',' ','-','-','a','p','p','-','n','a','m','e',' ','"','%','s','"',' ','%','s',0};
static const WCHAR winevdm[] = {'w','i','n','e','v','d','m','.','e','x','e',0};
static const WCHAR comW[] = {'.','c','o','m',0};
static const WCHAR pifW[] = {'.','p','i','f',0};
DWORD len;
WCHAR *p, *appname, *cmdline;
UNICODE_STRING pathW, cmdW;
/* check for .com or .pif extension */
if (status == STATUS_INVALID_IMAGE_NOT_MZ &&
(p = wcsrchr( params->ImagePathName.Buffer, '.' )) &&
(!wcsicmp( p, comW ) || !wcsicmp( p, pifW )))
status = STATUS_INVALID_IMAGE_WIN_16;
switch (status)
{
case STATUS_CONFLICTING_ADDRESSES:
case STATUS_NO_MEMORY:
case STATUS_INVALID_IMAGE_FORMAT:
case STATUS_INVALID_IMAGE_NOT_MZ:
status = unix_funcs->exec_process( &params->ImagePathName, &params->CommandLine, status );
break;
case STATUS_INVALID_IMAGE_WIN_16:
case STATUS_INVALID_IMAGE_NE_FORMAT:
case STATUS_INVALID_IMAGE_PROTECT:
len = wcslen(system_dir) + wcslen(winevdm) + 1;
if (!(appname = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
return STATUS_NO_MEMORY;
wcscpy( appname, (is_win64 || is_wow64) ? syswow64_dir : system_dir );
wcscat( appname, winevdm );
len += 16 + wcslen(params->ImagePathName.Buffer) + wcslen(params->CommandLine.Buffer);
if (!(cmdline = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
return STATUS_NO_MEMORY;
swprintf( cmdline, len, argsW, appname, params->ImagePathName.Buffer, params->CommandLine.Buffer );
RtlInitUnicodeString( &pathW, appname );
RtlInitUnicodeString( &cmdW, cmdline );
status = unix_funcs->exec_process( &pathW, &cmdW, status );
break;
}
return status;
}
/**********************************************************************
* RtlCreateUserProcess (NTDLL.@)
......
......@@ -613,8 +613,9 @@ static NTSTATUS spawn_process( const RTL_USER_PROCESS_PARAMETERS *params, int so
/***********************************************************************
* exec_process
*/
NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status )
NTSTATUS CDECL exec_process( NTSTATUS status )
{
RTL_USER_PROCESS_PARAMETERS *params = NtCurrentTeb()->Peb->ProcessParameters;
pe_image_info_t pe_info;
int unixdir, socketfd[2];
char **argv;
......@@ -631,7 +632,7 @@ NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTST
{
UNICODE_STRING image;
if (getenv( "WINEPRELOADRESERVE" )) return status;
image.Buffer = get_nt_pathname( path );
image.Buffer = get_nt_pathname( &params->ImagePathName );
image.Length = wcslen( image.Buffer ) * sizeof(WCHAR);
if ((status = get_pe_file_info( &image, &handle, &pe_info ))) return status;
break;
......@@ -647,7 +648,7 @@ NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTST
return status;
}
unixdir = get_unix_curdir( NtCurrentTeb()->Peb->ProcessParameters );
unixdir = get_unix_curdir( params );
if (socketpair( PF_UNIX, SOCK_STREAM, 0, socketfd ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
#ifdef SO_PASSCRED
......@@ -670,7 +671,7 @@ NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTST
if (!status)
{
if (!(argv = build_argv( cmdline, 2 ))) return STATUS_NO_MEMORY;
if (!(argv = build_argv( &params->CommandLine, 2 ))) return STATUS_NO_MEMORY;
fchdir( unixdir );
do
{
......
......@@ -117,7 +117,7 @@ extern USHORT * CDECL get_unix_codepage_data(void) DECLSPEC_HIDDEN;
extern void CDECL get_locales( WCHAR *sys, WCHAR *user ) DECLSPEC_HIDDEN;
extern void CDECL virtual_release_address_space(void) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL exec_process( NTSTATUS status ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL unwind_builtin_dll( ULONG type, struct _DISPATCHER_CONTEXT *dispatch,
CONTEXT *context ) DECLSPEC_HIDDEN;
......
......@@ -27,7 +27,7 @@
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 102
#define NTDLL_UNIXLIB_VERSION 103
struct unix_funcs
{
......@@ -82,7 +82,7 @@ struct unix_funcs
void (CDECL *virtual_release_address_space)(void);
/* thread/process functions */
NTSTATUS (CDECL *exec_process)( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status );
NTSTATUS (CDECL *exec_process)( NTSTATUS status );
/* file functions */
void (CDECL *set_show_dot_files)( BOOL enable );
......
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