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>
|
|
|
|
#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>
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-06-27 06:08:04 +02:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "wine/winuser16.h"
|
2005-06-06 22:13:08 +02:00
|
|
|
#include "winternl.h"
|
2003-09-17 07:31:32 +02:00
|
|
|
#include "kernel_private.h"
|
2003-11-27 01:59:36 +01:00
|
|
|
#include "wine/exception.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"
|
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);
|
2004-05-14 23:43:18 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(file);
|
2006-07-31 21:25:29 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-11-17 21:16:38 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
LPSTR lpEnvAddress;
|
|
|
|
LPSTR lpCmdLine;
|
|
|
|
LPSTR lpCmdShow;
|
|
|
|
DWORD dwReserved;
|
|
|
|
} LOADPARMS32;
|
|
|
|
|
2003-10-09 21:58:56 +02:00
|
|
|
static UINT process_error_mode;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
static DWORD shutdown_flags = 0;
|
|
|
|
static DWORD shutdown_priority = 0x280;
|
|
|
|
static DWORD process_dword;
|
|
|
|
|
2004-02-12 01:00:55 +01:00
|
|
|
HMODULE kernel32_handle = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2004-05-14 23:43:18 +02:00
|
|
|
const WCHAR *DIR_Windows = NULL;
|
|
|
|
const WCHAR *DIR_System = NULL;
|
|
|
|
|
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 */
|
|
|
|
|
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};
|
2003-10-04 06:09:41 +02:00
|
|
|
static const WCHAR winevdmW[] = {'w','i','n','e','v','d','m','.','e','x','e',0};
|
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
static void exec_process( LPCWSTR name );
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
extern void SHELL_LoadRegistry(void);
|
2005-06-14 13:42:34 +02:00
|
|
|
|
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
|
|
|
*/
|
2007-03-17 11:22:45 +01:00
|
|
|
static inline int 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").
|
|
|
|
*/
|
2007-03-17 11:22:45 +01:00
|
|
|
static inline int 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 ) ||
|
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 ) ||
|
|
|
|
!strncmp( var, "TMP=", sizeof("TMP=")-1 ));
|
2004-03-11 01:49:01 +01: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.
|
|
|
|
*/
|
|
|
|
static BOOL get_builtin_path( const WCHAR *libname, const WCHAR *ext, WCHAR *filename, UINT size )
|
|
|
|
{
|
|
|
|
WCHAR *file_part;
|
2004-05-13 22:21:25 +02:00
|
|
|
UINT len = strlenW( DIR_System );
|
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 */
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
if (strncmpiW( filename, DIR_System, len ) || filename[len] != '\\')
|
2003-10-04 06:09:41 +02:00
|
|
|
return FALSE;
|
|
|
|
while (filename[len] == '\\') len++;
|
2003-11-17 21:18:19 +01:00
|
|
|
if (filename + len != file_part) return FALSE;
|
2003-10-04 06:09:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
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_builtin_exe_file
|
|
|
|
*
|
|
|
|
* Open an exe file for a builtin exe.
|
|
|
|
*/
|
2003-10-04 06:09:41 +02:00
|
|
|
static void *open_builtin_exe_file( const WCHAR *name, char *error, int error_size,
|
2003-09-17 07:31:32 +02:00
|
|
|
int test_only, int *file_exists )
|
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
char exename[MAX_PATH];
|
|
|
|
WCHAR *p;
|
|
|
|
UINT i, len;
|
|
|
|
|
2005-11-28 10:35:10 +01:00
|
|
|
*file_exists = 0;
|
2003-10-04 06:09:41 +02:00
|
|
|
if ((p = strrchrW( name, '/' ))) name = p + 1;
|
|
|
|
if ((p = strrchrW( name, '\\' ))) name = p + 1;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/* we don't want to depend on the current codepage here */
|
|
|
|
len = strlenW( name ) + 1;
|
|
|
|
if (len >= sizeof(exename)) return NULL;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (name[i] > 127) return NULL;
|
|
|
|
exename[i] = (char)name[i];
|
|
|
|
if (exename[i] >= 'A' && exename[i] <= 'Z') exename[i] += 'a' - 'A';
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
return wine_dll_load_main_exe( exename, error, error_size, test_only, file_exists );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* open_exe_file
|
|
|
|
*
|
|
|
|
* Open a specific exe file, taking load order into account.
|
|
|
|
* Returns the file handle or 0 for a builtin exe.
|
|
|
|
*/
|
2003-10-04 06:09:41 +02:00
|
|
|
static HANDLE open_exe_file( const WCHAR *name )
|
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 */
|
2003-10-04 06:09:41 +02:00
|
|
|
if (!contains_path( name )) goto error;
|
|
|
|
if (!get_builtin_path( name, NULL, buffer, sizeof(buffer) )) goto error;
|
2006-02-22 16:21:12 +01: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
|
|
|
|
|
|
|
error:
|
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* find_exe_file
|
|
|
|
*
|
|
|
|
* Open an exe file, and return the full name and file handle.
|
|
|
|
* Returns FALSE if file could not be found.
|
|
|
|
* If file exists but cannot be opened, returns TRUE and set handle to INVALID_HANDLE_VALUE.
|
|
|
|
* If file is a builtin exe, returns TRUE and sets handle to 0.
|
|
|
|
*/
|
2003-10-04 06:09:41 +02:00
|
|
|
static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE *handle )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
static const WCHAR exeW[] = {'.','e','x','e',0};
|
2006-02-22 16:21:12 +01:00
|
|
|
int file_exists;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE("looking for %s\n", debugstr_w(name) );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if (!SearchPathW( NULL, name, exeW, buflen, buffer, NULL ) &&
|
|
|
|
!get_builtin_path( name, exeW, buffer, buflen ))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
/* no builtin found, try native without extension in case it is a Unix app */
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if (SearchPathW( NULL, name, NULL, buflen, buffer, NULL ))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "Trying native/Unix binary %s\n", debugstr_w(buffer) );
|
2004-09-15 20:02:49 +02:00
|
|
|
if ((*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE,
|
2003-09-17 07:31:32 +02:00
|
|
|
NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-02-22 16:21:12 +01:00
|
|
|
TRACE( "Trying native exe %s\n", debugstr_w(buffer) );
|
|
|
|
if ((*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
|
|
|
|
return TRUE;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2006-02-22 16:21:12 +01:00
|
|
|
TRACE( "Trying built-in exe %s\n", debugstr_w(buffer) );
|
|
|
|
open_builtin_exe_file( buffer, NULL, 0, 1, &file_exists );
|
|
|
|
if (file_exists)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2006-02-22 16:21:12 +01:00
|
|
|
*handle = 0;
|
|
|
|
return TRUE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2006-02-22 16:21:12 +01:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2003-10-11 01:33:21 +02:00
|
|
|
static BOOL build_initial_environment( char **environ )
|
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;
|
|
|
|
|
|
|
|
/* Compute the total size of the Unix environment */
|
|
|
|
for (e = environ; *e; e++)
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
/* Now allocate the environment */
|
2004-10-11 22:59:06 +02:00
|
|
|
ptr = NULL;
|
2003-10-04 06:09:41 +02:00
|
|
|
if (NtAllocateVirtualMemory(NtCurrentProcess(), &ptr, 0, &size,
|
|
|
|
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) != STATUS_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
NtCurrentTeb()->Peb->ProcessParameters->Environment = p = ptr;
|
|
|
|
endptr = p + size / sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* And fill it with the Unix environment */
|
|
|
|
for (e = environ; *e; e++)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
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)];
|
2004-05-14 07:03:29 +02:00
|
|
|
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
|
|
|
|
|
|
|
|
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);
|
|
|
|
env_value.Length = env_value.MaximumLength = info->DataLength;
|
|
|
|
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 */
|
2004-10-30 04:11:33 +02:00
|
|
|
if (info->Type == REG_EXPAND_SZ)
|
|
|
|
{
|
|
|
|
WCHAR buf_expanded[1024];
|
|
|
|
UNICODE_STRING env_expanded;
|
|
|
|
env_expanded.Length = env_expanded.MaximumLength = sizeof(buf_expanded);
|
|
|
|
env_expanded.Buffer=buf_expanded;
|
|
|
|
status = RtlExpandEnvironmentStrings_U(NULL, &env_value, &env_expanded, NULL);
|
|
|
|
if (status == STATUS_SUCCESS || status == STATUS_BUFFER_OVERFLOW)
|
|
|
|
RtlSetEnvironmentVariable( NULL, &env_name, &env_expanded );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2008-04-24 11:53:45 +02:00
|
|
|
static BOOL set_registry_environment(void)
|
2004-05-06 00:05:18 +02:00
|
|
|
{
|
|
|
|
static const WCHAR env_keyW[] = {'M','a','c','h','i','n','e','\\',
|
|
|
|
'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};
|
|
|
|
|
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 );
|
2004-05-14 07:03:29 +02:00
|
|
|
if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) == STATUS_SUCCESS)
|
|
|
|
{
|
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 */
|
2008-04-24 11:53:45 +02:00
|
|
|
if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &attr.RootDirectory ) != STATUS_SUCCESS) return ret;
|
2004-05-14 07:03:29 +02:00
|
|
|
RtlInitUnicodeString( &nameW, envW );
|
|
|
|
if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &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
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-05-06 15:54:07 +02:00
|
|
|
static const WCHAR profile_keyW[] = {'M','a','c','h','i','n','e','\\',
|
|
|
|
'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};
|
|
|
|
static const WCHAR all_users_valueW[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
|
2007-08-16 15:50:29 +02:00
|
|
|
static const WCHAR usernameW[] = {'U','S','E','R','N','A','M','E',0};
|
2008-05-06 15:54:07 +02:00
|
|
|
static const WCHAR userprofileW[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
|
|
|
|
static const WCHAR allusersW[] = {'A','L','L','U','S','E','R','S','P','R','O','F','I','L','E',0};
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
WCHAR *user_name = NULL, *profile_dir = NULL, *all_users_dir = NULL;
|
|
|
|
HANDLE hkey;
|
2007-08-16 15:50:29 +02:00
|
|
|
const char *name = wine_get_user_name();
|
2008-05-06 15:54:07 +02:00
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
/* set the USERNAME variable */
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
|
2007-08-16 15:50:29 +02:00
|
|
|
if (len)
|
|
|
|
{
|
2008-05-06 15:54:07 +02:00
|
|
|
user_name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, name, -1, user_name, len );
|
|
|
|
SetEnvironmentVariableW( usernameW, user_name );
|
2007-08-16 15:50:29 +02:00
|
|
|
}
|
2008-05-06 15:54:07 +02:00
|
|
|
|
|
|
|
/* set the USERPROFILE and ALLUSERSPROFILE variables */
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, profile_keyW );
|
|
|
|
if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
|
|
|
|
{
|
|
|
|
profile_dir = get_reg_value( hkey, profiles_valueW );
|
|
|
|
all_users_dir = get_reg_value( hkey, all_users_valueW );
|
|
|
|
NtClose( hkey );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile_dir)
|
|
|
|
{
|
|
|
|
WCHAR *value, *p;
|
|
|
|
|
|
|
|
if (all_users_dir) len = max( len, strlenW(all_users_dir) + 1 );
|
|
|
|
len += strlenW(profile_dir) + 1;
|
|
|
|
value = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
strcpyW( value, profile_dir );
|
|
|
|
p = value + strlenW(value);
|
|
|
|
if (p > value && p[-1] != '\\') *p++ = '\\';
|
|
|
|
strcpyW( p, user_name );
|
|
|
|
SetEnvironmentVariableW( userprofileW, value );
|
|
|
|
if (all_users_dir)
|
|
|
|
{
|
|
|
|
strcpyW( p, all_users_dir );
|
|
|
|
SetEnvironmentVariableW( allusersW, value );
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, all_users_dir );
|
|
|
|
HeapFree( GetProcessHeap(), 0, profile_dir );
|
|
|
|
HeapFree( GetProcessHeap(), 0, user_name );
|
2007-08-16 15:50:29 +02:00
|
|
|
}
|
2004-05-06 00:05:18 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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 '"'
|
|
|
|
* '\"' -> '\\\"'
|
|
|
|
* '\\"' -> '\\\\\"'
|
|
|
|
* - '\'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++)
|
|
|
|
{
|
|
|
|
int has_space,bcount;
|
|
|
|
WCHAR* a;
|
|
|
|
|
|
|
|
has_space=0;
|
|
|
|
bcount=0;
|
|
|
|
a=*arg;
|
|
|
|
if( !*a ) has_space=1;
|
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a=='\\') {
|
|
|
|
bcount++;
|
|
|
|
} else {
|
|
|
|
if (*a==' ' || *a=='\t') {
|
|
|
|
has_space=1;
|
|
|
|
} 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)
|
|
|
|
len+=2; /* for the quotes */
|
|
|
|
}
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
int has_space,has_quote;
|
|
|
|
WCHAR* a;
|
|
|
|
|
|
|
|
/* Check for quotes and spaces in this argument */
|
|
|
|
has_space=has_quote=0;
|
|
|
|
a=*arg;
|
|
|
|
if( !*a ) has_space=1;
|
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a==' ' || *a=='\t') {
|
|
|
|
has_space=1;
|
|
|
|
if (has_quote)
|
|
|
|
break;
|
|
|
|
} else if (*a=='"') {
|
|
|
|
has_quote=1;
|
|
|
|
if (has_space)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now transfer it to the command line */
|
|
|
|
if (has_space)
|
|
|
|
*p++='"';
|
|
|
|
if (has_quote) {
|
|
|
|
int bcount;
|
|
|
|
WCHAR* a;
|
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
if (has_space)
|
|
|
|
*p++='"';
|
|
|
|
*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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cwd)
|
|
|
|
{
|
|
|
|
WCHAR *dirW;
|
|
|
|
int lenW = MultiByteToWideChar( CP_UNIXCP, 0, cwd, -1, NULL, 0 );
|
|
|
|
if ((dirW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, cwd, -1, dirW, lenW );
|
|
|
|
RtlInitUnicodeString( &dir_str, dirW );
|
|
|
|
RtlSetCurrentDirectory_U( &dir_str );
|
|
|
|
RtlFreeUnicodeString( &dir_str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
if (!cur_dir->Handle) chdir("/"); /* change to root directory so as not to lock cdroms */
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* Initialize the windows and system directories from the environment.
|
|
|
|
*/
|
|
|
|
static void init_windows_dirs(void)
|
|
|
|
{
|
2004-07-16 00:07:21 +02:00
|
|
|
extern void __wine_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir );
|
|
|
|
|
2004-05-14 23:43:18 +02:00
|
|
|
static const WCHAR windirW[] = {'w','i','n','d','i','r',0};
|
|
|
|
static const WCHAR winsysdirW[] = {'w','i','n','s','y','s','d','i','r',0};
|
2008-02-27 12:58:40 +01:00
|
|
|
static const WCHAR default_windirW[] = {'C',':','\\','w','i','n','d','o','w','s',0};
|
2005-08-15 16:53:35 +02:00
|
|
|
static const WCHAR default_sysdirW[] = {'\\','s','y','s','t','e','m','3','2',0};
|
2004-05-14 23:43:18 +02:00
|
|
|
|
|
|
|
DWORD len;
|
|
|
|
WCHAR *buffer;
|
|
|
|
|
|
|
|
if ((len = GetEnvironmentVariableW( windirW, NULL, 0 )))
|
|
|
|
{
|
|
|
|
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
GetEnvironmentVariableW( windirW, buffer, len );
|
|
|
|
DIR_Windows = buffer;
|
|
|
|
}
|
2004-07-16 00:07:21 +02:00
|
|
|
else DIR_Windows = default_windirW;
|
2004-05-14 23:43:18 +02:00
|
|
|
|
|
|
|
if ((len = GetEnvironmentVariableW( winsysdirW, NULL, 0 )))
|
|
|
|
{
|
|
|
|
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
GetEnvironmentVariableW( winsysdirW, buffer, len );
|
|
|
|
DIR_System = buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-16 00:07:21 +02:00
|
|
|
len = strlenW( DIR_Windows );
|
|
|
|
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) + sizeof(default_sysdirW) );
|
|
|
|
memcpy( buffer, DIR_Windows, len * sizeof(WCHAR) );
|
|
|
|
memcpy( buffer + len, default_sysdirW, sizeof(default_sysdirW) );
|
|
|
|
DIR_System = buffer;
|
2004-05-14 23:43:18 +02:00
|
|
|
}
|
|
|
|
|
2008-04-17 20:33:47 +02:00
|
|
|
if (!CreateDirectoryW( DIR_Windows, NULL ) && GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
ERR( "directory %s could not be created, error %u\n",
|
|
|
|
debugstr_w(DIR_Windows), GetLastError() );
|
|
|
|
if (!CreateDirectoryW( DIR_System, NULL ) && GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
ERR( "directory %s could not be created, error %u\n",
|
|
|
|
debugstr_w(DIR_System), GetLastError() );
|
2004-05-14 23:43:18 +02:00
|
|
|
|
|
|
|
TRACE_(file)( "WindowsDir = %s\n", debugstr_w(DIR_Windows) );
|
|
|
|
TRACE_(file)( "SystemDir = %s\n", debugstr_w(DIR_System) );
|
2004-07-16 00:07:21 +02:00
|
|
|
|
|
|
|
/* set the directories in ntdll too */
|
|
|
|
__wine_init_windows_dir( DIR_Windows, DIR_System );
|
2004-05-14 23:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-04 12:51:04 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* start_wineboot
|
|
|
|
*
|
|
|
|
* Start the wineboot process if necessary. Return the event to wait on.
|
|
|
|
*/
|
|
|
|
static HANDLE start_wineboot(void)
|
|
|
|
{
|
|
|
|
static const WCHAR wineboot_eventW[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
|
|
|
|
HANDLE event;
|
|
|
|
|
|
|
|
if (!(event = CreateEventW( NULL, TRUE, FALSE, wineboot_eventW )))
|
|
|
|
{
|
|
|
|
ERR( "failed to create wineboot event, expect trouble\n" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS) /* we created it */
|
|
|
|
{
|
2008-01-16 19:23:09 +01:00
|
|
|
static const WCHAR command_line[] = {'\\','w','i','n','e','b','o','o','t','.','e','x','e',' ','-','-','i','n','i','t',0};
|
2008-01-04 12:51:04 +01:00
|
|
|
STARTUPINFOW si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
WCHAR cmdline[MAX_PATH + sizeof(command_line)/sizeof(WCHAR)];
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2008-01-04 12:51:04 +01:00
|
|
|
GetSystemDirectoryW( cmdline, MAX_PATH );
|
|
|
|
lstrcatW( cmdline, command_line );
|
|
|
|
if (CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi ))
|
|
|
|
{
|
|
|
|
TRACE( "started wineboot pid %04x tid %04x\n", pi.dwProcessId, pi.dwThreadId );
|
|
|
|
CloseHandle( pi.hThread );
|
|
|
|
CloseHandle( pi.hProcess );
|
|
|
|
|
|
|
|
}
|
|
|
|
else ERR( "failed to start wineboot, err %u\n", GetLastError() );
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* start_process
|
|
|
|
*
|
|
|
|
* Startup routine of a new process. Runs on the new process stack.
|
|
|
|
*/
|
|
|
|
static void start_process( void *arg )
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
2006-07-31 21:25:29 +02:00
|
|
|
PEB *peb = NtCurrentTeb()->Peb;
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
LPTHREAD_START_ROUTINE entry;
|
|
|
|
|
|
|
|
nt = RtlImageNtHeader( peb->ImageBaseAddress );
|
|
|
|
entry = (LPTHREAD_START_ROUTINE)((char *)peb->ImageBaseAddress +
|
|
|
|
nt->OptionalHeader.AddressOfEntryPoint);
|
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
2006-10-12 22:56:29 +02:00
|
|
|
DPRINTF( "%04x:Starting process %s (entryproc=%p)\n", GetCurrentThreadId(),
|
2006-07-31 21:25:29 +02:00
|
|
|
debugstr_w(peb->ProcessParameters->ImagePathName.Buffer), entry );
|
|
|
|
|
|
|
|
SetLastError( 0 ); /* clear error code */
|
|
|
|
if (peb->BeingDebugged) DbgBreakPoint();
|
2006-10-24 16:49:44 +02:00
|
|
|
ExitThread( entry( peb ) );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
__EXCEPT(UnhandledExceptionFilter)
|
|
|
|
{
|
|
|
|
TerminateThread( GetCurrentThread(), GetExceptionCode() );
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2008-01-20 21:23:08 +01:00
|
|
|
#ifdef HAVE_SETPROCTITLE
|
|
|
|
setproctitle("-%s", argv[1]);
|
|
|
|
#endif
|
|
|
|
|
2006-04-06 11:57:37 +02:00
|
|
|
#ifdef HAVE_PRCTL
|
|
|
|
int i, offset;
|
2006-07-19 15:04:57 +02:00
|
|
|
char *p, *prctl_name = argv[1];
|
|
|
|
char *end = argv[argc-1] + strlen(argv[argc-1]) + 1;
|
2006-04-06 11:57:37 +02:00
|
|
|
|
|
|
|
#ifndef PR_SET_NAME
|
|
|
|
# define PR_SET_NAME 15
|
|
|
|
#endif
|
|
|
|
|
2006-07-19 15:04:57 +02:00
|
|
|
if ((p = strrchr( prctl_name, '\\' ))) prctl_name = p + 1;
|
|
|
|
if ((p = strrchr( prctl_name, '/' ))) prctl_name = p + 1;
|
2006-04-06 11:57:37 +02:00
|
|
|
|
2006-07-19 15:04:57 +02:00
|
|
|
if (prctl( PR_SET_NAME, prctl_name ) != -1)
|
2006-04-06 11:57:37 +02:00
|
|
|
{
|
2006-07-19 15:04:57 +02:00
|
|
|
offset = argv[1] - argv[0];
|
|
|
|
memmove( argv[1] - offset, argv[1], end - argv[1] );
|
|
|
|
memset( end - offset, 0, offset );
|
|
|
|
for (i = 1; i < argc; i++) argv[i-1] = argv[i] - offset;
|
|
|
|
argv[i-1] = NULL;
|
2006-04-06 11:57:37 +02:00
|
|
|
}
|
|
|
|
else
|
2006-04-07 11:45:22 +02:00
|
|
|
#endif /* HAVE_PRCTL */
|
2006-04-06 11:57:37 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2003-10-10 02:12:17 +02:00
|
|
|
void __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};
|
|
|
|
static const WCHAR exeW[] = {'.','e','x','e',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;
|
2008-01-04 12:51:04 +01:00
|
|
|
HANDLE boot_event = 0;
|
2008-04-24 11:53:45 +02:00
|
|
|
BOOL got_environment = TRUE;
|
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);
|
|
|
|
|
|
|
|
LOCALE_Init();
|
|
|
|
|
|
|
|
if (!params->Environment)
|
|
|
|
{
|
|
|
|
/* Copy the parent environment */
|
|
|
|
if (!build_initial_environment( __wine_main_environ )) exit(1);
|
|
|
|
|
|
|
|
/* convert old configuration to new format */
|
|
|
|
convert_old_config();
|
|
|
|
|
|
|
|
got_environment = set_registry_environment();
|
|
|
|
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 );
|
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
|
|
|
{
|
2006-07-19 14:12:58 +02:00
|
|
|
if (!SearchPathW( NULL, __wine_main_wargv[0], exeW, MAX_PATH, main_exe_name, NULL ) &&
|
|
|
|
!get_builtin_path( __wine_main_wargv[0], exeW, main_exe_name, MAX_PATH ))
|
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
|
|
|
}
|
2006-07-19 14:12:58 +02:00
|
|
|
if (!build_command_line( __wine_main_wargv )) goto error;
|
2008-01-04 12:51:04 +01:00
|
|
|
boot_event = start_wineboot();
|
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
|
|
|
|
2004-03-26 00:41:04 +01:00
|
|
|
RtlInitUnicodeString( &NtCurrentTeb()->Peb->ProcessParameters->DllPath,
|
2006-02-22 17:02:25 +01:00
|
|
|
MODULE_get_dll_load_path(main_exe_name) );
|
2003-10-02 06:58:49 +02:00
|
|
|
|
2008-05-13 20:26:37 +02:00
|
|
|
if (boot_event)
|
|
|
|
{
|
|
|
|
if (WaitForSingleObject( boot_event, 30000 )) WARN( "boot event wait timed out\n" );
|
|
|
|
CloseHandle( boot_event );
|
|
|
|
/* if we didn't find environment section, try again now that wineboot has run */
|
|
|
|
if (!got_environment)
|
|
|
|
{
|
|
|
|
set_registry_environment();
|
|
|
|
set_additional_environment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2006-02-21 19:48:18 +01:00
|
|
|
FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, msg, sizeof(msg), NULL );
|
|
|
|
MESSAGE( "wine: could not load %s: %s", debugstr_w(main_exe_name), msg );
|
2006-02-22 09:57:19 +01:00
|
|
|
ExitProcess( error );
|
2006-02-21 19:48:18 +01:00
|
|
|
}
|
|
|
|
|
2008-03-26 17:08:38 +01:00
|
|
|
LdrInitializeThunk( 0, 0, 0, 0 );
|
2003-09-17 07:31:32 +02:00
|
|
|
/* switch to the new stack */
|
2008-03-26 17:08:38 +01:00
|
|
|
wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
|
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.
|
|
|
|
*/
|
2003-10-04 06:09:41 +02:00
|
|
|
static char **build_argv( const WCHAR *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;
|
|
|
|
|
|
|
|
len = WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW, -1, NULL, 0, NULL, NULL );
|
2008-10-31 14:02:04 +01:00
|
|
|
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
|
2003-10-04 06:09:41 +02:00
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW, -1, cmdline, len, NULL, NULL );
|
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)) {
|
|
|
|
/* unescaped '"' */
|
|
|
|
in_quotes=!in_quotes;
|
|
|
|
bcount=0;
|
|
|
|
} 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++;
|
|
|
|
in_quotes=!in_quotes;
|
|
|
|
} 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;
|
2003-10-04 06:09:41 +02:00
|
|
|
int count = 0, 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
|
|
|
|
2008-10-31 14:55:33 +01:00
|
|
|
for (i = 0; i < sizeof(unix_vars)/sizeof(unix_vars[0]); i++)
|
|
|
|
{
|
|
|
|
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 */
|
2008-10-31 14:55:33 +01:00
|
|
|
for (i = 0; i < sizeof(unix_vars)/sizeof(unix_vars[0]); i++)
|
|
|
|
{
|
|
|
|
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;
|
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.
|
|
|
|
*/
|
2008-07-10 12:20:56 +02:00
|
|
|
static int fork_and_exec( const char *filename, const WCHAR *cmdline, const WCHAR *env,
|
|
|
|
const char *newdir, DWORD flags, STARTUPINFOW *startup )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2008-07-10 12:20:56 +02:00
|
|
|
int fd[2], stdin_fd = -1, stdout_fd = -1;
|
2003-09-17 07:31:32 +02:00
|
|
|
int pid, err;
|
2008-10-31 14:55:33 +01:00
|
|
|
char **argv, **envp;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if (!env) env = GetEnvironmentStringsW();
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
if (pipe(fd) == -1)
|
|
|
|
{
|
2004-04-17 01:32:40 +02:00
|
|
|
SetLastError( ERROR_TOO_MANY_OPEN_FILES );
|
2003-09-17 07:31:32 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */
|
2008-07-10 12:20:56 +02:00
|
|
|
|
|
|
|
if (!(flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
|
|
|
|
{
|
|
|
|
HANDLE hstdin, hstdout;
|
|
|
|
|
|
|
|
if (startup->dwFlags & STARTF_USESTDHANDLES)
|
|
|
|
{
|
|
|
|
hstdin = startup->hStdInput;
|
|
|
|
hstdout = startup->hStdOutput;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hstdin = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_console_handle( hstdin )) hstdin = console_handle_unmap( hstdin );
|
|
|
|
if (is_console_handle( hstdout )) hstdout = console_handle_unmap( hstdout );
|
|
|
|
wine_server_handle_to_fd( hstdin, FILE_READ_DATA, &stdin_fd, NULL );
|
|
|
|
wine_server_handle_to_fd( hstdout, FILE_WRITE_DATA, &stdout_fd, NULL );
|
|
|
|
}
|
|
|
|
|
2008-10-31 14:02:04 +01:00
|
|
|
argv = build_argv( cmdline, 0 );
|
2008-10-31 14:55:33 +01:00
|
|
|
envp = build_envp( env );
|
2008-10-31 14:02:04 +01:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
if (!(pid = fork())) /* child */
|
|
|
|
{
|
|
|
|
close( fd[0] );
|
|
|
|
|
2008-01-14 15:49:12 +01:00
|
|
|
if (flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS))
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
if (!(pid = fork()))
|
|
|
|
{
|
|
|
|
int fd = open( "/dev/null", O_RDWR );
|
|
|
|
setsid();
|
|
|
|
/* close stdin and stdout */
|
|
|
|
if (fd != -1)
|
|
|
|
{
|
|
|
|
dup2( fd, 0 );
|
|
|
|
dup2( fd, 1 );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pid != -1) _exit(0); /* parent */
|
|
|
|
}
|
2008-07-10 12:20:56 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (stdin_fd != -1)
|
|
|
|
{
|
|
|
|
dup2( stdin_fd, 0 );
|
|
|
|
close( stdin_fd );
|
|
|
|
}
|
|
|
|
if (stdout_fd != -1)
|
|
|
|
{
|
|
|
|
dup2( stdout_fd, 1 );
|
|
|
|
close( stdout_fd );
|
|
|
|
}
|
|
|
|
}
|
2006-03-06 22:22:30 +01:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/* Reset signals that we previously set to SIG_IGN */
|
|
|
|
signal( SIGPIPE, SIG_DFL );
|
|
|
|
signal( SIGCHLD, SIG_DFL );
|
|
|
|
|
|
|
|
if (newdir) chdir(newdir);
|
|
|
|
|
|
|
|
if (argv && envp) execve( filename, argv, envp );
|
|
|
|
err = errno;
|
|
|
|
write( fd[1], &err, sizeof(err) );
|
|
|
|
_exit(1);
|
|
|
|
}
|
2008-10-31 14:02:04 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, argv );
|
2008-10-31 14:55:33 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, envp );
|
2008-07-10 12:20:56 +02:00
|
|
|
if (stdin_fd != -1) close( stdin_fd );
|
|
|
|
if (stdout_fd != -1) close( stdout_fd );
|
2003-09-17 07:31:32 +02:00
|
|
|
close( fd[1] );
|
|
|
|
if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0)) /* exec failed */
|
|
|
|
{
|
|
|
|
errno = err;
|
|
|
|
pid = -1;
|
|
|
|
}
|
|
|
|
if (pid == -1) FILE_SetDosError();
|
|
|
|
close( fd[0] );
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* create_user_params
|
|
|
|
*/
|
|
|
|
static RTL_USER_PROCESS_PARAMETERS *create_user_params( LPCWSTR filename, LPCWSTR cmdline,
|
2006-02-05 12:20:40 +01:00
|
|
|
LPCWSTR cur_dir, LPWSTR env, DWORD flags,
|
2004-07-16 05:54:35 +02:00
|
|
|
const STARTUPINFOW *startup )
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
2007-12-21 12:42:28 +01:00
|
|
|
UNICODE_STRING image_str, cmdline_str, curdir_str, desktop, title, runtime, newdir;
|
2003-10-04 06:09:41 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2004-02-05 02:23:42 +01:00
|
|
|
if(!GetLongPathNameW( filename, buffer, MAX_PATH ))
|
|
|
|
lstrcpynW( buffer, filename, MAX_PATH );
|
|
|
|
if(!GetFullPathNameW( buffer, MAX_PATH, buffer, NULL ))
|
|
|
|
lstrcpynW( buffer, filename, MAX_PATH );
|
|
|
|
RtlInitUnicodeString( &image_str, buffer );
|
2003-10-04 06:09:41 +02:00
|
|
|
|
|
|
|
RtlInitUnicodeString( &cmdline_str, cmdline );
|
2007-12-21 12:42:28 +01:00
|
|
|
newdir.Buffer = NULL;
|
|
|
|
if (cur_dir)
|
|
|
|
{
|
|
|
|
if (RtlDosPathNameToNtPathName_U( cur_dir, &newdir, NULL, NULL ))
|
|
|
|
{
|
|
|
|
/* skip \??\ prefix */
|
|
|
|
curdir_str.Buffer = newdir.Buffer + 4;
|
|
|
|
curdir_str.Length = newdir.Length - 4 * sizeof(WCHAR);
|
2007-12-23 13:54:31 +01:00
|
|
|
curdir_str.MaximumLength = newdir.MaximumLength - 4 * sizeof(WCHAR);
|
2007-12-21 12:42:28 +01:00
|
|
|
}
|
|
|
|
else cur_dir = NULL;
|
|
|
|
}
|
2003-10-04 06:09:41 +02:00
|
|
|
if (startup->lpDesktop) RtlInitUnicodeString( &desktop, startup->lpDesktop );
|
|
|
|
if (startup->lpTitle) RtlInitUnicodeString( &title, startup->lpTitle );
|
2004-09-03 03:05:30 +02:00
|
|
|
if (startup->lpReserved2 && startup->cbReserved2)
|
|
|
|
{
|
2004-10-25 23:47:23 +02:00
|
|
|
runtime.Length = 0;
|
|
|
|
runtime.MaximumLength = startup->cbReserved2;
|
2004-09-03 03:05:30 +02:00
|
|
|
runtime.Buffer = (WCHAR*)startup->lpReserved2;
|
|
|
|
}
|
2003-10-04 06:09:41 +02:00
|
|
|
|
2004-05-14 07:03:29 +02:00
|
|
|
status = RtlCreateProcessParameters( ¶ms, &image_str, NULL,
|
|
|
|
cur_dir ? &curdir_str : NULL,
|
2004-07-16 05:54:35 +02:00
|
|
|
&cmdline_str, env,
|
2003-10-04 06:09:41 +02:00
|
|
|
startup->lpTitle ? &title : NULL,
|
|
|
|
startup->lpDesktop ? &desktop : NULL,
|
2004-09-03 03:05:30 +02:00
|
|
|
NULL,
|
|
|
|
(startup->lpReserved2 && startup->cbReserved2) ? &runtime : NULL );
|
2007-12-21 12:42:28 +01:00
|
|
|
RtlFreeUnicodeString( &newdir );
|
2003-10-04 06:09:41 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-02-05 12:20:40 +01:00
|
|
|
if (flags & CREATE_NEW_PROCESS_GROUP) params->ConsoleFlags = 1;
|
2006-02-05 12:24:43 +01:00
|
|
|
if (flags & CREATE_NEW_CONSOLE) params->ConsoleHandle = (HANDLE)1; /* FIXME: cf. kernel_main.c */
|
2006-02-05 12:20:40 +01:00
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
if (startup->dwFlags & STARTF_USESTDHANDLES)
|
|
|
|
{
|
|
|
|
params->hStdInput = startup->hStdInput;
|
|
|
|
params->hStdOutput = startup->hStdOutput;
|
|
|
|
params->hStdError = startup->hStdError;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
params->hStdInput = GetStdHandle( STD_INPUT_HANDLE );
|
|
|
|
params->hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
|
|
|
|
params->hStdError = GetStdHandle( STD_ERROR_HANDLE );
|
|
|
|
}
|
2003-10-04 06:09:41 +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;
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2003-10-04 06:09:41 +02:00
|
|
|
static BOOL create_process( HANDLE hFile, LPCWSTR filename, LPWSTR cmd_line, LPWSTR env,
|
2004-05-14 07:03:29 +02:00
|
|
|
LPCWSTR cur_dir, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
2003-10-04 06:09:41 +02:00
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
2004-06-03 02:25:08 +02:00
|
|
|
LPPROCESS_INFORMATION info, LPCSTR unixdir,
|
2006-07-19 14:12:58 +02:00
|
|
|
void *res_start, void *res_end, int exec_only )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
BOOL ret, success = FALSE;
|
2008-07-10 12:20:56 +02:00
|
|
|
HANDLE process_info, hstdin, hstdout;
|
2004-07-16 05:54:35 +02:00
|
|
|
WCHAR *env_end;
|
2005-10-04 20:09:51 +02:00
|
|
|
char *winedebug = NULL;
|
2008-10-31 14:02:04 +01:00
|
|
|
char **argv;
|
2003-10-04 06:09:41 +02:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
2008-07-10 12:20:56 +02:00
|
|
|
int socketfd[2], stdin_fd = -1, stdout_fd = -1;
|
2003-09-17 07:31:32 +02:00
|
|
|
pid_t pid;
|
|
|
|
int err;
|
|
|
|
|
2004-07-16 05:54:35 +02:00
|
|
|
if (!env) RtlAcquirePebLock();
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2006-02-05 12:20:40 +01:00
|
|
|
if (!(params = create_user_params( filename, cmd_line, cur_dir, env, flags, startup )))
|
2004-07-16 05:54:35 +02:00
|
|
|
{
|
|
|
|
if (!env) RtlReleasePebLock();
|
2003-10-04 06:09:41 +02:00
|
|
|
return FALSE;
|
2004-07-16 05:54:35 +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};
|
|
|
|
if (!winedebug && !strncmpW( env_end, WINEDEBUG, sizeof(WINEDEBUG)/sizeof(WCHAR) - 1 ))
|
|
|
|
{
|
|
|
|
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
|
|
|
/* create the socket for the new process */
|
2004-06-03 02:25:08 +02:00
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
if (socketpair( PF_UNIX, SOCK_STREAM, 0, socketfd ) == -1)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2004-07-16 05:54:35 +02:00
|
|
|
if (!env) RtlReleasePebLock();
|
2005-10-04 20:09:51 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, winedebug );
|
2003-10-04 06:09:41 +02:00
|
|
|
RtlDestroyProcessParameters( params );
|
2004-04-17 01:32:40 +02:00
|
|
|
SetLastError( ERROR_TOO_MANY_OPEN_FILES );
|
2003-09-17 07:31:32 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
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 */
|
|
|
|
|
|
|
|
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];
|
|
|
|
req->exe_file = hFile;
|
|
|
|
req->process_access = PROCESS_ALL_ACCESS;
|
|
|
|
req->process_attr = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
req->thread_access = THREAD_ALL_ACCESS;
|
|
|
|
req->thread_attr = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle) ? OBJ_INHERIT : 0;
|
|
|
|
req->hstdin = params->hStdInput;
|
|
|
|
req->hstdout = params->hStdOutput;
|
|
|
|
req->hstderr = params->hStdError;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
if ((flags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS)) != 0)
|
|
|
|
{
|
|
|
|
/* this is temporary (for console handles). We have no way to control that the handle is invalid in child process otherwise */
|
|
|
|
if (is_console_handle(req->hstdin)) req->hstdin = INVALID_HANDLE_VALUE;
|
|
|
|
if (is_console_handle(req->hstdout)) req->hstdout = INVALID_HANDLE_VALUE;
|
|
|
|
if (is_console_handle(req->hstderr)) req->hstderr = INVALID_HANDLE_VALUE;
|
2008-07-10 12:20:56 +02:00
|
|
|
hstdin = hstdout = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_console_handle(req->hstdin)) req->hstdin = console_handle_unmap(req->hstdin);
|
|
|
|
if (is_console_handle(req->hstdout)) req->hstdout = console_handle_unmap(req->hstdout);
|
|
|
|
if (is_console_handle(req->hstderr)) req->hstderr = console_handle_unmap(req->hstderr);
|
2008-07-10 12:20:56 +02:00
|
|
|
hstdin = req->hstdin;
|
|
|
|
hstdout = req->hstdout;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
wine_server_add_data( req, params, params->Size );
|
2004-07-16 05:54:35 +02:00
|
|
|
wine_server_add_data( req, params->Environment, (env_end-params->Environment)*sizeof(WCHAR) );
|
2006-07-19 14:00:10 +02:00
|
|
|
if ((ret = !wine_server_call_err( req )))
|
|
|
|
{
|
|
|
|
info->dwProcessId = (DWORD)reply->pid;
|
|
|
|
info->dwThreadId = (DWORD)reply->tid;
|
|
|
|
info->hProcess = reply->phandle;
|
|
|
|
info->hThread = reply->thandle;
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
process_info = reply->info;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2003-06-27 06:08:04 +02:00
|
|
|
|
2004-07-16 05:54:35 +02:00
|
|
|
if (!env) RtlReleasePebLock();
|
2003-10-04 06:09:41 +02:00
|
|
|
RtlDestroyProcessParameters( params );
|
2003-09-17 07:31:32 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
2006-07-19 14:00:10 +02:00
|
|
|
close( socketfd[0] );
|
|
|
|
HeapFree( GetProcessHeap(), 0, winedebug );
|
2003-09-17 07:31:32 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-10 12:20:56 +02:00
|
|
|
if (hstdin) wine_server_handle_to_fd( hstdin, FILE_READ_DATA, &stdin_fd, NULL );
|
|
|
|
if (hstdout) wine_server_handle_to_fd( hstdout, FILE_WRITE_DATA, &stdout_fd, NULL );
|
|
|
|
|
2006-07-19 14:00:10 +02:00
|
|
|
/* create the child process */
|
2008-10-31 14:02:04 +01:00
|
|
|
argv = build_argv( cmd_line, 1 );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
if (exec_only || !(pid = fork())) /* child */
|
2006-07-19 14:00:10 +02:00
|
|
|
{
|
|
|
|
char preloader_reserve[64], socket_env[64];
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2008-01-14 15:49:12 +01:00
|
|
|
if (flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS))
|
|
|
|
{
|
|
|
|
if (!(pid = fork()))
|
|
|
|
{
|
|
|
|
int fd = open( "/dev/null", O_RDWR );
|
|
|
|
setsid();
|
|
|
|
/* close stdin and stdout */
|
|
|
|
if (fd != -1)
|
|
|
|
{
|
|
|
|
dup2( fd, 0 );
|
|
|
|
dup2( fd, 1 );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pid != -1) _exit(0); /* parent */
|
|
|
|
}
|
2008-07-10 12:20:56 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (stdin_fd != -1) dup2( stdin_fd, 0 );
|
|
|
|
if (stdout_fd != -1) dup2( stdout_fd, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stdin_fd != -1) close( stdin_fd );
|
|
|
|
if (stdout_fd != -1) close( stdout_fd );
|
2006-07-19 14:00:10 +02:00
|
|
|
|
|
|
|
/* Reset signals that we previously set to SIG_IGN */
|
|
|
|
signal( SIGPIPE, SIG_DFL );
|
|
|
|
signal( SIGCHLD, SIG_DFL );
|
|
|
|
|
|
|
|
sprintf( socket_env, "WINESERVERSOCKET=%u", socketfd[0] );
|
|
|
|
sprintf( preloader_reserve, "WINEPRELOADRESERVE=%lx-%lx",
|
|
|
|
(unsigned long)res_start, (unsigned long)res_end );
|
|
|
|
|
|
|
|
putenv( preloader_reserve );
|
|
|
|
putenv( socket_env );
|
|
|
|
if (winedebug) putenv( winedebug );
|
|
|
|
if (unixdir) chdir(unixdir);
|
|
|
|
|
|
|
|
if (argv) wine_exec_wine_binary( NULL, argv, getenv("WINELOADER") );
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the parent */
|
|
|
|
|
2008-07-10 12:20:56 +02:00
|
|
|
if (stdin_fd != -1) close( stdin_fd );
|
|
|
|
if (stdout_fd != -1) close( stdout_fd );
|
2006-07-19 14:00:10 +02:00
|
|
|
close( socketfd[0] );
|
2008-10-31 14:02:04 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, argv );
|
2006-07-19 14:00:10 +02:00
|
|
|
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 )
|
|
|
|
{
|
2006-07-19 14:00:10 +02:00
|
|
|
req->info = process_info;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* create_vdm_process
|
|
|
|
*
|
|
|
|
* Create a new VDM process for a 16-bit or DOS application.
|
|
|
|
*/
|
2004-05-14 07:03:29 +02:00
|
|
|
static BOOL create_vdm_process( LPCWSTR filename, LPWSTR cmd_line, LPWSTR env, LPCWSTR cur_dir,
|
2003-09-17 07:31:32 +02:00
|
|
|
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
2003-10-04 06:09:41 +02:00
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
2006-07-19 14:12:58 +02:00
|
|
|
LPPROCESS_INFORMATION info, LPCSTR unixdir, int exec_only )
|
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};
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
BOOL ret;
|
2003-10-04 06:09:41 +02:00
|
|
|
LPWSTR new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(strlenW(filename) + strlenW(cmd_line) + 30) * sizeof(WCHAR) );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
if (!new_cmd_line)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-10-04 06:09:41 +02:00
|
|
|
sprintfW( new_cmd_line, argsW, winevdmW, filename, cmd_line );
|
2004-05-14 07:03:29 +02:00
|
|
|
ret = create_process( 0, winevdmW, new_cmd_line, env, cur_dir, psa, tsa, inherit,
|
2006-07-19 14:12:58 +02:00
|
|
|
flags, startup, info, unixdir, NULL, NULL, exec_only );
|
2003-09-17 07:31:32 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, new_cmd_line );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* create_cmd_process
|
|
|
|
*
|
|
|
|
* Create a new cmd shell process for a .BAT file.
|
|
|
|
*/
|
2004-05-14 07:03:29 +02:00
|
|
|
static BOOL create_cmd_process( LPCWSTR filename, LPWSTR cmd_line, LPVOID env, LPCWSTR cur_dir,
|
2003-10-04 06:09:41 +02:00
|
|
|
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
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};
|
|
|
|
static const WCHAR slashcW[] = {' ','/','c',' ',0};
|
|
|
|
WCHAR comspec[MAX_PATH];
|
|
|
|
WCHAR *newcmdline;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!GetEnvironmentVariableW( comspecW, comspec, sizeof(comspec)/sizeof(WCHAR) ))
|
|
|
|
return FALSE;
|
|
|
|
if (!(newcmdline = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(strlenW(comspec) + 4 + strlenW(cmd_line) + 1) * sizeof(WCHAR))))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strcpyW( newcmdline, comspec );
|
|
|
|
strcatW( newcmdline, slashcW );
|
|
|
|
strcatW( newcmdline, cmd_line );
|
|
|
|
ret = CreateProcessW( comspec, newcmdline, psa, tsa, inherit,
|
|
|
|
flags, env, cur_dir, startup, info );
|
|
|
|
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,
|
|
|
|
int buflen, HANDLE *handle )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
static const WCHAR quotesW[] = {'"','%','s','"',0};
|
|
|
|
|
|
|
|
WCHAR *name, *pos, *ret = NULL;
|
|
|
|
const WCHAR *p;
|
2005-12-19 21:25:23 +01:00
|
|
|
BOOL got_space;
|
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 );
|
2003-09-17 07:31:32 +02:00
|
|
|
*handle = open_exe_file( buffer );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cmdline)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (find_exe_file( name, buffer, buflen, handle ))
|
|
|
|
ret = cmdline; /* no change necessary */
|
|
|
|
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;
|
2005-12-19 21:25:23 +01:00
|
|
|
got_space = FALSE;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
while (*p)
|
|
|
|
{
|
2005-12-19 21:25:23 +01:00
|
|
|
do *pos++ = *p++; while (*p && *p != ' ' && *p != '\t');
|
2003-09-17 07:31:32 +02:00
|
|
|
*pos = 0;
|
|
|
|
if (find_exe_file( name, buffer, buflen, handle ))
|
|
|
|
{
|
|
|
|
ret = cmdline;
|
|
|
|
break;
|
|
|
|
}
|
2005-12-19 21:25:23 +01:00
|
|
|
if (*p) got_space = TRUE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
2005-12-19 21:25:23 +01:00
|
|
|
if (ret && got_space) /* now build a new command-line with quotes */
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI 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 )
|
2003-10-04 06:09:41 +02:00
|
|
|
{
|
2004-05-13 22:21:25 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
WCHAR *app_nameW = NULL, *cmd_lineW = NULL, *cur_dirW = NULL;
|
|
|
|
UNICODE_STRING desktopW, titleW;
|
2003-10-04 06:09:41 +02:00
|
|
|
STARTUPINFOW infoW;
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
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;
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
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));
|
|
|
|
|
2004-05-13 22:21:25 +02:00
|
|
|
ret = CreateProcessW( app_nameW, cmd_lineW, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dirW, &infoW, info );
|
|
|
|
done:
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, app_nameW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmd_lineW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, cur_dirW );
|
2003-10-04 06:09:41 +02:00
|
|
|
RtlFreeUnicodeString( &desktopW );
|
|
|
|
RtlFreeUnicodeString( &titleW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CreateProcessW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI 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 )
|
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];
|
|
|
|
WCHAR *tidy_cmdline, *p, *envW = env;
|
2004-06-03 02:25:08 +02:00
|
|
|
void *res_start, *res_end;
|
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
|
|
|
|
2005-10-10 12:28:48 +02:00
|
|
|
if (!(tidy_cmdline = get_file_name( app_name, cmd_line, name, sizeof(name)/sizeof(WCHAR), &hFile )))
|
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
|
|
|
}
|
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
if (env && !(flags & CREATE_UNICODE_ENVIRONMENT)) /* convert environment to unicode */
|
|
|
|
{
|
|
|
|
char *p = env;
|
|
|
|
DWORD lenW;
|
|
|
|
|
|
|
|
while (*p) p += strlen(p) + 1;
|
|
|
|
p++; /* final null */
|
|
|
|
lenW = MultiByteToWideChar( CP_ACP, 0, env, p - (char*)env, NULL, 0 );
|
|
|
|
envW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, env, p - (char*)env, envW, lenW );
|
|
|
|
flags |= CREATE_UNICODE_ENVIRONMENT;
|
|
|
|
}
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
info->hThread = info->hProcess = 0;
|
|
|
|
info->dwProcessId = info->dwThreadId = 0;
|
|
|
|
|
|
|
|
/* Determine executable type */
|
|
|
|
|
|
|
|
if (!hFile) /* builtin exe */
|
|
|
|
{
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "starting %s as Winelib app\n", debugstr_w(name) );
|
2004-05-14 07:03:29 +02:00
|
|
|
retv = create_process( 0, name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
|
2006-07-19 14:12:58 +02:00
|
|
|
inherit, flags, startup_info, info, unixdir, NULL, NULL, FALSE );
|
2003-09-17 07:31:32 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:25:08 +02:00
|
|
|
switch( MODULE_GetBinaryType( hFile, &res_start, &res_end ))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
case BINARY_PE_EXE:
|
2004-06-03 02:25:08 +02:00
|
|
|
TRACE( "starting %s as Win32 binary (%p-%p)\n", debugstr_w(name), res_start, res_end );
|
2004-05-14 07:03:29 +02:00
|
|
|
retv = create_process( hFile, name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
|
2006-07-19 14:12:58 +02:00
|
|
|
inherit, flags, startup_info, info, unixdir, res_start, res_end, FALSE );
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
2004-09-10 23:16:02 +02:00
|
|
|
case BINARY_OS216:
|
2003-09-17 07:31:32 +02:00
|
|
|
case BINARY_WIN16:
|
|
|
|
case BINARY_DOS:
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "starting %s as Win16/DOS binary\n", debugstr_w(name) );
|
2004-05-14 07:03:29 +02:00
|
|
|
retv = create_vdm_process( name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
|
2006-07-19 14:12:58 +02:00
|
|
|
inherit, flags, startup_info, info, unixdir, FALSE );
|
2003-09-17 07:31:32 +02:00
|
|
|
break;
|
|
|
|
case BINARY_PE_DLL:
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "not starting %s since it is a dll\n", debugstr_w(name) );
|
2003-09-17 07:31:32 +02:00
|
|
|
SetLastError( ERROR_BAD_EXE_FORMAT );
|
|
|
|
break;
|
|
|
|
case BINARY_UNIX_LIB:
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_w(name) );
|
2004-05-14 07:03:29 +02:00
|
|
|
retv = create_process( hFile, name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
|
2006-07-19 14:12:58 +02:00
|
|
|
inherit, flags, startup_info, info, unixdir, NULL, NULL, FALSE );
|
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) );
|
2004-05-14 07:03:29 +02:00
|
|
|
retv = create_vdm_process( name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
|
2006-07-19 14:12:58 +02:00
|
|
|
inherit, flags, startup_info, info, unixdir, FALSE );
|
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) );
|
2004-05-14 07:03:29 +02:00
|
|
|
retv = create_cmd_process( name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
|
|
|
|
inherit, flags, startup_info, info );
|
2003-10-04 06:09:41 +02:00
|
|
|
break;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case BINARY_UNIX_EXE:
|
|
|
|
{
|
|
|
|
/* unknown file, try as unix executable */
|
2004-04-14 21:40:53 +02:00
|
|
|
char *unix_name;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-04 06:09:41 +02:00
|
|
|
TRACE( "starting %s as Unix binary\n", debugstr_w(name) );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2004-04-14 21:40:53 +02:00
|
|
|
if ((unix_name = wine_get_unix_file_name( name )))
|
|
|
|
{
|
2008-07-10 12:20:56 +02:00
|
|
|
retv = (fork_and_exec( unix_name, tidy_cmdline, envW, unixdir, flags, startup_info ) != -1);
|
2004-04-14 21:40:53 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, unix_name );
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CloseHandle( hFile );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (tidy_cmdline != cmd_line) HeapFree( GetProcessHeap(), 0, tidy_cmdline );
|
2003-10-04 06:09:41 +02:00
|
|
|
if (envW != env) HeapFree( GetProcessHeap(), 0, envW );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-19 14:12:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* exec_process
|
|
|
|
*/
|
|
|
|
static void exec_process( LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
WCHAR *p;
|
|
|
|
void *res_start, *res_end;
|
|
|
|
STARTUPINFOW startup_info;
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
|
|
|
|
hFile = open_exe_file( name );
|
|
|
|
if (!hFile || hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
memset( &startup_info, 0, sizeof(startup_info) );
|
|
|
|
startup_info.cb = sizeof(startup_info);
|
|
|
|
|
|
|
|
/* Determine executable type */
|
|
|
|
|
|
|
|
switch( MODULE_GetBinaryType( hFile, &res_start, &res_end ))
|
|
|
|
{
|
|
|
|
case BINARY_PE_EXE:
|
|
|
|
TRACE( "starting %s as Win32 binary (%p-%p)\n", debugstr_w(name), res_start, res_end );
|
|
|
|
create_process( hFile, name, GetCommandLineW(), NULL, NULL, NULL, NULL,
|
|
|
|
FALSE, 0, &startup_info, &info, NULL, res_start, res_end, TRUE );
|
|
|
|
break;
|
|
|
|
case BINARY_UNIX_LIB:
|
|
|
|
TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_w(name) );
|
|
|
|
create_process( hFile, name, GetCommandLineW(), NULL, NULL, NULL, NULL,
|
|
|
|
FALSE, 0, &startup_info, &info, NULL, NULL, NULL, TRUE );
|
|
|
|
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_OS216:
|
|
|
|
case BINARY_WIN16:
|
|
|
|
case BINARY_DOS:
|
|
|
|
TRACE( "starting %s as Win16/DOS binary\n", debugstr_w(name) );
|
|
|
|
create_vdm_process( name, GetCommandLineW(), NULL, NULL, NULL, NULL,
|
|
|
|
FALSE, 0, &startup_info, &info, NULL, TRUE );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CloseHandle( hFile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.@)
|
|
|
|
*/
|
|
|
|
UINT WINAPI WinExec( LPCSTR lpCmdLine, UINT nCmdShow )
|
|
|
|
{
|
|
|
|
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.@)
|
|
|
|
*/
|
|
|
|
HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
|
|
|
|
{
|
2003-11-17 21:16:38 +01:00
|
|
|
LOADPARMS32 *params = paramBlock;
|
2003-09-17 07:31:32 +02:00
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
HINSTANCE hInstance;
|
|
|
|
LPSTR cmdline, p;
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
BYTE len;
|
|
|
|
|
|
|
|
if (!name) return (HINSTANCE)ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!SearchPathA( NULL, name, ".exe", sizeof(filename), filename, NULL ) &&
|
|
|
|
!SearchPathA( NULL, name, NULL, sizeof(filename), filename, NULL ))
|
2007-05-23 09:36:53 +02:00
|
|
|
return ULongToHandle(GetLastError());
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
len = (BYTE)params->lpCmdLine[0];
|
|
|
|
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + len + 2 )))
|
|
|
|
return (HINSTANCE)ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
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() );
|
2003-09-17 07:31:32 +02:00
|
|
|
hInstance = (HINSTANCE)33;
|
|
|
|
/* Close off the handles */
|
|
|
|
CloseHandle( info.hThread );
|
|
|
|
CloseHandle( info.hProcess );
|
|
|
|
}
|
2007-05-23 09:36:53 +02:00
|
|
|
else if ((hInstance = ULongToHandle(GetLastError())) >= (HINSTANCE)32)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
|
|
|
FIXME("Strange error set by CreateProcess: %p\n", hInstance );
|
|
|
|
hInstance = (HINSTANCE)11;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
|
|
|
return hInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TerminateProcess (KERNEL32.@)
|
2006-03-31 13:33:04 +02:00
|
|
|
*
|
|
|
|
* Terminates a process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* handle [I] Process to terminate.
|
|
|
|
* exit_code [I] Exit code.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, check GetLastError().
|
2003-09-17 07:31:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtTerminateProcess( handle, exit_code );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
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__
|
|
|
|
__ASM_GLOBAL_FUNC( ExitProcess, /* Shrinker depend on this particular ExitProcess implementation */
|
|
|
|
"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"
|
|
|
|
"call " __ASM_NAME("process_ExitProcess") "\n\t"
|
|
|
|
"leave\n\t"
|
|
|
|
"ret $4" )
|
|
|
|
|
|
|
|
void WINAPI process_ExitProcess( DWORD status )
|
|
|
|
{
|
|
|
|
LdrShutdownProcess();
|
|
|
|
NtTerminateProcess(GetCurrentProcess(), status);
|
|
|
|
exit(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2003-10-08 05:57:02 +02:00
|
|
|
void WINAPI ExitProcess( DWORD status )
|
|
|
|
{
|
|
|
|
LdrShutdownProcess();
|
2005-09-06 11:25:19 +02:00
|
|
|
NtTerminateProcess(GetCurrentProcess(), status);
|
|
|
|
exit(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
|
|
|
NTSTATUS status;
|
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi,
|
|
|
|
sizeof(pbi), NULL);
|
|
|
|
if (status == STATUS_SUCCESS)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2004-06-14 19:02:00 +02:00
|
|
|
if (lpExitCode) *lpExitCode = pbi.ExitStatus;
|
|
|
|
return TRUE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2004-06-14 19:02:00 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetErrorMode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
UINT WINAPI SetErrorMode( UINT mode )
|
|
|
|
{
|
2003-10-09 21:58:56 +02:00
|
|
|
UINT old = process_error_mode;
|
|
|
|
process_error_mode = mode;
|
2003-09-17 07:31:32 +02:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2005-12-21 20:44:49 +01:00
|
|
|
* TlsAlloc [KERNEL32.@]
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
2005-12-21 20:44:49 +01:00
|
|
|
* Allocates a thread local storage index.
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-12-21 20:44:49 +01:00
|
|
|
* Success: TLS index.
|
2003-09-17 07:31:32 +02:00
|
|
|
* Failure: 0xFFFFFFFF
|
|
|
|
*/
|
|
|
|
DWORD WINAPI TlsAlloc( void )
|
|
|
|
{
|
2003-10-09 21:58:56 +02:00
|
|
|
DWORD index;
|
2005-03-19 18:14:12 +01:00
|
|
|
PEB * const peb = NtCurrentTeb()->Peb;
|
2003-10-09 21:58:56 +02:00
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
RtlAcquirePebLock();
|
2005-03-19 18:14:12 +01:00
|
|
|
index = RtlFindClearBitsAndSet( peb->TlsBitmap, 1, 0 );
|
2005-09-13 17:00:32 +02:00
|
|
|
if (index != ~0U) NtCurrentTeb()->TlsSlots[index] = 0; /* clear the value */
|
2005-03-19 18:14:12 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
index = RtlFindClearBitsAndSet( peb->TlsExpansionBitmap, 1, 0 );
|
2005-09-13 17:00:32 +02:00
|
|
|
if (index != ~0U)
|
2005-03-19 18:14:12 +01:00
|
|
|
{
|
|
|
|
if (!NtCurrentTeb()->TlsExpansionSlots &&
|
|
|
|
!(NtCurrentTeb()->TlsExpansionSlots = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
8 * sizeof(peb->TlsExpansionBitmapBits) * sizeof(void*) )))
|
|
|
|
{
|
|
|
|
RtlClearBits( peb->TlsExpansionBitmap, index, 1 );
|
2005-09-13 17:00:32 +02:00
|
|
|
index = ~0U;
|
2005-03-19 18:14:12 +01:00
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NtCurrentTeb()->TlsExpansionSlots[index] = 0; /* clear the value */
|
|
|
|
index += TLS_MINIMUM_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else SetLastError( ERROR_NO_MORE_ITEMS );
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
RtlReleasePebLock();
|
2003-10-09 21:58:56 +02:00
|
|
|
return index;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2005-12-21 20:44:49 +01:00
|
|
|
* TlsFree [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Releases a thread local storage index, making it available for reuse.
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
2005-12-21 20:44:49 +01:00
|
|
|
* PARAMS
|
|
|
|
* index [in] TLS index to free.
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2005-12-21 20:44:49 +01:00
|
|
|
BOOL WINAPI TlsFree( DWORD index )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-09 21:58:56 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
RtlAcquirePebLock();
|
2005-03-19 18:14:12 +01:00
|
|
|
if (index >= TLS_MINIMUM_AVAILABLE)
|
|
|
|
{
|
|
|
|
ret = RtlAreBitsSet( NtCurrentTeb()->Peb->TlsExpansionBitmap, index - TLS_MINIMUM_AVAILABLE, 1 );
|
|
|
|
if (ret) RtlClearBits( NtCurrentTeb()->Peb->TlsExpansionBitmap, index - TLS_MINIMUM_AVAILABLE, 1 );
|
|
|
|
}
|
|
|
|
else
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-03-19 18:14:12 +01:00
|
|
|
ret = RtlAreBitsSet( NtCurrentTeb()->Peb->TlsBitmap, index, 1 );
|
|
|
|
if (ret) RtlClearBits( NtCurrentTeb()->Peb->TlsBitmap, index, 1 );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2005-03-19 18:14:12 +01:00
|
|
|
if (ret) NtSetInformationThread( GetCurrentThread(), ThreadZeroTlsCell, &index, sizeof(index) );
|
2003-10-09 21:58:56 +02:00
|
|
|
else SetLastError( ERROR_INVALID_PARAMETER );
|
2003-09-17 07:31:32 +02:00
|
|
|
RtlReleasePebLock();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2005-12-21 20:44:49 +01:00
|
|
|
* TlsGetValue [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Gets value in a thread's TLS slot.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* index [in] TLS index to retrieve value for.
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-12-21 20:44:49 +01:00
|
|
|
* Success: Value stored in calling thread's TLS slot for index.
|
|
|
|
* Failure: 0 and GetLastError() returns NO_ERROR.
|
2003-09-17 07:31:32 +02:00
|
|
|
*/
|
2005-12-21 20:44:49 +01:00
|
|
|
LPVOID WINAPI TlsGetValue( DWORD index )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-03-19 18:14:12 +01:00
|
|
|
LPVOID ret;
|
|
|
|
|
|
|
|
if (index < TLS_MINIMUM_AVAILABLE)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-03-19 18:14:12 +01:00
|
|
|
ret = NtCurrentTeb()->TlsSlots[index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index -= TLS_MINIMUM_AVAILABLE;
|
|
|
|
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!NtCurrentTeb()->TlsExpansionSlots) ret = NULL;
|
|
|
|
else ret = NtCurrentTeb()->TlsExpansionSlots[index];
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
SetLastError( ERROR_SUCCESS );
|
2005-03-19 18:14:12 +01:00
|
|
|
return ret;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2005-12-21 20:44:49 +01:00
|
|
|
* TlsSetValue [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Stores a value in the thread's TLS slot.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* index [in] TLS index to set value for.
|
|
|
|
* value [in] Value to be stored.
|
2003-09-17 07:31:32 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2005-12-21 20:44:49 +01:00
|
|
|
BOOL WINAPI TlsSetValue( DWORD index, LPVOID value )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-03-19 18:14:12 +01:00
|
|
|
if (index < TLS_MINIMUM_AVAILABLE)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-03-19 18:14:12 +01:00
|
|
|
NtCurrentTeb()->TlsSlots[index] = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index -= TLS_MINIMUM_AVAILABLE;
|
|
|
|
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!NtCurrentTeb()->TlsExpansionSlots &&
|
|
|
|
!(NtCurrentTeb()->TlsExpansionSlots = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits) * sizeof(void*) )))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
NtCurrentTeb()->TlsExpansionSlots[index] = value;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessDword (KERNEL.485)
|
|
|
|
* GetProcessDword (KERNEL32.18)
|
|
|
|
* 'Of course you cannot directly access Windows internal structures'
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
|
|
|
|
{
|
|
|
|
DWORD x, y;
|
|
|
|
STARTUPINFOW siw;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%d, %d)\n", dwProcessID, offset );
|
2003-06-27 06:08:04 +02:00
|
|
|
|
|
|
|
if (dwProcessID && dwProcessID != GetCurrentProcessId())
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
ERR("%d: process %x not accessible\n", offset, dwProcessID);
|
2003-06-27 06:08:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( offset )
|
|
|
|
{
|
|
|
|
case GPD_APP_COMPAT_FLAGS:
|
|
|
|
return GetAppCompatFlags16(0);
|
|
|
|
case GPD_LOAD_DONE_EVENT:
|
|
|
|
return 0;
|
|
|
|
case GPD_HINSTANCE16:
|
|
|
|
return GetTaskDS16();
|
|
|
|
case GPD_WINDOWS_VERSION:
|
|
|
|
return GetExeVersion16();
|
|
|
|
case GPD_THDB:
|
2007-05-23 09:36:53 +02:00
|
|
|
return (DWORD_PTR)NtCurrentTeb() - 0x10 /* FIXME */;
|
2003-06-27 06:08:04 +02:00
|
|
|
case GPD_PDB:
|
2007-05-23 09:36:53 +02:00
|
|
|
return (DWORD_PTR)NtCurrentTeb()->Peb; /* FIXME: truncating a pointer */
|
2003-06-27 06:08:04 +02:00
|
|
|
case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
|
|
|
|
GetStartupInfoW(&siw);
|
2007-05-23 09:36:53 +02:00
|
|
|
return HandleToULong(siw.hStdOutput);
|
2003-06-27 06:08:04 +02:00
|
|
|
case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
|
|
|
|
GetStartupInfoW(&siw);
|
2007-05-23 09:36:53 +02:00
|
|
|
return HandleToULong(siw.hStdInput);
|
2003-06-27 06:08:04 +02:00
|
|
|
case GPD_STARTF_SHOWWINDOW:
|
|
|
|
GetStartupInfoW(&siw);
|
|
|
|
return siw.wShowWindow;
|
|
|
|
case GPD_STARTF_SIZE:
|
|
|
|
GetStartupInfoW(&siw);
|
|
|
|
x = siw.dwXSize;
|
|
|
|
if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
|
|
|
|
y = siw.dwYSize;
|
|
|
|
if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
|
|
|
|
return MAKELONG( x, y );
|
|
|
|
case GPD_STARTF_POSITION:
|
|
|
|
GetStartupInfoW(&siw);
|
|
|
|
x = siw.dwX;
|
|
|
|
if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
|
|
|
|
y = siw.dwY;
|
|
|
|
if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
|
|
|
|
return MAKELONG( x, y );
|
|
|
|
case GPD_STARTF_FLAGS:
|
|
|
|
GetStartupInfoW(&siw);
|
|
|
|
return siw.dwFlags;
|
|
|
|
case GPD_PARENT:
|
|
|
|
return 0;
|
|
|
|
case GPD_FLAGS:
|
|
|
|
return GetProcessFlags(0);
|
|
|
|
case GPD_USERDATA:
|
|
|
|
return process_dword;
|
|
|
|
default:
|
|
|
|
ERR("Unknown offset %d\n", offset );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessDword (KERNEL.484)
|
|
|
|
* 'Of course you cannot directly access Windows internal structures'
|
|
|
|
*/
|
|
|
|
void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%d, %d)\n", dwProcessID, offset );
|
2003-06-27 06:08:04 +02:00
|
|
|
|
|
|
|
if (dwProcessID && dwProcessID != GetCurrentProcessId())
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
ERR("%d: process %x not accessible\n", offset, dwProcessID);
|
2003-06-27 06:08:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( offset )
|
|
|
|
{
|
|
|
|
case GPD_APP_COMPAT_FLAGS:
|
|
|
|
case GPD_LOAD_DONE_EVENT:
|
|
|
|
case GPD_HINSTANCE16:
|
|
|
|
case GPD_WINDOWS_VERSION:
|
|
|
|
case GPD_THDB:
|
|
|
|
case GPD_PDB:
|
|
|
|
case GPD_STARTF_SHELLDATA:
|
|
|
|
case GPD_STARTF_HOTKEY:
|
|
|
|
case GPD_STARTF_SHOWWINDOW:
|
|
|
|
case GPD_STARTF_SIZE:
|
|
|
|
case GPD_STARTF_POSITION:
|
|
|
|
case GPD_STARTF_FLAGS:
|
|
|
|
case GPD_PARENT:
|
|
|
|
case GPD_FLAGS:
|
|
|
|
ERR("Not allowed to modify offset %d\n", offset );
|
|
|
|
break;
|
|
|
|
case GPD_USERDATA:
|
|
|
|
process_dword = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unknown offset %d\n", offset );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ExitProcess (KERNEL.466)
|
|
|
|
*/
|
|
|
|
void WINAPI ExitProcess16( WORD status )
|
|
|
|
{
|
|
|
|
DWORD count;
|
|
|
|
ReleaseThunkLock( &count );
|
|
|
|
ExitProcess( status );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* OpenProcess (KERNEL32.@)
|
2006-03-31 13:33:04 +02:00
|
|
|
*
|
|
|
|
* Opens a handle to a process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* access [I] Desired access rights assigned to the returned handle.
|
|
|
|
* inherit [I] Determines whether or not child processes will inherit the handle.
|
|
|
|
* id [I] Process identifier of the process to get a handle to.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Valid handle to the specified process.
|
|
|
|
* Failure: NULL, check GetLastError().
|
2003-06-27 06:08:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
|
|
|
|
{
|
2005-06-27 13:12:11 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
CLIENT_ID cid;
|
|
|
|
|
2007-05-23 09:36:53 +02:00
|
|
|
cid.UniqueProcess = ULongToHandle(id);
|
2005-06-27 13:12:11 +02:00
|
|
|
cid.UniqueThread = 0; /* FIXME ? */
|
|
|
|
|
|
|
|
attr.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
|
|
attr.RootDirectory = NULL;
|
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
|
2006-03-31 15:02:05 +02:00
|
|
|
if (GetVersion() & 0x80000000) access = PROCESS_ALL_ACCESS;
|
|
|
|
|
2005-06-27 13:12:11 +02:00
|
|
|
status = NtOpenProcess(&handle, access, &attr, &cid);
|
|
|
|
if (status != STATUS_SUCCESS)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2005-06-27 13:12:11 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return NULL;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
2005-06-27 13:12:11 +02:00
|
|
|
return handle;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MapProcessHandle (KERNEL.483)
|
2004-08-24 20:46:05 +02:00
|
|
|
* GetProcessId (KERNEL32.@)
|
2006-03-31 13:33:04 +02:00
|
|
|
*
|
|
|
|
* Gets the a unique identifier of a process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProcess [I] Handle to the process.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, check GetLastError().
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* The identifier is unique only on the machine and only until the process
|
|
|
|
* exits (including system shutdown).
|
2003-06-27 06:08:04 +02:00
|
|
|
*/
|
2004-08-24 20:46:05 +02:00
|
|
|
DWORD WINAPI GetProcessId( HANDLE hProcess )
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2004-06-14 19:02:00 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi,
|
|
|
|
sizeof(pbi), NULL);
|
|
|
|
if (status == STATUS_SUCCESS) return pbi.UniqueProcessId;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 06:24:49 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* CloseW32Handle (KERNEL.474)
|
|
|
|
* CloseHandle (KERNEL32.@)
|
2006-03-31 13:33:04 +02:00
|
|
|
*
|
|
|
|
* Closes a handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* handle [I] Handle to close.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, check GetLastError().
|
2003-10-08 06:24:49 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CloseHandle( HANDLE handle )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
/* stdio handles need special treatment */
|
|
|
|
if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
|
|
|
|
(handle == (HANDLE)STD_OUTPUT_HANDLE) ||
|
|
|
|
(handle == (HANDLE)STD_ERROR_HANDLE))
|
2007-05-23 09:36:53 +02:00
|
|
|
handle = GetStdHandle( HandleToULong(handle) );
|
2003-10-08 06:24:49 +02:00
|
|
|
|
|
|
|
if (is_console_handle(handle))
|
|
|
|
return CloseConsoleHandle(handle);
|
|
|
|
|
|
|
|
status = NtClose( handle );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* GetHandleInformation (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
|
|
|
|
{
|
2005-08-23 20:20:59 +02:00
|
|
|
OBJECT_DATA_INFORMATION info;
|
|
|
|
NTSTATUS status = NtQueryObject( handle, ObjectDataInformation, &info, sizeof(info), NULL );
|
|
|
|
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
else if (flags)
|
2003-10-08 06:24:49 +02:00
|
|
|
{
|
2005-08-23 20:20:59 +02:00
|
|
|
*flags = 0;
|
|
|
|
if (info.InheritHandle) *flags |= HANDLE_FLAG_INHERIT;
|
|
|
|
if (info.ProtectFromClose) *flags |= HANDLE_FLAG_PROTECT_FROM_CLOSE;
|
2003-10-08 06:24:49 +02:00
|
|
|
}
|
2005-08-23 20:20:59 +02:00
|
|
|
return !status;
|
2003-10-08 06:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* SetHandleInformation (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
|
|
|
|
{
|
2005-08-23 20:20:59 +02:00
|
|
|
OBJECT_DATA_INFORMATION info;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
/* if not setting both fields, retrieve current value first */
|
|
|
|
if ((mask & (HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE)) !=
|
|
|
|
(HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE))
|
2003-10-08 06:24:49 +02:00
|
|
|
{
|
2005-08-23 20:20:59 +02:00
|
|
|
if ((status = NtQueryObject( handle, ObjectDataInformation, &info, sizeof(info), NULL )))
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-10-08 06:24:49 +02:00
|
|
|
}
|
2005-08-23 20:20:59 +02:00
|
|
|
if (mask & HANDLE_FLAG_INHERIT)
|
|
|
|
info.InheritHandle = (flags & HANDLE_FLAG_INHERIT) != 0;
|
|
|
|
if (mask & HANDLE_FLAG_PROTECT_FROM_CLOSE)
|
|
|
|
info.ProtectFromClose = (flags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0;
|
|
|
|
|
|
|
|
status = NtSetInformationObject( handle, ObjectDataInformation, &info, sizeof(info) );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-10-08 06:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* DuplicateHandle (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
|
|
|
|
HANDLE dest_process, HANDLE *dest,
|
|
|
|
DWORD access, BOOL inherit, DWORD options )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (is_console_handle(source))
|
|
|
|
{
|
|
|
|
/* FIXME: this test is not sufficient, we need to test process ids, not handles */
|
|
|
|
if (source_process != dest_process ||
|
|
|
|
source_process != GetCurrentProcess())
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*dest = DuplicateConsoleHandle( source, access, inherit, options );
|
|
|
|
return (*dest != INVALID_HANDLE_VALUE);
|
|
|
|
}
|
|
|
|
status = NtDuplicateObject( source_process, source, dest_process, dest,
|
|
|
|
access, inherit ? OBJ_INHERIT : 0, options );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ConvertToGlobalHandle (KERNEL.476)
|
|
|
|
* 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
|
|
|
/***********************************************************************
|
|
|
|
* SetPriorityClass (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
|
|
|
|
{
|
2005-09-06 12:25:11 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
PROCESS_PRIORITY_CLASS ppc;
|
|
|
|
|
|
|
|
ppc.Foreground = FALSE;
|
|
|
|
switch (priorityclass)
|
|
|
|
{
|
|
|
|
case IDLE_PRIORITY_CLASS:
|
|
|
|
ppc.PriorityClass = PROCESS_PRIOCLASS_IDLE; break;
|
|
|
|
case BELOW_NORMAL_PRIORITY_CLASS:
|
|
|
|
ppc.PriorityClass = PROCESS_PRIOCLASS_BELOW_NORMAL; break;
|
|
|
|
case NORMAL_PRIORITY_CLASS:
|
|
|
|
ppc.PriorityClass = PROCESS_PRIOCLASS_NORMAL; break;
|
|
|
|
case ABOVE_NORMAL_PRIORITY_CLASS:
|
|
|
|
ppc.PriorityClass = PROCESS_PRIOCLASS_ABOVE_NORMAL; break;
|
|
|
|
case HIGH_PRIORITY_CLASS:
|
|
|
|
ppc.PriorityClass = PROCESS_PRIOCLASS_HIGH; break;
|
|
|
|
case REALTIME_PRIORITY_CLASS:
|
|
|
|
ppc.PriorityClass = PROCESS_PRIOCLASS_REALTIME; break;
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = NtSetInformationProcess(hprocess, ProcessPriorityClass,
|
|
|
|
&ppc, sizeof(ppc));
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2005-09-06 12:25:11 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
2005-09-06 12:25:11 +02:00
|
|
|
return TRUE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetPriorityClass (KERNEL32.@)
|
|
|
|
*/
|
2004-06-14 19:02:00 +02:00
|
|
|
DWORD WINAPI GetPriorityClass(HANDLE hProcess)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2004-06-14 19:02:00 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi,
|
|
|
|
sizeof(pbi), NULL);
|
2005-09-06 12:25:11 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (pbi.BasePriority)
|
|
|
|
{
|
|
|
|
case PROCESS_PRIOCLASS_IDLE: return IDLE_PRIORITY_CLASS;
|
|
|
|
case PROCESS_PRIOCLASS_BELOW_NORMAL: return BELOW_NORMAL_PRIORITY_CLASS;
|
|
|
|
case PROCESS_PRIOCLASS_NORMAL: return NORMAL_PRIORITY_CLASS;
|
|
|
|
case PROCESS_PRIOCLASS_ABOVE_NORMAL: return ABOVE_NORMAL_PRIORITY_CLASS;
|
|
|
|
case PROCESS_PRIOCLASS_HIGH: return HIGH_PRIORITY_CLASS;
|
|
|
|
case PROCESS_PRIOCLASS_REALTIME: return REALTIME_PRIORITY_CLASS;
|
|
|
|
}
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2004-06-14 19:02:00 +02:00
|
|
|
return 0;
|
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
|
|
|
{
|
2005-09-27 12:52:10 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtSetInformationProcess(hProcess, ProcessAffinityMask,
|
|
|
|
&affmask, sizeof(DWORD_PTR));
|
2008-06-19 11:44:41 +02:00
|
|
|
if (status)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2005-09-27 12:52:10 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
2005-09-27 12:52:10 +02:00
|
|
|
return TRUE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetProcessAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
|
2005-09-27 12:52:10 +02:00
|
|
|
PDWORD_PTR lpProcessAffinityMask,
|
|
|
|
PDWORD_PTR lpSystemAffinityMask )
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2005-09-27 12:52:10 +02:00
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(hProcess,
|
|
|
|
ProcessBasicInformation,
|
|
|
|
&pbi, sizeof(pbi), NULL);
|
|
|
|
if (status)
|
2003-06-27 06:08:04 +02:00
|
|
|
{
|
2005-09-27 12:52:10 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
2005-09-27 12:52:10 +02:00
|
|
|
if (lpProcessAffinityMask) *lpProcessAffinityMask = pbi.AffinityMask;
|
2008-01-16 21:01:33 +01:00
|
|
|
if (lpSystemAffinityMask) *lpSystemAffinityMask = (1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
|
2005-09-27 12:52:10 +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
|
|
|
{
|
2008-10-15 16:44:54 +02:00
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
|
|
|
|
if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
|
|
|
|
return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
|
|
|
|
nt->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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessWorkingSetSize [KERNEL32.@]
|
|
|
|
* Sets the min/max working set sizes for a specified process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hProcess [I] Handle to the process of interest
|
|
|
|
* minset [I] Specifies minimum working set size
|
|
|
|
* maxset [I] Specifies maximum working set size
|
|
|
|
*
|
2004-12-15 11:48:18 +01:00
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2003-06-27 06:08:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
|
|
|
|
SIZE_T maxset)
|
|
|
|
{
|
2006-11-16 09:37:40 +01:00
|
|
|
WARN("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
|
2003-06-27 06:08:04 +02:00
|
|
|
if(( minset == (SIZE_T)-1) && (maxset == (SIZE_T)-1)) {
|
|
|
|
/* Trim the working set to zero */
|
|
|
|
/* Swap the process out of physical RAM */
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessWorkingSetSize (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess, PSIZE_T minset,
|
|
|
|
PSIZE_T maxset)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p): stub\n",hProcess,minset,maxset);
|
|
|
|
/* 32 MB working set size */
|
|
|
|
if (minset) *minset = 32*1024*1024;
|
|
|
|
if (maxset) *maxset = 32*1024*1024;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessShutdownParameters (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME("(%08x, %08x): partial stub.\n", level, flags);
|
2003-06-27 06:08:04 +02:00
|
|
|
shutdown_flags = flags;
|
|
|
|
shutdown_priority = level;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessShutdownParameters (KERNEL32.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
|
|
|
|
{
|
|
|
|
*lpdwLevel = shutdown_priority;
|
|
|
|
*lpdwFlags = shutdown_flags;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessPriorityBoost (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessPriorityBoost(HANDLE hprocess,PBOOL pDisablePriorityBoost)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p): semi-stub\n", hprocess, pDisablePriorityBoost);
|
|
|
|
|
|
|
|
/* Report that no boost is present.. */
|
|
|
|
*pDisablePriorityBoost = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessPriorityBoost (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%d): stub\n",hprocess,disableboost);
|
|
|
|
/* Say we can do it. I doubt the program will notice that we don't. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReadProcessMemory (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, SIZE_T size,
|
|
|
|
SIZE_T *bytes_read )
|
|
|
|
{
|
2003-07-08 23:18:45 +02:00
|
|
|
NTSTATUS status = NtReadVirtualMemory( process, addr, buffer, size, bytes_read );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WriteProcessMemory (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPCVOID buffer, SIZE_T size,
|
|
|
|
SIZE_T *bytes_written )
|
|
|
|
{
|
2003-07-08 23:18:45 +02:00
|
|
|
NTSTATUS status = NtWriteVirtualMemory( process, addr, buffer, size, bytes_written );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-06-27 06:08:04 +02:00
|
|
|
}
|
|
|
|
|
2003-09-24 07:26:00 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* FlushInstructionCache (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize)
|
|
|
|
{
|
2004-08-04 20:15:04 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
status = NtFlushInstructionCache( hProcess, lpBaseAddress, dwSize );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-09-24 07:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 02:06:45 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetProcessIoCounters (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessIoCounters(HANDLE hProcess, PIO_COUNTERS ioc)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessIoCounters,
|
|
|
|
ioc, sizeof(*ioc), NULL);
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
2007-11-01 07:46:54 +01:00
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetProcessHandleCount (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessHandleCount(HANDLE hProcess, DWORD *cnt)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess(hProcess, ProcessHandleCount,
|
|
|
|
cnt, sizeof(*cnt), NULL);
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
2003-09-19 02:06:45 +02:00
|
|
|
return !status;
|
|
|
|
}
|
2003-06-27 06:08:04 +02:00
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
/* According to MSDN, if the calling process is not in a terminal
|
|
|
|
* services environment, then the sessionid returned is zero.
|
|
|
|
*/
|
|
|
|
*sessionid_ptr = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-27 06:08:04 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RegisterServiceProcess (KERNEL.491)
|
|
|
|
* 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 */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-11 15:42:19 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* IsWow64Process (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsWow64Process(HANDLE hProcess, PBOOL Wow64Process)
|
|
|
|
{
|
2008-03-21 16:36:01 +01:00
|
|
|
ULONG pbi;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess( hProcess, ProcessWow64Information, &pbi, sizeof(pbi), NULL );
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError( status ) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*Wow64Process = (pbi != 0);
|
2006-08-11 15:42:19 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-27 06:08:04 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
#undef GetCurrentProcess
|
|
|
|
HANDLE WINAPI GetCurrentProcess(void)
|
|
|
|
{
|
|
|
|
return (HANDLE)0xffffffff;
|
|
|
|
}
|
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;
|
|
|
|
}
|