2003-06-27 06:08:04 +02:00
|
|
|
/*
|
|
|
|
* Win32 processes
|
|
|
|
*
|
|
|
|
* Copyright 1996, 1998 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-06-27 06:08:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
2009-12-30 23:36:56 +01:00
|
|
|
#include <stdarg.h>
|
2003-09-17 07:31:32 +02:00
|
|
|
#include <stdio.h>
|
2004-03-10 00:51:02 +01:00
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2006-07-19 14:00:10 +02:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2006-04-06 11:57:37 +02:00
|
|
|
#ifdef HAVE_SYS_PRCTL_H
|
|
|
|
# include <sys/prctl.h>
|
|
|
|
#endif
|
2004-03-10 00:51:02 +01:00
|
|
|
#include <sys/types.h>
|
2011-12-01 01:20:24 +01:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
# include <sys/wait.h>
|
|
|
|
#endif
|
2011-09-06 12:11:46 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2005-06-06 22:13:08 +02:00
|
|
|
#include "winternl.h"
|
2019-07-01 17:44:38 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincon.h"
|
2003-09-17 07:31:32 +02:00
|
|
|
#include "kernel_private.h"
|
2011-05-12 14:19:40 +02:00
|
|
|
#include "psapi.h"
|
2017-12-04 13:13:05 +01:00
|
|
|
#include "wine/exception.h"
|
2009-12-28 22:19:31 +01:00
|
|
|
#include "wine/library.h"
|
2003-06-27 06:08:04 +02:00
|
|
|
#include "wine/server.h"
|
2003-10-04 06:09:41 +02:00
|
|
|
#include "wine/unicode.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2003-06-27 06:08:04 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(process);
|
2006-07-31 21:25:29 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2009-04-01 14:36:49 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
extern char **__wine_get_main_environment(void);
|
|
|
|
#else
|
2009-04-02 12:00:33 +02:00
|
|
|
extern char **__wine_main_environ;
|
|
|
|
static char **__wine_get_main_environment(void) { return __wine_main_environ; }
|
2009-04-01 14:36:49 +02:00
|
|
|
#endif
|
|
|
|
|
2003-11-17 21:16:38 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
LPSTR lpEnvAddress;
|
|
|
|
LPSTR lpCmdLine;
|
|
|
|
LPSTR lpCmdShow;
|
|
|
|
DWORD dwReserved;
|
|
|
|
} LOADPARMS32;
|
|
|
|
|
2009-07-07 11:42:03 +02:00
|
|
|
static BOOL is_wow64;
|
2013-10-03 00:08:57 +02:00
|
|
|
static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2004-02-12 01:00:55 +01:00
|
|
|
HMODULE kernel32_handle = 0;
|
2013-01-08 22:02:21 +01:00
|
|
|
SYSTEM_BASIC_INFORMATION system_info = { 0 };
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2018-02-19 19:45:58 +01:00
|
|
|
const WCHAR DIR_Windows[] = {'C',':','\\','w','i','n','d','o','w','s',0};
|
|
|
|
const WCHAR DIR_System[] = {'C',':','\\','w','i','n','d','o','w','s',
|
|
|
|
'\\','s','y','s','t','e','m','3','2',0};
|
2009-07-07 11:42:03 +02:00
|
|
|
const WCHAR *DIR_SysWow64 = NULL;
|
2004-05-14 23:43:18 +02:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/* Process flags */
|
|
|
|
#define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
|
|
|
|
#define PDB32_WIN16_PROC 0x0008 /* Win16 process */
|
|
|
|
#define PDB32_DOS_PROC 0x0010 /* Dos process */
|
|
|
|
#define PDB32_CONSOLE_PROC 0x0020 /* Console process */
|
|
|
|
#define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
|
|
|
|
#define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
|
|
|
|
|
2010-03-18 13:02:42 +01:00
|
|
|
static const WCHAR exeW[] = {'.','e','x','e',0};
|
2003-10-28 01:31:52 +01:00
|
|
|
static const WCHAR comW[] = {'.','c','o','m',0};
|
|
|
|
static const WCHAR batW[] = {'.','b','a','t',0};
|
2007-03-07 16:15:31 +01:00
|
|
|
static const WCHAR cmdW[] = {'.','c','m','d',0};
|
2005-03-07 20:24:43 +01:00
|
|
|
static const WCHAR pifW[] = {'.','p','i','f',0};
|
2018-10-08 16:58:40 +02:00
|
|
|
static WCHAR winevdm[] = {'C',':','\\','w','i','n','d','o','w','s',
|
|
|
|
'\\','s','y','s','t','e','m','3','2',
|
|
|
|
'\\','w','i','n','e','v','d','m','.','e','x','e',0};
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2018-10-11 16:54:19 +02:00
|
|
|
static const char * const cpu_names[] = { "x86", "x86_64", "PowerPC", "ARM", "ARM64" };
|
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
static void exec_process( LPCWSTR name );
|
|
|
|
|
2018-09-27 13:27:28 +02:00
|
|
|
/* return values for get_binary_info */
|
|
|
|
enum binary_type
|
|
|
|
{
|
|
|
|
BINARY_UNKNOWN = 0,
|
|
|
|
BINARY_PE,
|
|
|
|
BINARY_WIN16,
|
|
|
|
BINARY_UNIX_EXE,
|
|
|
|
BINARY_UNIX_LIB
|
|
|
|
};
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2003-10-04 06:09:41 +02:00
|
|
|
* contains_path
|
2003-09-17 07:31:32 +02:00
|
|
|
*/
|
2013-10-03 00:08:57 +02:00
|
|
|
static inline BOOL contains_path( LPCWSTR name )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
return ((*name && (name[1] == ':')) || strchrW(name, '/') || strchrW(name, '\\'));
|
|
|
|
}
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2004-03-11 01:49:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* is_special_env_var
|
|
|
|
*
|
|
|
|
* Check if an environment variable needs to be handled specially when
|
|
|
|
* passed through the Unix environment (i.e. prefixed with "WINE").
|
|
|
|
*/
|
2013-10-03 00:08:57 +02:00
|
|
|
static inline BOOL is_special_env_var( const char *var )
|
2004-03-11 01:49:01 +01:00
|
|
|
{
|
2004-03-12 00:22:29 +01:00
|
|
|
return (!strncmp( var, "PATH=", sizeof("PATH=")-1 ) ||
|
2010-01-28 12:22:24 +01:00
|
|
|
!strncmp( var, "PWD=", sizeof("PWD=")-1 ) ||
|
2004-07-16 05:54:35 +02:00
|
|
|
!strncmp( var, "HOME=", sizeof("HOME=")-1 ) ||
|
2004-03-12 00:22:29 +01:00
|
|
|
!strncmp( var, "TEMP=", sizeof("TEMP=")-1 ) ||
|
2016-02-16 04:48:10 +01:00
|
|
|
!strncmp( var, "TMP=", sizeof("TMP=")-1 ) ||
|
2018-03-01 17:04:58 +01:00
|
|
|
!strncmp( var, "QT_", sizeof("QT_")-1 ) ||
|
|
|
|
!strncmp( var, "VK_", sizeof("VK_")-1 ));
|
2004-03-11 01:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 20:40:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* is_path_prefix
|
|
|
|
*/
|
|
|
|
static inline unsigned int is_path_prefix( const WCHAR *prefix, const WCHAR *filename )
|
|
|
|
{
|
|
|
|
unsigned int len = strlenW( prefix );
|
|
|
|
|
|
|
|
if (strncmpiW( filename, prefix, len ) || filename[len] != '\\') return 0;
|
|
|
|
while (filename[len] == '\\') len++;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-27 14:23:52 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* is_64bit_arch
|
|
|
|
*/
|
2019-07-05 14:37:49 +02:00
|
|
|
static inline BOOL is_64bit_arch( client_cpu_t cpu )
|
2018-09-27 14:23:52 +02:00
|
|
|
{
|
2018-10-11 16:54:19 +02:00
|
|
|
return (cpu == CPU_x86_64 || cpu == CPU_ARM64);
|
2018-09-27 14:23:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-27 13:37:30 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_pe_info
|
|
|
|
*/
|
|
|
|
static NTSTATUS get_pe_info( HANDLE handle, pe_image_info_t *info )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE mapping;
|
|
|
|
|
|
|
|
status = NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY,
|
|
|
|
NULL, NULL, PAGE_READONLY, SEC_IMAGE, handle );
|
|
|
|
if (status) return status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_mapping_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( mapping );
|
|
|
|
req->access = SECTION_QUERY;
|
|
|
|
wine_server_set_reply( req, info, sizeof(*info) );
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
CloseHandle( mapping );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-27 13:27:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_binary_info
|
|
|
|
*/
|
2018-09-27 14:54:01 +02:00
|
|
|
static enum binary_type get_binary_info( HANDLE hfile, pe_image_info_t *info )
|
2018-09-27 13:27:28 +02:00
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned char magic[4];
|
|
|
|
unsigned char class;
|
|
|
|
unsigned char data;
|
|
|
|
unsigned char ignored1[10];
|
|
|
|
unsigned short type;
|
|
|
|
unsigned short machine;
|
|
|
|
unsigned char ignored2[8];
|
|
|
|
unsigned int phoff;
|
|
|
|
unsigned char ignored3[12];
|
|
|
|
unsigned short phnum;
|
|
|
|
} elf;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned char magic[4];
|
|
|
|
unsigned char class;
|
|
|
|
unsigned char data;
|
|
|
|
unsigned char ignored1[10];
|
|
|
|
unsigned short type;
|
|
|
|
unsigned short machine;
|
|
|
|
unsigned char ignored2[12];
|
|
|
|
unsigned __int64 phoff;
|
|
|
|
unsigned char ignored3[16];
|
|
|
|
unsigned short phnum;
|
|
|
|
} elf64;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int magic;
|
|
|
|
unsigned int cputype;
|
|
|
|
unsigned int cpusubtype;
|
|
|
|
unsigned int filetype;
|
|
|
|
} macho;
|
|
|
|
IMAGE_DOS_HEADER mz;
|
|
|
|
} header;
|
|
|
|
|
|
|
|
DWORD len;
|
2018-09-27 13:37:30 +02:00
|
|
|
NTSTATUS status;
|
2018-09-27 13:27:28 +02:00
|
|
|
|
|
|
|
memset( info, 0, sizeof(*info) );
|
|
|
|
|
2018-09-27 14:54:01 +02:00
|
|
|
status = get_pe_info( hfile, info );
|
2018-09-27 13:37:30 +02:00
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case STATUS_SUCCESS:
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_PE;
|
2018-09-27 13:37:30 +02:00
|
|
|
case STATUS_INVALID_IMAGE_WIN_32:
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_PE;
|
2018-09-27 13:37:30 +02:00
|
|
|
case STATUS_INVALID_IMAGE_WIN_64:
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_PE;
|
2018-09-27 13:37:30 +02:00
|
|
|
case STATUS_INVALID_IMAGE_WIN_16:
|
|
|
|
case STATUS_INVALID_IMAGE_NE_FORMAT:
|
|
|
|
case STATUS_INVALID_IMAGE_PROTECT:
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_WIN16;
|
2018-09-27 13:37:30 +02:00
|
|
|
}
|
|
|
|
|
2018-09-27 13:27:28 +02:00
|
|
|
/* Seek to the start of the file and read the header information. */
|
2018-09-27 14:44:47 +02:00
|
|
|
if (SetFilePointer( hfile, 0, NULL, SEEK_SET ) == -1) return BINARY_UNKNOWN;
|
|
|
|
if (!ReadFile( hfile, &header, sizeof(header), &len, NULL ) || len != sizeof(header))
|
|
|
|
return BINARY_UNKNOWN;
|
2018-09-27 13:27:28 +02:00
|
|
|
|
|
|
|
if (!memcmp( header.elf.magic, "\177ELF", 4 ))
|
|
|
|
{
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
BOOL byteswap = (header.elf.data == 1);
|
|
|
|
#else
|
|
|
|
BOOL byteswap = (header.elf.data == 2);
|
|
|
|
#endif
|
|
|
|
if (byteswap)
|
|
|
|
{
|
|
|
|
header.elf.type = RtlUshortByteSwap( header.elf.type );
|
|
|
|
header.elf.machine = RtlUshortByteSwap( header.elf.machine );
|
|
|
|
}
|
2018-09-27 14:44:47 +02:00
|
|
|
switch(header.elf.machine)
|
|
|
|
{
|
2018-10-11 16:54:19 +02:00
|
|
|
case 3: info->cpu = CPU_x86; break;
|
|
|
|
case 20: info->cpu = CPU_POWERPC; break;
|
|
|
|
case 40: info->cpu = CPU_ARM; break;
|
|
|
|
case 62: info->cpu = CPU_x86_64; break;
|
|
|
|
case 183: info->cpu = CPU_ARM64; break;
|
2018-09-27 14:44:47 +02:00
|
|
|
}
|
2018-09-27 13:27:28 +02:00
|
|
|
switch(header.elf.type)
|
|
|
|
{
|
|
|
|
case 2:
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_UNIX_EXE;
|
2018-09-27 13:27:28 +02:00
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
LARGE_INTEGER phoff;
|
|
|
|
unsigned short phnum;
|
|
|
|
unsigned int type;
|
|
|
|
if (header.elf.class == 2)
|
|
|
|
{
|
|
|
|
phoff.QuadPart = byteswap ? RtlUlonglongByteSwap( header.elf64.phoff ) : header.elf64.phoff;
|
|
|
|
phnum = byteswap ? RtlUshortByteSwap( header.elf64.phnum ) : header.elf64.phnum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
phoff.QuadPart = byteswap ? RtlUlongByteSwap( header.elf.phoff ) : header.elf.phoff;
|
|
|
|
phnum = byteswap ? RtlUshortByteSwap( header.elf.phnum ) : header.elf.phnum;
|
|
|
|
}
|
|
|
|
while (phnum--)
|
|
|
|
{
|
2018-09-27 14:44:47 +02:00
|
|
|
if (SetFilePointerEx( hfile, phoff, NULL, FILE_BEGIN ) == -1) return BINARY_UNKNOWN;
|
|
|
|
if (!ReadFile( hfile, &type, sizeof(type), &len, NULL ) || len < sizeof(type))
|
|
|
|
return BINARY_UNKNOWN;
|
2018-09-27 13:27:28 +02:00
|
|
|
if (byteswap) type = RtlUlongByteSwap( type );
|
2018-09-27 14:44:47 +02:00
|
|
|
if (type == 3) return BINARY_UNIX_EXE;
|
2018-09-27 13:27:28 +02:00
|
|
|
phoff.QuadPart += (header.elf.class == 2) ? 56 : 32;
|
|
|
|
}
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_UNIX_LIB;
|
2018-09-27 13:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Mach-o File with Endian set to Big Endian or Little Endian */
|
|
|
|
else if (header.macho.magic == 0xfeedface || header.macho.magic == 0xcefaedfe ||
|
|
|
|
header.macho.magic == 0xfeedfacf || header.macho.magic == 0xcffaedfe)
|
|
|
|
{
|
|
|
|
if (header.macho.magic == 0xcefaedfe || header.macho.magic == 0xcffaedfe)
|
|
|
|
{
|
|
|
|
header.macho.filetype = RtlUlongByteSwap( header.macho.filetype );
|
|
|
|
header.macho.cputype = RtlUlongByteSwap( header.macho.cputype );
|
|
|
|
}
|
|
|
|
switch(header.macho.cputype)
|
|
|
|
{
|
2018-10-11 16:54:19 +02:00
|
|
|
case 0x00000007: info->cpu = CPU_x86; break;
|
|
|
|
case 0x01000007: info->cpu = CPU_x86_64; break;
|
|
|
|
case 0x0000000c: info->cpu = CPU_ARM; break;
|
|
|
|
case 0x0100000c: info->cpu = CPU_ARM64; break;
|
|
|
|
case 0x00000012: info->cpu = CPU_POWERPC; break;
|
2018-09-27 14:54:01 +02:00
|
|
|
}
|
|
|
|
switch(header.macho.filetype)
|
|
|
|
{
|
|
|
|
case 2: return BINARY_UNIX_EXE;
|
|
|
|
case 8: return BINARY_UNIX_LIB;
|
2018-09-27 13:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-27 14:44:47 +02:00
|
|
|
return BINARY_UNKNOWN;
|
2018-09-27 13:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* get_builtin_path
|
|
|
|
*
|
|
|
|
* Get the path of a builtin module when the native file does not exist.
|
|
|
|
*/
|
2009-10-27 20:40:40 +01:00
|
|
|
static BOOL get_builtin_path( const WCHAR *libname, const WCHAR *ext, WCHAR *filename,
|
2018-09-27 14:54:01 +02:00
|
|
|
UINT size, BOOL *is_64bit )
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
|
|
|
WCHAR *file_part;
|
2009-10-27 20:40:40 +01:00
|
|
|
UINT len;
|
|
|
|
void *redir_disabled = 0;
|
2018-09-27 14:54:01 +02:00
|
|
|
|
|
|
|
*is_64bit = (sizeof(void*) > sizeof(int));
|
2009-10-27 20:40:40 +01:00
|
|
|
|
2010-03-18 13:02:42 +01:00
|
|
|
/* builtin names cannot be empty or contain spaces */
|
|
|
|
if (!libname[0] || strchrW( libname, ' ' ) || strchrW( libname, '\t' )) return FALSE;
|
|
|
|
|
2009-10-27 20:40:40 +01:00
|
|
|
if (is_wow64 && Wow64DisableWow64FsRedirection( &redir_disabled ))
|
|
|
|
Wow64RevertWow64FsRedirection( redir_disabled );
|
2003-10-04 06:09:41 +02:00
|
|
|
|
|
|
|
if (contains_path( libname ))
|
|
|
|
{
|
|
|
|
if (RtlGetFullPathName_U( libname, size * sizeof(WCHAR),
|
|
|
|
filename, &file_part ) > size * sizeof(WCHAR))
|
|
|
|
return FALSE; /* too long */
|
|
|
|
|
2009-10-27 20:40:40 +01:00
|
|
|
if ((len = is_path_prefix( DIR_System, filename )))
|
|
|
|
{
|
2018-09-27 14:54:01 +02:00
|
|
|
if (is_wow64 && redir_disabled) *is_64bit = TRUE;
|
2009-10-27 20:40:40 +01:00
|
|
|
}
|
|
|
|
else if (DIR_SysWow64 && (len = is_path_prefix( DIR_SysWow64, filename )))
|
|
|
|
{
|
2018-09-27 14:54:01 +02:00
|
|
|
*is_64bit = FALSE;
|
2009-10-27 20:40:40 +01:00
|
|
|
}
|
|
|
|
else return FALSE;
|
|
|
|
|
2003-11-17 21:18:19 +01:00
|
|
|
if (filename + len != file_part) return FALSE;
|
2003-10-04 06:09:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-27 20:40:40 +01:00
|
|
|
len = strlenW( DIR_System );
|
2003-10-04 06:09:41 +02:00
|
|
|
if (strlenW(libname) + len + 2 >= size) return FALSE; /* too long */
|
2004-05-13 22:21:25 +02:00
|
|
|
memcpy( filename, DIR_System, len * sizeof(WCHAR) );
|
2003-10-04 06:09:41 +02:00
|
|
|
file_part = filename + len;
|
|
|
|
if (file_part > filename && file_part[-1] != '\\') *file_part++ = '\\';
|
|
|
|
strcpyW( file_part, libname );
|
2018-09-27 14:54:01 +02:00
|
|
|
if (is_wow64 && redir_disabled) *is_64bit = TRUE;
|
2003-10-04 06:09:41 +02:00
|
|
|
}
|
|
|
|
if (ext && !strchrW( file_part, '.' ))
|
|
|
|
{
|
|
|
|
if (file_part + strlenW(file_part) + strlenW(ext) + 1 > filename + size)
|
|
|
|
return FALSE; /* too long */
|
|
|
|
strcatW( file_part, ext );
|
|
|
|
}
|
|
|
|
return TRUE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* open_exe_file
|
|
|
|
*
|
|
|
|
* Open a specific exe file, taking load order into account.
|
|
|
|
* Returns the file handle or 0 for a builtin exe.
|
|
|
|
*/
|
2018-09-27 14:54:01 +02:00
|
|
|
static HANDLE open_exe_file( const WCHAR *name, BOOL *is_64bit )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE("looking for %s\n", debugstr_w(name) );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2004-09-15 20:02:49 +02:00
|
|
|
if ((handle = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE,
|
2003-09-17 07:31:32 +02:00
|
|
|
NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2006-02-22 16:21:12 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2003-09-17 07:31:32 +02:00
|
|
|
/* file doesn't exist, check for builtin */
|
2018-09-27 14:54:01 +02:00
|
|
|
if (contains_path( name ) && get_builtin_path( name, NULL, buffer, sizeof(buffer), is_64bit ))
|
2009-05-18 12:07:10 +02:00
|
|
|
handle = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2006-02-22 16:21:12 +01:00
|
|
|
return handle;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* find_exe_file
|
|
|
|
*
|
|
|
|
* Open an exe file, and return the full name and file handle.
|
|
|
|
* Returns FALSE if file could not be found.
|
|
|
|
*/
|
2018-09-27 14:54:01 +02:00
|
|
|
static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE *handle )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2019-10-03 19:26:01 +02:00
|
|
|
WCHAR *load_path;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!set_ntstatus( RtlGetExePath( name, &load_path ))) return FALSE;
|
|
|
|
|
|
|
|
TRACE("looking for %s in %s\n", debugstr_w(name), debugstr_w(load_path) );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2019-10-03 19:26:01 +02:00
|
|
|
ret = (SearchPathW( load_path, name, exeW, buflen, buffer, NULL ) ||
|
|
|
|
/* no builtin found, try native without extension in case it is a Unix app */
|
|
|
|
SearchPathW( load_path, name, NULL, buflen, buffer, NULL ));
|
|
|
|
RtlReleasePath( load_path );
|
|
|
|
if (!ret) return FALSE;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2006-02-22 16:21:12 +01:00
|
|
|
TRACE( "Trying native exe %s\n", debugstr_w(buffer) );
|
2018-09-27 14:54:01 +02:00
|
|
|
*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
return (*handle != INVALID_HANDLE_VALUE);
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/***********************************************************************
|
2003-10-11 01:33:21 +02:00
|
|
|
* build_initial_environment
|
2003-10-04 06:09:41 +02:00
|
|
|
*
|
|
|
|
* Build the Win32 environment from the Unix environment
|
|
|
|
*/
|
2009-04-01 14:36:49 +02:00
|
|
|
static BOOL build_initial_environment(void)
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
2005-09-12 17:35:04 +02:00
|
|
|
SIZE_T size = 1;
|
2003-10-04 06:09:41 +02:00
|
|
|
char **e;
|
|
|
|
WCHAR *p, *endptr;
|
|
|
|
void *ptr;
|
2009-04-02 12:00:33 +02:00
|
|
|
char **env = __wine_get_main_environment();
|
2003-10-04 06:09:41 +02:00
|
|
|
|
|
|
|
/* Compute the total size of the Unix environment */
|
2009-04-02 12:00:33 +02:00
|
|
|
for (e = env; *e; e++)
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
2004-03-11 01:49:01 +01:00
|
|
|
if (is_special_env_var( *e )) continue;
|
2003-10-04 06:09:41 +02:00
|
|
|
size += MultiByteToWideChar( CP_UNIXCP, 0, *e, -1, NULL, 0 );
|
|
|
|
}
|
|
|
|
size *= sizeof(WCHAR);
|
|
|
|
|
2019-09-09 12:54:43 +02:00
|
|
|
if (!(ptr = RtlAllocateHeap( GetProcessHeap(), 0, size ))) return FALSE;
|
2003-10-04 06:09:41 +02:00
|
|
|
NtCurrentTeb()->Peb->ProcessParameters->Environment = p = ptr;
|
|
|
|
endptr = p + size / sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* And fill it with the Unix environment */
|
2009-04-02 12:00:33 +02:00
|
|
|
for (e = env; *e; e++)
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
|
|
|
char *str = *e;
|
2004-03-11 01:49:01 +01:00
|
|
|
|
|
|
|
/* skip Unix special variables and use the Wine variants instead */
|
2004-03-12 00:22:29 +01:00
|
|
|
if (!strncmp( str, "WINE", 4 ))
|
2004-03-11 01:49:01 +01:00
|
|
|
{
|
|
|
|
if (is_special_env_var( str + 4 )) str += 4;
|
2004-06-03 02:25:08 +02:00
|
|
|
else if (!strncmp( str, "WINEPRELOADRESERVE=", 19 )) continue; /* skip it */
|
2004-03-11 01:49:01 +01:00
|
|
|
}
|
|
|
|
else if (is_special_env_var( str )) continue; /* skip it */
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, str, -1, p, endptr - p );
|
|
|
|
p += strlenW(p) + 1;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-14 07:03:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_registry_variables
|
|
|
|
*
|
|
|
|
* Set environment variables by enumerating the values of a key;
|
|
|
|
* helper for set_registry_environment().
|
2004-10-30 04:11:33 +02:00
|
|
|
* Note that Windows happily truncates the value if it's too big.
|
2004-05-14 07:03:29 +02:00
|
|
|
*/
|
2005-06-17 15:58:33 +02:00
|
|
|
static void set_registry_variables( HANDLE hkey, ULONG type )
|
2004-05-14 07:03:29 +02:00
|
|
|
{
|
2010-01-28 14:53:24 +01:00
|
|
|
static const WCHAR pathW[] = {'P','A','T','H'};
|
|
|
|
static const WCHAR sep[] = {';',0};
|
2004-05-14 07:03:29 +02:00
|
|
|
UNICODE_STRING env_name, env_value;
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD size;
|
|
|
|
int index;
|
2004-10-30 04:11:33 +02:00
|
|
|
char buffer[1024*sizeof(WCHAR) + sizeof(KEY_VALUE_FULL_INFORMATION)];
|
2010-01-28 14:53:24 +01:00
|
|
|
WCHAR tmpbuf[1024];
|
|
|
|
UNICODE_STRING tmp;
|
2004-05-14 07:03:29 +02:00
|
|
|
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
|
|
|
|
|
2010-01-28 14:53:24 +01:00
|
|
|
tmp.Buffer = tmpbuf;
|
|
|
|
tmp.MaximumLength = sizeof(tmpbuf);
|
|
|
|
|
2004-05-14 07:03:29 +02:00
|
|
|
for (index = 0; ; index++)
|
|
|
|
{
|
|
|
|
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
|
|
|
|
buffer, sizeof(buffer), &size );
|
2004-10-30 04:11:33 +02:00
|
|
|
if (status != STATUS_SUCCESS && status != STATUS_BUFFER_OVERFLOW)
|
|
|
|
break;
|
|
|
|
if (info->Type != type)
|
|
|
|
continue;
|
2004-05-14 07:03:29 +02:00
|
|
|
env_name.Buffer = info->Name;
|
|
|
|
env_name.Length = env_name.MaximumLength = info->NameLength;
|
|
|
|
env_value.Buffer = (WCHAR *)(buffer + info->DataOffset);
|
2010-01-28 14:53:24 +01:00
|
|
|
env_value.Length = info->DataLength;
|
|
|
|
env_value.MaximumLength = sizeof(buffer) - info->DataOffset;
|
2004-05-14 07:03:29 +02:00
|
|
|
if (env_value.Length && !env_value.Buffer[env_value.Length/sizeof(WCHAR)-1])
|
2007-04-28 23:50:22 +02:00
|
|
|
env_value.Length -= sizeof(WCHAR); /* don't count terminating null if any */
|
2009-12-23 18:31:52 +01:00
|
|
|
if (!env_value.Length) continue;
|
2004-10-30 04:11:33 +02:00
|
|
|
if (info->Type == REG_EXPAND_SZ)
|
|
|
|
{
|
2010-01-28 14:53:24 +01:00
|
|
|
status = RtlExpandEnvironmentStrings_U( NULL, &env_value, &tmp, NULL );
|
|
|
|
if (status != STATUS_SUCCESS && status != STATUS_BUFFER_OVERFLOW) continue;
|
|
|
|
RtlCopyUnicodeString( &env_value, &tmp );
|
2004-10-30 04:11:33 +02:00
|
|
|
}
|
2010-01-28 14:53:24 +01:00
|
|
|
/* PATH is magic */
|
|
|
|
if (env_name.Length == sizeof(pathW) &&
|
2019-05-07 18:31:05 +02:00
|
|
|
!strncmpiW( env_name.Buffer, pathW, ARRAY_SIZE( pathW )) &&
|
2010-01-28 14:53:24 +01:00
|
|
|
!RtlQueryEnvironmentVariable_U( NULL, &env_name, &tmp ))
|
2004-10-30 04:11:33 +02:00
|
|
|
{
|
2010-01-28 14:53:24 +01:00
|
|
|
RtlAppendUnicodeToString( &tmp, sep );
|
|
|
|
if (RtlAppendUnicodeStringToString( &tmp, &env_value )) continue;
|
|
|
|
RtlCopyUnicodeString( &env_value, &tmp );
|
2004-10-30 04:11:33 +02:00
|
|
|
}
|
2010-01-28 14:53:24 +01:00
|
|
|
RtlSetEnvironmentVariable( NULL, &env_name, &env_value );
|
2004-05-14 07:03:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-06 00:05:18 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_registry_environment
|
|
|
|
*
|
|
|
|
* Set the environment variables specified in the registry.
|
2004-10-30 04:11:33 +02:00
|
|
|
*
|
|
|
|
* Note: Windows handles REG_SZ and REG_EXPAND_SZ in one pass with the
|
|
|
|
* consequence that REG_EXPAND_SZ cannot be used reliably as it depends
|
|
|
|
* on the order in which the variables are processed. But on Windows it
|
|
|
|
* does not really matter since they only use %SystemDrive% and
|
|
|
|
* %SystemRoot% which are predefined. But Wine defines these in the
|
|
|
|
* registry, so we need two passes.
|
2004-05-06 00:05:18 +02:00
|
|
|
*/
|
2010-01-28 13:16:40 +01:00
|
|
|
static BOOL set_registry_environment( BOOL volatile_only )
|
2004-05-06 00:05:18 +02:00
|
|
|
{
|
2015-11-19 12:53:33 +01:00
|
|
|
static const WCHAR env_keyW[] = {'\\','R','e','g','i','s','t','r','y','\\',
|
|
|
|
'M','a','c','h','i','n','e','\\',
|
2004-05-06 00:05:18 +02:00
|
|
|
'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'C','o','n','t','r','o','l','\\',
|
|
|
|
'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
|
|
|
|
'E','n','v','i','r','o','n','m','e','n','t',0};
|
2004-05-14 07:03:29 +02:00
|
|
|
static const WCHAR envW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
|
2009-12-23 18:31:46 +01:00
|
|
|
static const WCHAR volatile_envW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
|
2004-05-14 07:03:29 +02:00
|
|
|
|
2004-05-06 00:05:18 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
2004-05-14 07:03:29 +02:00
|
|
|
UNICODE_STRING nameW;
|
2005-06-17 15:58:33 +02:00
|
|
|
HANDLE hkey;
|
2008-04-24 11:53:45 +02:00
|
|
|
BOOL ret = FALSE;
|
2004-05-06 00:05:18 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
2004-05-14 07:03:29 +02:00
|
|
|
|
|
|
|
/* first the system environment variables */
|
2004-05-06 00:05:18 +02:00
|
|
|
RtlInitUnicodeString( &nameW, env_keyW );
|
2010-01-28 13:16:40 +01:00
|
|
|
if (!volatile_only && NtOpenKey( &hkey, KEY_READ, &attr ) == STATUS_SUCCESS)
|
2004-05-14 07:03:29 +02:00
|
|
|
{
|
2004-10-30 04:11:33 +02:00
|
|
|
set_registry_variables( hkey, REG_SZ );
|
|
|
|
set_registry_variables( hkey, REG_EXPAND_SZ );
|
2004-05-14 07:03:29 +02:00
|
|
|
NtClose( hkey );
|
2008-04-24 11:53:45 +02:00
|
|
|
ret = TRUE;
|
2004-05-14 07:03:29 +02:00
|
|
|
}
|
2004-05-06 00:05:18 +02:00
|
|
|
|
2004-05-14 07:03:29 +02:00
|
|
|
/* then the ones for the current user */
|
2009-11-30 13:57:16 +01:00
|
|
|
if (RtlOpenCurrentUser( KEY_READ, &attr.RootDirectory ) != STATUS_SUCCESS) return ret;
|
2004-05-14 07:03:29 +02:00
|
|
|
RtlInitUnicodeString( &nameW, envW );
|
2010-01-28 13:16:40 +01:00
|
|
|
if (!volatile_only && NtOpenKey( &hkey, KEY_READ, &attr ) == STATUS_SUCCESS)
|
2004-05-06 00:05:18 +02:00
|
|
|
{
|
2004-10-30 04:11:33 +02:00
|
|
|
set_registry_variables( hkey, REG_SZ );
|
|
|
|
set_registry_variables( hkey, REG_EXPAND_SZ );
|
2004-05-14 07:03:29 +02:00
|
|
|
NtClose( hkey );
|
2004-05-06 00:05:18 +02:00
|
|
|
}
|
2009-12-23 18:31:46 +01:00
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, volatile_envW );
|
|
|
|
if (NtOpenKey( &hkey, KEY_READ, &attr ) == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
set_registry_variables( hkey, REG_SZ );
|
|
|
|
set_registry_variables( hkey, REG_EXPAND_SZ );
|
|
|
|
NtClose( hkey );
|
|
|
|
}
|
|
|
|
|
2004-05-14 07:03:29 +02:00
|
|
|
NtClose( attr.RootDirectory );
|
2008-04-24 11:53:45 +02:00
|
|
|
return ret;
|
2004-05-06 00:05:18 +02:00
|
|
|
}
|
|
|
|
|
2008-05-06 15:54:07 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_reg_value
|
|
|
|
*/
|
|
|
|
static WCHAR *get_reg_value( HKEY hkey, const WCHAR *name )
|
|
|
|
{
|
|
|
|
char buffer[1024 * sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
|
|
|
|
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
|
|
|
|
DWORD len, size = sizeof(buffer);
|
|
|
|
WCHAR *ret = NULL;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
if (NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, buffer, size, &size ))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (size <= FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data )) return NULL;
|
|
|
|
len = (size - FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data )) / sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (info->Type == REG_EXPAND_SZ)
|
|
|
|
{
|
|
|
|
UNICODE_STRING value, expanded;
|
|
|
|
|
|
|
|
value.MaximumLength = len * sizeof(WCHAR);
|
|
|
|
value.Buffer = (WCHAR *)info->Data;
|
|
|
|
if (!value.Buffer[len - 1]) len--; /* don't count terminating null if any */
|
|
|
|
value.Length = len * sizeof(WCHAR);
|
|
|
|
expanded.Length = expanded.MaximumLength = 1024 * sizeof(WCHAR);
|
|
|
|
if (!(expanded.Buffer = HeapAlloc( GetProcessHeap(), 0, expanded.MaximumLength ))) return NULL;
|
|
|
|
if (!RtlExpandEnvironmentStrings_U( NULL, &value, &expanded, NULL )) ret = expanded.Buffer;
|
|
|
|
else RtlFreeUnicodeString( &expanded );
|
|
|
|
}
|
|
|
|
else if (info->Type == REG_SZ)
|
|
|
|
{
|
|
|
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
memcpy( ret, info->Data, len * sizeof(WCHAR) );
|
|
|
|
ret[len] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:40:11 +02:00
|
|
|
/* set an environment variable for one of the wine path variables */
|
|
|
|
static void set_wine_path_variable( const WCHAR *name, const char *unix_path )
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name, var_name;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &var_name, name );
|
|
|
|
if (unix_path)
|
|
|
|
{
|
|
|
|
RtlInitAnsiString( &unix_name, unix_path );
|
|
|
|
if (wine_unix_to_nt_file_name( &unix_name, &nt_name )) return;
|
|
|
|
RtlSetEnvironmentVariable( NULL, &var_name, &nt_name );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
}
|
|
|
|
else RtlSetEnvironmentVariable( NULL, &var_name, NULL );
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:54:07 +02:00
|
|
|
|
2007-08-16 15:50:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_additional_environment
|
|
|
|
*
|
|
|
|
* Set some additional environment variables not specified in the registry.
|
|
|
|
*/
|
|
|
|
static void set_additional_environment(void)
|
|
|
|
{
|
2015-11-19 12:53:33 +01:00
|
|
|
static const WCHAR profile_keyW[] = {'\\','R','e','g','i','s','t','r','y','\\',
|
|
|
|
'M','a','c','h','i','n','e','\\',
|
2008-05-06 15:54:07 +02:00
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s',' ','N','T','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'P','r','o','f','i','l','e','L','i','s','t',0};
|
|
|
|
static const WCHAR profiles_valueW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
|
2018-08-16 09:52:57 +02:00
|
|
|
static const WCHAR public_valueW[] = {'P','u','b','l','i','c',0};
|
2014-10-27 23:50:34 +01:00
|
|
|
static const WCHAR computernameW[] = {'C','O','M','P','U','T','E','R','N','A','M','E',0};
|
2008-05-06 15:54:07 +02:00
|
|
|
static const WCHAR allusersW[] = {'A','L','L','U','S','E','R','S','P','R','O','F','I','L','E',0};
|
2017-08-16 21:40:32 +02:00
|
|
|
static const WCHAR programdataW[] = {'P','r','o','g','r','a','m','D','a','t','a',0};
|
2018-08-16 09:52:57 +02:00
|
|
|
static const WCHAR publicW[] = {'P','U','B','L','I','C',0};
|
2008-05-06 15:54:07 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
2018-08-17 12:14:34 +02:00
|
|
|
WCHAR *profile_dir = NULL, *program_data_dir = NULL, *public_dir = NULL;
|
2019-07-04 15:40:11 +02:00
|
|
|
WCHAR buf[32];
|
2008-05-06 15:54:07 +02:00
|
|
|
HANDLE hkey;
|
2019-07-06 17:05:47 +02:00
|
|
|
DWORD len;
|
2008-05-06 15:54:07 +02:00
|
|
|
|
2014-10-27 23:50:34 +01:00
|
|
|
/* ComputerName */
|
2018-07-30 21:18:09 +02:00
|
|
|
len = ARRAY_SIZE( buf );
|
2014-10-27 23:50:34 +01:00
|
|
|
if (GetComputerNameW( buf, &len ))
|
|
|
|
SetEnvironmentVariableW( computernameW, buf );
|
|
|
|
|
2010-01-28 13:34:05 +01:00
|
|
|
/* set the ALLUSERSPROFILE variables */
|
2008-05-06 15:54:07 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, profile_keyW );
|
2009-11-30 13:57:16 +01:00
|
|
|
if (!NtOpenKey( &hkey, KEY_READ, &attr ))
|
2008-05-06 15:54:07 +02:00
|
|
|
{
|
|
|
|
profile_dir = get_reg_value( hkey, profiles_valueW );
|
2017-08-16 21:40:32 +02:00
|
|
|
program_data_dir = get_reg_value( hkey, programdataW );
|
2018-08-16 09:52:57 +02:00
|
|
|
public_dir = get_reg_value( hkey, public_valueW );
|
2008-05-06 15:54:07 +02:00
|
|
|
NtClose( hkey );
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:40:32 +02:00
|
|
|
if (program_data_dir)
|
|
|
|
{
|
2018-08-17 12:14:34 +02:00
|
|
|
SetEnvironmentVariableW( allusersW, program_data_dir );
|
2017-08-16 21:40:32 +02:00
|
|
|
SetEnvironmentVariableW( programdataW, program_data_dir );
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:52:57 +02:00
|
|
|
if (public_dir)
|
|
|
|
{
|
|
|
|
SetEnvironmentVariableW( publicW, public_dir );
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:54:07 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, profile_dir );
|
2017-08-16 21:40:32 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, program_data_dir );
|
2018-08-16 09:52:57 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, public_dir );
|
2007-08-16 15:50:29 +02:00
|
|
|
}
|
2004-05-06 00:05:18 +02:00
|
|
|
|
2010-12-14 22:48:44 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* set_wow64_environment
|
|
|
|
*
|
|
|
|
* Set the environment variables that change across 32/64/Wow64.
|
|
|
|
*/
|
|
|
|
static void set_wow64_environment(void)
|
|
|
|
{
|
|
|
|
static const WCHAR archW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0};
|
|
|
|
static const WCHAR arch6432W[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','W','6','4','3','2',0};
|
|
|
|
static const WCHAR x86W[] = {'x','8','6',0};
|
2015-11-19 12:53:33 +01:00
|
|
|
static const WCHAR versionW[] = {'\\','R','e','g','i','s','t','r','y','\\',
|
|
|
|
'M','a','c','h','i','n','e','\\',
|
2010-12-14 22:48:44 +01:00
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
|
|
|
|
static const WCHAR progdirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
|
|
|
|
static const WCHAR progdir86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
|
|
|
|
static const WCHAR progfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s',0};
|
|
|
|
static const WCHAR progw6432W[] = {'P','r','o','g','r','a','m','W','6','4','3','2',0};
|
|
|
|
static const WCHAR commondirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0};
|
|
|
|
static const WCHAR commondir86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
|
|
|
|
static const WCHAR commonfilesW[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s',0};
|
|
|
|
static const WCHAR commonw6432W[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','W','6','4','3','2',0};
|
2019-07-06 17:05:47 +02:00
|
|
|
static const WCHAR winedlldirW[] = {'W','I','N','E','D','L','L','D','I','R','%','u',0};
|
|
|
|
static const WCHAR winehomedirW[] = {'W','I','N','E','H','O','M','E','D','I','R',0};
|
|
|
|
static const WCHAR winedatadirW[] = {'W','I','N','E','D','A','T','A','D','I','R',0};
|
|
|
|
static const WCHAR winebuilddirW[] = {'W','I','N','E','B','U','I','L','D','D','I','R',0};
|
|
|
|
static const WCHAR wineconfigdirW[] = {'W','I','N','E','C','O','N','F','I','G','D','I','R',0};
|
2010-12-14 22:48:44 +01:00
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
2019-07-06 17:05:47 +02:00
|
|
|
const char *path;
|
|
|
|
WCHAR buf[64];
|
2010-12-14 22:48:44 +01:00
|
|
|
WCHAR *value;
|
|
|
|
HANDLE hkey;
|
2019-07-06 17:05:47 +02:00
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
/* set the Wine paths */
|
|
|
|
|
|
|
|
set_wine_path_variable( winedatadirW, wine_get_data_dir() );
|
|
|
|
set_wine_path_variable( winehomedirW, getenv("HOME") );
|
|
|
|
set_wine_path_variable( winebuilddirW, wine_get_build_dir() );
|
|
|
|
set_wine_path_variable( wineconfigdirW, wine_get_config_dir() );
|
|
|
|
for (i = 0; (path = wine_dll_enum_load_path( i )); i++)
|
|
|
|
{
|
|
|
|
sprintfW( buf, winedlldirW, i );
|
|
|
|
set_wine_path_variable( buf, path );
|
|
|
|
}
|
|
|
|
sprintfW( buf, winedlldirW, i );
|
|
|
|
set_wine_path_variable( buf, NULL );
|
2010-12-14 22:48:44 +01:00
|
|
|
|
|
|
|
/* set the PROCESSOR_ARCHITECTURE variable */
|
|
|
|
|
2019-07-06 17:05:47 +02:00
|
|
|
if (GetEnvironmentVariableW( arch6432W, buf, ARRAY_SIZE( buf )))
|
2010-12-14 22:48:44 +01:00
|
|
|
{
|
|
|
|
if (is_win64)
|
|
|
|
{
|
2019-07-06 17:05:47 +02:00
|
|
|
SetEnvironmentVariableW( archW, buf );
|
2010-12-14 22:48:44 +01:00
|
|
|
SetEnvironmentVariableW( arch6432W, NULL );
|
|
|
|
}
|
|
|
|
}
|
2019-07-06 17:05:47 +02:00
|
|
|
else if (GetEnvironmentVariableW( archW, buf, ARRAY_SIZE( buf )))
|
2010-12-14 22:48:44 +01:00
|
|
|
{
|
|
|
|
if (is_wow64)
|
|
|
|
{
|
2019-07-06 17:05:47 +02:00
|
|
|
SetEnvironmentVariableW( arch6432W, buf );
|
2010-12-14 22:48:44 +01:00
|
|
|
SetEnvironmentVariableW( archW, x86W );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, versionW );
|
|
|
|
if (NtOpenKey( &hkey, KEY_READ | KEY_WOW64_64KEY, &attr )) return;
|
|
|
|
|
|
|
|
/* set the ProgramFiles variables */
|
|
|
|
|
|
|
|
if ((value = get_reg_value( hkey, progdirW )))
|
|
|
|
{
|
|
|
|
if (is_win64 || is_wow64) SetEnvironmentVariableW( progw6432W, value );
|
|
|
|
if (is_win64 || !is_wow64) SetEnvironmentVariableW( progfilesW, value );
|
2010-12-22 09:03:13 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, value );
|
2010-12-14 22:48:44 +01:00
|
|
|
}
|
|
|
|
if (is_wow64 && (value = get_reg_value( hkey, progdir86W )))
|
2010-12-22 09:03:13 +01:00
|
|
|
{
|
2010-12-14 22:48:44 +01:00
|
|
|
SetEnvironmentVariableW( progfilesW, value );
|
2010-12-22 09:03:13 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, value );
|
|
|
|
}
|
2010-12-14 22:48:44 +01:00
|
|
|
|
|
|
|
/* set the CommonProgramFiles variables */
|
|
|
|
|
|
|
|
if ((value = get_reg_value( hkey, commondirW )))
|
|
|
|
{
|
|
|
|
if (is_win64 || is_wow64) SetEnvironmentVariableW( commonw6432W, value );
|
|
|
|
if (is_win64 || !is_wow64) SetEnvironmentVariableW( commonfilesW, value );
|
2010-12-22 09:03:13 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, value );
|
2010-12-14 22:48:44 +01:00
|
|
|
}
|
|
|
|
if (is_wow64 && (value = get_reg_value( hkey, commondir86W )))
|
2010-12-22 09:03:13 +01:00
|
|
|
{
|
2010-12-14 22:48:44 +01:00
|
|
|
SetEnvironmentVariableW( commonfilesW, value );
|
2010-12-22 09:03:13 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, value );
|
|
|
|
}
|
2010-12-14 22:48:44 +01:00
|
|
|
|
|
|
|
NtClose( hkey );
|
|
|
|
}
|
|
|
|
|
2003-10-09 00:38:52 +02:00
|
|
|
/***********************************************************************
|
2003-10-10 02:12:17 +02:00
|
|
|
* set_library_wargv
|
2003-10-09 00:38:52 +02:00
|
|
|
*
|
2003-10-10 02:12:17 +02:00
|
|
|
* Set the Wine library Unicode argv global variables.
|
2003-10-09 00:38:52 +02:00
|
|
|
*/
|
2003-10-10 02:12:17 +02:00
|
|
|
static void set_library_wargv( char **argv )
|
2003-10-09 00:38:52 +02:00
|
|
|
{
|
|
|
|
int argc;
|
2004-08-18 23:03:32 +02:00
|
|
|
char *q;
|
2003-10-09 00:38:52 +02:00
|
|
|
WCHAR *p;
|
|
|
|
WCHAR **wargv;
|
|
|
|
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;
|
2004-08-18 23:03:32 +02:00
|
|
|
|
|
|
|
/* convert argv back from Unicode since it has to be in the Ansi codepage not the Unix one */
|
|
|
|
|
|
|
|
for (argc = 0; wargv[argc]; argc++)
|
|
|
|
total += WideCharToMultiByte( CP_ACP, 0, wargv[argc], -1, NULL, 0, NULL, NULL );
|
|
|
|
|
|
|
|
argv = RtlAllocateHeap( GetProcessHeap(), 0, total + (argc + 1) * sizeof(*argv) );
|
|
|
|
q = (char *)(argv + argc + 1);
|
|
|
|
for (argc = 0; wargv[argc]; argc++)
|
|
|
|
{
|
|
|
|
DWORD reslen = WideCharToMultiByte( CP_ACP, 0, wargv[argc], -1, q, total, NULL, NULL );
|
|
|
|
argv[argc] = q;
|
|
|
|
q += reslen;
|
|
|
|
total -= reslen;
|
|
|
|
}
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
2006-07-19 15:04:57 +02:00
|
|
|
__wine_main_argc = argc;
|
2004-08-18 23:03:32 +02:00
|
|
|
__wine_main_argv = argv;
|
2003-10-09 00:38:52 +02:00
|
|
|
__wine_main_wargv = wargv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 12:59:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-09 00:38:52 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* build_command_line
|
|
|
|
*
|
|
|
|
* Build the command line of a process from the argv array.
|
|
|
|
*
|
|
|
|
* Note that it does NOT necessarily include the file name.
|
|
|
|
* Sometimes we don't even have any command line options at all.
|
|
|
|
*
|
|
|
|
* We must quote and escape characters so that the argv array can be rebuilt
|
|
|
|
* from the command line:
|
|
|
|
* - spaces and tabs must be quoted
|
|
|
|
* 'a b' -> '"a b"'
|
|
|
|
* - quotes must be escaped
|
|
|
|
* '"' -> '\"'
|
|
|
|
* - if '\'s are followed by a '"', they must be doubled and followed by '\"',
|
|
|
|
* resulting in an odd number of '\' followed by a '"'
|
|
|
|
* '\"' -> '\\\"'
|
|
|
|
* '\\"' -> '\\\\\"'
|
2017-02-10 01:26:36 +01:00
|
|
|
* - '\'s are followed by the closing '"' must be doubled,
|
|
|
|
* resulting in an even number of '\' followed by a '"'
|
|
|
|
* ' \' -> '" \\"'
|
|
|
|
* ' \\' -> '" \\\\"'
|
2003-10-09 00:38:52 +02:00
|
|
|
* - '\'s that are not followed by a '"' can be left as is
|
|
|
|
* 'a\b' == 'a\b'
|
|
|
|
* 'a\\b' == 'a\\b'
|
|
|
|
*/
|
|
|
|
static BOOL build_command_line( WCHAR **argv )
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
WCHAR **arg;
|
|
|
|
LPWSTR p;
|
|
|
|
RTL_USER_PROCESS_PARAMETERS* rupp = NtCurrentTeb()->Peb->ProcessParameters;
|
|
|
|
|
|
|
|
if (rupp->CommandLine.Buffer) return TRUE; /* already got it from the server */
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
for (arg = argv; *arg; arg++)
|
|
|
|
{
|
2013-09-26 08:42:49 +02:00
|
|
|
BOOL has_space;
|
|
|
|
int bcount;
|
2003-10-09 00:38:52 +02:00
|
|
|
WCHAR* a;
|
|
|
|
|
2013-09-26 08:42:49 +02:00
|
|
|
has_space=FALSE;
|
2003-10-09 00:38:52 +02:00
|
|
|
bcount=0;
|
|
|
|
a=*arg;
|
2013-09-26 08:42:49 +02:00
|
|
|
if( !*a ) has_space=TRUE;
|
2003-10-09 00:38:52 +02:00
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a=='\\') {
|
|
|
|
bcount++;
|
|
|
|
} else {
|
|
|
|
if (*a==' ' || *a=='\t') {
|
2013-09-26 08:42:49 +02:00
|
|
|
has_space=TRUE;
|
2003-10-09 00:38:52 +02:00
|
|
|
} else if (*a=='"') {
|
2005-03-02 14:53:50 +01:00
|
|
|
/* doubling of '\' preceding a '"',
|
2003-10-09 00:38:52 +02:00
|
|
|
* plus escaping of said '"'
|
|
|
|
*/
|
|
|
|
len+=2*bcount+1;
|
|
|
|
}
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
len+=(a-*arg)+1 /* for the separating space */;
|
|
|
|
if (has_space)
|
2017-02-10 01:26:36 +01:00
|
|
|
len+=2+bcount; /* for the quotes and doubling of '\' preceding the closing quote */
|
2003-10-09 00:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(rupp->CommandLine.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR))))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
p = rupp->CommandLine.Buffer;
|
|
|
|
rupp->CommandLine.Length = (len - 1) * sizeof(WCHAR);
|
|
|
|
rupp->CommandLine.MaximumLength = len * sizeof(WCHAR);
|
|
|
|
for (arg = argv; *arg; arg++)
|
|
|
|
{
|
2013-09-26 08:42:49 +02:00
|
|
|
BOOL has_space,has_quote;
|
2003-10-09 00:38:52 +02:00
|
|
|
WCHAR* a;
|
2017-02-10 01:26:36 +01:00
|
|
|
int bcount;
|
2003-10-09 00:38:52 +02:00
|
|
|
|
|
|
|
/* Check for quotes and spaces in this argument */
|
2013-09-26 08:42:49 +02:00
|
|
|
has_space=has_quote=FALSE;
|
2003-10-09 00:38:52 +02:00
|
|
|
a=*arg;
|
2013-09-26 08:42:49 +02:00
|
|
|
if( !*a ) has_space=TRUE;
|
2003-10-09 00:38:52 +02:00
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a==' ' || *a=='\t') {
|
2013-09-26 08:42:49 +02:00
|
|
|
has_space=TRUE;
|
2003-10-09 00:38:52 +02:00
|
|
|
if (has_quote)
|
|
|
|
break;
|
|
|
|
} else if (*a=='"') {
|
2013-09-26 08:42:49 +02:00
|
|
|
has_quote=TRUE;
|
2003-10-09 00:38:52 +02:00
|
|
|
if (has_space)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now transfer it to the command line */
|
|
|
|
if (has_space)
|
|
|
|
*p++='"';
|
2017-02-10 01:26:36 +01:00
|
|
|
if (has_quote || has_space) {
|
2003-10-09 00:38:52 +02:00
|
|
|
bcount=0;
|
|
|
|
a=*arg;
|
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a=='\\') {
|
|
|
|
*p++=*a;
|
|
|
|
bcount++;
|
|
|
|
} else {
|
|
|
|
if (*a=='"') {
|
|
|
|
int i;
|
|
|
|
|
2005-03-02 14:53:50 +01:00
|
|
|
/* Double all the '\\' preceding this '"', plus one */
|
2003-10-09 00:38:52 +02:00
|
|
|
for (i=0;i<=bcount;i++)
|
|
|
|
*p++='\\';
|
|
|
|
*p++='"';
|
|
|
|
} else {
|
|
|
|
*p++=*a;
|
|
|
|
}
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WCHAR* x = *arg;
|
|
|
|
while ((*p=*x++)) p++;
|
|
|
|
}
|
2017-02-10 01:26:36 +01:00
|
|
|
if (has_space) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Double all the '\' preceding the closing quote */
|
|
|
|
for (i=0;i<bcount;i++)
|
|
|
|
*p++='\\';
|
2003-10-09 00:38:52 +02:00
|
|
|
*p++='"';
|
2017-02-10 01:26:36 +01:00
|
|
|
}
|
2003-10-09 00:38:52 +02:00
|
|
|
*p++=' ';
|
|
|
|
}
|
|
|
|
if (p > rupp->CommandLine.Buffer)
|
|
|
|
p--; /* remove last space */
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-14 07:03:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* init_current_directory
|
|
|
|
*
|
|
|
|
* Initialize the current directory from the Unix cwd or the parent info.
|
|
|
|
*/
|
|
|
|
static void init_current_directory( CURDIR *cur_dir )
|
|
|
|
{
|
|
|
|
UNICODE_STRING dir_str;
|
2009-10-15 12:05:55 +02:00
|
|
|
const char *pwd;
|
2004-05-14 07:03:29 +02:00
|
|
|
char *cwd;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
/* if we received a cur dir from the parent, try this first */
|
|
|
|
|
|
|
|
if (cur_dir->DosPath.Length)
|
|
|
|
{
|
|
|
|
if (RtlSetCurrentDirectory_U( &cur_dir->DosPath ) == STATUS_SUCCESS) goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now try to get it from the Unix cwd */
|
|
|
|
|
|
|
|
for (size = 256; ; size *= 2)
|
|
|
|
{
|
|
|
|
if (!(cwd = HeapAlloc( GetProcessHeap(), 0, size ))) break;
|
|
|
|
if (getcwd( cwd, size )) break;
|
|
|
|
HeapFree( GetProcessHeap(), 0, cwd );
|
|
|
|
if (errno == ERANGE) continue;
|
|
|
|
cwd = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-15 12:05:55 +02:00
|
|
|
/* try to use PWD if it is valid, so that we don't resolve symlinks */
|
|
|
|
|
|
|
|
pwd = getenv( "PWD" );
|
2004-05-14 07:03:29 +02:00
|
|
|
if (cwd)
|
2009-10-15 12:05:55 +02:00
|
|
|
{
|
|
|
|
struct stat st1, st2;
|
|
|
|
|
|
|
|
if (!pwd || stat( pwd, &st1 ) == -1 ||
|
|
|
|
(!stat( cwd, &st2 ) && (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)))
|
|
|
|
pwd = cwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pwd)
|
2004-05-14 07:03:29 +02:00
|
|
|
{
|
2009-12-04 12:39:19 +01:00
|
|
|
ANSI_STRING unix_name;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
RtlInitAnsiString( &unix_name, pwd );
|
|
|
|
if (!wine_unix_to_nt_file_name( &unix_name, &nt_name ))
|
2004-05-14 07:03:29 +02:00
|
|
|
{
|
2009-12-04 12:39:19 +01:00
|
|
|
UNICODE_STRING dos_path;
|
|
|
|
/* skip the \??\ prefix, nt_name is 0 terminated */
|
|
|
|
RtlInitUnicodeString( &dos_path, nt_name.Buffer + 4 );
|
|
|
|
RtlSetCurrentDirectory_U( &dos_path );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2004-05-14 07:03:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cur_dir->DosPath.Length) /* still not initialized */
|
|
|
|
{
|
|
|
|
MESSAGE("Warning: could not find DOS drive for current working directory '%s', "
|
|
|
|
"starting in the Windows directory.\n", cwd ? cwd : "" );
|
|
|
|
RtlInitUnicodeString( &dir_str, DIR_Windows );
|
|
|
|
RtlSetCurrentDirectory_U( &dir_str );
|
|
|
|
}
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, cwd );
|
2004-05-14 07:03:29 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
TRACE( "starting in %s %p\n", debugstr_w( cur_dir->DosPath.Buffer ), cur_dir->Handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-14 23:43:18 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* init_windows_dirs
|
|
|
|
*/
|
|
|
|
static void init_windows_dirs(void)
|
|
|
|
{
|
2018-02-19 19:45:58 +01:00
|
|
|
static const WCHAR default_syswow64W[] = {'C',':','\\','w','i','n','d','o','w','s',
|
|
|
|
'\\','s','y','s','w','o','w','6','4',0};
|
2004-05-14 23:43:18 +02:00
|
|
|
|
2010-03-29 17:57:02 +02:00
|
|
|
if (is_win64 || is_wow64) /* SysWow64 is always defined on 64-bit */
|
2009-07-07 11:42:03 +02:00
|
|
|
{
|
2018-02-19 19:45:58 +01:00
|
|
|
DIR_SysWow64 = default_syswow64W;
|
2018-10-08 16:58:40 +02:00
|
|
|
memcpy( winevdm, default_syswow64W, sizeof(default_syswow64W) - sizeof(WCHAR) );
|
2009-07-07 11:42:03 +02:00
|
|
|
}
|
2004-05-14 23:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-04 12:51:04 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* start_wineboot
|
|
|
|
*
|
2009-08-18 12:14:12 +02:00
|
|
|
* Start the wineboot process if necessary. Return the handles to wait on.
|
2008-01-04 12:51:04 +01:00
|
|
|
*/
|
2009-08-18 12:14:12 +02:00
|
|
|
static void start_wineboot( HANDLE handles[2] )
|
2008-01-04 12:51:04 +01:00
|
|
|
{
|
|
|
|
static const WCHAR wineboot_eventW[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
|
|
|
|
|
2009-08-18 12:14:12 +02:00
|
|
|
handles[1] = 0;
|
|
|
|
if (!(handles[0] = CreateEventW( NULL, TRUE, FALSE, wineboot_eventW )))
|
2008-01-04 12:51:04 +01:00
|
|
|
{
|
|
|
|
ERR( "failed to create wineboot event, expect trouble\n" );
|
2009-08-18 12:14:12 +02:00
|
|
|
return;
|
2008-01-04 12:51:04 +01:00
|
|
|
}
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS) /* we created it */
|
|
|
|
{
|
2009-10-21 18:03:32 +02:00
|
|
|
static const WCHAR wineboot[] = {'\\','w','i','n','e','b','o','o','t','.','e','x','e',0};
|
|
|
|
static const WCHAR args[] = {' ','-','-','i','n','i','t',0};
|
2008-01-04 12:51:04 +01:00
|
|
|
STARTUPINFOW si;
|
|
|
|
PROCESS_INFORMATION pi;
|
2009-10-21 18:03:32 +02:00
|
|
|
void *redir;
|
2009-10-27 20:48:47 +01:00
|
|
|
WCHAR app[MAX_PATH];
|
2018-07-30 21:18:09 +02:00
|
|
|
WCHAR cmdline[MAX_PATH + ARRAY_SIZE( wineboot ) + ARRAY_SIZE( args )];
|
2008-01-04 12:51:04 +01:00
|
|
|
|
|
|
|
memset( &si, 0, sizeof(si) );
|
|
|
|
si.cb = sizeof(si);
|
2008-01-14 15:49:56 +01:00
|
|
|
si.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
si.hStdInput = 0;
|
|
|
|
si.hStdOutput = 0;
|
|
|
|
si.hStdError = GetStdHandle( STD_ERROR_HANDLE );
|
|
|
|
|
2018-07-30 21:18:09 +02:00
|
|
|
GetSystemDirectoryW( app, MAX_PATH - ARRAY_SIZE( wineboot ));
|
2009-10-27 20:48:47 +01:00
|
|
|
lstrcatW( app, wineboot );
|
2009-10-21 18:03:32 +02:00
|
|
|
|
|
|
|
Wow64DisableWow64FsRedirection( &redir );
|
2009-10-27 20:48:47 +01:00
|
|
|
strcpyW( cmdline, app );
|
|
|
|
strcatW( cmdline, args );
|
|
|
|
if (CreateProcessW( app, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi ))
|
2008-01-04 12:51:04 +01:00
|
|
|
{
|
|
|
|
TRACE( "started wineboot pid %04x tid %04x\n", pi.dwProcessId, pi.dwThreadId );
|
|
|
|
CloseHandle( pi.hThread );
|
2009-08-18 12:14:12 +02:00
|
|
|
handles[1] = pi.hProcess;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR( "failed to start wineboot, err %u\n", GetLastError() );
|
|
|
|
CloseHandle( handles[0] );
|
|
|
|
handles[0] = 0;
|
2008-01-04 12:51:04 +01:00
|
|
|
}
|
2009-10-21 18:03:32 +02:00
|
|
|
Wow64RevertWow64FsRedirection( redir );
|
2008-01-04 12:51:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-28 11:20:28 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
extern DWORD call_process_entry( PEB *peb, LPTHREAD_START_ROUTINE entry );
|
|
|
|
__ASM_GLOBAL_FUNC( call_process_entry,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
2018-07-08 21:19:56 +02:00
|
|
|
"pushl 4(%ebp)\n\t" /* deliberately mis-align the stack by 8, Doom 3 needs this */
|
|
|
|
"pushl 4(%ebp)\n\t" /* Driller expects readable address at this offset */
|
|
|
|
"pushl 4(%ebp)\n\t"
|
2010-05-28 11:20:28 +02:00
|
|
|
"pushl 8(%ebp)\n\t"
|
|
|
|
"call *12(%ebp)\n\t"
|
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret" )
|
2017-12-04 13:13:05 +01:00
|
|
|
|
|
|
|
extern void WINAPI start_process( LPTHREAD_START_ROUTINE entry, PEB *peb ) DECLSPEC_HIDDEN;
|
|
|
|
extern void WINAPI start_process_wrapper(void) DECLSPEC_HIDDEN;
|
|
|
|
__ASM_GLOBAL_FUNC( start_process_wrapper,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"pushl %ebx\n\t" /* arg */
|
|
|
|
"pushl %eax\n\t" /* entry */
|
|
|
|
"call " __ASM_NAME("start_process") )
|
2010-05-28 11:20:28 +02:00
|
|
|
#else
|
|
|
|
static inline DWORD call_process_entry( PEB *peb, LPTHREAD_START_ROUTINE entry )
|
|
|
|
{
|
|
|
|
return entry( peb );
|
|
|
|
}
|
2017-12-04 13:13:05 +01:00
|
|
|
static void WINAPI start_process( LPTHREAD_START_ROUTINE entry, PEB *peb );
|
|
|
|
#define start_process_wrapper start_process
|
2010-05-28 11:20:28 +02:00
|
|
|
#endif
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* start_process
|
|
|
|
*
|
|
|
|
* Startup routine of a new process. Runs on the new process stack.
|
|
|
|
*/
|
2017-12-04 13:13:05 +01:00
|
|
|
void WINAPI start_process( LPTHREAD_START_ROUTINE entry, PEB *peb )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2017-02-10 17:21:32 +01:00
|
|
|
BOOL being_debugged;
|
2009-02-26 13:19:43 +01:00
|
|
|
|
2017-02-09 20:11:52 +01:00
|
|
|
if (!entry)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2009-08-29 11:07:17 +02:00
|
|
|
ERR( "%s doesn't have an entry point, it cannot be executed\n",
|
|
|
|
debugstr_w(peb->ProcessParameters->ImagePathName.Buffer) );
|
|
|
|
ExitThread( 1 );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2009-08-29 11:07:17 +02:00
|
|
|
|
2017-11-25 11:47:36 +01:00
|
|
|
TRACE_(relay)( "\1Starting process %s (entryproc=%p)\n",
|
|
|
|
debugstr_w(peb->ProcessParameters->ImagePathName.Buffer), entry );
|
2009-08-29 11:07:17 +02:00
|
|
|
|
2017-12-04 13:13:05 +01:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
if (!CheckRemoteDebuggerPresent( GetCurrentProcess(), &being_debugged ))
|
|
|
|
being_debugged = FALSE;
|
2017-02-10 17:21:32 +01:00
|
|
|
|
2017-12-04 13:13:05 +01:00
|
|
|
SetLastError( 0 ); /* clear error code */
|
|
|
|
if (being_debugged) DbgBreakPoint();
|
|
|
|
ExitThread( call_process_entry( peb, entry ));
|
|
|
|
}
|
|
|
|
__EXCEPT(UnhandledExceptionFilter)
|
|
|
|
{
|
2019-07-04 13:37:45 +02:00
|
|
|
TerminateProcess( GetCurrentProcess(), GetExceptionCode() );
|
2017-12-04 13:13:05 +01:00
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
abort(); /* should not be reached */
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-06 11:57:37 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_process_name
|
|
|
|
*
|
|
|
|
* Change the process name in the ps output.
|
|
|
|
*/
|
2006-07-19 15:04:57 +02:00
|
|
|
static void set_process_name( int argc, char *argv[] )
|
2006-04-06 11:57:37 +02:00
|
|
|
{
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
BOOL shift_strings;
|
|
|
|
char *p, *name;
|
|
|
|
int i;
|
|
|
|
|
2008-01-20 21:23:08 +01:00
|
|
|
#ifdef HAVE_SETPROCTITLE
|
|
|
|
setproctitle("-%s", argv[1]);
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
shift_strings = FALSE;
|
|
|
|
#else
|
|
|
|
p = argv[0];
|
2006-04-06 11:57:37 +02:00
|
|
|
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
shift_strings = (argc >= 2);
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
p += strlen(p) + 1;
|
|
|
|
if (p != argv[i])
|
|
|
|
{
|
|
|
|
shift_strings = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-04-06 11:57:37 +02:00
|
|
|
#endif
|
|
|
|
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
if (shift_strings)
|
2006-04-06 11:57:37 +02:00
|
|
|
{
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
int offset = argv[1] - argv[0];
|
|
|
|
char *end = argv[argc-1] + strlen(argv[argc-1]) + 1;
|
|
|
|
memmove( argv[0], argv[1], end - argv[1] );
|
2006-07-19 15:04:57 +02:00
|
|
|
memset( end - offset, 0, offset );
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
argv[i-1] = argv[i] - offset;
|
2006-07-19 15:04:57 +02:00
|
|
|
argv[i-1] = NULL;
|
2006-04-06 11:57:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-19 15:04:57 +02:00
|
|
|
/* remove argv[0] */
|
|
|
|
memmove( argv, argv + 1, argc * sizeof(argv[0]) );
|
2006-04-06 11:57:37 +02:00
|
|
|
}
|
kernel32: Overhaul the handling of argv in set_process_name().
This fixes several problems with the code:
* The code had been assuming that the argument strings pointed to by the argv
array are contiguous iff certain process-name-setting functions are available.
This doesn't seem reliable. Instead, test if it's true and shift the strings
if so.
However, setproctitle() is specifically documented as a preferred alternative
to the technique of overwriting the arg strings, so don't shift the strings
if that's available.
* Use the last path component, recognizing backslash as a path separator, for
setprogname() in addition to prctl(). First, setprogname() is documented as
searching for the last component itself, but it doesn't understand Windows-
style paths, so we need to help it. Second, on some platforms (e.g. macOS),
setprogname(), like prctl(), has a fairly small internal length limit (e.g.
32 characters). So, concentrate on the most meaningful part of the path.
* Remove argv[0] from argv whether or not there are any process-name-setting
functions available. This is necessary for the proper functioning of Wine,
so it must be done on all platforms. This part of the logic was lost with
commit 5a4576ee0.
* Call all available process-name-setting functions instead of treating them
as mutually exclusive alternatives. This is also logic that was lost with
commit 5a4576ee0.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-07-12 06:44:20 +02:00
|
|
|
|
|
|
|
name = argv[0];
|
|
|
|
if ((p = strrchr( name, '\\' ))) name = p + 1;
|
|
|
|
if ((p = strrchr( name, '/' ))) name = p + 1;
|
|
|
|
|
|
|
|
#if defined(HAVE_SETPROGNAME)
|
|
|
|
setprogname( name );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PRCTL
|
|
|
|
#ifndef PR_SET_NAME
|
|
|
|
# define PR_SET_NAME 15
|
|
|
|
#endif
|
|
|
|
prctl( PR_SET_NAME, name );
|
2016-02-19 23:33:33 +01:00
|
|
|
#endif /* HAVE_PRCTL */
|
2006-04-06 11:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
2003-10-10 02:12:17 +02:00
|
|
|
* __wine_kernel_init
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
|
|
|
* Wine initialisation: load and start the main exe file.
|
|
|
|
*/
|
2019-02-14 16:45:03 +01:00
|
|
|
void * CDECL __wine_kernel_init(void)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2008-04-24 11:53:45 +02:00
|
|
|
static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0};
|
2006-02-21 19:48:18 +01:00
|
|
|
static const WCHAR dotW[] = {'.',0};
|
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
WCHAR *p, main_exe_name[MAX_PATH+1];
|
2003-10-09 06:59:03 +02:00
|
|
|
PEB *peb = NtCurrentTeb()->Peb;
|
2008-04-24 11:53:45 +02:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = peb->ProcessParameters;
|
2009-08-18 12:14:12 +02:00
|
|
|
HANDLE boot_events[2];
|
2008-04-24 11:53:45 +02:00
|
|
|
BOOL got_environment = TRUE;
|
2019-10-03 14:14:36 +02:00
|
|
|
WCHAR *load_path, *dummy;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
/* Initialize everything */
|
2008-04-24 11:53:45 +02:00
|
|
|
|
|
|
|
setbuf(stdout,NULL);
|
|
|
|
setbuf(stderr,NULL);
|
|
|
|
kernel32_handle = GetModuleHandleW(kernel32W);
|
2009-07-07 11:42:03 +02:00
|
|
|
IsWow64Process( GetCurrentProcess(), &is_wow64 );
|
2018-10-09 14:49:54 +02:00
|
|
|
RtlSetUnhandledExceptionFilter( UnhandledExceptionFilter );
|
2008-04-24 11:53:45 +02:00
|
|
|
|
|
|
|
LOCALE_Init();
|
|
|
|
|
|
|
|
if (!params->Environment)
|
|
|
|
{
|
|
|
|
/* Copy the parent environment */
|
2009-04-01 14:36:49 +02:00
|
|
|
if (!build_initial_environment()) exit(1);
|
2008-04-24 11:53:45 +02:00
|
|
|
|
|
|
|
/* convert old configuration to new format */
|
|
|
|
convert_old_config();
|
|
|
|
|
2010-01-28 13:16:40 +01:00
|
|
|
got_environment = set_registry_environment( FALSE );
|
2008-04-24 11:53:45 +02:00
|
|
|
set_additional_environment();
|
|
|
|
}
|
|
|
|
|
|
|
|
init_windows_dirs();
|
|
|
|
init_current_directory( ¶ms->CurrentDirectory );
|
|
|
|
|
2006-07-19 15:04:57 +02:00
|
|
|
set_process_name( __wine_main_argc, __wine_main_argv );
|
2006-07-19 14:12:58 +02:00
|
|
|
set_library_wargv( __wine_main_argv );
|
2009-08-18 12:14:12 +02:00
|
|
|
boot_events[0] = boot_events[1] = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2006-02-21 19:48:18 +01:00
|
|
|
if (peb->ProcessParameters->ImagePathName.Buffer)
|
|
|
|
{
|
|
|
|
strcpyW( main_exe_name, peb->ProcessParameters->ImagePathName.Buffer );
|
|
|
|
}
|
|
|
|
else
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2018-09-27 14:54:01 +02:00
|
|
|
BOOL is_64bit;
|
2009-10-27 20:40:40 +01:00
|
|
|
|
2019-10-03 19:26:01 +02:00
|
|
|
RtlGetExePath( __wine_main_wargv[0], &load_path );
|
|
|
|
if (!SearchPathW( load_path, __wine_main_wargv[0], exeW, MAX_PATH, main_exe_name, NULL ) &&
|
2018-09-27 14:54:01 +02:00
|
|
|
!get_builtin_path( __wine_main_wargv[0], exeW, main_exe_name, MAX_PATH, &is_64bit ))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2006-07-19 14:12:58 +02:00
|
|
|
MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] );
|
2006-02-22 09:57:19 +01:00
|
|
|
ExitProcess( GetLastError() );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2019-10-03 19:26:01 +02:00
|
|
|
RtlReleasePath( load_path );
|
2009-04-02 12:59:32 +02:00
|
|
|
update_library_argv0( main_exe_name );
|
2006-07-19 14:12:58 +02:00
|
|
|
if (!build_command_line( __wine_main_wargv )) goto error;
|
2009-08-18 12:14:12 +02:00
|
|
|
start_wineboot( boot_events );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
2006-02-21 19:48:18 +01:00
|
|
|
/* if there's no extension, append a dot to prevent LoadLibrary from appending .dll */
|
|
|
|
p = strrchrW( main_exe_name, '.' );
|
|
|
|
if (!p || strchrW( p, '/' ) || strchrW( p, '\\' )) strcatW( main_exe_name, dotW );
|
|
|
|
|
2006-02-22 09:57:19 +01:00
|
|
|
TRACE( "starting process name=%s argv[0]=%s\n",
|
2006-07-19 14:12:58 +02:00
|
|
|
debugstr_w(main_exe_name), debugstr_w(__wine_main_wargv[0]) );
|
2003-09-30 03:04:19 +02:00
|
|
|
|
2019-10-03 14:14:36 +02:00
|
|
|
LdrGetDllPath( main_exe_name, 0, &load_path, &dummy );
|
|
|
|
RtlInitUnicodeString( &NtCurrentTeb()->Peb->ProcessParameters->DllPath, load_path );
|
2003-10-02 06:58:49 +02:00
|
|
|
|
2009-08-18 12:14:12 +02:00
|
|
|
if (boot_events[0])
|
2008-05-13 20:26:37 +02:00
|
|
|
{
|
2010-03-30 16:50:06 +02:00
|
|
|
DWORD timeout = 2 * 60 * 1000, count = 1;
|
2009-08-18 12:17:04 +02:00
|
|
|
|
2009-08-18 12:14:12 +02:00
|
|
|
if (boot_events[1]) count++;
|
2010-03-30 16:50:06 +02:00
|
|
|
if (!got_environment) timeout = 5 * 60 * 1000; /* initial prefix creation can take longer */
|
2009-08-18 12:17:04 +02:00
|
|
|
if (WaitForMultipleObjects( count, boot_events, FALSE, timeout ) == WAIT_TIMEOUT)
|
2009-08-18 12:14:12 +02:00
|
|
|
ERR( "boot event wait timed out\n" );
|
|
|
|
CloseHandle( boot_events[0] );
|
|
|
|
if (boot_events[1]) CloseHandle( boot_events[1] );
|
2010-01-28 13:16:40 +01:00
|
|
|
/* reload environment now that wineboot has run */
|
|
|
|
set_registry_environment( got_environment );
|
|
|
|
set_additional_environment();
|
2008-05-13 20:26:37 +02:00
|
|
|
}
|
2010-12-14 22:48:44 +01:00
|
|
|
set_wow64_environment();
|
2008-05-13 20:26:37 +02:00
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
if (!(peb->ImageBaseAddress = LoadLibraryExW( main_exe_name, 0, DONT_RESOLVE_DLL_REFERENCES )))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2009-11-29 16:42:50 +01:00
|
|
|
DWORD_PTR args[1];
|
|
|
|
WCHAR msgW[1024];
|
2006-07-19 14:12:58 +02:00
|
|
|
char msg[1024];
|
|
|
|
DWORD error = GetLastError();
|
|
|
|
|
|
|
|
/* if Win16/DOS format, or unavailable address, exec a new process with the proper setup */
|
2006-09-09 23:14:26 +02:00
|
|
|
if (error == ERROR_BAD_EXE_FORMAT ||
|
|
|
|
error == ERROR_INVALID_ADDRESS ||
|
|
|
|
error == ERROR_NOT_ENOUGH_MEMORY)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2006-07-19 14:12:58 +02:00
|
|
|
if (!getenv("WINEPRELOADRESERVE")) exec_process( main_exe_name );
|
|
|
|
/* if we get back here, it failed */
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2009-02-23 17:46:50 +01:00
|
|
|
else if (error == ERROR_MOD_NOT_FOUND)
|
|
|
|
{
|
2018-10-08 16:58:40 +02:00
|
|
|
if (!strcmpiW( main_exe_name, winevdm ) && __wine_main_argc > 3)
|
2009-02-23 17:46:50 +01:00
|
|
|
{
|
|
|
|
/* args 1 and 2 are --app-name full_path */
|
|
|
|
MESSAGE( "wine: could not run %s: 16-bit/DOS support missing\n",
|
|
|
|
debugstr_w(__wine_main_wargv[3]) );
|
|
|
|
ExitProcess( ERROR_BAD_EXE_FORMAT );
|
|
|
|
}
|
2010-03-18 13:02:42 +01:00
|
|
|
MESSAGE( "wine: cannot find %s\n", debugstr_w(main_exe_name) );
|
|
|
|
ExitProcess( ERROR_FILE_NOT_FOUND );
|
2009-02-23 17:46:50 +01:00
|
|
|
}
|
2009-11-29 16:42:50 +01:00
|
|
|
args[0] = (DWORD_PTR)main_exe_name;
|
|
|
|
FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
2018-07-30 21:18:09 +02:00
|
|
|
NULL, error, 0, msgW, ARRAY_SIZE( msgW ), (__ms_va_list *)args );
|
2011-10-26 00:16:21 +02:00
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, msgW, -1, msg, sizeof(msg), NULL, NULL );
|
2009-11-29 16:42:50 +01:00
|
|
|
MESSAGE( "wine: %s", msg );
|
2006-02-22 09:57:19 +01:00
|
|
|
ExitProcess( error );
|
2006-02-21 19:48:18 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 13:44:40 +01:00
|
|
|
if (!params->CurrentDirectory.Handle) chdir("/"); /* avoid locking removable devices */
|
|
|
|
|
2019-02-14 16:45:03 +01:00
|
|
|
return start_process_wrapper;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
ExitProcess( GetLastError() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* build_argv
|
|
|
|
*
|
|
|
|
* Build an argv array from a command-line.
|
|
|
|
* 'reserved' is the number of args to reserve before the first one.
|
|
|
|
*/
|
2018-10-24 12:20:38 +02:00
|
|
|
static char **build_argv( const UNICODE_STRING *cmdlineW, int reserved )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char** argv;
|
2003-10-04 06:09:41 +02:00
|
|
|
char *arg,*s,*d,*cmdline;
|
|
|
|
int in_quotes,bcount,len;
|
|
|
|
|
2018-10-24 12:20:38 +02:00
|
|
|
len = WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW->Buffer, cmdlineW->Length / sizeof(WCHAR),
|
|
|
|
NULL, 0, NULL, NULL );
|
|
|
|
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, len + 1 ))) return NULL;
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW->Buffer, cmdlineW->Length / sizeof(WCHAR),
|
|
|
|
cmdline, len, NULL, NULL );
|
|
|
|
cmdline[len++] = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
argc=reserved+1;
|
|
|
|
bcount=0;
|
|
|
|
in_quotes=0;
|
|
|
|
s=cmdline;
|
|
|
|
while (1) {
|
|
|
|
if (*s=='\0' || ((*s==' ' || *s=='\t') && !in_quotes)) {
|
|
|
|
/* space */
|
|
|
|
argc++;
|
|
|
|
/* skip the remaining spaces */
|
|
|
|
while (*s==' ' || *s=='\t') {
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (*s=='\0')
|
|
|
|
break;
|
|
|
|
bcount=0;
|
|
|
|
continue;
|
|
|
|
} else if (*s=='\\') {
|
|
|
|
/* '\', count them */
|
|
|
|
bcount++;
|
|
|
|
} else if ((*s=='"') && ((bcount & 1)==0)) {
|
2019-02-26 09:39:25 +01:00
|
|
|
if (in_quotes && s[1] == '"') {
|
|
|
|
s++;
|
|
|
|
} else {
|
|
|
|
/* unescaped '"' */
|
|
|
|
in_quotes=!in_quotes;
|
|
|
|
bcount=0;
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
} else {
|
|
|
|
/* a regular character */
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
2008-10-31 14:02:04 +01:00
|
|
|
if (!(argv = HeapAlloc( GetProcessHeap(), 0, argc*sizeof(*argv) + len )))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
2003-09-17 07:31:32 +02:00
|
|
|
return NULL;
|
2008-10-31 14:02:04 +01:00
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2008-10-31 14:02:04 +01:00
|
|
|
arg = d = s = (char *)(argv + argc);
|
|
|
|
memcpy( d, cmdline, len );
|
2003-09-17 07:31:32 +02:00
|
|
|
bcount=0;
|
|
|
|
in_quotes=0;
|
|
|
|
argc=reserved;
|
|
|
|
while (*s) {
|
|
|
|
if ((*s==' ' || *s=='\t') && !in_quotes) {
|
|
|
|
/* Close the argument and copy it */
|
|
|
|
*d=0;
|
|
|
|
argv[argc++]=arg;
|
|
|
|
|
|
|
|
/* skip the remaining spaces */
|
|
|
|
do {
|
|
|
|
s++;
|
|
|
|
} while (*s==' ' || *s=='\t');
|
|
|
|
|
|
|
|
/* Start with a new argument */
|
|
|
|
arg=d=s;
|
|
|
|
bcount=0;
|
|
|
|
} else if (*s=='\\') {
|
|
|
|
/* '\\' */
|
|
|
|
*d++=*s++;
|
|
|
|
bcount++;
|
|
|
|
} else if (*s=='"') {
|
|
|
|
/* '"' */
|
|
|
|
if ((bcount & 1)==0) {
|
2005-02-25 15:07:56 +01:00
|
|
|
/* Preceded by an even number of '\', this is half that
|
2003-09-17 07:31:32 +02:00
|
|
|
* number of '\', plus a '"' which we discard.
|
|
|
|
*/
|
|
|
|
d-=bcount/2;
|
|
|
|
s++;
|
2019-02-26 09:39:25 +01:00
|
|
|
if(in_quotes && *s == '"') {
|
|
|
|
*d++='"';
|
|
|
|
s++;
|
|
|
|
} else {
|
|
|
|
in_quotes=!in_quotes;
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
} else {
|
2005-02-25 15:07:56 +01:00
|
|
|
/* Preceded by an odd number of '\', this is half that
|
2003-09-17 07:31:32 +02:00
|
|
|
* number of '\' followed by a '"'
|
|
|
|
*/
|
|
|
|
d=d-bcount/2-1;
|
|
|
|
*d++='"';
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
bcount=0;
|
|
|
|
} else {
|
|
|
|
/* a regular character */
|
|
|
|
*d++=*s++;
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*arg) {
|
|
|
|
*d='\0';
|
|
|
|
argv[argc++]=arg;
|
|
|
|
}
|
|
|
|
argv[argc]=NULL;
|
|
|
|
|
2008-10-31 14:02:04 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
2003-09-17 07:31:32 +02:00
|
|
|
return argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* build_envp
|
|
|
|
*
|
|
|
|
* Build the environment of a new child process.
|
|
|
|
*/
|
2004-07-16 05:54:35 +02:00
|
|
|
static char **build_envp( const WCHAR *envW )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2008-10-31 14:55:33 +01:00
|
|
|
static const char * const unix_vars[] = { "PATH", "TEMP", "TMP", "HOME" };
|
|
|
|
|
2004-06-03 02:25:08 +02:00
|
|
|
const WCHAR *end;
|
2003-09-17 07:31:32 +02:00
|
|
|
char **envp;
|
2004-06-03 02:25:08 +02:00
|
|
|
char *env, *p;
|
2009-02-17 18:56:22 +01:00
|
|
|
int count = 1, length;
|
2008-10-31 14:55:33 +01:00
|
|
|
unsigned int i;
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2004-06-03 02:25:08 +02:00
|
|
|
for (end = envW; *end; count++) end += strlenW(end) + 1;
|
|
|
|
end++;
|
|
|
|
length = WideCharToMultiByte( CP_UNIXCP, 0, envW, end - envW, NULL, 0, NULL, NULL );
|
2008-10-31 14:55:33 +01:00
|
|
|
if (!(env = HeapAlloc( GetProcessHeap(), 0, length ))) return NULL;
|
2004-06-03 02:25:08 +02:00
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, envW, end - envW, env, length, NULL, NULL );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2008-10-31 14:55:33 +01:00
|
|
|
for (p = env; *p; p += strlen(p) + 1)
|
|
|
|
if (is_special_env_var( p )) length += 4; /* prefix it with "WINE" */
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2018-07-30 21:18:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( unix_vars ); i++)
|
2008-10-31 14:55:33 +01:00
|
|
|
{
|
|
|
|
if (!(p = getenv(unix_vars[i]))) continue;
|
|
|
|
length += strlen(unix_vars[i]) + strlen(p) + 2;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((envp = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*envp) + length )))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
char **envptr = envp;
|
2008-10-31 14:55:33 +01:00
|
|
|
char *dst = (char *)(envp + count);
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2004-07-16 05:54:35 +02:00
|
|
|
/* some variables must not be modified, so we get them directly from the unix env */
|
2018-07-30 21:18:09 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( unix_vars ); i++)
|
2008-10-31 14:55:33 +01:00
|
|
|
{
|
|
|
|
if (!(p = getenv(unix_vars[i]))) continue;
|
|
|
|
*envptr++ = strcpy( dst, unix_vars[i] );
|
|
|
|
strcat( dst, "=" );
|
|
|
|
strcat( dst, p );
|
|
|
|
dst += strlen(dst) + 1;
|
|
|
|
}
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/* now put the Windows environment strings */
|
|
|
|
for (p = env; *p; p += strlen(p) + 1)
|
|
|
|
{
|
2004-07-16 05:54:35 +02:00
|
|
|
if (*p == '=') continue; /* skip drive curdirs, this crashes some unix apps */
|
|
|
|
if (!strncmp( p, "WINEPRELOADRESERVE=", sizeof("WINEPRELOADRESERVE=")-1 )) continue;
|
2009-03-10 18:22:38 +01:00
|
|
|
if (!strncmp( p, "WINELOADERNOEXEC=", sizeof("WINELOADERNOEXEC=")-1 )) continue;
|
2006-07-19 14:00:10 +02:00
|
|
|
if (!strncmp( p, "WINESERVERSOCKET=", sizeof("WINESERVERSOCKET=")-1 )) continue;
|
2004-03-11 01:49:01 +01:00
|
|
|
if (is_special_env_var( p )) /* prefix it with "WINE" */
|
2008-10-31 14:55:33 +01:00
|
|
|
{
|
|
|
|
*envptr++ = strcpy( dst, "WINE" );
|
|
|
|
strcat( dst, p );
|
|
|
|
}
|
2004-07-16 05:54:35 +02:00
|
|
|
else
|
2008-10-31 14:55:33 +01:00
|
|
|
{
|
|
|
|
*envptr++ = strcpy( dst, p );
|
|
|
|
}
|
|
|
|
dst += strlen(dst) + 1;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
*envptr = 0;
|
|
|
|
}
|
2008-10-31 14:55:33 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, env );
|
2003-09-17 07:31:32 +02:00
|
|
|
return envp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* fork_and_exec
|
|
|
|
*
|
|
|
|
* Fork and exec a new Unix binary, checking for errors.
|
|
|
|
*/
|
2018-10-24 11:32:16 +02:00
|
|
|
static int fork_and_exec( const RTL_USER_PROCESS_PARAMETERS *params, const char *newdir )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2011-02-05 03:47:10 +01:00
|
|
|
int fd[2], stdin_fd = -1, stdout_fd = -1, stderr_fd = -1;
|
2003-09-17 07:31:32 +02:00
|
|
|
int pid, err;
|
2018-10-15 17:05:31 +02:00
|
|
|
char *filename, **argv, **envp;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2018-10-15 17:05:31 +02:00
|
|
|
if (!(filename = wine_get_unix_file_name( params->ImagePathName.Buffer ))) return -1;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2009-07-01 12:13:46 +02:00
|
|
|
#ifdef HAVE_PIPE2
|
|
|
|
if (pipe2( fd, O_CLOEXEC ) == -1)
|
|
|
|
#endif
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2009-07-01 12:13:46 +02:00
|
|
|
if (pipe(fd) == -1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_TOO_MANY_OPEN_FILES );
|
2018-10-15 17:05:31 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, filename );
|
2009-07-01 12:13:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fcntl( fd[0], F_SETFD, FD_CLOEXEC );
|
|
|
|
fcntl( fd[1], F_SETFD, FD_CLOEXEC );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2008-07-10 12:20:56 +02:00
|
|
|
|
2018-10-15 17:05:31 +02:00
|
|
|
wine_server_handle_to_fd( params->hStdInput, FILE_READ_DATA, &stdin_fd, NULL );
|
|
|
|
wine_server_handle_to_fd( params->hStdOutput, FILE_WRITE_DATA, &stdout_fd, NULL );
|
|
|
|
wine_server_handle_to_fd( params->hStdError, FILE_WRITE_DATA, &stderr_fd, NULL );
|
2008-07-10 12:20:56 +02:00
|
|
|
|
2018-10-24 12:20:38 +02:00
|
|
|
argv = build_argv( ¶ms->CommandLine, 0 );
|
2018-10-15 17:05:31 +02:00
|
|
|
envp = build_envp( params->Environment );
|
2008-10-31 14:02:04 +01:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
if (!(pid = fork())) /* child */
|
|
|
|
{
|
2011-12-01 01:20:24 +01:00
|
|
|
if (!(pid = fork())) /* grandchild */
|
2008-01-14 15:49:12 +01:00
|
|
|
{
|
2011-12-01 01:20:24 +01:00
|
|
|
close( fd[0] );
|
|
|
|
|
2018-10-24 11:32:16 +02:00
|
|
|
if (params->ConsoleFlags || params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC ||
|
|
|
|
(params->hStdInput == INVALID_HANDLE_VALUE && params->hStdOutput == INVALID_HANDLE_VALUE))
|
2008-01-14 15:49:12 +01:00
|
|
|
{
|
2011-10-21 08:19:17 +02:00
|
|
|
int nullfd = open( "/dev/null", O_RDWR );
|
2008-01-14 15:49:12 +01:00
|
|
|
setsid();
|
|
|
|
/* close stdin and stdout */
|
2011-10-21 08:19:17 +02:00
|
|
|
if (nullfd != -1)
|
2008-01-14 15:49:12 +01:00
|
|
|
{
|
2011-10-21 08:19:17 +02:00
|
|
|
dup2( nullfd, 0 );
|
|
|
|
dup2( nullfd, 1 );
|
|
|
|
close( nullfd );
|
2008-01-14 15:49:12 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-01 01:20:24 +01:00
|
|
|
else
|
2011-02-05 03:47:10 +01:00
|
|
|
{
|
2011-12-01 01:20:24 +01:00
|
|
|
if (stdin_fd != -1)
|
|
|
|
{
|
|
|
|
dup2( stdin_fd, 0 );
|
|
|
|
close( stdin_fd );
|
|
|
|
}
|
|
|
|
if (stdout_fd != -1)
|
|
|
|
{
|
|
|
|
dup2( stdout_fd, 1 );
|
|
|
|
close( stdout_fd );
|
|
|
|
}
|
|
|
|
if (stderr_fd != -1)
|
|
|
|
{
|
|
|
|
dup2( stderr_fd, 2 );
|
|
|
|
close( stderr_fd );
|
|
|
|
}
|
2011-02-05 03:47:10 +01:00
|
|
|
}
|
2006-03-06 22:22:30 +01:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
/* Reset signals that we previously set to SIG_IGN */
|
|
|
|
signal( SIGPIPE, SIG_DFL );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
if (newdir) chdir(newdir);
|
|
|
|
|
|
|
|
if (argv && envp) execve( filename, argv, envp );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid <= 0) /* grandchild if exec failed or child if fork failed */
|
|
|
|
{
|
|
|
|
err = errno;
|
|
|
|
write( fd[1], &err, sizeof(err) );
|
|
|
|
_exit(1);
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
_exit(0); /* child if fork succeeded */
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2008-10-31 14:02:04 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, argv );
|
2008-10-31 14:55:33 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, envp );
|
2018-10-15 17:05:31 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, filename );
|
2008-07-10 12:20:56 +02:00
|
|
|
if (stdin_fd != -1) close( stdin_fd );
|
|
|
|
if (stdout_fd != -1) close( stdout_fd );
|
2011-02-05 03:47:10 +01:00
|
|
|
if (stderr_fd != -1) close( stderr_fd );
|
2003-09-17 07:31:32 +02:00
|
|
|
close( fd[1] );
|
2011-12-01 01:20:24 +01:00
|
|
|
if (pid != -1)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2011-12-01 01:20:24 +01:00
|
|
|
/* reap child */
|
|
|
|
do {
|
|
|
|
err = waitpid(pid, NULL, 0);
|
|
|
|
} while (err < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
if (read( fd[0], &err, sizeof(err) ) > 0) /* exec or second fork failed */
|
|
|
|
{
|
|
|
|
errno = err;
|
|
|
|
pid = -1;
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
if (pid == -1) FILE_SetDosError();
|
|
|
|
close( fd[0] );
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-11 17:48:25 +02:00
|
|
|
static inline const WCHAR *get_params_string( const RTL_USER_PROCESS_PARAMETERS *params,
|
|
|
|
const UNICODE_STRING *str )
|
2009-08-20 20:05:21 +02:00
|
|
|
{
|
2018-10-11 17:48:25 +02:00
|
|
|
if (params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED) return str->Buffer;
|
|
|
|
return (const WCHAR *)((const char *)params + (UINT_PTR)str->Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD append_string( void **ptr, const RTL_USER_PROCESS_PARAMETERS *params,
|
|
|
|
const UNICODE_STRING *str )
|
|
|
|
{
|
|
|
|
const WCHAR *buffer = get_params_string( params, str );
|
|
|
|
memcpy( *ptr, buffer, str->Length );
|
|
|
|
*ptr = (WCHAR *)*ptr + str->Length / sizeof(WCHAR);
|
|
|
|
return str->Length;
|
2009-08-20 20:05:21 +02:00
|
|
|
}
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/***********************************************************************
|
2009-08-20 20:05:21 +02:00
|
|
|
* create_startup_info
|
2003-10-04 06:09:41 +02:00
|
|
|
*/
|
2018-10-11 17:48:25 +02:00
|
|
|
static startup_info_t *create_startup_info( const RTL_USER_PROCESS_PARAMETERS *params, DWORD *info_size )
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
2009-08-20 20:05:21 +02:00
|
|
|
startup_info_t *info;
|
|
|
|
DWORD size;
|
|
|
|
void *ptr;
|
2018-10-11 17:48:25 +02:00
|
|
|
|
|
|
|
size = sizeof(*info);
|
|
|
|
size += params->CurrentDirectory.DosPath.Length;
|
|
|
|
size += params->DllPath.Length;
|
|
|
|
size += params->ImagePathName.Length;
|
|
|
|
size += params->CommandLine.Length;
|
|
|
|
size += params->WindowTitle.Length;
|
|
|
|
size += params->Desktop.Length;
|
|
|
|
size += params->ShellInfo.Length;
|
|
|
|
size += params->RuntimeInfo.Length;
|
|
|
|
size = (size + 1) & ~1;
|
|
|
|
*info_size = size;
|
|
|
|
|
|
|
|
if (!(info = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) return NULL;
|
|
|
|
|
|
|
|
info->console_flags = params->ConsoleFlags;
|
|
|
|
info->console = wine_server_obj_handle( params->ConsoleHandle );
|
|
|
|
info->hstdin = wine_server_obj_handle( params->hStdInput );
|
|
|
|
info->hstdout = wine_server_obj_handle( params->hStdOutput );
|
|
|
|
info->hstderr = wine_server_obj_handle( params->hStdError );
|
|
|
|
info->x = params->dwX;
|
|
|
|
info->y = params->dwY;
|
|
|
|
info->xsize = params->dwXSize;
|
|
|
|
info->ysize = params->dwYSize;
|
|
|
|
info->xchars = params->dwXCountChars;
|
|
|
|
info->ychars = params->dwYCountChars;
|
|
|
|
info->attribute = params->dwFillAttribute;
|
|
|
|
info->flags = params->dwFlags;
|
|
|
|
info->show = params->wShowWindow;
|
|
|
|
|
|
|
|
ptr = info + 1;
|
|
|
|
info->curdir_len = append_string( &ptr, params, ¶ms->CurrentDirectory.DosPath );
|
|
|
|
info->dllpath_len = append_string( &ptr, params, ¶ms->DllPath );
|
|
|
|
info->imagepath_len = append_string( &ptr, params, ¶ms->ImagePathName );
|
|
|
|
info->cmdline_len = append_string( &ptr, params, ¶ms->CommandLine );
|
|
|
|
info->title_len = append_string( &ptr, params, ¶ms->WindowTitle );
|
|
|
|
info->desktop_len = append_string( &ptr, params, ¶ms->Desktop );
|
|
|
|
info->shellinfo_len = append_string( &ptr, params, ¶ms->ShellInfo );
|
|
|
|
info->runtime_len = append_string( &ptr, params, ¶ms->RuntimeInfo );
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* create_process_params
|
|
|
|
*/
|
|
|
|
static RTL_USER_PROCESS_PARAMETERS *create_process_params( LPCWSTR filename, LPCWSTR cmdline,
|
2018-10-16 15:25:57 +02:00
|
|
|
LPCWSTR cur_dir, void *env, DWORD flags,
|
2018-10-11 17:48:25 +02:00
|
|
|
const STARTUPINFOW *startup )
|
|
|
|
{
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
|
|
|
UNICODE_STRING imageW, curdirW, cmdlineW, titleW, desktopW, runtimeW, newdirW;
|
2009-08-20 20:05:21 +02:00
|
|
|
WCHAR imagepath[MAX_PATH];
|
2018-10-16 15:25:57 +02:00
|
|
|
WCHAR *envW = env;
|
2009-08-20 20:05:21 +02:00
|
|
|
|
|
|
|
if(!GetLongPathNameW( filename, imagepath, MAX_PATH ))
|
|
|
|
lstrcpynW( imagepath, filename, MAX_PATH );
|
|
|
|
if(!GetFullPathNameW( imagepath, MAX_PATH, imagepath, NULL ))
|
|
|
|
lstrcpynW( imagepath, filename, MAX_PATH );
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2018-10-16 15:25:57 +02:00
|
|
|
if (env && !(flags & CREATE_UNICODE_ENVIRONMENT)) /* convert environment to unicode */
|
|
|
|
{
|
|
|
|
char *e = env;
|
|
|
|
DWORD lenW;
|
|
|
|
|
|
|
|
while (*e) e += strlen(e) + 1;
|
|
|
|
e++; /* final null */
|
|
|
|
lenW = MultiByteToWideChar( CP_ACP, 0, env, e - (char *)env, NULL, 0 );
|
|
|
|
if ((envW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, env, e - (char *)env, envW, lenW );
|
|
|
|
}
|
|
|
|
|
2018-10-11 17:48:25 +02:00
|
|
|
newdirW.Buffer = NULL;
|
2007-12-21 12:42:28 +01:00
|
|
|
if (cur_dir)
|
|
|
|
{
|
2018-10-11 17:48:25 +02:00
|
|
|
if (RtlDosPathNameToNtPathName_U( cur_dir, &newdirW, NULL, NULL ))
|
|
|
|
cur_dir = newdirW.Buffer + 4; /* skip \??\ prefix */
|
2009-08-20 20:05:21 +02:00
|
|
|
else
|
|
|
|
cur_dir = NULL;
|
2007-12-21 12:42:28 +01:00
|
|
|
}
|
2018-10-11 17:48:25 +02:00
|
|
|
RtlInitUnicodeString( &imageW, imagepath );
|
|
|
|
RtlInitUnicodeString( &curdirW, cur_dir );
|
|
|
|
RtlInitUnicodeString( &cmdlineW, cmdline );
|
|
|
|
RtlInitUnicodeString( &titleW, startup->lpTitle ? startup->lpTitle : imagepath );
|
|
|
|
RtlInitUnicodeString( &desktopW, startup->lpDesktop );
|
|
|
|
runtimeW.Buffer = (WCHAR *)startup->lpReserved2;
|
|
|
|
runtimeW.Length = runtimeW.MaximumLength = startup->cbReserved2;
|
2018-10-24 12:21:06 +02:00
|
|
|
if (RtlCreateProcessParametersEx( ¶ms, &imageW, NULL, cur_dir ? &curdirW : NULL,
|
|
|
|
&cmdlineW, envW, &titleW, &desktopW,
|
|
|
|
NULL, &runtimeW, PROCESS_PARAMS_FLAG_NORMALIZED ))
|
2018-10-16 15:25:57 +02:00
|
|
|
{
|
|
|
|
if (envW != env) HeapFree( GetProcessHeap(), 0, envW );
|
2018-10-11 17:48:25 +02:00
|
|
|
return NULL;
|
2018-10-16 15:25:57 +02:00
|
|
|
}
|
2009-08-20 20:05:21 +02:00
|
|
|
|
2018-10-11 17:48:25 +02:00
|
|
|
if (flags & CREATE_NEW_PROCESS_GROUP) params->ConsoleFlags = 1;
|
|
|
|
if (flags & CREATE_NEW_CONSOLE) params->ConsoleHandle = KERNEL32_CONSOLE_ALLOC;
|
2006-02-05 12:20:40 +01:00
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
if (startup->dwFlags & STARTF_USESTDHANDLES)
|
|
|
|
{
|
2018-10-11 17:48:25 +02:00
|
|
|
params->hStdInput = startup->hStdInput;
|
|
|
|
params->hStdOutput = startup->hStdOutput;
|
|
|
|
params->hStdError = startup->hStdError;
|
2009-08-20 20:05:21 +02:00
|
|
|
}
|
2017-01-25 22:04:13 +01:00
|
|
|
else if (flags & DETACHED_PROCESS)
|
|
|
|
{
|
2018-10-11 17:48:25 +02:00
|
|
|
params->hStdInput = INVALID_HANDLE_VALUE;
|
|
|
|
params->hStdOutput = INVALID_HANDLE_VALUE;
|
|
|
|
params->hStdError = INVALID_HANDLE_VALUE;
|
2017-01-25 22:04:13 +01:00
|
|
|
}
|
2009-08-20 20:05:21 +02:00
|
|
|
else
|
|
|
|
{
|
2018-10-11 17:48:25 +02:00
|
|
|
params->hStdInput = NtCurrentTeb()->Peb->ProcessParameters->hStdInput;
|
|
|
|
params->hStdOutput = NtCurrentTeb()->Peb->ProcessParameters->hStdOutput;
|
|
|
|
params->hStdError = NtCurrentTeb()->Peb->ProcessParameters->hStdError;
|
2009-08-20 20:05:21 +02:00
|
|
|
}
|
2018-10-11 17:48:25 +02:00
|
|
|
|
|
|
|
if (flags & CREATE_NEW_CONSOLE)
|
2009-08-20 20:05:21 +02:00
|
|
|
{
|
|
|
|
/* this is temporary (for console handles). We have no way to control that the handle is invalid in child process otherwise */
|
2018-10-11 17:48:25 +02:00
|
|
|
if (is_console_handle(params->hStdInput)) params->hStdInput = INVALID_HANDLE_VALUE;
|
|
|
|
if (is_console_handle(params->hStdOutput)) params->hStdOutput = INVALID_HANDLE_VALUE;
|
|
|
|
if (is_console_handle(params->hStdError)) params->hStdError = INVALID_HANDLE_VALUE;
|
2006-07-19 14:00:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-11 17:48:25 +02:00
|
|
|
if (is_console_handle(params->hStdInput)) params->hStdInput = (HANDLE)((UINT_PTR)params->hStdInput & ~3);
|
|
|
|
if (is_console_handle(params->hStdOutput)) params->hStdOutput = (HANDLE)((UINT_PTR)params->hStdOutput & ~3);
|
|
|
|
if (is_console_handle(params->hStdError)) params->hStdError = (HANDLE)((UINT_PTR)params->hStdError & ~3);
|
2009-08-20 20:05:21 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 17:48:25 +02:00
|
|
|
params->dwX = startup->dwX;
|
|
|
|
params->dwY = startup->dwY;
|
|
|
|
params->dwXSize = startup->dwXSize;
|
|
|
|
params->dwYSize = startup->dwYSize;
|
|
|
|
params->dwXCountChars = startup->dwXCountChars;
|
|
|
|
params->dwYCountChars = startup->dwYCountChars;
|
|
|
|
params->dwFillAttribute = startup->dwFillAttribute;
|
|
|
|
params->dwFlags = startup->dwFlags;
|
|
|
|
params->wShowWindow = startup->wShowWindow;
|
2009-08-20 20:05:21 +02:00
|
|
|
|
2018-10-16 15:25:57 +02:00
|
|
|
if (envW != env) HeapFree( GetProcessHeap(), 0, envW );
|
2018-10-11 17:48:25 +02:00
|
|
|
return params;
|
2003-10-04 06:09:41 +02:00
|
|
|
}
|
|
|
|
|
2010-03-29 17:57:02 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_alternate_loader
|
|
|
|
*
|
|
|
|
* Get the name of the alternate (32 or 64 bit) Wine loader.
|
|
|
|
*/
|
|
|
|
static const char *get_alternate_loader( char **ret_env )
|
|
|
|
{
|
|
|
|
char *env;
|
|
|
|
const char *loader = NULL;
|
|
|
|
const char *loader_env = getenv( "WINELOADER" );
|
|
|
|
|
|
|
|
*ret_env = NULL;
|
|
|
|
|
2018-11-26 14:06:39 +01:00
|
|
|
if (wine_get_build_dir()) loader = is_win64 ? "loader/wine" : "loader/wine64";
|
2010-03-29 17:57:02 +02:00
|
|
|
|
|
|
|
if (loader_env)
|
|
|
|
{
|
|
|
|
int len = strlen( loader_env );
|
2010-05-16 17:01:52 +02:00
|
|
|
if (!is_win64)
|
2010-03-29 17:57:02 +02:00
|
|
|
{
|
|
|
|
if (!(env = HeapAlloc( GetProcessHeap(), 0, sizeof("WINELOADER=") + len + 2 ))) return NULL;
|
|
|
|
strcpy( env, "WINELOADER=" );
|
|
|
|
strcat( env, loader_env );
|
2010-05-16 17:01:52 +02:00
|
|
|
strcat( env, "64" );
|
2010-03-29 17:57:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(env = HeapAlloc( GetProcessHeap(), 0, sizeof("WINELOADER=") + len ))) return NULL;
|
|
|
|
strcpy( env, "WINELOADER=" );
|
|
|
|
strcat( env, loader_env );
|
|
|
|
len += sizeof("WINELOADER=") - 1;
|
2010-05-16 17:01:52 +02:00
|
|
|
if (!strcmp( env + len - 2, "64" )) env[len - 2] = 0;
|
2010-03-29 17:57:02 +02:00
|
|
|
}
|
|
|
|
if (!loader)
|
|
|
|
{
|
|
|
|
if ((loader = strrchr( env, '/' ))) loader++;
|
|
|
|
else loader = env;
|
|
|
|
}
|
2010-03-31 10:22:25 +02:00
|
|
|
*ret_env = env;
|
2010-03-29 17:57:02 +02:00
|
|
|
}
|
2010-05-16 17:01:52 +02:00
|
|
|
if (!loader) loader = is_win64 ? "wine" : "wine64";
|
2010-03-29 17:57:02 +02:00
|
|
|
return loader;
|
|
|
|
}
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2010-11-16 08:41:14 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
/***********************************************************************
|
|
|
|
* terminate_main_thread
|
|
|
|
*
|
|
|
|
* On some versions of Mac OS X, the execve system call fails with
|
|
|
|
* ENOTSUP if the process has multiple threads. Wine is always multi-
|
|
|
|
* threaded on Mac OS X because it specifically reserves the main thread
|
|
|
|
* for use by the system frameworks (see apple_main_thread() in
|
|
|
|
* libs/wine/loader.c). So, when we need to exec without first forking,
|
|
|
|
* we need to terminate the main thread first. We do this by installing
|
|
|
|
* a custom run loop source onto the main run loop and signaling it.
|
|
|
|
* The source's "perform" callback is pthread_exit and it will be
|
|
|
|
* executed on the main thread, terminating it.
|
|
|
|
*
|
|
|
|
* Returns TRUE if there's still hope the main thread has terminated or
|
|
|
|
* will soon. Return FALSE if we've given up.
|
|
|
|
*/
|
|
|
|
static BOOL terminate_main_thread(void)
|
|
|
|
{
|
|
|
|
static int delayms;
|
|
|
|
|
|
|
|
if (!delayms)
|
|
|
|
{
|
|
|
|
CFRunLoopSourceContext source_context = { 0 };
|
|
|
|
CFRunLoopSourceRef source;
|
|
|
|
|
|
|
|
source_context.perform = pthread_exit;
|
|
|
|
if (!(source = CFRunLoopSourceCreate( NULL, 0, &source_context )))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
CFRunLoopAddSource( CFRunLoopGetMain(), source, kCFRunLoopCommonModes );
|
|
|
|
CFRunLoopSourceSignal( source );
|
|
|
|
CFRunLoopWakeUp( CFRunLoopGetMain() );
|
|
|
|
CFRelease( source );
|
|
|
|
|
|
|
|
delayms = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delayms > 1000)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
usleep(delayms * 1000);
|
|
|
|
delayms *= 2;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-07 22:03:29 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* set_stdio_fd
|
|
|
|
*/
|
|
|
|
static void set_stdio_fd( int stdin_fd, int stdout_fd )
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
if (stdin_fd == -1 || stdout_fd == -1)
|
|
|
|
{
|
|
|
|
fd = open( "/dev/null", O_RDWR );
|
|
|
|
if (stdin_fd == -1) stdin_fd = fd;
|
|
|
|
if (stdout_fd == -1) stdout_fd = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
dup2( stdin_fd, 0 );
|
|
|
|
dup2( stdout_fd, 1 );
|
|
|
|
if (fd != -1) close( fd );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 22:46:25 +02:00
|
|
|
/***********************************************************************
|
2018-10-22 11:45:54 +02:00
|
|
|
* spawn_loader
|
2011-06-16 22:46:25 +02:00
|
|
|
*/
|
2018-10-24 11:32:16 +02:00
|
|
|
static pid_t spawn_loader( const RTL_USER_PROCESS_PARAMETERS *params, int socketfd,
|
|
|
|
const char *unixdir, char *winedebug, const pe_image_info_t *pe_info )
|
2011-06-16 22:46:25 +02:00
|
|
|
{
|
|
|
|
pid_t pid;
|
2018-10-24 11:32:16 +02:00
|
|
|
int stdin_fd = -1, stdout_fd = -1;
|
2011-06-16 22:46:25 +02:00
|
|
|
char *wineloader = NULL;
|
|
|
|
const char *loader = NULL;
|
|
|
|
char **argv;
|
|
|
|
|
2018-10-24 12:20:38 +02:00
|
|
|
argv = build_argv( ¶ms->CommandLine, 1 );
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2018-10-11 16:54:19 +02:00
|
|
|
if (!is_win64 ^ !is_64bit_arch( pe_info->cpu ))
|
2011-06-16 22:46:25 +02:00
|
|
|
loader = get_alternate_loader( &wineloader );
|
|
|
|
|
2018-10-24 11:32:16 +02:00
|
|
|
wine_server_handle_to_fd( params->hStdInput, FILE_READ_DATA, &stdin_fd, NULL );
|
|
|
|
wine_server_handle_to_fd( params->hStdOutput, FILE_WRITE_DATA, &stdout_fd, NULL );
|
|
|
|
|
2018-10-22 11:45:54 +02:00
|
|
|
if (!(pid = fork())) /* child */
|
2011-06-16 22:46:25 +02:00
|
|
|
{
|
2018-10-22 11:45:54 +02:00
|
|
|
if (!(pid = fork())) /* grandchild */
|
2011-06-16 22:46:25 +02:00
|
|
|
{
|
2011-12-01 01:20:24 +01:00
|
|
|
char preloader_reserve[64], socket_env[64];
|
2018-09-27 14:54:01 +02:00
|
|
|
ULONGLONG res_start = pe_info->base;
|
|
|
|
ULONGLONG res_end = pe_info->base + pe_info->map_size;
|
2011-12-01 01:20:24 +01:00
|
|
|
|
2018-10-24 11:32:16 +02:00
|
|
|
if (params->ConsoleFlags || params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC ||
|
|
|
|
(params->hStdInput == INVALID_HANDLE_VALUE && params->hStdOutput == INVALID_HANDLE_VALUE))
|
2011-06-16 22:46:25 +02:00
|
|
|
{
|
|
|
|
setsid();
|
2019-05-07 22:03:29 +02:00
|
|
|
set_stdio_fd( -1, -1 ); /* close stdin and stdout */
|
2011-12-01 01:20:24 +01:00
|
|
|
}
|
2019-05-07 22:03:29 +02:00
|
|
|
else set_stdio_fd( stdin_fd, stdout_fd );
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
if (stdin_fd != -1) close( stdin_fd );
|
|
|
|
if (stdout_fd != -1) close( stdout_fd );
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
/* Reset signals that we previously set to SIG_IGN */
|
|
|
|
signal( SIGPIPE, SIG_DFL );
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
sprintf( socket_env, "WINESERVERSOCKET=%u", socketfd );
|
2017-10-23 11:35:24 +02:00
|
|
|
sprintf( preloader_reserve, "WINEPRELOADRESERVE=%x%08x-%x%08x",
|
2018-09-27 13:37:30 +02:00
|
|
|
(ULONG)(res_start >> 32), (ULONG)res_start, (ULONG)(res_end >> 32), (ULONG)res_end );
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2011-12-01 01:20:24 +01:00
|
|
|
putenv( preloader_reserve );
|
|
|
|
putenv( socket_env );
|
|
|
|
if (winedebug) putenv( winedebug );
|
|
|
|
if (wineloader) putenv( wineloader );
|
|
|
|
if (unixdir) chdir(unixdir);
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2018-10-22 11:45:54 +02:00
|
|
|
if (argv) wine_exec_wine_binary( loader, argv, getenv("WINELOADER") );
|
2011-12-01 01:20:24 +01:00
|
|
|
_exit(1);
|
2011-06-16 22:46:25 +02:00
|
|
|
}
|
2011-12-01 01:20:24 +01:00
|
|
|
|
|
|
|
_exit(pid == -1);
|
2011-06-16 22:46:25 +02:00
|
|
|
}
|
2011-12-01 01:20:24 +01:00
|
|
|
|
|
|
|
if (pid != -1)
|
|
|
|
{
|
|
|
|
/* reap child */
|
|
|
|
pid_t wret;
|
|
|
|
do {
|
|
|
|
wret = waitpid(pid, NULL, 0);
|
|
|
|
} while (wret < 0 && errno == EINTR);
|
|
|
|
}
|
|
|
|
|
2018-10-24 11:32:16 +02:00
|
|
|
if (stdin_fd != -1) close( stdin_fd );
|
|
|
|
if (stdout_fd != -1) close( stdout_fd );
|
2011-06-16 22:46:25 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, wineloader );
|
|
|
|
HeapFree( GetProcessHeap(), 0, argv );
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
2018-10-22 11:45:54 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* exec_loader
|
|
|
|
*/
|
|
|
|
static NTSTATUS exec_loader( const RTL_USER_PROCESS_PARAMETERS *params, int socketfd,
|
|
|
|
const pe_image_info_t *pe_info )
|
|
|
|
{
|
|
|
|
char *wineloader = NULL;
|
|
|
|
const char *loader = NULL;
|
|
|
|
char **argv;
|
|
|
|
char preloader_reserve[64], socket_env[64];
|
|
|
|
ULONGLONG res_start = pe_info->base;
|
|
|
|
ULONGLONG res_end = pe_info->base + pe_info->map_size;
|
|
|
|
|
2018-10-24 12:20:38 +02:00
|
|
|
if (!(argv = build_argv( ¶ms->CommandLine, 1 ))) return STATUS_NO_MEMORY;
|
2018-10-22 11:45:54 +02:00
|
|
|
|
|
|
|
if (!is_win64 ^ !is_64bit_arch( pe_info->cpu ))
|
|
|
|
loader = get_alternate_loader( &wineloader );
|
|
|
|
|
|
|
|
/* Reset signals that we previously set to SIG_IGN */
|
|
|
|
signal( SIGPIPE, SIG_DFL );
|
|
|
|
|
|
|
|
sprintf( socket_env, "WINESERVERSOCKET=%u", socketfd );
|
|
|
|
sprintf( preloader_reserve, "WINEPRELOADRESERVE=%x%08x-%x%08x",
|
|
|
|
(ULONG)(res_start >> 32), (ULONG)res_start, (ULONG)(res_end >> 32), (ULONG)res_end );
|
|
|
|
|
|
|
|
putenv( preloader_reserve );
|
|
|
|
putenv( socket_env );
|
|
|
|
if (wineloader) putenv( wineloader );
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wine_exec_wine_binary( loader, argv, getenv("WINELOADER") );
|
|
|
|
}
|
|
|
|
#ifdef __APPLE__
|
2018-10-24 07:30:17 +02:00
|
|
|
while (errno == ENOTSUP && terminate_main_thread());
|
2018-10-22 11:45:54 +02:00
|
|
|
#else
|
|
|
|
while (0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, wineloader );
|
|
|
|
HeapFree( GetProcessHeap(), 0, argv );
|
|
|
|
return STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
}
|
|
|
|
|
2018-09-20 13:26:35 +02:00
|
|
|
/* creates a struct security_descriptor and contained information in one contiguous piece of memory */
|
|
|
|
static NTSTATUS alloc_object_attributes( const SECURITY_ATTRIBUTES *attr, struct object_attributes **ret,
|
|
|
|
data_size_t *ret_len )
|
|
|
|
{
|
|
|
|
unsigned int len = sizeof(**ret);
|
|
|
|
PSID owner = NULL, group = NULL;
|
|
|
|
ACL *dacl, *sacl;
|
|
|
|
BOOLEAN dacl_present, sacl_present, defaulted;
|
|
|
|
PSECURITY_DESCRIPTOR sd = NULL;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
*ret_len = 0;
|
|
|
|
|
|
|
|
if (attr) sd = attr->lpSecurityDescriptor;
|
|
|
|
|
|
|
|
if (sd)
|
|
|
|
{
|
|
|
|
len += sizeof(struct security_descriptor);
|
|
|
|
|
|
|
|
if ((status = RtlGetOwnerSecurityDescriptor( sd, &owner, &defaulted ))) return status;
|
|
|
|
if ((status = RtlGetGroupSecurityDescriptor( sd, &group, &defaulted ))) return status;
|
|
|
|
if ((status = RtlGetSaclSecurityDescriptor( sd, &sacl_present, &sacl, &defaulted ))) return status;
|
|
|
|
if ((status = RtlGetDaclSecurityDescriptor( sd, &dacl_present, &dacl, &defaulted ))) return status;
|
|
|
|
if (owner) len += RtlLengthSid( owner );
|
|
|
|
if (group) len += RtlLengthSid( group );
|
|
|
|
if (sacl_present && sacl) len += sacl->AclSize;
|
|
|
|
if (dacl_present && dacl) len += dacl->AclSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = (len + 3) & ~3; /* DWORD-align the entire structure */
|
|
|
|
|
|
|
|
*ret = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
|
|
|
|
if (!*ret) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
(*ret)->attributes = (attr && attr->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
|
|
|
|
if (sd)
|
|
|
|
{
|
|
|
|
struct security_descriptor *descr = (struct security_descriptor *)(*ret + 1);
|
|
|
|
unsigned char *ptr = (unsigned char *)(descr + 1);
|
|
|
|
|
|
|
|
descr->control = ((SECURITY_DESCRIPTOR *)sd)->Control & ~SE_SELF_RELATIVE;
|
|
|
|
if (owner) descr->owner_len = RtlLengthSid( owner );
|
|
|
|
if (group) descr->group_len = RtlLengthSid( group );
|
|
|
|
if (sacl_present && sacl) descr->sacl_len = sacl->AclSize;
|
|
|
|
if (dacl_present && dacl) descr->dacl_len = dacl->AclSize;
|
|
|
|
|
|
|
|
memcpy( ptr, owner, descr->owner_len );
|
|
|
|
ptr += descr->owner_len;
|
|
|
|
memcpy( ptr, group, descr->group_len );
|
|
|
|
ptr += descr->group_len;
|
|
|
|
memcpy( ptr, sacl, descr->sacl_len );
|
|
|
|
ptr += descr->sacl_len;
|
|
|
|
memcpy( ptr, dacl, descr->dacl_len );
|
|
|
|
(*ret)->sd_len = (sizeof(*descr) + descr->owner_len + descr->group_len + descr->sacl_len +
|
|
|
|
descr->dacl_len + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
|
|
|
|
}
|
|
|
|
*ret_len = len;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-10-22 11:45:54 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* replace_process
|
|
|
|
*
|
|
|
|
* Replace the existing process by exec'ing a new one.
|
|
|
|
*/
|
|
|
|
static BOOL replace_process( HANDLE handle, const RTL_USER_PROCESS_PARAMETERS *params,
|
|
|
|
const pe_image_info_t *pe_info )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
int socketfd[2];
|
|
|
|
|
|
|
|
if (socketpair( PF_UNIX, SOCK_STREAM, 0, socketfd ) == -1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_TOO_MANY_OPEN_FILES );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#ifdef SO_PASSCRED
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int enable = 1;
|
|
|
|
setsockopt( socketfd[0], SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
wine_server_send_fd( socketfd[1] );
|
|
|
|
close( socketfd[1] );
|
|
|
|
|
|
|
|
SERVER_START_REQ( exec_process )
|
|
|
|
{
|
|
|
|
req->socket_fd = socketfd[1];
|
|
|
|
req->exe_file = wine_server_obj_handle( handle );
|
|
|
|
req->cpu = pe_info->cpu;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case STATUS_INVALID_IMAGE_WIN_64:
|
|
|
|
ERR( "64-bit application %s not supported in 32-bit prefix\n",
|
|
|
|
debugstr_w( params->ImagePathName.Buffer ));
|
|
|
|
break;
|
|
|
|
case STATUS_INVALID_IMAGE_FORMAT:
|
|
|
|
ERR( "%s not supported on this installation (%s binary)\n",
|
|
|
|
debugstr_w( params->ImagePathName.Buffer ), cpu_names[pe_info->cpu] );
|
|
|
|
break;
|
|
|
|
case STATUS_SUCCESS:
|
|
|
|
status = exec_loader( params, socketfd[0], pe_info );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
close( socketfd[0] );
|
|
|
|
SetLastError( RtlNtStatusToDosError( status ));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* create_process
|
|
|
|
*
|
|
|
|
* Create a new process. If hFile is a valid handle we have an exe
|
|
|
|
* file, otherwise it is a Winelib app.
|
|
|
|
*/
|
2018-10-15 17:00:31 +02:00
|
|
|
static BOOL create_process( HANDLE hFile, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
|
|
|
BOOL inherit, DWORD flags, const RTL_USER_PROCESS_PARAMETERS *params,
|
2018-10-22 11:45:54 +02:00
|
|
|
LPPROCESS_INFORMATION info, LPCSTR unixdir, const pe_image_info_t *pe_info )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2013-11-22 12:32:48 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
BOOL success = FALSE;
|
2018-09-20 13:26:35 +02:00
|
|
|
HANDLE process_info, process_handle = 0;
|
|
|
|
struct object_attributes *objattr;
|
|
|
|
data_size_t attr_len;
|
2004-07-16 05:54:35 +02:00
|
|
|
WCHAR *env_end;
|
2005-10-04 20:09:51 +02:00
|
|
|
char *winedebug = NULL;
|
2009-08-20 20:05:21 +02:00
|
|
|
startup_info_t *startup_info;
|
|
|
|
DWORD startup_info_size;
|
2018-10-24 11:32:16 +02:00
|
|
|
int socketfd[2];
|
2003-09-17 07:31:32 +02:00
|
|
|
pid_t pid;
|
2018-10-11 16:54:19 +02:00
|
|
|
int err;
|
2009-08-12 15:58:39 +02:00
|
|
|
|
2011-06-16 22:46:25 +02:00
|
|
|
/* create the socket for the new process */
|
|
|
|
|
|
|
|
if (socketpair( PF_UNIX, SOCK_STREAM, 0, socketfd ) == -1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_TOO_MANY_OPEN_FILES );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-16 14:11:45 +02:00
|
|
|
#ifdef SO_PASSCRED
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int enable = 1;
|
|
|
|
setsockopt( socketfd[0], SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable) );
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-16 22:46:25 +02:00
|
|
|
|
2018-10-15 17:00:31 +02:00
|
|
|
if (!(startup_info = create_startup_info( params, &startup_info_size )))
|
2004-07-16 05:54:35 +02:00
|
|
|
{
|
2011-06-16 22:46:25 +02:00
|
|
|
close( socketfd[0] );
|
|
|
|
close( socketfd[1] );
|
2003-10-04 06:09:41 +02:00
|
|
|
return FALSE;
|
2004-07-16 05:54:35 +02:00
|
|
|
}
|
2018-10-11 17:48:25 +02:00
|
|
|
env_end = params->Environment;
|
2005-10-04 20:09:51 +02:00
|
|
|
while (*env_end)
|
|
|
|
{
|
|
|
|
static const WCHAR WINEDEBUG[] = {'W','I','N','E','D','E','B','U','G','=',0};
|
2018-07-30 21:18:09 +02:00
|
|
|
if (!winedebug && !strncmpW( env_end, WINEDEBUG, ARRAY_SIZE( WINEDEBUG ) - 1 ))
|
2005-10-04 20:09:51 +02:00
|
|
|
{
|
|
|
|
DWORD len = WideCharToMultiByte( CP_UNIXCP, 0, env_end, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((winedebug = HeapAlloc( GetProcessHeap(), 0, len )))
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, env_end, -1, winedebug, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
env_end += strlenW(env_end) + 1;
|
|
|
|
}
|
2004-07-16 05:54:35 +02:00
|
|
|
env_end++;
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
wine_server_send_fd( socketfd[1] );
|
|
|
|
close( socketfd[1] );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
/* create the process on the server side */
|
|
|
|
|
2018-09-20 13:39:28 +02:00
|
|
|
alloc_object_attributes( psa, &objattr, &attr_len );
|
2003-09-17 07:31:32 +02:00
|
|
|
SERVER_START_REQ( new_process )
|
|
|
|
{
|
2006-07-19 14:00:10 +02:00
|
|
|
req->inherit_all = inherit;
|
|
|
|
req->create_flags = flags;
|
|
|
|
req->socket_fd = socketfd[1];
|
2008-12-08 16:05:17 +01:00
|
|
|
req->exe_file = wine_server_obj_handle( hFile );
|
2018-09-20 13:26:35 +02:00
|
|
|
req->access = PROCESS_ALL_ACCESS;
|
2018-10-11 16:54:19 +02:00
|
|
|
req->cpu = pe_info->cpu;
|
2009-08-20 20:05:21 +02:00
|
|
|
req->info_size = startup_info_size;
|
2018-09-20 13:39:28 +02:00
|
|
|
wine_server_add_data( req, objattr, attr_len );
|
2009-08-20 20:05:21 +02:00
|
|
|
wine_server_add_data( req, startup_info, startup_info_size );
|
2018-10-11 17:48:25 +02:00
|
|
|
wine_server_add_data( req, params->Environment, (env_end - params->Environment) * sizeof(WCHAR) );
|
2013-11-22 12:32:48 +01:00
|
|
|
if (!(status = wine_server_call( req )))
|
2006-07-19 14:00:10 +02:00
|
|
|
{
|
|
|
|
info->dwProcessId = (DWORD)reply->pid;
|
2018-09-20 13:26:35 +02:00
|
|
|
process_handle = wine_server_ptr_handle( reply->handle );
|
2006-07-19 14:00:10 +02:00
|
|
|
}
|
2008-12-08 16:05:17 +01:00
|
|
|
process_info = wine_server_ptr_handle( reply->info );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2018-09-20 13:39:28 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, objattr );
|
2003-06-27 06:08:04 +02:00
|
|
|
|
2018-09-20 13:26:35 +02:00
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
alloc_object_attributes( tsa, &objattr, &attr_len );
|
|
|
|
SERVER_START_REQ( new_thread )
|
|
|
|
{
|
|
|
|
req->process = wine_server_obj_handle( process_handle );
|
|
|
|
req->access = THREAD_ALL_ACCESS;
|
|
|
|
req->suspend = !!(flags & CREATE_SUSPENDED);
|
|
|
|
req->request_fd = -1;
|
|
|
|
wine_server_add_data( req, objattr, attr_len );
|
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
info->hProcess = process_handle;
|
|
|
|
info->hThread = wine_server_ptr_handle( reply->handle );
|
|
|
|
info->dwThreadId = reply->tid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
HeapFree( GetProcessHeap(), 0, objattr );
|
|
|
|
}
|
|
|
|
|
2013-11-22 12:32:48 +01:00
|
|
|
if (status)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2013-11-22 12:32:48 +01:00
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case STATUS_INVALID_IMAGE_WIN_64:
|
2018-10-15 17:00:31 +02:00
|
|
|
ERR( "64-bit application %s not supported in 32-bit prefix\n",
|
|
|
|
debugstr_w( params->ImagePathName.Buffer ));
|
2013-11-22 12:32:48 +01:00
|
|
|
break;
|
|
|
|
case STATUS_INVALID_IMAGE_FORMAT:
|
|
|
|
ERR( "%s not supported on this installation (%s binary)\n",
|
2018-10-15 17:00:31 +02:00
|
|
|
debugstr_w( params->ImagePathName.Buffer ), cpu_names[pe_info->cpu] );
|
2013-11-22 12:32:48 +01:00
|
|
|
break;
|
|
|
|
}
|
2006-07-19 14:00:10 +02:00
|
|
|
close( socketfd[0] );
|
2018-09-20 13:26:35 +02:00
|
|
|
CloseHandle( process_handle );
|
2009-08-20 20:05:21 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, startup_info );
|
2006-07-19 14:00:10 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, winedebug );
|
2013-11-22 12:32:48 +01:00
|
|
|
SetLastError( RtlNtStatusToDosError( status ));
|
2003-09-17 07:31:32 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-20 20:05:21 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, startup_info );
|
2008-07-10 12:20:56 +02:00
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
/* create the child process */
|
|
|
|
|
2018-10-24 11:32:16 +02:00
|
|
|
pid = spawn_loader( params, socketfd[0], unixdir, winedebug, pe_info );
|
2006-07-19 14:00:10 +02:00
|
|
|
|
|
|
|
close( socketfd[0] );
|
|
|
|
HeapFree( GetProcessHeap(), 0, winedebug );
|
|
|
|
if (pid == -1)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
FILE_SetDosError();
|
2006-07-19 14:00:10 +02:00
|
|
|
goto error;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for the new process info to be ready */
|
|
|
|
|
|
|
|
WaitForSingleObject( process_info, INFINITE );
|
|
|
|
SERVER_START_REQ( get_new_process_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->info = wine_server_obj_handle( process_info );
|
2006-07-19 14:00:10 +02:00
|
|
|
wine_server_call( req );
|
|
|
|
success = reply->success;
|
|
|
|
err = reply->exit_code;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
if (!success)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2006-07-19 14:00:10 +02:00
|
|
|
SetLastError( err ? err : ERROR_INTERNAL_ERROR );
|
|
|
|
goto error;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
CloseHandle( process_info );
|
2006-07-19 14:00:10 +02:00
|
|
|
return success;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CloseHandle( process_info );
|
|
|
|
CloseHandle( info->hProcess );
|
|
|
|
CloseHandle( info->hThread );
|
|
|
|
info->hProcess = info->hThread = 0;
|
|
|
|
info->dwProcessId = info->dwThreadId = 0;
|
|
|
|
return FALSE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2018-10-22 11:45:54 +02:00
|
|
|
* get_vdm_params
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
2018-10-22 11:45:54 +02:00
|
|
|
* Build the parameters needed to launch a new VDM process.
|
2003-09-17 07:31:32 +02:00
|
|
|
*/
|
2018-10-22 11:45:54 +02:00
|
|
|
static RTL_USER_PROCESS_PARAMETERS *get_vdm_params( const RTL_USER_PROCESS_PARAMETERS *params,
|
|
|
|
pe_image_info_t *pe_info )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
static const WCHAR argsW[] = {'%','s',' ','-','-','a','p','p','-','n','a','m','e',' ','"','%','s','"',' ','%','s',0};
|
|
|
|
|
2018-10-22 11:45:54 +02:00
|
|
|
WCHAR *new_cmd_line;
|
2018-10-15 17:00:31 +02:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *new_params;
|
|
|
|
UNICODE_STRING imageW, cmdlineW;
|
2017-04-27 22:14:37 +02:00
|
|
|
|
|
|
|
new_cmd_line = HeapAlloc(GetProcessHeap(), 0,
|
2018-10-15 17:00:31 +02:00
|
|
|
(strlenW(params->ImagePathName.Buffer) +
|
|
|
|
strlenW(params->CommandLine.Buffer) +
|
|
|
|
strlenW(winevdm) + 16) * sizeof(WCHAR));
|
2003-09-17 07:31:32 +02:00
|
|
|
if (!new_cmd_line)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
2018-10-22 11:45:54 +02:00
|
|
|
return NULL;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2018-10-15 17:00:31 +02:00
|
|
|
sprintfW( new_cmd_line, argsW, winevdm, params->ImagePathName.Buffer, params->CommandLine.Buffer );
|
|
|
|
RtlInitUnicodeString( &imageW, winevdm );
|
|
|
|
RtlInitUnicodeString( &cmdlineW, new_cmd_line );
|
|
|
|
if (RtlCreateProcessParametersEx( &new_params, &imageW, ¶ms->DllPath,
|
|
|
|
¶ms->CurrentDirectory.DosPath, &cmdlineW,
|
|
|
|
params->Environment, ¶ms->WindowTitle, ¶ms->Desktop,
|
|
|
|
¶ms->ShellInfo, ¶ms->RuntimeInfo,
|
|
|
|
PROCESS_PARAMS_FLAG_NORMALIZED ))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, new_cmd_line );
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
new_params->hStdInput = params->hStdInput;
|
|
|
|
new_params->hStdOutput = params->hStdOutput;
|
|
|
|
new_params->hStdError = params->hStdError;
|
|
|
|
new_params->dwX = params->dwX;
|
|
|
|
new_params->dwY = params->dwY;
|
|
|
|
new_params->dwXSize = params->dwXSize;
|
|
|
|
new_params->dwYSize = params->dwYSize;
|
|
|
|
new_params->dwXCountChars = params->dwXCountChars;
|
|
|
|
new_params->dwYCountChars = params->dwYCountChars;
|
|
|
|
new_params->dwFillAttribute = params->dwFillAttribute;
|
|
|
|
new_params->dwFlags = params->dwFlags;
|
|
|
|
new_params->wShowWindow = params->wShowWindow;
|
|
|
|
|
2018-10-22 11:45:54 +02:00
|
|
|
memset( pe_info, 0, sizeof(*pe_info) );
|
|
|
|
pe_info->cpu = CPU_x86;
|
|
|
|
return new_params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* create_vdm_process
|
|
|
|
*
|
|
|
|
* Create a new VDM process for a 16-bit or DOS application.
|
|
|
|
*/
|
|
|
|
static BOOL create_vdm_process( LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
|
|
|
BOOL inherit, DWORD flags, const RTL_USER_PROCESS_PARAMETERS *params,
|
|
|
|
LPPROCESS_INFORMATION info, LPCSTR unixdir )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
pe_image_info_t pe_info;
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *new_params;
|
|
|
|
|
|
|
|
if (!(new_params = get_vdm_params( params, &pe_info ))) return FALSE;
|
|
|
|
|
|
|
|
ret = create_process( 0, psa, tsa, inherit, flags, new_params, info, unixdir, &pe_info );
|
2018-10-15 17:00:31 +02:00
|
|
|
RtlDestroyProcessParameters( new_params );
|
2003-09-17 07:31:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* create_cmd_process
|
|
|
|
*
|
|
|
|
* Create a new cmd shell process for a .BAT file.
|
|
|
|
*/
|
2018-10-16 21:50:58 +02:00
|
|
|
static BOOL create_cmd_process( LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
2003-10-04 06:09:41 +02:00
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
2018-10-15 17:00:31 +02:00
|
|
|
const RTL_USER_PROCESS_PARAMETERS *params,
|
2004-05-14 07:03:29 +02:00
|
|
|
LPPROCESS_INFORMATION info )
|
2003-10-04 06:09:41 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
static const WCHAR comspecW[] = {'C','O','M','S','P','E','C',0};
|
2018-08-31 03:09:32 +02:00
|
|
|
static const WCHAR cmdW[] = {'\\','c','m','d','.','e','x','e',0};
|
2018-05-04 22:39:49 +02:00
|
|
|
static const WCHAR slashscW[] = {' ','/','s','/','c',' ',0};
|
|
|
|
static const WCHAR quotW[] = {'"',0};
|
2003-10-04 06:09:41 +02:00
|
|
|
WCHAR comspec[MAX_PATH];
|
2018-10-16 21:50:58 +02:00
|
|
|
WCHAR *newcmdline, *cur_dir = NULL;
|
2003-10-04 06:09:41 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2018-07-30 21:18:09 +02:00
|
|
|
if (!GetEnvironmentVariableW( comspecW, comspec, ARRAY_SIZE( comspec )))
|
2018-08-31 03:09:32 +02:00
|
|
|
{
|
2018-11-14 20:46:01 +01:00
|
|
|
GetSystemDirectoryW( comspec, ARRAY_SIZE( comspec ) - ARRAY_SIZE( cmdW ));
|
2018-08-31 03:09:32 +02:00
|
|
|
strcatW( comspec, cmdW );
|
|
|
|
}
|
2003-10-04 06:09:41 +02:00
|
|
|
if (!(newcmdline = HeapAlloc( GetProcessHeap(), 0,
|
2018-10-15 17:00:31 +02:00
|
|
|
(strlenW(comspec) + 7 +
|
|
|
|
strlenW(params->CommandLine.Buffer) + 2) * sizeof(WCHAR))))
|
2003-10-04 06:09:41 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strcpyW( newcmdline, comspec );
|
2018-05-04 22:39:49 +02:00
|
|
|
strcatW( newcmdline, slashscW );
|
|
|
|
strcatW( newcmdline, quotW );
|
2018-10-15 17:00:31 +02:00
|
|
|
strcatW( newcmdline, params->CommandLine.Buffer );
|
2018-05-04 22:39:49 +02:00
|
|
|
strcatW( newcmdline, quotW );
|
2018-10-16 21:50:58 +02:00
|
|
|
if (params->CurrentDirectory.DosPath.Length) cur_dir = params->CurrentDirectory.DosPath.Buffer;
|
2003-10-04 06:09:41 +02:00
|
|
|
ret = CreateProcessW( comspec, newcmdline, psa, tsa, inherit,
|
2018-10-16 15:25:57 +02:00
|
|
|
flags | CREATE_UNICODE_ENVIRONMENT, params->Environment, cur_dir,
|
2018-10-15 17:00:31 +02:00
|
|
|
startup, info );
|
2003-10-04 06:09:41 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, newcmdline );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* get_file_name
|
|
|
|
*
|
|
|
|
* Helper for CreateProcess: retrieve the file name to load from the
|
|
|
|
* app name and command line. Store the file name in buffer, and
|
|
|
|
* return a possibly modified command line.
|
|
|
|
* Also returns a handle to the opened file if it's a Windows binary.
|
|
|
|
*/
|
2003-10-04 06:09:41 +02:00
|
|
|
static LPWSTR get_file_name( LPCWSTR appname, LPWSTR cmdline, LPWSTR buffer,
|
2018-09-27 14:54:01 +02:00
|
|
|
int buflen, HANDLE *handle, BOOL *is_64bit )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
static const WCHAR quotesW[] = {'"','%','s','"',0};
|
|
|
|
|
2010-03-18 13:02:42 +01:00
|
|
|
WCHAR *name, *pos, *first_space, *ret = NULL;
|
2003-10-04 06:09:41 +02:00
|
|
|
const WCHAR *p;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
/* if we have an app name, everything is easy */
|
|
|
|
|
|
|
|
if (appname)
|
|
|
|
{
|
|
|
|
/* use the unmodified app name as file name */
|
2003-10-04 06:09:41 +02:00
|
|
|
lstrcpynW( buffer, appname, buflen );
|
2018-09-27 14:54:01 +02:00
|
|
|
*handle = open_exe_file( buffer, is_64bit );
|
2003-09-17 07:31:32 +02:00
|
|
|
if (!(ret = cmdline) || !cmdline[0])
|
|
|
|
{
|
|
|
|
/* no command-line, create one */
|
2003-10-31 00:06:10 +01:00
|
|
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(appname) + 3) * sizeof(WCHAR) )))
|
2003-10-04 06:09:41 +02:00
|
|
|
sprintfW( ret, quotesW, appname );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first check for a quoted file name */
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if ((cmdline[0] == '"') && ((p = strchrW( cmdline + 1, '"' ))))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
int len = p - cmdline - 1;
|
|
|
|
/* extract the quoted portion as file name */
|
2003-10-04 06:09:41 +02:00
|
|
|
if (!(name = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
|
|
|
|
memcpy( name, cmdline + 1, len * sizeof(WCHAR) );
|
2003-09-17 07:31:32 +02:00
|
|
|
name[len] = 0;
|
|
|
|
|
2018-09-27 14:54:01 +02:00
|
|
|
if (!find_exe_file( name, buffer, buflen, handle )) goto done;
|
2010-03-18 13:02:42 +01:00
|
|
|
ret = cmdline; /* no change necessary */
|
2003-09-17 07:31:32 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now try the command-line word by word */
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if (!(name = HeapAlloc( GetProcessHeap(), 0, (strlenW(cmdline) + 1) * sizeof(WCHAR) )))
|
|
|
|
return NULL;
|
2003-09-17 07:31:32 +02:00
|
|
|
pos = name;
|
|
|
|
p = cmdline;
|
2010-03-18 13:02:42 +01:00
|
|
|
first_space = NULL;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2010-03-18 13:02:42 +01:00
|
|
|
for (;;)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2010-03-18 13:02:42 +01:00
|
|
|
while (*p && *p != ' ' && *p != '\t') *pos++ = *p++;
|
2003-09-17 07:31:32 +02:00
|
|
|
*pos = 0;
|
2018-09-27 14:54:01 +02:00
|
|
|
if (find_exe_file( name, buffer, buflen, handle ))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
ret = cmdline;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-18 13:02:42 +01:00
|
|
|
if (!first_space) first_space = pos;
|
2010-03-29 19:37:35 +02:00
|
|
|
if (!(*pos++ = *p++)) break;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
2010-03-18 13:02:42 +01:00
|
|
|
if (!ret)
|
|
|
|
{
|
2011-12-13 20:25:53 +01:00
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
2010-03-18 13:02:42 +01:00
|
|
|
}
|
|
|
|
else if (first_space) /* build a new command-line with quotes */
|
2005-12-19 21:25:23 +01:00
|
|
|
{
|
|
|
|
if (!(ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(cmdline) + 3) * sizeof(WCHAR) )))
|
|
|
|
goto done;
|
|
|
|
sprintfW( ret, quotesW, name );
|
|
|
|
strcatW( ret, p );
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, name );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:24:41 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessInternalW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateProcessInternalW( HANDLE token, LPCWSTR app_name, LPWSTR cmd_line,
|
|
|
|
LPSECURITY_ATTRIBUTES process_attr, LPSECURITY_ATTRIBUTES thread_attr,
|
|
|
|
BOOL inherit, DWORD flags, LPVOID env, LPCWSTR cur_dir,
|
|
|
|
LPSTARTUPINFOW startup_info, LPPROCESS_INFORMATION info,
|
|
|
|
HANDLE *new_token )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
BOOL retv = FALSE;
|
|
|
|
HANDLE hFile = 0;
|
2004-04-14 21:40:53 +02:00
|
|
|
char *unixdir = NULL;
|
2003-10-04 06:09:41 +02:00
|
|
|
WCHAR name[MAX_PATH];
|
2018-10-16 15:25:57 +02:00
|
|
|
WCHAR *tidy_cmdline, *p;
|
2018-10-15 17:00:31 +02:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = NULL;
|
2018-09-27 14:54:01 +02:00
|
|
|
pe_image_info_t pe_info;
|
|
|
|
enum binary_type type;
|
|
|
|
BOOL is_64bit;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
/* Process the AppName and/or CmdLine to get module name and path */
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE("app %s cmdline %s\n", debugstr_w(app_name), debugstr_w(cmd_line) );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2018-10-26 13:24:41 +02:00
|
|
|
if (token) FIXME("Creating a process with a token is not yet implemented\n");
|
|
|
|
if (new_token) FIXME("No support for returning created process token\n");
|
|
|
|
|
2018-09-27 14:54:01 +02:00
|
|
|
if (!(tidy_cmdline = get_file_name( app_name, cmd_line, name, ARRAY_SIZE( name ), &hFile, &is_64bit )))
|
2003-09-17 07:31:32 +02:00
|
|
|
return FALSE;
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) goto done;
|
|
|
|
|
|
|
|
/* Warn if unsupported features are used */
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if (flags & (IDLE_PRIORITY_CLASS | HIGH_PRIORITY_CLASS | REALTIME_PRIORITY_CLASS |
|
|
|
|
CREATE_NEW_PROCESS_GROUP | CREATE_SEPARATE_WOW_VDM | CREATE_SHARED_WOW_VDM |
|
|
|
|
CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW |
|
|
|
|
PROFILE_USER | PROFILE_KERNEL | PROFILE_SERVER))
|
2006-10-12 22:56:29 +02:00
|
|
|
WARN("(%s,...): ignoring some flags in %x\n", debugstr_w(name), flags);
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
if (cur_dir)
|
|
|
|
{
|
2006-03-27 05:53:09 +02:00
|
|
|
if (!(unixdir = wine_get_unix_file_name( cur_dir )))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_DIRECTORY);
|
|
|
|
goto done;
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR buf[MAX_PATH];
|
2004-04-14 21:40:53 +02:00
|
|
|
if (GetCurrentDirectoryW(MAX_PATH, buf)) unixdir = wine_get_unix_file_name( buf );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info->hThread = info->hProcess = 0;
|
|
|
|
info->dwProcessId = info->dwThreadId = 0;
|
|
|
|
|
2018-10-16 15:25:57 +02:00
|
|
|
if (!(params = create_process_params( name, tidy_cmdline, cur_dir, env, flags, startup_info )))
|
2018-10-15 17:00:31 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2018-09-27 14:54:01 +02:00
|
|
|
if (!hFile)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2018-09-27 14:54:01 +02:00
|
|
|
memset( &pe_info, 0, sizeof(pe_info) );
|
|
|
|
type = BINARY_UNIX_LIB;
|
|
|
|
/* assume current arch */
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2018-10-11 16:54:19 +02:00
|
|
|
pe_info.cpu = is_64bit ? CPU_x86_64 : CPU_x86;
|
2018-09-27 14:54:01 +02:00
|
|
|
#elif defined(__powerpc__)
|
2018-10-11 16:54:19 +02:00
|
|
|
pe_info.cpu = CPU_POWERPC;
|
|
|
|
#elif defined(__arm__)
|
|
|
|
pe_info.cpu = CPU_ARM;
|
2018-09-27 14:54:01 +02:00
|
|
|
#elif defined(__aarch64__)
|
2018-10-11 16:54:19 +02:00
|
|
|
pe_info.cpu = CPU_ARM64;
|
2018-09-27 14:54:01 +02:00
|
|
|
#endif
|
2009-08-12 15:43:08 +02:00
|
|
|
}
|
2018-09-27 14:54:01 +02:00
|
|
|
else type = get_binary_info( hFile, &pe_info );
|
|
|
|
|
|
|
|
switch (type)
|
2009-08-12 15:43:08 +02:00
|
|
|
{
|
|
|
|
case BINARY_PE:
|
2018-09-27 14:54:01 +02:00
|
|
|
if (pe_info.image_charact & IMAGE_FILE_DLL)
|
|
|
|
{
|
|
|
|
TRACE( "not starting %s since it is a dll\n", debugstr_w(name) );
|
|
|
|
SetLastError( ERROR_BAD_EXE_FORMAT );
|
|
|
|
break;
|
|
|
|
}
|
2018-10-11 16:54:19 +02:00
|
|
|
TRACE( "starting %s as Win%d binary (%s-%s, %s)\n",
|
|
|
|
debugstr_w(name), is_64bit_arch(pe_info.cpu) ? 64 : 32,
|
2018-09-27 14:54:01 +02:00
|
|
|
wine_dbgstr_longlong(pe_info.base), wine_dbgstr_longlong(pe_info.base + pe_info.map_size),
|
2018-10-11 16:54:19 +02:00
|
|
|
cpu_names[pe_info.cpu] );
|
2018-10-15 17:00:31 +02:00
|
|
|
retv = create_process( hFile, process_attr, thread_attr,
|
2018-10-22 11:45:54 +02:00
|
|
|
inherit, flags, params, info, unixdir, &pe_info );
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
|
|
|
case BINARY_WIN16:
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "starting %s as Win16/DOS binary\n", debugstr_w(name) );
|
2018-10-22 11:45:54 +02:00
|
|
|
retv = create_vdm_process( process_attr, thread_attr, inherit, flags, params, info, unixdir );
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
|
|
|
case BINARY_UNIX_LIB:
|
2010-03-29 17:57:02 +02:00
|
|
|
TRACE( "starting %s as %d-bit Winelib app\n",
|
2018-10-11 16:54:19 +02:00
|
|
|
debugstr_w(name), is_64bit_arch(pe_info.cpu) ? 64 : 32 );
|
2018-10-15 17:00:31 +02:00
|
|
|
retv = create_process( hFile, process_attr, thread_attr,
|
2018-10-22 11:45:54 +02:00
|
|
|
inherit, flags, params, info, unixdir, &pe_info );
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
|
|
|
case BINARY_UNKNOWN:
|
|
|
|
/* check for .com or .bat extension */
|
2003-10-04 06:09:41 +02:00
|
|
|
if ((p = strrchrW( name, '.' )))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-03-07 20:24:43 +01:00
|
|
|
if (!strcmpiW( p, comW ) || !strcmpiW( p, pifW ))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "starting %s as DOS binary\n", debugstr_w(name) );
|
2018-10-15 17:00:31 +02:00
|
|
|
retv = create_vdm_process( process_attr, thread_attr,
|
2018-10-22 11:45:54 +02:00
|
|
|
inherit, flags, params, info, unixdir );
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-03-07 16:15:31 +01:00
|
|
|
if (!strcmpiW( p, batW ) || !strcmpiW( p, cmdW ) )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "starting %s as batch binary\n", debugstr_w(name) );
|
2018-10-16 21:50:58 +02:00
|
|
|
retv = create_cmd_process( process_attr, thread_attr,
|
2018-10-15 17:00:31 +02:00
|
|
|
inherit, flags, startup_info, params, info );
|
2003-10-04 06:09:41 +02:00
|
|
|
break;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case BINARY_UNIX_EXE:
|
2018-10-15 17:05:31 +02:00
|
|
|
/* unknown file, try as unix executable */
|
|
|
|
TRACE( "starting %s as Unix binary\n", debugstr_w(name) );
|
2018-10-24 11:32:16 +02:00
|
|
|
retv = (fork_and_exec( params, unixdir ) != -1);
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-10-27 19:41:38 +01:00
|
|
|
if (hFile) CloseHandle( hFile );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
done:
|
2018-10-15 17:00:31 +02:00
|
|
|
RtlDestroyProcessParameters( params );
|
2003-09-17 07:31:32 +02:00
|
|
|
if (tidy_cmdline != cmd_line) HeapFree( GetProcessHeap(), 0, tidy_cmdline );
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, unixdir );
|
2008-05-06 10:25:32 +02:00
|
|
|
if (retv)
|
|
|
|
TRACE( "started process pid %04x tid %04x\n", info->dwProcessId, info->dwThreadId );
|
2003-09-17 07:31:32 +02:00
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-16 19:38:08 +01:00
|
|
|
/**********************************************************************
|
2018-10-26 13:24:41 +02:00
|
|
|
* CreateProcessInternalA (KERNEL32.@)
|
2011-03-16 19:38:08 +01:00
|
|
|
*/
|
2018-10-26 13:24:41 +02:00
|
|
|
BOOL WINAPI CreateProcessInternalA( HANDLE token, LPCSTR app_name, LPSTR cmd_line,
|
|
|
|
LPSECURITY_ATTRIBUTES process_attr, LPSECURITY_ATTRIBUTES thread_attr,
|
|
|
|
BOOL inherit, DWORD flags, LPVOID env, LPCSTR cur_dir,
|
|
|
|
LPSTARTUPINFOA startup_info, LPPROCESS_INFORMATION info,
|
|
|
|
HANDLE *new_token )
|
2011-03-16 19:38:08 +01:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
WCHAR *app_nameW = NULL, *cmd_lineW = NULL, *cur_dirW = NULL;
|
|
|
|
UNICODE_STRING desktopW, titleW;
|
|
|
|
STARTUPINFOW infoW;
|
|
|
|
|
|
|
|
desktopW.Buffer = NULL;
|
|
|
|
titleW.Buffer = NULL;
|
|
|
|
if (app_name && !(app_nameW = FILE_name_AtoW( app_name, TRUE ))) goto done;
|
|
|
|
if (cmd_line && !(cmd_lineW = FILE_name_AtoW( cmd_line, TRUE ))) goto done;
|
|
|
|
if (cur_dir && !(cur_dirW = FILE_name_AtoW( cur_dir, TRUE ))) goto done;
|
|
|
|
|
|
|
|
if (startup_info->lpDesktop) RtlCreateUnicodeStringFromAsciiz( &desktopW, startup_info->lpDesktop );
|
|
|
|
if (startup_info->lpTitle) RtlCreateUnicodeStringFromAsciiz( &titleW, startup_info->lpTitle );
|
|
|
|
|
|
|
|
memcpy( &infoW, startup_info, sizeof(infoW) );
|
|
|
|
infoW.lpDesktop = desktopW.Buffer;
|
|
|
|
infoW.lpTitle = titleW.Buffer;
|
|
|
|
|
|
|
|
if (startup_info->lpReserved)
|
|
|
|
FIXME("StartupInfo.lpReserved is used, please report (%s)\n",
|
|
|
|
debugstr_a(startup_info->lpReserved));
|
|
|
|
|
2018-10-26 13:24:41 +02:00
|
|
|
ret = CreateProcessInternalW( token, app_nameW, cmd_lineW, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dirW, &infoW, info, new_token );
|
2011-03-16 19:38:08 +01:00
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, app_nameW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmd_lineW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, cur_dirW );
|
|
|
|
RtlFreeUnicodeString( &desktopW );
|
|
|
|
RtlFreeUnicodeString( &titleW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-26 13:24:41 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA( LPCSTR app_name, LPSTR cmd_line, LPSECURITY_ATTRIBUTES process_attr,
|
|
|
|
LPSECURITY_ATTRIBUTES thread_attr, BOOL inherit,
|
|
|
|
DWORD flags, LPVOID env, LPCSTR cur_dir,
|
|
|
|
LPSTARTUPINFOA startup_info, LPPROCESS_INFORMATION info )
|
|
|
|
{
|
|
|
|
return CreateProcessInternalA( NULL, app_name, cmd_line, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dir, startup_info, info, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-16 19:38:08 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIBUTES process_attr,
|
|
|
|
LPSECURITY_ATTRIBUTES thread_attr, BOOL inherit, DWORD flags,
|
|
|
|
LPVOID env, LPCWSTR cur_dir, LPSTARTUPINFOW startup_info,
|
|
|
|
LPPROCESS_INFORMATION info )
|
|
|
|
{
|
2018-10-26 13:24:41 +02:00
|
|
|
return CreateProcessInternalW( NULL, app_name, cmd_line, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dir, startup_info, info, NULL );
|
2011-03-16 19:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-26 13:31:08 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessAsUserA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessAsUserA( HANDLE token, LPCSTR app_name, LPSTR cmd_line,
|
|
|
|
LPSECURITY_ATTRIBUTES process_attr,
|
|
|
|
LPSECURITY_ATTRIBUTES thread_attr,
|
|
|
|
BOOL inherit, DWORD flags, LPVOID env, LPCSTR cur_dir,
|
|
|
|
LPSTARTUPINFOA startup_info,
|
|
|
|
LPPROCESS_INFORMATION info )
|
|
|
|
{
|
|
|
|
return CreateProcessInternalA( token, app_name, cmd_line, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dir, startup_info, info, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessAsUserW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessAsUserW( HANDLE token, LPCWSTR app_name, LPWSTR cmd_line,
|
|
|
|
LPSECURITY_ATTRIBUTES process_attr,
|
|
|
|
LPSECURITY_ATTRIBUTES thread_attr,
|
|
|
|
BOOL inherit, DWORD flags, LPVOID env, LPCWSTR cur_dir,
|
|
|
|
LPSTARTUPINFOW startup_info,
|
|
|
|
LPPROCESS_INFORMATION info )
|
|
|
|
{
|
|
|
|
return CreateProcessInternalW( token, app_name, cmd_line, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dir, startup_info, info, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* exec_process
|
|
|
|
*/
|
|
|
|
static void exec_process( LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
WCHAR *p;
|
2018-10-15 17:00:31 +02:00
|
|
|
STARTUPINFOW startup_info = { sizeof(startup_info) };
|
2018-10-22 11:45:54 +02:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params, *new_params;
|
2018-09-27 14:54:01 +02:00
|
|
|
pe_image_info_t pe_info;
|
|
|
|
BOOL is_64bit;
|
2006-07-19 14:12:58 +02:00
|
|
|
|
2018-09-27 14:54:01 +02:00
|
|
|
hFile = open_exe_file( name, &is_64bit );
|
2006-07-19 14:12:58 +02:00
|
|
|
if (!hFile || hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
2018-10-15 17:00:31 +02:00
|
|
|
if (!(params = create_process_params( name, GetCommandLineW(), NULL, NULL, 0, &startup_info )))
|
|
|
|
return;
|
2006-07-19 14:12:58 +02:00
|
|
|
|
|
|
|
/* Determine executable type */
|
|
|
|
|
2018-09-27 14:54:01 +02:00
|
|
|
switch (get_binary_info( hFile, &pe_info ))
|
2006-07-19 14:12:58 +02:00
|
|
|
{
|
2009-08-12 15:43:08 +02:00
|
|
|
case BINARY_PE:
|
2018-09-27 14:54:01 +02:00
|
|
|
if (pe_info.image_charact & IMAGE_FILE_DLL) break;
|
2018-10-11 16:54:19 +02:00
|
|
|
TRACE( "starting %s as Win%d binary (%s-%s, %s)\n",
|
|
|
|
debugstr_w(name), is_64bit_arch(pe_info.cpu) ? 64 : 32,
|
2018-09-27 14:54:01 +02:00
|
|
|
wine_dbgstr_longlong(pe_info.base), wine_dbgstr_longlong(pe_info.base + pe_info.map_size),
|
2018-10-11 16:54:19 +02:00
|
|
|
cpu_names[pe_info.cpu] );
|
2018-10-22 11:45:54 +02:00
|
|
|
replace_process( hFile, params, &pe_info );
|
2006-07-19 14:12:58 +02:00
|
|
|
break;
|
|
|
|
case BINARY_UNIX_LIB:
|
|
|
|
TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_w(name) );
|
2018-10-22 11:45:54 +02:00
|
|
|
replace_process( hFile, params, &pe_info );
|
2006-07-19 14:12:58 +02:00
|
|
|
break;
|
|
|
|
case BINARY_UNKNOWN:
|
|
|
|
/* check for .com or .pif extension */
|
|
|
|
if (!(p = strrchrW( name, '.' ))) break;
|
|
|
|
if (strcmpiW( p, comW ) && strcmpiW( p, pifW )) break;
|
|
|
|
/* fall through */
|
|
|
|
case BINARY_WIN16:
|
|
|
|
TRACE( "starting %s as Win16/DOS binary\n", debugstr_w(name) );
|
2018-10-22 11:45:54 +02:00
|
|
|
if (!(new_params = get_vdm_params( params, &pe_info ))) break;
|
|
|
|
replace_process( 0, new_params, &pe_info );
|
|
|
|
RtlDestroyProcessParameters( new_params );
|
2006-07-19 14:12:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CloseHandle( hFile );
|
2018-10-22 11:45:54 +02:00
|
|
|
RtlDestroyProcessParameters( params );
|
2006-07-19 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wait_input_idle
|
|
|
|
*
|
|
|
|
* Wrapper to call WaitForInputIdle USER function
|
|
|
|
*/
|
|
|
|
typedef DWORD (WINAPI *WaitForInputIdle_ptr)( HANDLE hProcess, DWORD dwTimeOut );
|
|
|
|
|
|
|
|
static DWORD wait_input_idle( HANDLE process, DWORD timeout )
|
|
|
|
{
|
|
|
|
HMODULE mod = GetModuleHandleA( "user32.dll" );
|
|
|
|
if (mod)
|
|
|
|
{
|
|
|
|
WaitForInputIdle_ptr ptr = (WaitForInputIdle_ptr)GetProcAddress( mod, "WaitForInputIdle" );
|
|
|
|
if (ptr) return ptr( process, timeout );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinExec (KERNEL32.@)
|
|
|
|
*/
|
2015-11-12 16:05:01 +01:00
|
|
|
UINT WINAPI DECLSPEC_HOTPATCH WinExec( LPCSTR lpCmdLine, UINT nCmdShow )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
char *cmdline;
|
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
memset( &startup, 0, sizeof(startup) );
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = nCmdShow;
|
|
|
|
|
2006-12-04 19:55:35 +01:00
|
|
|
/* cmdline needs to be writable for CreateProcess */
|
2003-09-17 07:31:32 +02:00
|
|
|
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(lpCmdLine)+1 ))) return 0;
|
|
|
|
strcpy( cmdline, lpCmdLine );
|
|
|
|
|
|
|
|
if (CreateProcessA( NULL, cmdline, NULL, NULL, FALSE,
|
|
|
|
0, NULL, NULL, &startup, &info ))
|
|
|
|
{
|
|
|
|
/* Give 30 seconds to the app to come up */
|
2003-10-16 21:31:11 +02:00
|
|
|
if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
|
2006-10-12 22:56:29 +02:00
|
|
|
WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
|
2003-09-17 07:31:32 +02:00
|
|
|
ret = 33;
|
|
|
|
/* Close off the handles */
|
|
|
|
CloseHandle( info.hThread );
|
|
|
|
CloseHandle( info.hProcess );
|
|
|
|
}
|
|
|
|
else if ((ret = GetLastError()) >= 32)
|
|
|
|
{
|
|
|
|
FIXME("Strange error set by CreateProcess: %d\n", ret );
|
|
|
|
ret = 11;
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* LoadModule (KERNEL32.@)
|
|
|
|
*/
|
2010-10-11 12:16:51 +02:00
|
|
|
DWORD WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-11-17 21:16:38 +01:00
|
|
|
LOADPARMS32 *params = paramBlock;
|
2003-09-17 07:31:32 +02:00
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
2010-10-11 12:16:51 +02:00
|
|
|
DWORD ret;
|
2003-09-17 07:31:32 +02:00
|
|
|
LPSTR cmdline, p;
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
BYTE len;
|
|
|
|
|
2010-10-11 12:16:51 +02:00
|
|
|
if (!name) return ERROR_FILE_NOT_FOUND;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
if (!SearchPathA( NULL, name, ".exe", sizeof(filename), filename, NULL ) &&
|
|
|
|
!SearchPathA( NULL, name, NULL, sizeof(filename), filename, NULL ))
|
2010-10-11 12:16:51 +02:00
|
|
|
return GetLastError();
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
len = (BYTE)params->lpCmdLine[0];
|
|
|
|
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + len + 2 )))
|
2010-10-11 12:16:51 +02:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
strcpy( cmdline, filename );
|
|
|
|
p = cmdline + strlen(cmdline);
|
|
|
|
*p++ = ' ';
|
|
|
|
memcpy( p, params->lpCmdLine + 1, len );
|
|
|
|
p[len] = 0;
|
|
|
|
|
|
|
|
memset( &startup, 0, sizeof(startup) );
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
if (params->lpCmdShow)
|
|
|
|
{
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
2003-11-17 21:16:38 +01:00
|
|
|
startup.wShowWindow = ((WORD *)params->lpCmdShow)[1];
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CreateProcessA( filename, cmdline, NULL, NULL, FALSE, 0,
|
|
|
|
params->lpEnvAddress, NULL, &startup, &info ))
|
|
|
|
{
|
|
|
|
/* Give 30 seconds to the app to come up */
|
2003-10-16 21:31:11 +02:00
|
|
|
if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
|
2006-10-12 22:56:29 +02:00
|
|
|
WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
|
2010-10-11 12:16:51 +02:00
|
|
|
ret = 33;
|
2003-09-17 07:31:32 +02:00
|
|
|
/* Close off the handles */
|
|
|
|
CloseHandle( info.hThread );
|
|
|
|
CloseHandle( info.hProcess );
|
|
|
|
}
|
2010-10-11 12:16:51 +02:00
|
|
|
else if ((ret = GetLastError()) >= 32)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2010-10-11 12:16:51 +02:00
|
|
|
FIXME("Strange error set by CreateProcess: %u\n", ret );
|
|
|
|
ret = 11;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
2010-10-11 12:16:51 +02:00
|
|
|
return ret;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 05:57:02 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ExitProcess (KERNEL32.@)
|
2006-03-31 13:33:04 +02:00
|
|
|
*
|
|
|
|
* Exits the current process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* status [I] Status code to exit with.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-10-08 05:57:02 +02:00
|
|
|
*/
|
2008-10-07 18:16:19 +02:00
|
|
|
#ifdef __i386__
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC( ExitProcess, 4, /* Shrinker depend on this particular ExitProcess implementation */
|
2008-10-07 18:16:19 +02:00
|
|
|
"pushl %ebp\n\t"
|
|
|
|
".byte 0x8B, 0xEC\n\t" /* movl %esp, %ebp */
|
|
|
|
".byte 0x6A, 0x00\n\t" /* pushl $0 */
|
|
|
|
".byte 0x68, 0x00, 0x00, 0x00, 0x00\n\t" /* pushl $0 - 4 bytes immediate */
|
|
|
|
"pushl 8(%ebp)\n\t"
|
2019-05-16 18:13:45 +02:00
|
|
|
"call " __ASM_STDCALL("RtlExitUserProcess",4) "\n\t"
|
2008-10-07 18:16:19 +02:00
|
|
|
"leave\n\t"
|
|
|
|
"ret $4" )
|
|
|
|
#else
|
|
|
|
|
2003-10-08 05:57:02 +02:00
|
|
|
void WINAPI ExitProcess( DWORD status )
|
|
|
|
{
|
2013-07-19 12:15:15 +02:00
|
|
|
RtlExitUserProcess( status );
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
2008-10-07 18:16:19 +02:00
|
|
|
#endif
|
2003-10-08 05:57:02 +02:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
2005-12-21 20:44:49 +01:00
|
|
|
* GetExitCodeProcess [KERNEL32.@]
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
2005-12-21 20:44:49 +01:00
|
|
|
* Gets termination status of specified process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProcess [in] Handle to the process.
|
|
|
|
* lpExitCode [out] Address to receive termination status.
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2005-12-21 20:44:49 +01:00
|
|
|
BOOL WINAPI GetExitCodeProcess( HANDLE hProcess, LPDWORD lpExitCode )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2004-06-14 19:02:00 +02:00
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( NtQueryInformationProcess( hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL )))
|
|
|
|
return FALSE;
|
|
|
|
if (lpExitCode) *lpExitCode = pbi.ExitStatus;
|
|
|
|
return TRUE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-08 22:30:38 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* FatalExit (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
void WINAPI FatalExit( int code )
|
|
|
|
{
|
|
|
|
WARN( "FatalExit\n" );
|
|
|
|
ExitProcess( code );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-27 06:08:04 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessFlags (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetProcessFlags( DWORD processid )
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
|
|
|
if (processid && processid != GetCurrentProcessId()) return 0;
|
|
|
|
|
|
|
|
if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
|
|
|
|
{
|
|
|
|
if (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
|
|
|
flags |= PDB32_CONSOLE_PROC;
|
|
|
|
}
|
|
|
|
if (!AreFileApisANSI()) flags |= PDB32_FILE_APIS_OEM;
|
|
|
|
if (IsDebuggerPresent()) flags |= PDB32_DEBUGGED;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 06:24:49 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ConvertToGlobalHandle (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
|
|
|
|
{
|
|
|
|
HANDLE ret = INVALID_HANDLE_VALUE;
|
|
|
|
DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
|
|
|
|
DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetHandleContext (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context)
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME("(%p,%d), stub. In case this got called by WSOCK32/WS2_32: "
|
2003-10-08 06:24:49 +02:00
|
|
|
"the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetHandleContext (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetHandleContext(HANDLE hnd)
|
|
|
|
{
|
|
|
|
FIXME("(%p), stub. In case this got called by WSOCK32/WS2_32: "
|
|
|
|
"the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateSocketHandle (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSocketHandle(void)
|
|
|
|
{
|
|
|
|
FIXME("(), stub. In case this got called by WSOCK32/WS2_32: "
|
|
|
|
"the external WINSOCK DLLs won't work with WINE, don't use them.\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-27 06:08:04 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
2004-10-20 01:55:15 +02:00
|
|
|
BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR affmask )
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2019-10-01 09:36:16 +02:00
|
|
|
return set_ntstatus( NtSetInformationProcess( hProcess, ProcessAffinityMask,
|
|
|
|
&affmask, sizeof(DWORD_PTR) ));
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetProcessAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
2011-04-14 19:57:34 +02:00
|
|
|
BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, PDWORD_PTR process_mask, PDWORD_PTR system_mask )
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2011-04-14 19:57:34 +02:00
|
|
|
if (process_mask)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( NtQueryInformationProcess( hProcess, ProcessAffinityMask,
|
|
|
|
process_mask, sizeof(*process_mask), NULL )))
|
|
|
|
return FALSE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
2019-10-01 09:36:16 +02:00
|
|
|
if (system_mask)
|
2015-01-21 13:23:36 +01:00
|
|
|
{
|
|
|
|
SYSTEM_BASIC_INFORMATION info;
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )))
|
|
|
|
return FALSE;
|
|
|
|
*system_mask = info.ActiveProcessorsAffinityMask;
|
2015-01-21 13:23:36 +01:00
|
|
|
}
|
2019-10-01 09:36:16 +02:00
|
|
|
return TRUE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessVersion (KERNEL32.@)
|
|
|
|
*/
|
2008-10-15 16:44:54 +02:00
|
|
|
DWORD WINAPI GetProcessVersion( DWORD pid )
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2008-10-15 16:44:54 +02:00
|
|
|
HANDLE process;
|
|
|
|
NTSTATUS status;
|
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
SIZE_T count;
|
|
|
|
PEB peb;
|
|
|
|
IMAGE_DOS_HEADER dos;
|
|
|
|
IMAGE_NT_HEADERS nt;
|
|
|
|
DWORD ver = 0;
|
2003-06-27 06:08:04 +02:00
|
|
|
|
2008-10-15 16:44:54 +02:00
|
|
|
if (!pid || pid == GetCurrentProcessId())
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2011-10-21 08:19:17 +02:00
|
|
|
IMAGE_NT_HEADERS *pnt;
|
2008-10-15 16:44:54 +02:00
|
|
|
|
2011-10-21 08:19:17 +02:00
|
|
|
if ((pnt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
|
|
|
|
return ((pnt->OptionalHeader.MajorSubsystemVersion << 16) |
|
|
|
|
pnt->OptionalHeader.MinorSubsystemVersion);
|
2003-06-27 06:08:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2008-10-15 16:44:54 +02:00
|
|
|
|
|
|
|
process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
|
|
|
|
if (!process) return 0;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(process, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
|
|
|
|
if (status) goto err;
|
|
|
|
|
|
|
|
status = NtReadVirtualMemory(process, pbi.PebBaseAddress, &peb, sizeof(peb), &count);
|
|
|
|
if (status || count != sizeof(peb)) goto err;
|
|
|
|
|
|
|
|
memset(&dos, 0, sizeof(dos));
|
|
|
|
status = NtReadVirtualMemory(process, peb.ImageBaseAddress, &dos, sizeof(dos), &count);
|
|
|
|
if (status || count != sizeof(dos)) goto err;
|
|
|
|
if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto err;
|
|
|
|
|
|
|
|
memset(&nt, 0, sizeof(nt));
|
|
|
|
status = NtReadVirtualMemory(process, (char *)peb.ImageBaseAddress + dos.e_lfanew, &nt, sizeof(nt), &count);
|
|
|
|
if (status || count != sizeof(nt)) goto err;
|
|
|
|
if (nt.Signature != IMAGE_NT_SIGNATURE) goto err;
|
|
|
|
|
|
|
|
ver = MAKELONG(nt.OptionalHeader.MinorSubsystemVersion, nt.OptionalHeader.MajorSubsystemVersion);
|
|
|
|
|
|
|
|
err:
|
|
|
|
CloseHandle(process);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
|
|
|
|
return ver;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-16 16:59:21 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessWorkingSetSize [KERNEL32.@]
|
|
|
|
* Sets the min/max working set sizes for a specified process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* process [I] Handle to the process of interest
|
|
|
|
* minset [I] Specifies minimum working set size
|
|
|
|
* maxset [I] Specifies maximum working set size
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessWorkingSetSize(HANDLE process, SIZE_T minset, SIZE_T maxset)
|
|
|
|
{
|
|
|
|
return SetProcessWorkingSetSizeEx(process, minset, maxset, 0);
|
|
|
|
}
|
|
|
|
|
2011-04-19 14:21:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* K32EmptyWorkingSet (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI K32EmptyWorkingSet(HANDLE hProcess)
|
|
|
|
{
|
|
|
|
return SetProcessWorkingSetSize(hProcess, (SIZE_T)-1, (SIZE_T)-1);
|
|
|
|
}
|
|
|
|
|
2017-09-13 07:10:49 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessWorkingSetSize (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessWorkingSetSize(HANDLE process, SIZE_T *minset, SIZE_T *maxset)
|
|
|
|
{
|
|
|
|
return GetProcessWorkingSetSizeEx(process, minset, maxset, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 02:06:45 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetProcessIoCounters (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessIoCounters(HANDLE hProcess, PIO_COUNTERS ioc)
|
|
|
|
{
|
2019-10-01 09:36:16 +02:00
|
|
|
return set_ntstatus( NtQueryInformationProcess(hProcess, ProcessIoCounters, ioc, sizeof(*ioc), NULL ));
|
2007-11-01 07:46:54 +01:00
|
|
|
}
|
|
|
|
|
2009-06-10 20:39:42 +02:00
|
|
|
/******************************************************************
|
|
|
|
* QueryFullProcessImageNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueryFullProcessImageNameA(HANDLE hProcess, DWORD dwFlags, LPSTR lpExeName, PDWORD pdwSize)
|
|
|
|
{
|
|
|
|
BOOL retval;
|
|
|
|
DWORD pdwSizeW = *pdwSize;
|
|
|
|
LPWSTR lpExeNameW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *pdwSize * sizeof(WCHAR));
|
|
|
|
|
|
|
|
retval = QueryFullProcessImageNameW(hProcess, dwFlags, lpExeNameW, &pdwSizeW);
|
|
|
|
|
|
|
|
if(retval)
|
|
|
|
retval = (0 != WideCharToMultiByte(CP_ACP, 0, lpExeNameW, -1,
|
|
|
|
lpExeName, *pdwSize, NULL, NULL));
|
|
|
|
if(retval)
|
|
|
|
*pdwSize = strlen(lpExeName);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpExeNameW);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-03-29 23:36:33 +02:00
|
|
|
/******************************************************************
|
|
|
|
* QueryFullProcessImageNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueryFullProcessImageNameW(HANDLE hProcess, DWORD dwFlags, LPWSTR lpExeName, PDWORD pdwSize)
|
|
|
|
{
|
|
|
|
BYTE buffer[sizeof(UNICODE_STRING) + MAX_PATH*sizeof(WCHAR)]; /* this buffer should be enough */
|
|
|
|
UNICODE_STRING *dynamic_buffer = NULL;
|
|
|
|
UNICODE_STRING *result = NULL;
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD needed;
|
|
|
|
|
2011-10-03 23:56:12 +02:00
|
|
|
/* FIXME: On Windows, ProcessImageFileName return an NT path. In Wine it
|
|
|
|
* is a DOS path and we depend on this. */
|
2009-04-22 16:54:16 +02:00
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessImageFileName, buffer,
|
|
|
|
sizeof(buffer) - sizeof(WCHAR), &needed);
|
2009-03-29 23:36:33 +02:00
|
|
|
if (status == STATUS_INFO_LENGTH_MISMATCH)
|
|
|
|
{
|
2009-04-22 16:54:16 +02:00
|
|
|
dynamic_buffer = HeapAlloc(GetProcessHeap(), 0, needed + sizeof(WCHAR));
|
2009-03-29 23:36:33 +02:00
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessImageFileName, (LPBYTE)dynamic_buffer, needed, &needed);
|
|
|
|
result = dynamic_buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = (PUNICODE_STRING)buffer;
|
|
|
|
|
|
|
|
if (status) goto cleanup;
|
|
|
|
|
|
|
|
if (dwFlags & PROCESS_NAME_NATIVE)
|
|
|
|
{
|
2011-10-03 23:56:12 +02:00
|
|
|
WCHAR drive[3];
|
|
|
|
WCHAR device[1024];
|
|
|
|
DWORD ntlen, devlen;
|
|
|
|
|
|
|
|
if (result->Buffer[1] != ':' || result->Buffer[0] < 'A' || result->Buffer[0] > 'Z')
|
2009-03-29 23:36:33 +02:00
|
|
|
{
|
2011-10-03 23:56:12 +02:00
|
|
|
/* We cannot convert it to an NT device path so fail */
|
|
|
|
status = STATUS_NO_SUCH_DEVICE;
|
2009-03-29 23:36:33 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-10-03 23:56:12 +02:00
|
|
|
/* Find this drive's NT device path */
|
|
|
|
drive[0] = result->Buffer[0];
|
|
|
|
drive[1] = ':';
|
|
|
|
drive[2] = 0;
|
2018-07-30 21:18:09 +02:00
|
|
|
if (!QueryDosDeviceW(drive, device, ARRAY_SIZE(device)))
|
2011-10-03 23:56:12 +02:00
|
|
|
{
|
|
|
|
status = STATUS_NO_SUCH_DEVICE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
devlen = lstrlenW(device);
|
|
|
|
ntlen = devlen + (result->Length/sizeof(WCHAR) - 2);
|
|
|
|
if (ntlen + 1 > *pdwSize)
|
|
|
|
{
|
2015-03-17 06:34:03 +01:00
|
|
|
status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
goto cleanup;
|
2011-10-03 23:56:12 +02:00
|
|
|
}
|
|
|
|
*pdwSize = ntlen;
|
|
|
|
|
|
|
|
memcpy(lpExeName, device, devlen * sizeof(*device));
|
|
|
|
memcpy(lpExeName + devlen, result->Buffer + 2, result->Length - 2 * sizeof(WCHAR));
|
|
|
|
lpExeName[*pdwSize] = 0;
|
|
|
|
TRACE("NT path: %s\n", debugstr_w(lpExeName));
|
2009-03-29 23:36:33 +02:00
|
|
|
}
|
2011-10-03 23:56:12 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (result->Length/sizeof(WCHAR) + 1 > *pdwSize)
|
|
|
|
{
|
|
|
|
status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-03-29 23:36:33 +02:00
|
|
|
|
2011-10-03 23:56:12 +02:00
|
|
|
*pdwSize = result->Length/sizeof(WCHAR);
|
|
|
|
memcpy( lpExeName, result->Buffer, result->Length );
|
|
|
|
lpExeName[*pdwSize] = 0;
|
|
|
|
}
|
2009-03-29 23:36:33 +02:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
HeapFree(GetProcessHeap(), 0, dynamic_buffer);
|
2019-10-01 09:36:16 +02:00
|
|
|
return set_ntstatus( status );
|
2009-03-29 23:36:33 +02:00
|
|
|
}
|
|
|
|
|
2011-04-08 14:17:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* K32GetProcessImageFileNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI K32GetProcessImageFileNameA( HANDLE process, LPSTR file, DWORD size )
|
|
|
|
{
|
2011-08-05 09:56:26 +02:00
|
|
|
return QueryFullProcessImageNameA(process, PROCESS_NAME_NATIVE, file, &size) ? size : 0;
|
2011-04-08 14:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* K32GetProcessImageFileNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI K32GetProcessImageFileNameW( HANDLE process, LPWSTR file, DWORD size )
|
|
|
|
{
|
|
|
|
return QueryFullProcessImageNameW(process, PROCESS_NAME_NATIVE, file, &size) ? size : 0;
|
|
|
|
}
|
|
|
|
|
2011-05-03 23:08:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* K32EnumProcesses (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI K32EnumProcesses(DWORD *lpdwProcessIDs, DWORD cb, DWORD *lpcbUsed)
|
|
|
|
{
|
|
|
|
SYSTEM_PROCESS_INFORMATION *spi;
|
|
|
|
ULONG size = 0x4000;
|
|
|
|
void *buf = NULL;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
do {
|
|
|
|
size *= 2;
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (!buf)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
status = NtQuerySystemInformation(SystemProcessInformation, buf, size, NULL);
|
|
|
|
} while(status == STATUS_INFO_LENGTH_MISMATCH);
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( status ))
|
2011-05-03 23:08:42 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi = buf;
|
|
|
|
|
|
|
|
for (*lpcbUsed = 0; cb >= sizeof(DWORD); cb -= sizeof(DWORD))
|
|
|
|
{
|
|
|
|
*lpdwProcessIDs++ = HandleToUlong(spi->UniqueProcessId);
|
|
|
|
*lpcbUsed += sizeof(DWORD);
|
|
|
|
|
|
|
|
if (spi->NextEntryOffset == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-11 15:06:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* K32QueryWorkingSet (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI K32QueryWorkingSet( HANDLE process, LPVOID buffer, DWORD size )
|
|
|
|
{
|
|
|
|
TRACE( "(%p, %p, %d)\n", process, buffer, size );
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL ));
|
2011-05-11 15:06:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* K32QueryWorkingSetEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI K32QueryWorkingSetEx( HANDLE process, LPVOID buffer, DWORD size )
|
|
|
|
{
|
|
|
|
TRACE( "(%p, %p, %d)\n", process, buffer, size );
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL ));
|
2011-05-11 15:06:45 +02:00
|
|
|
}
|
|
|
|
|
2011-05-12 14:19:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* K32GetProcessMemoryInfo (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Retrieve memory usage information for a given process
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI K32GetProcessMemoryInfo(HANDLE process,
|
|
|
|
PPROCESS_MEMORY_COUNTERS pmc, DWORD cb)
|
|
|
|
{
|
|
|
|
VM_COUNTERS vmc;
|
|
|
|
|
|
|
|
if (cb < sizeof(PROCESS_MEMORY_COUNTERS))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( NtQueryInformationProcess( process, ProcessVmCounters, &vmc, sizeof(vmc), NULL )))
|
2011-05-12 14:19:40 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pmc->cb = sizeof(PROCESS_MEMORY_COUNTERS);
|
|
|
|
pmc->PageFaultCount = vmc.PageFaultCount;
|
|
|
|
pmc->PeakWorkingSetSize = vmc.PeakWorkingSetSize;
|
|
|
|
pmc->WorkingSetSize = vmc.WorkingSetSize;
|
|
|
|
pmc->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage;
|
|
|
|
pmc->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage;
|
|
|
|
pmc->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage;
|
|
|
|
pmc->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage;
|
|
|
|
pmc->PagefileUsage = vmc.PagefileUsage;
|
|
|
|
pmc->PeakPagefileUsage = vmc.PeakPagefileUsage;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ProcessIdToSessionId (KERNEL32.@)
|
|
|
|
* This function is available on Terminal Server 4SP4 and Windows 2000
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
|
|
|
|
{
|
2015-10-08 14:20:05 +02:00
|
|
|
if (procid != GetCurrentProcessId())
|
|
|
|
FIXME("Unsupported for other processes.\n");
|
|
|
|
|
|
|
|
*sessionid_ptr = NtCurrentTeb()->Peb->SessionId;
|
2003-09-17 07:31:32 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-27 06:08:04 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RegisterServiceProcess (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* A service process calls this function to ensure that it continues to run
|
|
|
|
* even after a user logged off.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
|
|
|
|
{
|
2004-12-15 11:48:18 +01:00
|
|
|
/* I don't think that Wine needs to do anything in this function */
|
2003-06-27 06:08:04 +02:00
|
|
|
return 1; /* success */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentProcess (KERNEL32.@)
|
2004-12-15 11:48:18 +01:00
|
|
|
*
|
|
|
|
* Get a handle to the current process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* A handle representing the current process.
|
2003-06-27 06:08:04 +02:00
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
HANDLE WINAPI KERNEL32_GetCurrentProcess(void)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2008-12-08 15:51:22 +01:00
|
|
|
return (HANDLE)~(ULONG_PTR)0;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
2006-02-22 12:54:16 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CmdBatNotification (KERNEL32.@)
|
|
|
|
*
|
2006-03-31 13:33:04 +02:00
|
|
|
* Notifies the system that a batch file has started or finished.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* bBatchRunning [I] TRUE if a batch file has started or
|
|
|
|
* FALSE if a batch file has finished executing.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Unknown.
|
2006-02-22 12:54:16 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CmdBatNotification( BOOL bBatchRunning )
|
|
|
|
{
|
|
|
|
FIXME("%d\n", bBatchRunning);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-01-30 03:37:17 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RegisterApplicationRestart (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI RegisterApplicationRestart(PCWSTR pwzCommandLine, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%d)\n", debugstr_w(pwzCommandLine), dwFlags);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-07-16 05:00:13 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* WTSGetActiveConsoleSessionId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WTSGetActiveConsoleSessionId(void)
|
|
|
|
{
|
2014-01-28 00:57:59 +01:00
|
|
|
static int once;
|
|
|
|
if (!once++) FIXME("stub\n");
|
2015-10-08 14:20:50 +02:00
|
|
|
/* Return current session id. */
|
|
|
|
return NtCurrentTeb()->Peb->SessionId;
|
2009-07-16 05:00:13 +02:00
|
|
|
}
|
2010-09-22 06:17:29 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetSystemDEPPolicy (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DEP_SYSTEM_POLICY_TYPE WINAPI GetSystemDEPPolicy(void)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return OptIn;
|
|
|
|
}
|
2011-05-22 01:31:58 +02:00
|
|
|
|
2010-11-05 14:10:04 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* SetProcessDEPPolicy (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessDEPPolicy(DWORD newDEP)
|
|
|
|
{
|
|
|
|
FIXME("(%d): stub\n", newDEP);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-05-22 01:31:58 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ApplicationRecoveryFinished (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
VOID WINAPI ApplicationRecoveryFinished(BOOL success)
|
|
|
|
{
|
|
|
|
FIXME(": stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
}
|
2011-05-22 01:35:01 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ApplicationRecoveryInProgress (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI ApplicationRecoveryInProgress(PBOOL canceled)
|
|
|
|
{
|
|
|
|
FIXME(":%p stub\n", canceled);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2011-05-22 23:18:06 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* RegisterApplicationRecoveryCallback (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI RegisterApplicationRecoveryCallback(APPLICATION_RECOVERY_CALLBACK callback, PVOID param, DWORD pingint, DWORD flags)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p, %d, %d: stub\n", callback, param, pingint, flags);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2011-06-23 11:09:57 +02:00
|
|
|
|
2018-08-27 18:26:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetApplicationRestartSettings (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI GetApplicationRestartSettings(HANDLE process, WCHAR *cmdline, DWORD *size, DWORD *flags)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p, %p, %p)\n", process, cmdline, size, flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-06-23 11:09:57 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* GetNumaNodeProcessorMask (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumaNodeProcessorMask(UCHAR node, PULONGLONG mask)
|
|
|
|
{
|
|
|
|
FIXME("(%c %p): stub\n", node, mask);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetNumaAvailableMemoryNode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumaAvailableMemoryNode(UCHAR node, PULONGLONG available_bytes)
|
|
|
|
{
|
|
|
|
FIXME("(%c %p): stub\n", node, available_bytes);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-10-20 00:59:05 +02:00
|
|
|
|
2019-05-08 22:34:08 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* GetNumaAvailableMemoryNodeEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumaAvailableMemoryNodeEx(USHORT node, PULONGLONG available_bytes)
|
|
|
|
{
|
|
|
|
FIXME("(%hu %p): stub\n", node, available_bytes);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-06-29 06:27:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetNumaProcessorNode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumaProcessorNode(UCHAR processor, PUCHAR node)
|
|
|
|
{
|
|
|
|
SYSTEM_INFO si;
|
|
|
|
|
|
|
|
TRACE("(%d, %p)\n", processor, node);
|
|
|
|
|
|
|
|
GetSystemInfo( &si );
|
|
|
|
if (processor < si.dwNumberOfProcessors)
|
|
|
|
{
|
|
|
|
*node = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*node = 0xFF;
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-08 22:34:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetNumaProcessorNodeEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumaProcessorNodeEx(PPROCESSOR_NUMBER processor, PUSHORT node_number)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNumaProximityNode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumaProximityNode(ULONG proximity_id, PUCHAR node_number)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-10-20 00:59:05 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* GetProcessDEPPolicy (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessDEPPolicy(HANDLE process, LPDWORD flags, PBOOL permanent)
|
|
|
|
{
|
2014-10-21 07:46:10 +02:00
|
|
|
ULONG dep_flags;
|
|
|
|
|
|
|
|
TRACE("(%p %p %p)\n", process, flags, permanent);
|
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (!set_ntstatus( NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
|
|
|
|
&dep_flags, sizeof(dep_flags), NULL )))
|
|
|
|
return FALSE;
|
2014-10-21 07:46:10 +02:00
|
|
|
|
2019-10-01 09:36:16 +02:00
|
|
|
if (flags)
|
|
|
|
{
|
|
|
|
*flags = 0;
|
|
|
|
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
|
|
|
|
*flags |= PROCESS_DEP_ENABLE;
|
|
|
|
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
|
|
|
|
*flags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
|
2014-10-21 07:46:10 +02:00
|
|
|
}
|
2019-10-01 09:36:16 +02:00
|
|
|
|
|
|
|
if (permanent) *permanent = (dep_flags & MEM_EXECUTE_OPTION_PERMANENT) != 0;
|
|
|
|
return TRUE;
|
2012-05-01 22:26:24 +02:00
|
|
|
}
|
2011-10-20 00:59:05 +02:00
|
|
|
|
2012-05-01 22:26:24 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* FlushProcessWriteBuffers (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
VOID WINAPI FlushProcessWriteBuffers(void)
|
|
|
|
{
|
2012-05-03 00:00:36 +02:00
|
|
|
static int once = 0;
|
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
FIXME(": stub\n");
|
2011-10-20 00:59:05 +02:00
|
|
|
}
|
2014-06-18 01:24:48 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnregisterApplicationRestart (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI UnregisterApplicationRestart(void)
|
|
|
|
{
|
|
|
|
FIXME(": stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2015-01-23 05:49:59 +01:00
|
|
|
|
2018-03-05 04:59:54 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* CreateUmsCompletionList (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateUmsCompletionList(PUMS_COMPLETION_LIST *list)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", list );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:59:55 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* CreateUmsThreadContext (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateUmsThreadContext(PUMS_CONTEXT *ctx)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", ctx );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:59:57 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DeleteUmsCompletionList (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteUmsCompletionList(PUMS_COMPLETION_LIST list)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", list );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:59:58 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DeleteUmsThreadContext (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteUmsThreadContext(PUMS_CONTEXT ctx)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", ctx );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:59:59 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DequeueUmsCompletionListItems (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DequeueUmsCompletionListItems(void *list, DWORD timeout, PUMS_CONTEXT *ctx)
|
|
|
|
{
|
|
|
|
FIXME( "%p,%08x,%p: stub\n", list, timeout, ctx );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:00 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* EnterUmsSchedulingMode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnterUmsSchedulingMode(UMS_SCHEDULER_STARTUP_INFO *info)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", info );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:02 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ExecuteUmsThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ExecuteUmsThread(PUMS_CONTEXT ctx)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", ctx );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:03 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentUmsThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
PUMS_CONTEXT WINAPI GetCurrentUmsThread(void)
|
|
|
|
{
|
|
|
|
FIXME( "stub\n" );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:04 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* GetNextUmsListItem (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
PUMS_CONTEXT WINAPI GetNextUmsListItem(PUMS_CONTEXT ctx)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", ctx );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:05 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* GetUmsCompletionListEvent (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetUmsCompletionListEvent(PUMS_COMPLETION_LIST list, HANDLE *event)
|
|
|
|
{
|
|
|
|
FIXME( "%p,%p: stub\n", list, event );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:07 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* QueryUmsThreadInformation (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueryUmsThreadInformation(PUMS_CONTEXT ctx, UMS_THREAD_INFO_CLASS class,
|
|
|
|
void *buf, ULONG length, ULONG *ret_length)
|
|
|
|
{
|
|
|
|
FIXME( "%p,%08x,%p,%08x,%p: stub\n", ctx, class, buf, length, ret_length );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:08 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetUmsThreadInformation (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetUmsThreadInformation(PUMS_CONTEXT ctx, UMS_THREAD_INFO_CLASS class,
|
|
|
|
void *buf, ULONG length)
|
|
|
|
{
|
|
|
|
FIXME( "%p,%08x,%p,%08x: stub\n", ctx, class, buf, length );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-05 05:00:09 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* UmsThreadYield (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UmsThreadYield(void *param)
|
|
|
|
{
|
|
|
|
FIXME( "%p: stub\n", param );
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-01-18 23:38:26 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* BaseFlushAppcompatCache (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI BaseFlushAppcompatCache(void)
|
|
|
|
{
|
|
|
|
FIXME(": stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|