2003-06-27 04:08:04 +00: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2004-03-09 23:51:02 +00:00
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-06-27 04:08:04 +00:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "wine/winuser16.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "ntstatus.h"
|
2003-08-28 19:57:35 +00:00
|
|
|
#include "thread.h"
|
2003-09-17 05:31:32 +00:00
|
|
|
#include "file.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "kernel_private.h"
|
2003-11-27 00:59:36 +00:00
|
|
|
#include "wine/exception.h"
|
2003-06-27 04:08:04 +00:00
|
|
|
#include "wine/server.h"
|
2003-10-04 04:09:41 +00:00
|
|
|
#include "wine/unicode.h"
|
2003-06-27 04:08:04 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(process);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(server);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
|
|
|
|
2003-11-17 20:16:38 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
LPSTR lpEnvAddress;
|
|
|
|
LPSTR lpCmdLine;
|
|
|
|
LPSTR lpCmdShow;
|
|
|
|
DWORD dwReserved;
|
|
|
|
} LOADPARMS32;
|
|
|
|
|
2003-10-09 19:58:56 +00:00
|
|
|
static UINT process_error_mode;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
static HANDLE main_exe_file;
|
|
|
|
static DWORD shutdown_flags = 0;
|
|
|
|
static DWORD shutdown_priority = 0x280;
|
|
|
|
static DWORD process_dword;
|
|
|
|
static BOOL oem_file_apis;
|
|
|
|
|
2003-10-08 03:57:02 +00:00
|
|
|
static unsigned int server_startticks;
|
2003-09-17 05:31:32 +00:00
|
|
|
int main_create_flags = 0;
|
2004-02-12 00:00:55 +00:00
|
|
|
HMODULE kernel32_handle = 0;
|
2003-09-17 05:31:32 +00: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 00:31:52 +00:00
|
|
|
static const WCHAR comW[] = {'.','c','o','m',0};
|
|
|
|
static const WCHAR batW[] = {'.','b','a','t',0};
|
2003-10-04 04:09:41 +00:00
|
|
|
static const WCHAR winevdmW[] = {'w','i','n','e','v','d','m','.','e','x','e',0};
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
extern void SHELL_LoadRegistry(void);
|
2003-10-04 04:09:41 +00:00
|
|
|
extern void VERSION_Init( const WCHAR *appname );
|
2003-10-02 04:58:49 +00:00
|
|
|
extern void MODULE_InitLoadPath(void);
|
2003-10-14 05:32:30 +00:00
|
|
|
extern void LOCALE_Init(void);
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
2003-10-04 04:09:41 +00:00
|
|
|
* contains_path
|
2003-09-17 05:31:32 +00:00
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
inline static int contains_path( LPCWSTR name )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
return ((*name && (name[1] == ':')) || strchrW(name, '/') || strchrW(name, '\\'));
|
|
|
|
}
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2004-03-11 00:49:01 +00: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").
|
|
|
|
*/
|
|
|
|
inline static int is_special_env_var( const char *var )
|
|
|
|
{
|
|
|
|
return (!memcmp( var, "PATH=", sizeof("PATH=")-1 ) ||
|
|
|
|
!memcmp( var, "TEMP=", sizeof("TEMP=")-1 ) ||
|
|
|
|
!memcmp( var, "TMP=", sizeof("TMP=")-1 ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 04:09:41 +00: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;
|
|
|
|
WCHAR sysdir[MAX_PATH];
|
|
|
|
UINT len = GetSystemDirectoryW( sysdir, MAX_PATH );
|
|
|
|
|
|
|
|
if (contains_path( libname ))
|
|
|
|
{
|
|
|
|
if (RtlGetFullPathName_U( libname, size * sizeof(WCHAR),
|
|
|
|
filename, &file_part ) > size * sizeof(WCHAR))
|
|
|
|
return FALSE; /* too long */
|
|
|
|
|
|
|
|
if (strncmpiW( filename, sysdir, len ) || filename[len] != '\\')
|
|
|
|
return FALSE;
|
|
|
|
while (filename[len] == '\\') len++;
|
2003-11-17 20:18:19 +00:00
|
|
|
if (filename + len != file_part) return FALSE;
|
2003-10-04 04:09:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strlenW(libname) + len + 2 >= size) return FALSE; /* too long */
|
|
|
|
memcpy( filename, sysdir, len * sizeof(WCHAR) );
|
|
|
|
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 05:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* open_builtin_exe_file
|
|
|
|
*
|
|
|
|
* Open an exe file for a builtin exe.
|
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
static void *open_builtin_exe_file( const WCHAR *name, char *error, int error_size,
|
2003-09-17 05:31:32 +00:00
|
|
|
int test_only, int *file_exists )
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
char exename[MAX_PATH];
|
|
|
|
WCHAR *p;
|
|
|
|
UINT i, len;
|
|
|
|
|
|
|
|
if ((p = strrchrW( name, '/' ))) name = p + 1;
|
|
|
|
if ((p = strrchrW( name, '\\' ))) name = p + 1;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-04 04:09:41 +00: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 05:31:32 +00: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 04:09:41 +00:00
|
|
|
static HANDLE open_exe_file( const WCHAR *name )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
enum loadorder_type loadorder[LOADORDER_NTYPES];
|
2003-10-04 04:09:41 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2003-09-17 05:31:32 +00:00
|
|
|
HANDLE handle;
|
|
|
|
int i, file_exists;
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE("looking for %s\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if ((handle = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ,
|
2003-09-17 05:31:32 +00:00
|
|
|
NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
/* file doesn't exist, check for builtin */
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!contains_path( name )) goto error;
|
|
|
|
if (!get_builtin_path( name, NULL, buffer, sizeof(buffer) )) goto error;
|
2003-09-17 05:31:32 +00:00
|
|
|
name = buffer;
|
|
|
|
}
|
|
|
|
|
2003-11-25 01:03:04 +00:00
|
|
|
MODULE_GetLoadOrderW( loadorder, NULL, name );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
for(i = 0; i < LOADORDER_NTYPES; i++)
|
|
|
|
{
|
|
|
|
if (loadorder[i] == LOADORDER_INVALID) break;
|
|
|
|
switch(loadorder[i])
|
|
|
|
{
|
|
|
|
case LOADORDER_DLL:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "Trying native exe %s\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
if (handle != INVALID_HANDLE_VALUE) return handle;
|
|
|
|
break;
|
|
|
|
case LOADORDER_BI:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "Trying built-in exe %s\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
open_builtin_exe_file( name, NULL, 0, 1, &file_exists );
|
|
|
|
if (file_exists)
|
|
|
|
{
|
|
|
|
if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
|
|
|
|
|
|
|
|
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 04:09:41 +00:00
|
|
|
static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE *handle )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
static const WCHAR exeW[] = {'.','e','x','e',0};
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
enum loadorder_type loadorder[LOADORDER_NTYPES];
|
|
|
|
int i, file_exists;
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE("looking for %s\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!SearchPathW( NULL, name, exeW, buflen, buffer, NULL ) &&
|
|
|
|
!get_builtin_path( name, exeW, buffer, buflen ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
/* no builtin found, try native without extension in case it is a Unix app */
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (SearchPathW( NULL, name, NULL, buflen, buffer, NULL ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "Trying native/Unix binary %s\n", debugstr_w(buffer) );
|
|
|
|
if ((*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ,
|
2003-09-17 05:31:32 +00:00
|
|
|
NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-25 01:03:04 +00:00
|
|
|
MODULE_GetLoadOrderW( loadorder, NULL, buffer );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
for(i = 0; i < LOADORDER_NTYPES; i++)
|
|
|
|
{
|
|
|
|
if (loadorder[i] == LOADORDER_INVALID) break;
|
|
|
|
switch(loadorder[i])
|
|
|
|
{
|
|
|
|
case LOADORDER_DLL:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "Trying native exe %s\n", debugstr_w(buffer) );
|
|
|
|
if ((*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ,
|
2003-09-17 05:31:32 +00:00
|
|
|
NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
|
|
|
|
return TRUE;
|
|
|
|
if (GetLastError() != ERROR_FILE_NOT_FOUND) return TRUE;
|
|
|
|
break;
|
|
|
|
case LOADORDER_BI:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "Trying built-in exe %s\n", debugstr_w(buffer) );
|
2003-09-17 05:31:32 +00:00
|
|
|
open_builtin_exe_file( buffer, NULL, 0, 1, &file_exists );
|
|
|
|
if (file_exists)
|
|
|
|
{
|
|
|
|
*handle = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 04:04:57 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* load_pe_exe
|
|
|
|
*
|
|
|
|
* Load a PE format EXE file.
|
|
|
|
*/
|
2003-10-06 21:18:51 +00:00
|
|
|
static HMODULE load_pe_exe( const WCHAR *name, HANDLE file )
|
2003-09-19 04:04:57 +00:00
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
HANDLE mapping;
|
|
|
|
void *module;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
DWORD len = 0;
|
2003-10-06 21:18:51 +00:00
|
|
|
UINT drive_type;
|
2003-09-19 04:04:57 +00:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
size.QuadPart = 0;
|
|
|
|
|
|
|
|
if (NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ,
|
|
|
|
&attr, &size, 0, SEC_IMAGE, file ) != STATUS_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
module = NULL;
|
|
|
|
if (NtMapViewOfSection( mapping, GetCurrentProcess(), &module, 0, 0, &size, &len,
|
|
|
|
ViewShare, 0, PAGE_READONLY ) != STATUS_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
NtClose( mapping );
|
|
|
|
|
|
|
|
/* virus check */
|
|
|
|
nt = RtlImageNtHeader( module );
|
|
|
|
if (nt->OptionalHeader.AddressOfEntryPoint)
|
|
|
|
{
|
|
|
|
if (!RtlImageRvaToSection( nt, module, nt->OptionalHeader.AddressOfEntryPoint ))
|
2003-10-06 21:18:51 +00:00
|
|
|
MESSAGE("VIRUS WARNING: PE module %s has an invalid entrypoint (0x%08lx) "
|
2003-09-19 04:04:57 +00:00
|
|
|
"outside all sections (possibly infected by Tchernobyl/SpaceFiller virus)!\n",
|
2003-10-06 21:18:51 +00:00
|
|
|
debugstr_w(name), nt->OptionalHeader.AddressOfEntryPoint );
|
2003-09-19 04:04:57 +00:00
|
|
|
}
|
2003-10-06 21:18:51 +00:00
|
|
|
|
|
|
|
drive_type = GetDriveTypeW( name );
|
|
|
|
/* don't keep the file handle open on removable media */
|
|
|
|
if (drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_CDROM)
|
|
|
|
{
|
|
|
|
CloseHandle( main_exe_file );
|
|
|
|
main_exe_file = 0;
|
|
|
|
}
|
|
|
|
|
2003-09-19 04:04:57 +00:00
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
/***********************************************************************
|
2003-10-10 23:33:21 +00:00
|
|
|
* build_initial_environment
|
2003-10-04 04:09:41 +00:00
|
|
|
*
|
|
|
|
* Build the Win32 environment from the Unix environment
|
|
|
|
*/
|
2003-10-10 23:33:21 +00:00
|
|
|
static BOOL build_initial_environment( char **environ )
|
2003-10-04 04:09:41 +00:00
|
|
|
{
|
|
|
|
ULONG size = 1;
|
|
|
|
char **e;
|
|
|
|
WCHAR *p, *endptr;
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
/* Compute the total size of the Unix environment */
|
|
|
|
for (e = environ; *e; e++)
|
|
|
|
{
|
2004-03-11 00:49:01 +00:00
|
|
|
if (is_special_env_var( *e )) continue;
|
2003-10-04 04:09:41 +00:00
|
|
|
size += MultiByteToWideChar( CP_UNIXCP, 0, *e, -1, NULL, 0 );
|
|
|
|
}
|
|
|
|
size *= sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* Now allocate the environment */
|
|
|
|
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 00:49:01 +00:00
|
|
|
|
|
|
|
/* skip Unix special variables and use the Wine variants instead */
|
|
|
|
if (!memcmp( str, "WINE", 4 ))
|
|
|
|
{
|
|
|
|
if (is_special_env_var( str + 4 )) str += 4;
|
|
|
|
}
|
|
|
|
else if (is_special_env_var( str )) continue; /* skip it */
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, str, -1, p, endptr - p );
|
|
|
|
p += strlenW(p) + 1;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 22:38:52 +00:00
|
|
|
/***********************************************************************
|
2003-10-10 00:12:17 +00:00
|
|
|
* set_library_wargv
|
2003-10-08 22:38:52 +00:00
|
|
|
*
|
2003-10-10 00:12:17 +00:00
|
|
|
* Set the Wine library Unicode argv global variables.
|
2003-10-08 22:38:52 +00:00
|
|
|
*/
|
2003-10-10 00:12:17 +00:00
|
|
|
static void set_library_wargv( char **argv )
|
2003-10-08 22:38:52 +00:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
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;
|
|
|
|
__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=='"') {
|
|
|
|
/* doubling of '\' preceeding a '"',
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/* Double all the '\\' preceeding this '"', plus one */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
/* make sure the unicode string doesn't point beyond the end pointer */
|
|
|
|
static inline void fix_unicode_string( UNICODE_STRING *str, char *end_ptr )
|
|
|
|
{
|
|
|
|
if ((char *)str->Buffer >= end_ptr)
|
|
|
|
{
|
|
|
|
str->Length = str->MaximumLength = 0;
|
|
|
|
str->Buffer = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((char *)str->Buffer + str->MaximumLength > end_ptr)
|
|
|
|
{
|
|
|
|
str->MaximumLength = (end_ptr - (char *)str->Buffer) & ~(sizeof(WCHAR) - 1);
|
|
|
|
}
|
|
|
|
if (str->Length >= str->MaximumLength)
|
|
|
|
{
|
|
|
|
if (str->MaximumLength >= sizeof(WCHAR))
|
|
|
|
str->Length = str->MaximumLength - sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
str->Length = str->MaximumLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* init_user_process_params
|
|
|
|
*
|
|
|
|
* Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
|
|
|
|
*/
|
|
|
|
static RTL_USER_PROCESS_PARAMETERS *init_user_process_params( size_t info_size )
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
DWORD size;
|
|
|
|
NTSTATUS status;
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
|
|
|
|
|
|
|
size = info_size;
|
|
|
|
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, NULL, &size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE )) != STATUS_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_startup_info )
|
|
|
|
{
|
|
|
|
wine_server_set_reply( req, ptr, info_size );
|
|
|
|
wine_server_call( req );
|
|
|
|
info_size = wine_server_reply_size( reply );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
params = ptr;
|
|
|
|
params->Size = info_size;
|
|
|
|
params->AllocationSize = size;
|
|
|
|
|
|
|
|
/* make sure the strings are valid */
|
|
|
|
fix_unicode_string( ¶ms->CurrentDirectoryName, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->DllPath, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->ImagePathName, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->CommandLine, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->WindowTitle, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->Desktop, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->ShellInfo, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->RuntimeInfo, (char *)info_size );
|
|
|
|
|
|
|
|
return RtlNormalizeProcessParams( params );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* process_init
|
|
|
|
*
|
|
|
|
* Main process initialisation code
|
|
|
|
*/
|
2003-10-10 23:33:21 +00:00
|
|
|
static BOOL process_init( char *argv[], char **environ )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2004-02-12 00:00:55 +00:00
|
|
|
static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0};
|
2003-09-17 05:31:32 +00:00
|
|
|
BOOL ret;
|
|
|
|
size_t info_size = 0;
|
2003-10-09 04:59:03 +00:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
2003-10-09 19:58:56 +00:00
|
|
|
PEB *peb = NtCurrentTeb()->Peb;
|
2003-10-04 04:09:41 +00:00
|
|
|
HANDLE hstdin, hstdout, hstderr;
|
2004-01-08 03:36:53 +00:00
|
|
|
extern void __wine_dbg_kernel32_init(void);
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2004-01-07 04:50:11 +00:00
|
|
|
PTHREAD_Init();
|
|
|
|
|
2004-01-08 03:36:53 +00:00
|
|
|
__wine_dbg_kernel32_init(); /* hack: register debug channels early */
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
setbuf(stdout,NULL);
|
|
|
|
setbuf(stderr,NULL);
|
|
|
|
setlocale(LC_CTYPE,"");
|
|
|
|
|
|
|
|
/* Retrieve startup info from the server */
|
|
|
|
SERVER_START_REQ( init_process )
|
|
|
|
{
|
2003-10-14 01:30:42 +00:00
|
|
|
req->peb = peb;
|
|
|
|
req->ldt_copy = &wine_ldt_copy;
|
2003-09-17 05:31:32 +00:00
|
|
|
if ((ret = !wine_server_call_err( req )))
|
|
|
|
{
|
|
|
|
main_exe_file = reply->exe_file;
|
|
|
|
main_create_flags = reply->create_flags;
|
|
|
|
info_size = reply->info_size;
|
|
|
|
server_startticks = reply->server_start;
|
2003-10-04 04:09:41 +00:00
|
|
|
hstdin = reply->hstdin;
|
|
|
|
hstdout = reply->hstdout;
|
|
|
|
hstderr = reply->hstderr;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (!ret) return FALSE;
|
|
|
|
|
|
|
|
if (info_size == 0)
|
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
params = peb->ProcessParameters;
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
/* This is wine specific: we have no parent (we're started from unix)
|
2003-09-17 05:31:32 +00:00
|
|
|
* so, create a simple console with bare handles to unix stdio
|
|
|
|
* input & output streams (aka simple console)
|
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, TRUE, ¶ms->hStdInput );
|
|
|
|
wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, ¶ms->hStdOutput );
|
|
|
|
wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, TRUE, ¶ms->hStdError );
|
|
|
|
|
|
|
|
/* <hack: to be changed later on> */
|
|
|
|
params->CurrentDirectoryName.Length = 3 * sizeof(WCHAR);
|
|
|
|
params->CurrentDirectoryName.MaximumLength = RtlGetLongestNtPathLength() * sizeof(WCHAR);
|
|
|
|
params->CurrentDirectoryName.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, params->CurrentDirectoryName.MaximumLength);
|
|
|
|
params->CurrentDirectoryName.Buffer[0] = 'C';
|
|
|
|
params->CurrentDirectoryName.Buffer[1] = ':';
|
|
|
|
params->CurrentDirectoryName.Buffer[2] = '\\';
|
|
|
|
params->CurrentDirectoryName.Buffer[3] = '\0';
|
|
|
|
/* </hack: to be changed later on> */
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!(params = init_user_process_params( info_size ))) return FALSE;
|
2003-10-09 19:58:56 +00:00
|
|
|
peb->ProcessParameters = params;
|
2003-10-04 04:09:41 +00:00
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/* convert value from server:
|
|
|
|
* + 0 => INVALID_HANDLE_VALUE
|
|
|
|
* + console handle need to be mapped
|
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!hstdin)
|
|
|
|
hstdin = INVALID_HANDLE_VALUE;
|
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(hstdin)))
|
|
|
|
hstdin = console_handle_map(hstdin);
|
|
|
|
|
|
|
|
if (!hstdout)
|
|
|
|
hstdout = INVALID_HANDLE_VALUE;
|
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(hstdout)))
|
|
|
|
hstdout = console_handle_map(hstdout);
|
|
|
|
|
|
|
|
if (!hstderr)
|
|
|
|
hstderr = INVALID_HANDLE_VALUE;
|
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(hstderr)))
|
|
|
|
hstderr = console_handle_map(hstderr);
|
|
|
|
|
|
|
|
params->hStdInput = hstdin;
|
|
|
|
params->hStdOutput = hstdout;
|
|
|
|
params->hStdError = hstderr;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
|
2004-02-12 00:00:55 +00:00
|
|
|
kernel32_handle = GetModuleHandleW(kernel32W);
|
|
|
|
|
2003-10-14 05:32:30 +00:00
|
|
|
LOCALE_Init();
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/* Copy the parent environment */
|
2003-10-10 23:33:21 +00:00
|
|
|
if (!build_initial_environment( environ )) return FALSE;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* Parse command line arguments */
|
|
|
|
OPTIONS_ParseOptions( !info_size ? argv : NULL );
|
|
|
|
|
|
|
|
/* initialise DOS drives */
|
|
|
|
if (!DRIVE_Init()) return FALSE;
|
|
|
|
|
|
|
|
/* initialise DOS directories */
|
|
|
|
if (!DIR_Init()) return FALSE;
|
|
|
|
|
|
|
|
/* registry initialisation */
|
|
|
|
SHELL_LoadRegistry();
|
|
|
|
|
|
|
|
/* global boot finished, the rest is process-local */
|
2003-09-18 23:27:19 +00:00
|
|
|
SERVER_START_REQ( boot_done )
|
|
|
|
{
|
|
|
|
req->debug_level = TRACE_ON(server);
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* start_process
|
|
|
|
*
|
|
|
|
* Startup routine of a new process. Runs on the new process stack.
|
|
|
|
*/
|
|
|
|
static void start_process( void *arg )
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
2003-10-24 00:32:36 +00:00
|
|
|
PEB *peb = NtCurrentTeb()->Peb;
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
LPTHREAD_START_ROUTINE entry;
|
|
|
|
|
2004-02-07 01:11:54 +00:00
|
|
|
LdrInitializeThunk( main_exe_file, 0, 0, 0 );
|
2003-10-24 00:32:36 +00:00
|
|
|
|
|
|
|
nt = RtlImageNtHeader( peb->ImageBaseAddress );
|
|
|
|
entry = (LPTHREAD_START_ROUTINE)((char *)peb->ImageBaseAddress +
|
|
|
|
nt->OptionalHeader.AddressOfEntryPoint);
|
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
DPRINTF( "%04lx:Starting process %s (entryproc=%p)\n", GetCurrentThreadId(),
|
|
|
|
debugstr_w(peb->ProcessParameters->ImagePathName.Buffer), entry );
|
|
|
|
|
|
|
|
SetLastError( 0 ); /* clear error code */
|
|
|
|
if (peb->BeingDebugged) DbgBreakPoint();
|
|
|
|
ExitProcess( entry( peb ) );
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
__EXCEPT(UnhandledExceptionFilter)
|
|
|
|
{
|
|
|
|
TerminateThread( GetCurrentThread(), GetExceptionCode() );
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-10-10 00:12:17 +00:00
|
|
|
* __wine_kernel_init
|
2003-09-17 05:31:32 +00:00
|
|
|
*
|
|
|
|
* Wine initialisation: load and start the main exe file.
|
|
|
|
*/
|
2003-10-10 00:12:17 +00:00
|
|
|
void __wine_kernel_init(void)
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
WCHAR *main_exe_name, *p;
|
|
|
|
char error[1024];
|
2003-09-17 05:31:32 +00:00
|
|
|
DWORD stack_size = 0;
|
|
|
|
int file_exists;
|
2003-10-09 04:59:03 +00:00
|
|
|
PEB *peb = NtCurrentTeb()->Peb;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* Initialize everything */
|
2003-10-10 23:33:21 +00:00
|
|
|
if (!process_init( __wine_main_argv, __wine_main_environ )) exit(1);
|
2003-10-11 05:26:31 +00:00
|
|
|
/* update argc in case options have been removed */
|
|
|
|
for (__wine_main_argc = 0; __wine_main_argv[__wine_main_argc]; __wine_main_argc++) /*nothing*/;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-10 00:12:17 +00:00
|
|
|
__wine_main_argv++; /* remove argv[0] (wine itself) */
|
|
|
|
__wine_main_argc--;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-09 04:59:03 +00:00
|
|
|
if (!(main_exe_name = peb->ProcessParameters->ImagePathName.Buffer))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
WCHAR exe_nameW[MAX_PATH];
|
|
|
|
|
2003-10-10 00:12:17 +00:00
|
|
|
if (!__wine_main_argv[0]) OPTIONS_Usage();
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-10 00:12:17 +00:00
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, __wine_main_argv[0], -1, exe_nameW, MAX_PATH );
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!find_exe_file( exe_nameW, buffer, MAX_PATH, &main_exe_file ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-10 00:12:17 +00:00
|
|
|
MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
if (main_exe_file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: cannot open %s\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
}
|
2003-10-09 04:59:03 +00:00
|
|
|
RtlCreateUnicodeString( &peb->ProcessParameters->ImagePathName, buffer );
|
|
|
|
main_exe_name = peb->ProcessParameters->ImagePathName.Buffer;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 01:04:19 +00:00
|
|
|
TRACE( "starting process name=%s file=%p argv[0]=%s\n",
|
2003-10-10 00:12:17 +00:00
|
|
|
debugstr_w(main_exe_name), main_exe_file, debugstr_a(__wine_main_argv[0]) );
|
2003-09-30 01:04:19 +00:00
|
|
|
|
2003-10-02 04:58:49 +00:00
|
|
|
MODULE_InitLoadPath();
|
|
|
|
VERSION_Init( main_exe_name );
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
if (!main_exe_file) /* no file handle -> Winelib app */
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting Winelib app %s\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
if (open_builtin_exe_file( main_exe_name, error, sizeof(error), 0, &file_exists ))
|
|
|
|
goto found;
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: cannot open builtin library for %s: %s\n",
|
|
|
|
debugstr_w(main_exe_name), error );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( MODULE_GetBinaryType( main_exe_file ))
|
|
|
|
{
|
|
|
|
case BINARY_PE_EXE:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting Win32 binary %s\n", debugstr_w(main_exe_name) );
|
2003-10-09 04:59:03 +00:00
|
|
|
if ((peb->ImageBaseAddress = load_pe_exe( main_exe_name, main_exe_file )))
|
|
|
|
goto found;
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: could not load %s as Win32 binary\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
case BINARY_PE_DLL:
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: %s is a DLL, not an executable\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
case BINARY_UNKNOWN:
|
|
|
|
/* check for .com extension */
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!(p = strrchrW( main_exe_name, '.' )) || strcmpiW( p, comW ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: cannot determine executable type for %s\n",
|
|
|
|
debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case BINARY_WIN16:
|
|
|
|
case BINARY_DOS:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting Win16/DOS binary %s\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
CloseHandle( main_exe_file );
|
|
|
|
main_exe_file = 0;
|
2003-10-10 00:12:17 +00:00
|
|
|
__wine_main_argv--;
|
|
|
|
__wine_main_argc++;
|
|
|
|
__wine_main_argv[0] = "winevdm.exe";
|
2003-10-04 04:09:41 +00:00
|
|
|
if (open_builtin_exe_file( winevdmW, error, sizeof(error), 0, &file_exists ))
|
2003-09-17 05:31:32 +00:00
|
|
|
goto found;
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: trying to run %s, cannot open builtin library for 'winevdm.exe': %s\n",
|
|
|
|
debugstr_w(main_exe_name), error );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
case BINARY_OS216:
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: %s is an OS/2 binary, not supported\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
case BINARY_UNIX_EXE:
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: %s is a Unix binary, not supported\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
case BINARY_UNIX_LIB:
|
|
|
|
{
|
|
|
|
DOS_FULL_NAME full_name;
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting Winelib app %s\n", debugstr_w(main_exe_name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
CloseHandle( main_exe_file );
|
|
|
|
main_exe_file = 0;
|
2003-10-04 04:09:41 +00:00
|
|
|
if (DOSFS_GetFullName( main_exe_name, TRUE, &full_name ) &&
|
|
|
|
wine_dlopen( full_name.long_name, RTLD_NOW, error, sizeof(error) ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-08 22:38:52 +00:00
|
|
|
static const WCHAR soW[] = {'.','s','o',0};
|
2003-10-04 04:09:41 +00:00
|
|
|
if ((p = strrchrW( main_exe_name, '.' )) && !strcmpW( p, soW ))
|
|
|
|
{
|
|
|
|
*p = 0;
|
|
|
|
/* update the unicode string */
|
2003-10-09 04:59:03 +00:00
|
|
|
RtlInitUnicodeString( &peb->ProcessParameters->ImagePathName, main_exe_name );
|
2003-10-04 04:09:41 +00:00
|
|
|
}
|
2003-09-17 05:31:32 +00:00
|
|
|
goto found;
|
|
|
|
}
|
2003-10-04 04:09:41 +00:00
|
|
|
MESSAGE( "wine: could not load %s: %s\n", debugstr_w(main_exe_name), error );
|
2003-09-17 05:31:32 +00:00
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
found:
|
2003-11-22 00:08:26 +00:00
|
|
|
wine_free_pe_load_area(); /* the main binary is loaded, we don't need this anymore */
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/* build command line */
|
2003-10-10 00:12:17 +00:00
|
|
|
set_library_wargv( __wine_main_argv );
|
2003-10-08 22:38:52 +00:00
|
|
|
if (!build_command_line( __wine_main_wargv )) goto error;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-09 04:59:03 +00:00
|
|
|
stack_size = RtlImageNtHeader(peb->ImageBaseAddress)->OptionalHeader.SizeOfStackReserve;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* allocate main thread stack */
|
|
|
|
if (!THREAD_InitStack( NtCurrentTeb(), stack_size )) goto error;
|
|
|
|
|
|
|
|
/* switch to the new stack */
|
|
|
|
wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
|
|
|
|
|
|
|
|
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 04:09:41 +00:00
|
|
|
static char **build_argv( const WCHAR *cmdlineW, int reserved )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char** argv;
|
2003-10-04 04:09:41 +00:00
|
|
|
char *arg,*s,*d,*cmdline;
|
|
|
|
int in_quotes,bcount,len;
|
|
|
|
|
|
|
|
len = WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW, -1, NULL, 0, NULL, NULL );
|
|
|
|
if (!(cmdline = malloc(len))) return NULL;
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW, -1, cmdline, len, NULL, NULL );
|
2003-09-17 05:31:32 +00: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++;
|
|
|
|
}
|
|
|
|
argv=malloc(argc*sizeof(*argv));
|
|
|
|
if (!argv)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
arg=d=s=cmdline;
|
|
|
|
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) {
|
|
|
|
/* Preceeded by an even number of '\', this is half that
|
|
|
|
* number of '\', plus a '"' which we discard.
|
|
|
|
*/
|
|
|
|
d-=bcount/2;
|
|
|
|
s++;
|
|
|
|
in_quotes=!in_quotes;
|
|
|
|
} else {
|
|
|
|
/* Preceeded by an odd number of '\', this is half that
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
return argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-10 23:33:21 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* alloc_env_string
|
|
|
|
*
|
|
|
|
* Allocate an environment string; helper for build_envp
|
|
|
|
*/
|
|
|
|
static char *alloc_env_string( const char *name, const char *value )
|
|
|
|
{
|
|
|
|
char *ret = malloc( strlen(name) + strlen(value) + 1 );
|
|
|
|
strcpy( ret, name );
|
|
|
|
strcat( ret, value );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* build_envp
|
|
|
|
*
|
|
|
|
* Build the environment of a new child process.
|
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
static char **build_envp( const WCHAR *envW, const WCHAR *extra_envW )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
const WCHAR *p;
|
2003-09-17 05:31:32 +00:00
|
|
|
char **envp;
|
2003-10-04 04:09:41 +00:00
|
|
|
char *env, *extra_env = NULL;
|
|
|
|
int count = 0, length;
|
|
|
|
|
|
|
|
if (extra_envW)
|
|
|
|
{
|
|
|
|
for (p = extra_envW; *p; count++) p += strlenW(p) + 1;
|
|
|
|
p++;
|
|
|
|
length = WideCharToMultiByte( CP_UNIXCP, 0, extra_envW, p - extra_envW,
|
|
|
|
NULL, 0, NULL, NULL );
|
|
|
|
if ((extra_env = malloc( length )))
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, extra_envW, p - extra_envW,
|
|
|
|
extra_env, length, NULL, NULL );
|
|
|
|
}
|
|
|
|
for (p = envW; *p; count++) p += strlenW(p) + 1;
|
|
|
|
p++;
|
|
|
|
length = WideCharToMultiByte( CP_UNIXCP, 0, envW, p - envW, NULL, 0, NULL, NULL );
|
|
|
|
if (!(env = malloc( length ))) return NULL;
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, envW, p - envW, env, length, NULL, NULL );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-10 23:33:21 +00:00
|
|
|
count += 4;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
if ((envp = malloc( count * sizeof(*envp) )))
|
|
|
|
{
|
|
|
|
char **envptr = envp;
|
2003-10-04 04:09:41 +00:00
|
|
|
char *p;
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/* first the extra strings */
|
2003-10-04 04:09:41 +00:00
|
|
|
if (extra_env) for (p = extra_env; *p; p += strlen(p) + 1) *envptr++ = p;
|
2004-03-11 00:49:01 +00:00
|
|
|
/* then put PATH, TEMP, TMP, HOME and WINEPREFIX from the unix env */
|
2003-10-10 23:33:21 +00:00
|
|
|
if ((p = getenv("PATH"))) *envptr++ = alloc_env_string( "PATH=", p );
|
2004-03-11 00:49:01 +00:00
|
|
|
if ((p = getenv("TEMP"))) *envptr++ = alloc_env_string( "TEMP=", p );
|
|
|
|
if ((p = getenv("TMP"))) *envptr++ = alloc_env_string( "TMP=", p );
|
2003-10-10 23:33:21 +00:00
|
|
|
if ((p = getenv("HOME"))) *envptr++ = alloc_env_string( "HOME=", p );
|
|
|
|
if ((p = getenv("WINEPREFIX"))) *envptr++ = alloc_env_string( "WINEPREFIX=", p );
|
2003-09-17 05:31:32 +00:00
|
|
|
/* now put the Windows environment strings */
|
|
|
|
for (p = env; *p; p += strlen(p) + 1)
|
|
|
|
{
|
2004-01-20 21:51:27 +00:00
|
|
|
if (extra_env && p[0]=='=' && 'A'<=p[1] && p[1]<='Z' && p[2]==':' && p[3]=='=')
|
|
|
|
continue; /* skipped */
|
2004-03-11 00:49:01 +00:00
|
|
|
if (is_special_env_var( p )) /* prefix it with "WINE" */
|
|
|
|
*envptr++ = alloc_env_string( "WINE", p );
|
2003-09-17 05:31:32 +00:00
|
|
|
else if (memcmp( p, "HOME=", 5 ) &&
|
2003-10-04 04:09:41 +00:00
|
|
|
memcmp( p, "WINEPREFIX=", 11 )) *envptr++ = p;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
*envptr = 0;
|
|
|
|
}
|
|
|
|
return envp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* fork_and_exec
|
|
|
|
*
|
|
|
|
* Fork and exec a new Unix binary, checking for errors.
|
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
static int fork_and_exec( const char *filename, const WCHAR *cmdline,
|
|
|
|
const WCHAR *env, const char *newdir )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
int pid, err;
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!env) env = GetEnvironmentStringsW();
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
if (pipe(fd) == -1)
|
|
|
|
{
|
|
|
|
FILE_SetDosError();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */
|
|
|
|
if (!(pid = fork())) /* child */
|
|
|
|
{
|
|
|
|
char **argv = build_argv( cmdline, 0 );
|
|
|
|
char **envp = build_envp( env, NULL );
|
|
|
|
close( fd[0] );
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
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 04:09:41 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* create_user_params
|
|
|
|
*/
|
|
|
|
static RTL_USER_PROCESS_PARAMETERS *create_user_params( LPCWSTR filename, LPCWSTR cmdline,
|
|
|
|
const STARTUPINFOW *startup )
|
|
|
|
{
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
|
|
|
UNICODE_STRING image_str, cmdline_str, desktop, title;
|
|
|
|
NTSTATUS status;
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2004-02-05 01:23:42 +00: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 04:09:41 +00:00
|
|
|
|
|
|
|
RtlInitUnicodeString( &cmdline_str, cmdline );
|
|
|
|
if (startup->lpDesktop) RtlInitUnicodeString( &desktop, startup->lpDesktop );
|
|
|
|
if (startup->lpTitle) RtlInitUnicodeString( &title, startup->lpTitle );
|
|
|
|
|
|
|
|
status = RtlCreateProcessParameters( ¶ms, &image_str, NULL, NULL, &cmdline_str, NULL,
|
|
|
|
startup->lpTitle ? &title : NULL,
|
|
|
|
startup->lpDesktop ? &desktop : NULL,
|
|
|
|
NULL, NULL );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
params->Environment = NULL; /* we pass it through the Unix environment */
|
|
|
|
params->hStdInput = startup->hStdInput;
|
|
|
|
params->hStdOutput = startup->hStdOutput;
|
|
|
|
params->hStdError = startup->hStdError;
|
|
|
|
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 05:31:32 +00: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 04:09:41 +00:00
|
|
|
static BOOL create_process( HANDLE hFile, LPCWSTR filename, LPWSTR cmd_line, LPWSTR env,
|
2003-09-17 05:31:32 +00:00
|
|
|
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
2003-10-04 04:09:41 +00:00
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
2003-09-17 05:31:32 +00:00
|
|
|
LPPROCESS_INFORMATION info, LPCSTR unixdir )
|
|
|
|
{
|
|
|
|
BOOL ret, success = FALSE;
|
|
|
|
HANDLE process_info;
|
2003-10-04 04:09:41 +00:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
|
|
|
WCHAR *extra_env = NULL;
|
2003-09-17 05:31:32 +00:00
|
|
|
int startfd[2];
|
|
|
|
int execfd[2];
|
|
|
|
pid_t pid;
|
|
|
|
int err;
|
|
|
|
char dummy = 0;
|
|
|
|
|
|
|
|
if (!env)
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
env = GetEnvironmentStringsW();
|
2003-09-17 05:31:32 +00:00
|
|
|
extra_env = DRIVE_BuildEnv();
|
|
|
|
}
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!(params = create_user_params( filename, cmd_line, startup )))
|
|
|
|
{
|
|
|
|
if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/* create the synchronization pipes */
|
|
|
|
|
|
|
|
if (pipe( startfd ) == -1)
|
|
|
|
{
|
|
|
|
FILE_SetDosError();
|
2003-10-04 04:09:41 +00:00
|
|
|
RtlDestroyProcessParameters( params );
|
|
|
|
if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
|
2003-09-17 05:31:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pipe( execfd ) == -1)
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
FILE_SetDosError();
|
2003-09-17 05:31:32 +00:00
|
|
|
close( startfd[0] );
|
|
|
|
close( startfd[1] );
|
2003-10-04 04:09:41 +00:00
|
|
|
RtlDestroyProcessParameters( params );
|
|
|
|
if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
|
2003-09-17 05:31:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
fcntl( execfd[1], F_SETFD, 1 ); /* set close on exec */
|
|
|
|
|
|
|
|
/* create the child process */
|
|
|
|
|
|
|
|
if (!(pid = fork())) /* child */
|
|
|
|
{
|
|
|
|
char **argv = build_argv( cmd_line, 1 );
|
|
|
|
char **envp = build_envp( env, extra_env );
|
|
|
|
|
|
|
|
close( startfd[1] );
|
|
|
|
close( execfd[0] );
|
|
|
|
|
|
|
|
/* wait for parent to tell us to start */
|
|
|
|
if (read( startfd[0], &dummy, 1 ) != 1) _exit(1);
|
|
|
|
|
|
|
|
close( startfd[0] );
|
|
|
|
/* Reset signals that we previously set to SIG_IGN */
|
|
|
|
signal( SIGPIPE, SIG_DFL );
|
|
|
|
signal( SIGCHLD, SIG_DFL );
|
|
|
|
|
|
|
|
if (unixdir) chdir(unixdir);
|
|
|
|
|
2003-11-11 22:21:29 +00:00
|
|
|
if (argv && envp)
|
|
|
|
{
|
|
|
|
/* first, try for a WINELOADER environment variable */
|
|
|
|
argv[0] = getenv("WINELOADER");
|
|
|
|
if (argv[0]) execve( argv[0], argv, envp );
|
|
|
|
/* now use the standard search strategy */
|
|
|
|
wine_exec_wine_binary( NULL, argv, envp );
|
|
|
|
}
|
2003-09-17 05:31:32 +00:00
|
|
|
err = errno;
|
|
|
|
write( execfd[1], &err, sizeof(err) );
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the parent */
|
|
|
|
|
|
|
|
close( startfd[0] );
|
|
|
|
close( execfd[1] );
|
|
|
|
if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
|
|
|
|
if (pid == -1)
|
|
|
|
{
|
|
|
|
close( startfd[1] );
|
|
|
|
close( execfd[0] );
|
|
|
|
FILE_SetDosError();
|
2003-10-04 04:09:41 +00:00
|
|
|
RtlDestroyProcessParameters( params );
|
2003-09-17 05:31:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the process on the server side */
|
|
|
|
|
|
|
|
SERVER_START_REQ( new_process )
|
|
|
|
{
|
|
|
|
req->inherit_all = inherit;
|
|
|
|
req->create_flags = flags;
|
|
|
|
req->unix_pid = pid;
|
|
|
|
req->exe_file = hFile;
|
|
|
|
if (startup->dwFlags & STARTF_USESTDHANDLES)
|
|
|
|
{
|
|
|
|
req->hstdin = startup->hStdInput;
|
|
|
|
req->hstdout = startup->hStdOutput;
|
|
|
|
req->hstderr = startup->hStdError;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
req->hstdin = GetStdHandle( STD_INPUT_HANDLE );
|
|
|
|
req->hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
|
|
|
|
req->hstderr = GetStdHandle( STD_ERROR_HANDLE );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
wine_server_add_data( req, params, params->Size );
|
2003-09-17 05:31:32 +00:00
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
process_info = reply->info;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2003-06-27 04:08:04 +00:00
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
RtlDestroyProcessParameters( params );
|
2003-09-17 05:31:32 +00:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
close( startfd[1] );
|
|
|
|
close( execfd[0] );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tell child to start and wait for it to exec */
|
|
|
|
|
|
|
|
write( startfd[1], &dummy, 1 );
|
|
|
|
close( startfd[1] );
|
|
|
|
|
|
|
|
if (read( execfd[0], &err, sizeof(err) ) > 0) /* exec failed */
|
|
|
|
{
|
|
|
|
errno = err;
|
|
|
|
FILE_SetDosError();
|
|
|
|
close( execfd[0] );
|
|
|
|
CloseHandle( process_info );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-01-20 02:11:06 +00:00
|
|
|
close( execfd[0] );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* wait for the new process info to be ready */
|
|
|
|
|
|
|
|
WaitForSingleObject( process_info, INFINITE );
|
|
|
|
SERVER_START_REQ( get_new_process_info )
|
|
|
|
{
|
|
|
|
req->info = process_info;
|
|
|
|
req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle);
|
|
|
|
req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle);
|
|
|
|
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;
|
|
|
|
success = reply->success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (ret && !success) /* new process failed to start */
|
|
|
|
{
|
|
|
|
DWORD exitcode;
|
|
|
|
if (GetExitCodeProcess( info->hProcess, &exitcode )) SetLastError( exitcode );
|
|
|
|
CloseHandle( info->hThread );
|
|
|
|
CloseHandle( info->hProcess );
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
CloseHandle( process_info );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* create_vdm_process
|
|
|
|
*
|
|
|
|
* Create a new VDM process for a 16-bit or DOS application.
|
|
|
|
*/
|
2003-10-04 04:09:41 +00:00
|
|
|
static BOOL create_vdm_process( LPCWSTR filename, LPWSTR cmd_line, LPWSTR env,
|
2003-09-17 05:31:32 +00:00
|
|
|
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
2003-10-04 04:09:41 +00:00
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
2003-09-17 05:31:32 +00:00
|
|
|
LPPROCESS_INFORMATION info, LPCSTR unixdir )
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
static const WCHAR argsW[] = {'%','s',' ','-','-','a','p','p','-','n','a','m','e',' ','"','%','s','"',' ','%','s',0};
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
BOOL ret;
|
2003-10-04 04:09:41 +00:00
|
|
|
LPWSTR new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(strlenW(filename) + strlenW(cmd_line) + 30) * sizeof(WCHAR) );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
if (!new_cmd_line)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-10-04 04:09:41 +00:00
|
|
|
sprintfW( new_cmd_line, argsW, winevdmW, filename, cmd_line );
|
|
|
|
ret = create_process( 0, winevdmW, new_cmd_line, env, psa, tsa, inherit,
|
2003-09-17 05:31:32 +00:00
|
|
|
flags, startup, info, unixdir );
|
|
|
|
HeapFree( GetProcessHeap(), 0, new_cmd_line );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* create_cmd_process
|
|
|
|
*
|
|
|
|
* Create a new cmd shell process for a .BAT file.
|
|
|
|
*/
|
|
|
|
static BOOL create_cmd_process( LPCWSTR filename, LPWSTR cmd_line, LPVOID env,
|
|
|
|
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
|
|
|
|
BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
|
|
|
|
LPPROCESS_INFORMATION info, LPCWSTR cur_dir )
|
|
|
|
|
|
|
|
{
|
|
|
|
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 05:31:32 +00: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 04:09:41 +00:00
|
|
|
static LPWSTR get_file_name( LPCWSTR appname, LPWSTR cmdline, LPWSTR buffer,
|
|
|
|
int buflen, HANDLE *handle )
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
static const WCHAR quotesW[] = {'"','%','s','"',0};
|
|
|
|
|
|
|
|
WCHAR *name, *pos, *ret = NULL;
|
|
|
|
const WCHAR *p;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* if we have an app name, everything is easy */
|
|
|
|
|
|
|
|
if (appname)
|
|
|
|
{
|
|
|
|
/* use the unmodified app name as file name */
|
2003-10-04 04:09:41 +00:00
|
|
|
lstrcpynW( buffer, appname, buflen );
|
2003-09-17 05:31:32 +00:00
|
|
|
*handle = open_exe_file( buffer );
|
|
|
|
if (!(ret = cmdline) || !cmdline[0])
|
|
|
|
{
|
|
|
|
/* no command-line, create one */
|
2003-10-30 23:06:10 +00:00
|
|
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(appname) + 3) * sizeof(WCHAR) )))
|
2003-10-04 04:09:41 +00:00
|
|
|
sprintfW( ret, quotesW, appname );
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cmdline)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first check for a quoted file name */
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if ((cmdline[0] == '"') && ((p = strchrW( cmdline + 1, '"' ))))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
int len = p - cmdline - 1;
|
|
|
|
/* extract the quoted portion as file name */
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!(name = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
|
|
|
|
memcpy( name, cmdline + 1, len * sizeof(WCHAR) );
|
2003-09-17 05:31:32 +00: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 04:09:41 +00:00
|
|
|
if (!(name = HeapAlloc( GetProcessHeap(), 0, (strlenW(cmdline) + 1) * sizeof(WCHAR) )))
|
|
|
|
return NULL;
|
2003-09-17 05:31:32 +00:00
|
|
|
pos = name;
|
|
|
|
p = cmdline;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
do *pos++ = *p++; while (*p && *p != ' ');
|
|
|
|
*pos = 0;
|
|
|
|
if (find_exe_file( name, buffer, buflen, handle ))
|
|
|
|
{
|
|
|
|
ret = cmdline;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!ret || !strchrW( name, ' ' )) goto done; /* no change necessary */
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* now build a new command-line with quotes */
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!(ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(cmdline) + 3) * sizeof(WCHAR) )))
|
|
|
|
goto done;
|
|
|
|
sprintfW( ret, quotesW, name );
|
|
|
|
strcatW( ret, p );
|
2003-09-17 05:31:32 +00: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 04:09:41 +00:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
UNICODE_STRING app_nameW, cmd_lineW, cur_dirW, desktopW, titleW;
|
|
|
|
STARTUPINFOW infoW;
|
|
|
|
|
|
|
|
if (app_name) RtlCreateUnicodeStringFromAsciiz( &app_nameW, app_name );
|
|
|
|
else app_nameW.Buffer = NULL;
|
|
|
|
if (cmd_line) RtlCreateUnicodeStringFromAsciiz( &cmd_lineW, cmd_line );
|
|
|
|
else cmd_lineW.Buffer = NULL;
|
|
|
|
if (cur_dir) RtlCreateUnicodeStringFromAsciiz( &cur_dirW, cur_dir );
|
|
|
|
else cur_dirW.Buffer = NULL;
|
|
|
|
if (startup_info->lpDesktop) RtlCreateUnicodeStringFromAsciiz( &desktopW, startup_info->lpDesktop );
|
|
|
|
else desktopW.Buffer = NULL;
|
|
|
|
if (startup_info->lpTitle) RtlCreateUnicodeStringFromAsciiz( &titleW, startup_info->lpTitle );
|
|
|
|
else titleW.Buffer = NULL;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
ret = CreateProcessW( app_nameW.Buffer, cmd_lineW.Buffer, process_attr, thread_attr,
|
|
|
|
inherit, flags, env, cur_dirW.Buffer, &infoW, info );
|
|
|
|
|
|
|
|
RtlFreeUnicodeString( &app_nameW );
|
|
|
|
RtlFreeUnicodeString( &cmd_lineW );
|
|
|
|
RtlFreeUnicodeString( &cur_dirW );
|
|
|
|
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 05:31:32 +00:00
|
|
|
{
|
|
|
|
BOOL retv = FALSE;
|
|
|
|
HANDLE hFile = 0;
|
|
|
|
const char *unixdir = NULL;
|
|
|
|
DOS_FULL_NAME full_dir;
|
2003-10-04 04:09:41 +00:00
|
|
|
WCHAR name[MAX_PATH];
|
|
|
|
WCHAR *tidy_cmdline, *p, *envW = env;
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
/* Process the AppName and/or CmdLine to get module name and path */
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE("app %s cmdline %s\n", debugstr_w(app_name), debugstr_w(cmd_line) );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
if (!(tidy_cmdline = get_file_name( app_name, cmd_line, name, sizeof(name), &hFile )))
|
|
|
|
return FALSE;
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) goto done;
|
|
|
|
|
|
|
|
/* Warn if unsupported features are used */
|
|
|
|
|
2003-10-04 04:09:41 +00: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))
|
|
|
|
WARN("(%s,...): ignoring some flags in %lx\n", debugstr_w(name), flags);
|
2003-09-17 05:31:32 +00:00
|
|
|
|
|
|
|
if (cur_dir)
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
if (DOSFS_GetFullName( cur_dir, TRUE, &full_dir )) unixdir = full_dir.long_name;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR buf[MAX_PATH];
|
|
|
|
if (GetCurrentDirectoryW(MAX_PATH, buf))
|
|
|
|
{
|
|
|
|
if (DOSFS_GetFullName( buf, TRUE, &full_dir )) unixdir = full_dir.long_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-04 04:09:41 +00: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 05:31:32 +00:00
|
|
|
info->hThread = info->hProcess = 0;
|
|
|
|
info->dwProcessId = info->dwThreadId = 0;
|
|
|
|
|
|
|
|
/* Determine executable type */
|
|
|
|
|
|
|
|
if (!hFile) /* builtin exe */
|
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting %s as Winelib app\n", debugstr_w(name) );
|
|
|
|
retv = create_process( 0, name, tidy_cmdline, envW, process_attr, thread_attr,
|
2003-09-17 05:31:32 +00:00
|
|
|
inherit, flags, startup_info, info, unixdir );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( MODULE_GetBinaryType( hFile ))
|
|
|
|
{
|
|
|
|
case BINARY_PE_EXE:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting %s as Win32 binary\n", debugstr_w(name) );
|
|
|
|
retv = create_process( hFile, name, tidy_cmdline, envW, process_attr, thread_attr,
|
2003-09-17 05:31:32 +00:00
|
|
|
inherit, flags, startup_info, info, unixdir );
|
|
|
|
break;
|
|
|
|
case BINARY_WIN16:
|
|
|
|
case BINARY_DOS:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting %s as Win16/DOS binary\n", debugstr_w(name) );
|
|
|
|
retv = create_vdm_process( name, tidy_cmdline, envW, process_attr, thread_attr,
|
2003-09-17 05:31:32 +00:00
|
|
|
inherit, flags, startup_info, info, unixdir );
|
|
|
|
break;
|
|
|
|
case BINARY_OS216:
|
2003-10-04 04:09:41 +00:00
|
|
|
FIXME( "%s is OS/2 binary, not supported\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
SetLastError( ERROR_BAD_EXE_FORMAT );
|
|
|
|
break;
|
|
|
|
case BINARY_PE_DLL:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "not starting %s since it is a dll\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
SetLastError( ERROR_BAD_EXE_FORMAT );
|
|
|
|
break;
|
|
|
|
case BINARY_UNIX_LIB:
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_w(name) );
|
|
|
|
retv = create_process( hFile, name, tidy_cmdline, envW, process_attr, thread_attr,
|
2003-09-17 05:31:32 +00:00
|
|
|
inherit, flags, startup_info, info, unixdir );
|
|
|
|
break;
|
|
|
|
case BINARY_UNKNOWN:
|
|
|
|
/* check for .com or .bat extension */
|
2003-10-04 04:09:41 +00:00
|
|
|
if ((p = strrchrW( name, '.' )))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!strcmpiW( p, comW ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting %s as DOS binary\n", debugstr_w(name) );
|
|
|
|
retv = create_vdm_process( name, tidy_cmdline, envW, process_attr, thread_attr,
|
2003-09-17 05:31:32 +00:00
|
|
|
inherit, flags, startup_info, info, unixdir );
|
|
|
|
break;
|
|
|
|
}
|
2003-10-04 04:09:41 +00:00
|
|
|
if (!strcmpiW( p, batW ))
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting %s as batch binary\n", debugstr_w(name) );
|
|
|
|
retv = create_cmd_process( name, tidy_cmdline, envW, process_attr, thread_attr,
|
|
|
|
inherit, flags, startup_info, info, cur_dir );
|
|
|
|
break;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case BINARY_UNIX_EXE:
|
|
|
|
{
|
|
|
|
/* unknown file, try as unix executable */
|
|
|
|
DOS_FULL_NAME full_name;
|
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
TRACE( "starting %s as Unix binary\n", debugstr_w(name) );
|
2003-09-17 05:31:32 +00:00
|
|
|
|
2003-10-04 04:09:41 +00:00
|
|
|
if (DOSFS_GetFullName( name, TRUE, &full_name ))
|
|
|
|
retv = (fork_and_exec( full_name.long_name, tidy_cmdline, envW, unixdir ) != -1);
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CloseHandle( hFile );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (tidy_cmdline != cmd_line) HeapFree( GetProcessHeap(), 0, tidy_cmdline );
|
2003-10-04 04:09:41 +00:00
|
|
|
if (envW != env) HeapFree( GetProcessHeap(), 0, envW );
|
2003-09-17 05:31:32 +00:00
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/* cmdline needs to be writeable for CreateProcess */
|
|
|
|
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 19:31:11 +00:00
|
|
|
if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
|
2003-09-17 05:31:32 +00:00
|
|
|
WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
|
|
|
|
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 20:16:38 +00:00
|
|
|
LOADPARMS32 *params = paramBlock;
|
2003-09-17 05:31:32 +00: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 ))
|
|
|
|
return (HINSTANCE)GetLastError();
|
|
|
|
|
|
|
|
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 20:16:38 +00:00
|
|
|
startup.wShowWindow = ((WORD *)params->lpCmdShow)[1];
|
2003-09-17 05:31:32 +00: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 19:31:11 +00:00
|
|
|
if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
|
2003-09-17 05:31:32 +00:00
|
|
|
WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
|
|
|
|
hInstance = (HINSTANCE)33;
|
|
|
|
/* Close off the handles */
|
|
|
|
CloseHandle( info.hThread );
|
|
|
|
CloseHandle( info.hProcess );
|
|
|
|
}
|
|
|
|
else if ((hInstance = (HINSTANCE)GetLastError()) >= (HINSTANCE)32)
|
|
|
|
{
|
|
|
|
FIXME("Strange error set by CreateProcess: %p\n", hInstance );
|
|
|
|
hInstance = (HINSTANCE)11;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
|
|
|
return hInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TerminateProcess (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtTerminateProcess( handle, exit_code );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 03:57:02 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* ExitProcess (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
void WINAPI ExitProcess( DWORD status )
|
|
|
|
{
|
|
|
|
LdrShutdownProcess();
|
|
|
|
SERVER_START_REQ( terminate_process )
|
|
|
|
{
|
|
|
|
/* send the exit code to the server */
|
|
|
|
req->handle = GetCurrentProcess();
|
|
|
|
req->exit_code = status;
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
exit( status );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetExitCodeProcess [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Gets termination status of specified process
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetExitCodeProcess(
|
|
|
|
HANDLE hProcess, /* [in] handle to the process */
|
|
|
|
LPDWORD lpExitCode) /* [out] address to receive termination status */
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ( get_process_info )
|
|
|
|
{
|
|
|
|
req->handle = hProcess;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
if (ret && lpExitCode) *lpExitCode = reply->exit_code;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetErrorMode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
UINT WINAPI SetErrorMode( UINT mode )
|
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
UINT old = process_error_mode;
|
|
|
|
process_error_mode = mode;
|
2003-09-17 05:31:32 +00:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* TlsAlloc [KERNEL32.@] Allocates a TLS index.
|
|
|
|
*
|
|
|
|
* Allocates a thread local storage index
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TLS Index
|
|
|
|
* Failure: 0xFFFFFFFF
|
|
|
|
*/
|
|
|
|
DWORD WINAPI TlsAlloc( void )
|
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
DWORD index;
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
RtlAcquirePebLock();
|
2003-10-09 19:58:56 +00:00
|
|
|
index = RtlFindClearBitsAndSet( NtCurrentTeb()->Peb->TlsBitmap, 1, 0 );
|
|
|
|
if (index != ~0UL) NtCurrentTeb()->TlsSlots[index] = 0; /* clear the value */
|
|
|
|
else SetLastError( ERROR_NO_MORE_ITEMS );
|
2003-09-17 05:31:32 +00:00
|
|
|
RtlReleasePebLock();
|
2003-10-09 19:58:56 +00:00
|
|
|
return index;
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* TlsFree [KERNEL32.@] Releases a TLS index.
|
|
|
|
*
|
|
|
|
* Releases a thread local storage index, making it available for reuse
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI TlsFree(
|
|
|
|
DWORD index) /* [in] TLS Index to free */
|
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
BOOL ret;
|
|
|
|
|
2003-09-17 05:31:32 +00:00
|
|
|
RtlAcquirePebLock();
|
2003-10-09 19:58:56 +00:00
|
|
|
ret = RtlAreBitsSet( NtCurrentTeb()->Peb->TlsBitmap, index, 1 );
|
|
|
|
if (ret)
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
RtlClearBits( NtCurrentTeb()->Peb->TlsBitmap, index, 1 );
|
|
|
|
NtSetInformationThread( GetCurrentThread(), ThreadZeroTlsCell, &index, sizeof(index) );
|
2003-09-17 05:31:32 +00:00
|
|
|
}
|
2003-10-09 19:58:56 +00:00
|
|
|
else SetLastError( ERROR_INVALID_PARAMETER );
|
2003-09-17 05:31:32 +00:00
|
|
|
RtlReleasePebLock();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* TlsGetValue [KERNEL32.@] Gets value in a thread's TLS slot
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Value stored in calling thread's TLS slot for index
|
|
|
|
* Failure: 0 and GetLastError returns NO_ERROR
|
|
|
|
*/
|
|
|
|
LPVOID WINAPI TlsGetValue(
|
|
|
|
DWORD index) /* [in] TLS index to retrieve value for */
|
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
if (index >= NtCurrentTeb()->Peb->TlsBitmap->SizeOfBitMap)
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
SetLastError( ERROR_SUCCESS );
|
|
|
|
return NtCurrentTeb()->TlsSlots[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* TlsSetValue [KERNEL32.@] Stores a value in the thread's TLS slot.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI TlsSetValue(
|
|
|
|
DWORD index, /* [in] TLS index to set value for */
|
|
|
|
LPVOID value) /* [in] Value to be stored */
|
|
|
|
{
|
2003-10-09 19:58:56 +00:00
|
|
|
if (index >= NtCurrentTeb()->Peb->TlsBitmap->SizeOfBitMap)
|
2003-09-17 05:31:32 +00:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
NtCurrentTeb()->TlsSlots[index] = value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-06-27 04:08:04 +00: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;
|
|
|
|
|
|
|
|
TRACE("(%ld, %d)\n", dwProcessID, offset );
|
|
|
|
|
|
|
|
if (dwProcessID && dwProcessID != GetCurrentProcessId())
|
|
|
|
{
|
|
|
|
ERR("%d: process %lx not accessible\n", offset, dwProcessID);
|
|
|
|
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:
|
|
|
|
return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
|
|
|
|
case GPD_PDB:
|
|
|
|
return (DWORD)NtCurrentTeb()->Peb;
|
|
|
|
case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
|
|
|
|
GetStartupInfoW(&siw);
|
|
|
|
return (DWORD)siw.hStdOutput;
|
|
|
|
case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
|
|
|
|
GetStartupInfoW(&siw);
|
|
|
|
return (DWORD)siw.hStdInput;
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
TRACE("(%ld, %d)\n", dwProcessID, offset );
|
|
|
|
|
|
|
|
if (dwProcessID && dwProcessID != GetCurrentProcessId())
|
|
|
|
{
|
|
|
|
ERR("%d: process %lx not accessible\n", offset, dwProcessID);
|
|
|
|
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.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
|
|
|
|
{
|
|
|
|
HANDLE ret = 0;
|
|
|
|
SERVER_START_REQ( open_process )
|
|
|
|
{
|
|
|
|
req->pid = id;
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
if (!wine_server_call_err( req )) ret = reply->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* MapProcessHandle (KERNEL.483)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI MapProcessHandle( HANDLE handle )
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
SERVER_START_REQ( get_process_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
if (!wine_server_call_err( req )) ret = reply->pid;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 04:24:49 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* CloseW32Handle (KERNEL.474)
|
|
|
|
* CloseHandle (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
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))
|
|
|
|
handle = GetStdHandle( (DWORD)handle );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ( set_handle_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = 0;
|
|
|
|
req->mask = 0;
|
|
|
|
req->fd = -1;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
if (ret && flags) *flags = reply->old_flags;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* SetHandleInformation (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ( set_handle_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = flags;
|
|
|
|
req->mask = mask;
|
|
|
|
req->fd = -1;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%ld), 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,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 04:08:04 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* SetPriorityClass (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ( set_process_info )
|
|
|
|
{
|
|
|
|
req->handle = hprocess;
|
|
|
|
req->priority = priorityclass;
|
|
|
|
req->mask = SET_PROCESS_INFO_PRIORITY;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetPriorityClass (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetPriorityClass(HANDLE hprocess)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
SERVER_START_REQ( get_process_info )
|
|
|
|
{
|
|
|
|
req->handle = hprocess;
|
|
|
|
if (!wine_server_call_err( req )) ret = reply->priority;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetProcessAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ( set_process_info )
|
|
|
|
{
|
|
|
|
req->handle = hProcess;
|
|
|
|
req->affinity = affmask;
|
|
|
|
req->mask = SET_PROCESS_INFO_AFFINITY;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetProcessAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
|
|
|
|
LPDWORD lpProcessAffinityMask,
|
|
|
|
LPDWORD lpSystemAffinityMask )
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
SERVER_START_REQ( get_process_info )
|
|
|
|
{
|
|
|
|
req->handle = hProcess;
|
|
|
|
if (!wine_server_call_err( req ))
|
|
|
|
{
|
|
|
|
if (lpProcessAffinityMask) *lpProcessAffinityMask = reply->process_affinity;
|
|
|
|
if (lpSystemAffinityMask) *lpSystemAffinityMask = reply->system_affinity;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessVersion (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetProcessVersion( DWORD processid )
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
|
|
|
|
if (processid && processid != GetCurrentProcessId())
|
|
|
|
{
|
|
|
|
FIXME("should use ReadProcessMemory\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
|
|
|
|
return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
|
|
|
|
nt->OptionalHeader.MinorSubsystemVersion);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* RETURNS STD
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
|
|
|
|
SIZE_T maxset)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
|
|
|
|
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 21:18:45 +00:00
|
|
|
NTSTATUS status = NtReadVirtualMemory( process, addr, buffer, size, bytes_read );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-06-27 04:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WriteProcessMemory (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPCVOID buffer, SIZE_T size,
|
|
|
|
SIZE_T *bytes_written )
|
|
|
|
{
|
2003-07-08 21:18:45 +00:00
|
|
|
NTSTATUS status = NtWriteVirtualMemory( process, addr, buffer, size, bytes_written );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-06-27 04:08:04 +00:00
|
|
|
}
|
|
|
|
|
2003-09-24 05:26:00 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* FlushInstructionCache (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize)
|
|
|
|
{
|
|
|
|
if (GetVersion() & 0x80000000) return TRUE; /* not NT, always TRUE */
|
|
|
|
FIXME("(%p,%p,0x%08lx): stub\n",hProcess, lpBaseAddress, dwSize);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 00:06:45 +00: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) );
|
|
|
|
return !status;
|
|
|
|
}
|
2003-06-27 04:08:04 +00:00
|
|
|
|
2003-09-17 05:31:32 +00: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 04:08:04 +00: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)
|
|
|
|
{
|
|
|
|
/* I don't think that Wine needs to do anything in that function */
|
|
|
|
return 1; /* success */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* SetFileApisToOEM (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
VOID WINAPI SetFileApisToOEM(void)
|
|
|
|
{
|
|
|
|
oem_file_apis = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* SetFileApisToANSI (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
VOID WINAPI SetFileApisToANSI(void)
|
|
|
|
{
|
|
|
|
oem_file_apis = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE: Set of file functions is using ANSI code page
|
|
|
|
* FALSE: Set of file functions is using OEM code page
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AreFileApisANSI(void)
|
|
|
|
{
|
|
|
|
return !oem_file_apis;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 03:57:02 +00:00
|
|
|
/***********************************************************************
|
2004-02-20 20:19:23 +00:00
|
|
|
* GetSystemMSecCount (SYSTEM.6)
|
2003-10-08 03:57:02 +00:00
|
|
|
* GetTickCount (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Returns the number of milliseconds, modulo 2^32, since the start
|
|
|
|
* of the wineserver.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetTickCount(void)
|
|
|
|
{
|
|
|
|
struct timeval t;
|
|
|
|
gettimeofday( &t, NULL );
|
|
|
|
return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-27 04:08:04 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentProcess (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
#undef GetCurrentProcess
|
|
|
|
HANDLE WINAPI GetCurrentProcess(void)
|
|
|
|
{
|
|
|
|
return (HANDLE)0xffffffff;
|
|
|
|
}
|