Alexandre Julliard : ntdll: Move the NT path conversion for exec process to the Unix library.
Alexandre Julliard
julliard at winehq.org
Wed Sep 2 15:24:32 CDT 2020
Module: wine
Branch: master
Commit: 52e9baddbce3f6d8aa768379ec6d7e82b47545c6
URL: https://source.winehq.org/git/wine.git/?a=commit;h=52e9baddbce3f6d8aa768379ec6d7e82b47545c6
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Sep 2 14:31:00 2020 +0200
ntdll: Move the NT path conversion for exec process to the Unix library.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/process.c | 23 +++++++++++---------
dlls/ntdll/unix/process.c | 55 +++++++++++++++++++++++++++++++----------------
2 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c
index c0b36be38e..7afd2a40a5 100644
--- a/dlls/ntdll/process.c
+++ b/dlls/ntdll/process.c
@@ -59,13 +59,13 @@ PEB * WINAPI RtlGetCurrentPeb(void)
*/
NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status )
{
- static const WCHAR argsW[] = {'%','s','%','s',' ','-','-','a','p','p','-','n','a','m','e',' ','"','%','s','"',' ','%','s',0};
+ 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, *cmdline;
+ WCHAR *p, *appname, *cmdline;
UNICODE_STRING pathW, cmdW;
/* check for .com or .pif extension */
@@ -80,20 +80,23 @@ NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status )
case STATUS_NO_MEMORY:
case STATUS_INVALID_IMAGE_FORMAT:
case STATUS_INVALID_IMAGE_NOT_MZ:
- if (!RtlDosPathNameToNtPathName_U( params->ImagePathName.Buffer, &pathW, NULL, NULL ))
- return status;
- status = unix_funcs->exec_process( &pathW, ¶ms->CommandLine, status );
+ status = unix_funcs->exec_process( ¶ms->ImagePathName, ¶ms->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) + 16 + wcslen(params->ImagePathName.Buffer) +
- wcslen(params->CommandLine.Buffer));
+ 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, (is_win64 || is_wow64) ? syswow64_dir : system_dir,
- winevdm, params->ImagePathName.Buffer, params->CommandLine.Buffer );
- RtlInitUnicodeString( &pathW, winevdm );
+ 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;
diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c
index 6b41080cee..82c0452f8e 100644
--- a/dlls/ntdll/unix/process.c
+++ b/dlls/ntdll/unix/process.c
@@ -474,35 +474,47 @@ static ULONG get_env_size( const RTL_USER_PROCESS_PARAMETERS *params, char **win
/***********************************************************************
- * get_unix_curdir
+ * get_nt_pathname
+ *
+ * Simplified version of RtlDosPathNameToNtPathName_U.
*/
-static int get_unix_curdir( const RTL_USER_PROCESS_PARAMETERS *params )
+static WCHAR *get_nt_pathname( const UNICODE_STRING *str )
{
static const WCHAR ntprefixW[] = {'\\','?','?','\\',0};
static const WCHAR uncprefixW[] = {'U','N','C','\\',0};
- const UNICODE_STRING *curdir = ¶ms->CurrentDirectory.DosPath;
- const WCHAR *dir = curdir->Buffer;
- UNICODE_STRING nt_name;
- OBJECT_ATTRIBUTES attr;
- IO_STATUS_BLOCK io;
- NTSTATUS status;
- HANDLE handle;
- int fd = -1;
+ const WCHAR *name = str->Buffer;
+ WCHAR *ret;
- if (!(nt_name.Buffer = malloc( curdir->Length + 8 * sizeof(WCHAR) ))) return -1;
+ if (!(ret = malloc( str->Length + 8 * sizeof(WCHAR) ))) return NULL;
- /* simplified version of RtlDosPathNameToNtPathName_U */
- wcscpy( nt_name.Buffer, ntprefixW );
- if (dir[0] == '\\' && dir[1] == '\\')
+ wcscpy( ret, ntprefixW );
+ if (name[0] == '\\' && name[1] == '\\')
{
- if ((dir[2] == '.' || dir[2] == '?') && dir[3] == '\\') dir += 4;
+ if ((name[2] == '.' || name[2] == '?') && name[3] == '\\') name += 4;
else
{
- wcscat( nt_name.Buffer, uncprefixW );
- dir += 2;
+ wcscat( ret, uncprefixW );
+ name += 2;
}
}
- wcscat( nt_name.Buffer, dir );
+ wcscat( ret, name );
+ return ret;
+}
+
+
+/***********************************************************************
+ * get_unix_curdir
+ */
+static int get_unix_curdir( const RTL_USER_PROCESS_PARAMETERS *params )
+{
+ UNICODE_STRING nt_name;
+ OBJECT_ATTRIBUTES attr;
+ IO_STATUS_BLOCK io;
+ NTSTATUS status;
+ HANDLE handle;
+ int fd = -1;
+
+ if (!(nt_name.Buffer = get_nt_pathname( ¶ms->CurrentDirectory.DosPath ))) return -1;
nt_name.Length = wcslen( nt_name.Buffer ) * sizeof(WCHAR);
InitializeObjectAttributes( &attr, &nt_name, OBJ_CASE_INSENSITIVE, 0, NULL );
@@ -616,9 +628,14 @@ NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTST
case STATUS_NO_MEMORY:
case STATUS_INVALID_IMAGE_FORMAT:
case STATUS_INVALID_IMAGE_NOT_MZ:
+ {
+ UNICODE_STRING image;
if (getenv( "WINEPRELOADRESERVE" )) return status;
- if ((status = get_pe_file_info( path, &handle, &pe_info ))) return status;
+ image.Buffer = get_nt_pathname( path );
+ image.Length = wcslen( image.Buffer ) * sizeof(WCHAR);
+ if ((status = get_pe_file_info( &image, &handle, &pe_info ))) return status;
break;
+ }
case STATUS_INVALID_IMAGE_WIN_16:
case STATUS_INVALID_IMAGE_NE_FORMAT:
case STATUS_INVALID_IMAGE_PROTECT:
More information about the wine-cvs
mailing list