4 * Copyright 1996, 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
31 #include "wine/winbase16.h"
32 #include "wine/winuser16.h"
40 #include "kernel_private.h"
41 #include "wine/server.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(process);
46 WINE_DECLARE_DEBUG_CHANNEL(server);
47 WINE_DECLARE_DEBUG_CHANNEL(relay);
49 static UINT process_error_mode;
51 static HANDLE main_exe_file;
52 static DWORD shutdown_flags = 0;
53 static DWORD shutdown_priority = 0x280;
54 static DWORD process_dword;
55 static BOOL oem_file_apis;
57 static unsigned int server_startticks;
58 int main_create_flags = 0;
61 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
62 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
63 #define PDB32_DOS_PROC 0x0010 /* Dos process */
64 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
65 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
66 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
68 static const WCHAR comW[] = {'.','c','o','m',0};
69 static const WCHAR batW[] = {'.','b','a','t',0};
70 static const WCHAR winevdmW[] = {'w','i','n','e','v','d','m','.','e','x','e',0};
72 extern void SHELL_LoadRegistry(void);
73 extern void VERSION_Init( const WCHAR *appname );
74 extern void MODULE_InitLoadPath(void);
75 extern void LOCALE_Init(void);
77 /***********************************************************************
80 inline static int contains_path( LPCWSTR name )
82 return ((*name && (name[1] == ':')) || strchrW(name, '/') || strchrW(name, '\\'));
86 /***************************************************************************
89 * Get the path of a builtin module when the native file does not exist.
91 static BOOL get_builtin_path( const WCHAR *libname, const WCHAR *ext, WCHAR *filename, UINT size )
94 WCHAR sysdir[MAX_PATH];
95 UINT len = GetSystemDirectoryW( sysdir, MAX_PATH );
97 if (contains_path( libname ))
99 if (RtlGetFullPathName_U( libname, size * sizeof(WCHAR),
100 filename, &file_part ) > size * sizeof(WCHAR))
101 return FALSE; /* too long */
103 if (strncmpiW( filename, sysdir, len ) || filename[len] != '\\')
105 while (filename[len] == '\\') len++;
106 if (filename != file_part) return FALSE;
110 if (strlenW(libname) + len + 2 >= size) return FALSE; /* too long */
111 memcpy( filename, sysdir, len * sizeof(WCHAR) );
112 file_part = filename + len;
113 if (file_part > filename && file_part[-1] != '\\') *file_part++ = '\\';
114 strcpyW( file_part, libname );
116 if (ext && !strchrW( file_part, '.' ))
118 if (file_part + strlenW(file_part) + strlenW(ext) + 1 > filename + size)
119 return FALSE; /* too long */
120 strcatW( file_part, ext );
126 /***********************************************************************
127 * open_builtin_exe_file
129 * Open an exe file for a builtin exe.
131 static void *open_builtin_exe_file( const WCHAR *name, char *error, int error_size,
132 int test_only, int *file_exists )
134 char exename[MAX_PATH];
138 if ((p = strrchrW( name, '/' ))) name = p + 1;
139 if ((p = strrchrW( name, '\\' ))) name = p + 1;
141 /* we don't want to depend on the current codepage here */
142 len = strlenW( name ) + 1;
143 if (len >= sizeof(exename)) return NULL;
144 for (i = 0; i < len; i++)
146 if (name[i] > 127) return NULL;
147 exename[i] = (char)name[i];
148 if (exename[i] >= 'A' && exename[i] <= 'Z') exename[i] += 'a' - 'A';
150 return wine_dll_load_main_exe( exename, error, error_size, test_only, file_exists );
154 /***********************************************************************
157 * Open a specific exe file, taking load order into account.
158 * Returns the file handle or 0 for a builtin exe.
160 static HANDLE open_exe_file( const WCHAR *name )
162 enum loadorder_type loadorder[LOADORDER_NTYPES];
163 WCHAR buffer[MAX_PATH];
167 TRACE("looking for %s\n", debugstr_w(name) );
169 if ((handle = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ,
170 NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
172 /* file doesn't exist, check for builtin */
173 if (!contains_path( name )) goto error;
174 if (!get_builtin_path( name, NULL, buffer, sizeof(buffer) )) goto error;
178 MODULE_GetLoadOrderW( loadorder, NULL, name, TRUE );
180 for(i = 0; i < LOADORDER_NTYPES; i++)
182 if (loadorder[i] == LOADORDER_INVALID) break;
186 TRACE( "Trying native exe %s\n", debugstr_w(name) );
187 if (handle != INVALID_HANDLE_VALUE) return handle;
190 TRACE( "Trying built-in exe %s\n", debugstr_w(name) );
191 open_builtin_exe_file( name, NULL, 0, 1, &file_exists );
194 if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
201 if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
204 SetLastError( ERROR_FILE_NOT_FOUND );
205 return INVALID_HANDLE_VALUE;
209 /***********************************************************************
212 * Open an exe file, and return the full name and file handle.
213 * Returns FALSE if file could not be found.
214 * If file exists but cannot be opened, returns TRUE and set handle to INVALID_HANDLE_VALUE.
215 * If file is a builtin exe, returns TRUE and sets handle to 0.
217 static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE *handle )
219 static const WCHAR exeW[] = {'.','e','x','e',0};
221 enum loadorder_type loadorder[LOADORDER_NTYPES];
224 TRACE("looking for %s\n", debugstr_w(name) );
226 if (!SearchPathW( NULL, name, exeW, buflen, buffer, NULL ) &&
227 !get_builtin_path( name, exeW, buffer, buflen ))
229 /* no builtin found, try native without extension in case it is a Unix app */
231 if (SearchPathW( NULL, name, NULL, buflen, buffer, NULL ))
233 TRACE( "Trying native/Unix binary %s\n", debugstr_w(buffer) );
234 if ((*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ,
235 NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
241 MODULE_GetLoadOrderW( loadorder, NULL, buffer, TRUE );
243 for(i = 0; i < LOADORDER_NTYPES; i++)
245 if (loadorder[i] == LOADORDER_INVALID) break;
249 TRACE( "Trying native exe %s\n", debugstr_w(buffer) );
250 if ((*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ,
251 NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
253 if (GetLastError() != ERROR_FILE_NOT_FOUND) return TRUE;
256 TRACE( "Trying built-in exe %s\n", debugstr_w(buffer) );
257 open_builtin_exe_file( buffer, NULL, 0, 1, &file_exists );
268 SetLastError( ERROR_FILE_NOT_FOUND );
273 /**********************************************************************
276 * Load a PE format EXE file.
278 static HMODULE load_pe_exe( const WCHAR *name, HANDLE file )
280 IMAGE_NT_HEADERS *nt;
283 OBJECT_ATTRIBUTES attr;
288 attr.Length = sizeof(attr);
289 attr.RootDirectory = 0;
290 attr.ObjectName = NULL;
292 attr.SecurityDescriptor = NULL;
293 attr.SecurityQualityOfService = NULL;
296 if (NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ,
297 &attr, &size, 0, SEC_IMAGE, file ) != STATUS_SUCCESS)
301 if (NtMapViewOfSection( mapping, GetCurrentProcess(), &module, 0, 0, &size, &len,
302 ViewShare, 0, PAGE_READONLY ) != STATUS_SUCCESS)
308 nt = RtlImageNtHeader( module );
309 if (nt->OptionalHeader.AddressOfEntryPoint)
311 if (!RtlImageRvaToSection( nt, module, nt->OptionalHeader.AddressOfEntryPoint ))
312 MESSAGE("VIRUS WARNING: PE module %s has an invalid entrypoint (0x%08lx) "
313 "outside all sections (possibly infected by Tchernobyl/SpaceFiller virus)!\n",
314 debugstr_w(name), nt->OptionalHeader.AddressOfEntryPoint );
317 drive_type = GetDriveTypeW( name );
318 /* don't keep the file handle open on removable media */
319 if (drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_CDROM)
321 CloseHandle( main_exe_file );
328 /***********************************************************************
329 * build_initial_environment
331 * Build the Win32 environment from the Unix environment
333 static BOOL build_initial_environment( char **environ )
340 /* Compute the total size of the Unix environment */
341 for (e = environ; *e; e++)
343 if (!memcmp(*e, "PATH=", 5)) continue;
344 size += MultiByteToWideChar( CP_UNIXCP, 0, *e, -1, NULL, 0 );
346 size *= sizeof(WCHAR);
348 /* Now allocate the environment */
349 if (NtAllocateVirtualMemory(NtCurrentProcess(), &ptr, 0, &size,
350 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) != STATUS_SUCCESS)
353 NtCurrentTeb()->Peb->ProcessParameters->Environment = p = ptr;
354 endptr = p + size / sizeof(WCHAR);
356 /* And fill it with the Unix environment */
357 for (e = environ; *e; e++)
360 /* skip Unix PATH and store WINEPATH as PATH */
361 if (!memcmp(str, "PATH=", 5)) continue;
362 if (!memcmp(str, "WINEPATH=", 9 )) str += 4;
363 MultiByteToWideChar( CP_UNIXCP, 0, str, -1, p, endptr - p );
371 /***********************************************************************
374 * Set the Wine library Unicode argv global variables.
376 static void set_library_wargv( char **argv )
383 for (argc = 0; argv[argc]; argc++)
384 total += MultiByteToWideChar( CP_UNIXCP, 0, argv[argc], -1, NULL, 0 );
386 wargv = RtlAllocateHeap( GetProcessHeap(), 0,
387 total * sizeof(WCHAR) + (argc + 1) * sizeof(*wargv) );
388 p = (WCHAR *)(wargv + argc + 1);
389 for (argc = 0; argv[argc]; argc++)
391 DWORD reslen = MultiByteToWideChar( CP_UNIXCP, 0, argv[argc], -1, p, total );
397 __wine_main_wargv = wargv;
401 /***********************************************************************
404 * Build the command line of a process from the argv array.
406 * Note that it does NOT necessarily include the file name.
407 * Sometimes we don't even have any command line options at all.
409 * We must quote and escape characters so that the argv array can be rebuilt
410 * from the command line:
411 * - spaces and tabs must be quoted
413 * - quotes must be escaped
415 * - if '\'s are followed by a '"', they must be doubled and followed by '\"',
416 * resulting in an odd number of '\' followed by a '"'
419 * - '\'s that are not followed by a '"' can be left as is
423 static BOOL build_command_line( WCHAR **argv )
428 RTL_USER_PROCESS_PARAMETERS* rupp = NtCurrentTeb()->Peb->ProcessParameters;
430 if (rupp->CommandLine.Buffer) return TRUE; /* already got it from the server */
433 for (arg = argv; *arg; arg++)
435 int has_space,bcount;
441 if( !*a ) has_space=1;
446 if (*a==' ' || *a=='\t') {
448 } else if (*a=='"') {
449 /* doubling of '\' preceeding a '"',
450 * plus escaping of said '"'
458 len+=(a-*arg)+1 /* for the separating space */;
460 len+=2; /* for the quotes */
463 if (!(rupp->CommandLine.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR))))
466 p = rupp->CommandLine.Buffer;
467 rupp->CommandLine.Length = (len - 1) * sizeof(WCHAR);
468 rupp->CommandLine.MaximumLength = len * sizeof(WCHAR);
469 for (arg = argv; *arg; arg++)
471 int has_space,has_quote;
474 /* Check for quotes and spaces in this argument */
475 has_space=has_quote=0;
477 if( !*a ) has_space=1;
479 if (*a==' ' || *a=='\t') {
483 } else if (*a=='"') {
491 /* Now transfer it to the command line */
508 /* Double all the '\\' preceeding this '"', plus one */
509 for (i=0;i<=bcount;i++)
521 while ((*p=*x++)) p++;
527 if (p > rupp->CommandLine.Buffer)
528 p--; /* remove last space */
535 /* make sure the unicode string doesn't point beyond the end pointer */
536 static inline void fix_unicode_string( UNICODE_STRING *str, char *end_ptr )
538 if ((char *)str->Buffer >= end_ptr)
540 str->Length = str->MaximumLength = 0;
544 if ((char *)str->Buffer + str->MaximumLength > end_ptr)
546 str->MaximumLength = (end_ptr - (char *)str->Buffer) & ~(sizeof(WCHAR) - 1);
548 if (str->Length >= str->MaximumLength)
550 if (str->MaximumLength >= sizeof(WCHAR))
551 str->Length = str->MaximumLength - sizeof(WCHAR);
553 str->Length = str->MaximumLength = 0;
558 /***********************************************************************
559 * init_user_process_params
561 * Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
563 static RTL_USER_PROCESS_PARAMETERS *init_user_process_params( size_t info_size )
568 RTL_USER_PROCESS_PARAMETERS *params;
571 if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, NULL, &size,
572 MEM_COMMIT, PAGE_READWRITE )) != STATUS_SUCCESS)
575 SERVER_START_REQ( get_startup_info )
577 wine_server_set_reply( req, ptr, info_size );
578 wine_server_call( req );
579 info_size = wine_server_reply_size( reply );
584 params->Size = info_size;
585 params->AllocationSize = size;
587 /* make sure the strings are valid */
588 fix_unicode_string( ¶ms->CurrentDirectoryName, (char *)info_size );
589 fix_unicode_string( ¶ms->DllPath, (char *)info_size );
590 fix_unicode_string( ¶ms->ImagePathName, (char *)info_size );
591 fix_unicode_string( ¶ms->CommandLine, (char *)info_size );
592 fix_unicode_string( ¶ms->WindowTitle, (char *)info_size );
593 fix_unicode_string( ¶ms->Desktop, (char *)info_size );
594 fix_unicode_string( ¶ms->ShellInfo, (char *)info_size );
595 fix_unicode_string( ¶ms->RuntimeInfo, (char *)info_size );
597 return RtlNormalizeProcessParams( params );
601 /***********************************************************************
604 * Main process initialisation code
606 static BOOL process_init( char *argv[], char **environ )
609 size_t info_size = 0;
610 RTL_USER_PROCESS_PARAMETERS *params;
611 PEB *peb = NtCurrentTeb()->Peb;
612 HANDLE hstdin, hstdout, hstderr;
616 setlocale(LC_CTYPE,"");
618 /* Retrieve startup info from the server */
619 SERVER_START_REQ( init_process )
622 req->ldt_copy = &wine_ldt_copy;
623 if ((ret = !wine_server_call_err( req )))
625 main_exe_file = reply->exe_file;
626 main_create_flags = reply->create_flags;
627 info_size = reply->info_size;
628 server_startticks = reply->server_start;
629 hstdin = reply->hstdin;
630 hstdout = reply->hstdout;
631 hstderr = reply->hstderr;
635 if (!ret) return FALSE;
639 params = peb->ProcessParameters;
641 /* This is wine specific: we have no parent (we're started from unix)
642 * so, create a simple console with bare handles to unix stdio
643 * input & output streams (aka simple console)
645 wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, TRUE, ¶ms->hStdInput );
646 wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, ¶ms->hStdOutput );
647 wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, TRUE, ¶ms->hStdError );
649 /* <hack: to be changed later on> */
650 params->CurrentDirectoryName.Length = 3 * sizeof(WCHAR);
651 params->CurrentDirectoryName.MaximumLength = RtlGetLongestNtPathLength() * sizeof(WCHAR);
652 params->CurrentDirectoryName.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, params->CurrentDirectoryName.MaximumLength);
653 params->CurrentDirectoryName.Buffer[0] = 'C';
654 params->CurrentDirectoryName.Buffer[1] = ':';
655 params->CurrentDirectoryName.Buffer[2] = '\\';
656 params->CurrentDirectoryName.Buffer[3] = '\0';
657 /* </hack: to be changed later on> */
661 if (!(params = init_user_process_params( info_size ))) return FALSE;
662 peb->ProcessParameters = params;
664 /* convert value from server:
665 * + 0 => INVALID_HANDLE_VALUE
666 * + console handle need to be mapped
669 hstdin = INVALID_HANDLE_VALUE;
670 else if (VerifyConsoleIoHandle(console_handle_map(hstdin)))
671 hstdin = console_handle_map(hstdin);
674 hstdout = INVALID_HANDLE_VALUE;
675 else if (VerifyConsoleIoHandle(console_handle_map(hstdout)))
676 hstdout = console_handle_map(hstdout);
679 hstderr = INVALID_HANDLE_VALUE;
680 else if (VerifyConsoleIoHandle(console_handle_map(hstderr)))
681 hstderr = console_handle_map(hstderr);
683 params->hStdInput = hstdin;
684 params->hStdOutput = hstdout;
685 params->hStdError = hstderr;
690 /* Copy the parent environment */
691 if (!build_initial_environment( environ )) return FALSE;
693 /* Parse command line arguments */
694 OPTIONS_ParseOptions( !info_size ? argv : NULL );
696 /* initialise DOS drives */
697 if (!DRIVE_Init()) return FALSE;
699 /* initialise DOS directories */
700 if (!DIR_Init()) return FALSE;
702 /* registry initialisation */
703 SHELL_LoadRegistry();
705 /* global boot finished, the rest is process-local */
706 SERVER_START_REQ( boot_done )
708 req->debug_level = TRACE_ON(server);
709 wine_server_call( req );
717 /***********************************************************************
720 * Startup routine of a new process. Runs on the new process stack.
722 static void start_process( void *arg )
726 PEB *peb = NtCurrentTeb()->Peb;
727 IMAGE_NT_HEADERS *nt;
728 LPTHREAD_START_ROUTINE entry;
730 LdrInitializeThunk( main_exe_file, CreateFileW, 0, 0 );
732 nt = RtlImageNtHeader( peb->ImageBaseAddress );
733 entry = (LPTHREAD_START_ROUTINE)((char *)peb->ImageBaseAddress +
734 nt->OptionalHeader.AddressOfEntryPoint);
737 DPRINTF( "%04lx:Starting process %s (entryproc=%p)\n", GetCurrentThreadId(),
738 debugstr_w(peb->ProcessParameters->ImagePathName.Buffer), entry );
740 SetLastError( 0 ); /* clear error code */
741 if (peb->BeingDebugged) DbgBreakPoint();
742 ExitProcess( entry( peb ) );
744 __EXCEPT(UnhandledExceptionFilter)
746 TerminateThread( GetCurrentThread(), GetExceptionCode() );
752 /***********************************************************************
755 * Wine initialisation: load and start the main exe file.
757 void __wine_kernel_init(void)
759 WCHAR *main_exe_name, *p;
761 DWORD stack_size = 0;
763 PEB *peb = NtCurrentTeb()->Peb;
765 /* Initialize everything */
766 if (!process_init( __wine_main_argv, __wine_main_environ )) exit(1);
767 /* update argc in case options have been removed */
768 for (__wine_main_argc = 0; __wine_main_argv[__wine_main_argc]; __wine_main_argc++) /*nothing*/;
770 __wine_main_argv++; /* remove argv[0] (wine itself) */
773 if (!(main_exe_name = peb->ProcessParameters->ImagePathName.Buffer))
775 WCHAR buffer[MAX_PATH];
776 WCHAR exe_nameW[MAX_PATH];
778 if (!__wine_main_argv[0]) OPTIONS_Usage();
780 MultiByteToWideChar( CP_UNIXCP, 0, __wine_main_argv[0], -1, exe_nameW, MAX_PATH );
781 if (!find_exe_file( exe_nameW, buffer, MAX_PATH, &main_exe_file ))
783 MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] );
786 if (main_exe_file == INVALID_HANDLE_VALUE)
788 MESSAGE( "wine: cannot open %s\n", debugstr_w(main_exe_name) );
791 RtlCreateUnicodeString( &peb->ProcessParameters->ImagePathName, buffer );
792 main_exe_name = peb->ProcessParameters->ImagePathName.Buffer;
795 TRACE( "starting process name=%s file=%p argv[0]=%s\n",
796 debugstr_w(main_exe_name), main_exe_file, debugstr_a(__wine_main_argv[0]) );
798 MODULE_InitLoadPath();
799 VERSION_Init( main_exe_name );
801 if (!main_exe_file) /* no file handle -> Winelib app */
803 TRACE( "starting Winelib app %s\n", debugstr_w(main_exe_name) );
804 if (open_builtin_exe_file( main_exe_name, error, sizeof(error), 0, &file_exists ))
806 MESSAGE( "wine: cannot open builtin library for %s: %s\n",
807 debugstr_w(main_exe_name), error );
811 switch( MODULE_GetBinaryType( main_exe_file ))
814 TRACE( "starting Win32 binary %s\n", debugstr_w(main_exe_name) );
815 if ((peb->ImageBaseAddress = load_pe_exe( main_exe_name, main_exe_file )))
817 MESSAGE( "wine: could not load %s as Win32 binary\n", debugstr_w(main_exe_name) );
820 MESSAGE( "wine: %s is a DLL, not an executable\n", debugstr_w(main_exe_name) );
823 /* check for .com extension */
824 if (!(p = strrchrW( main_exe_name, '.' )) || strcmpiW( p, comW ))
826 MESSAGE( "wine: cannot determine executable type for %s\n",
827 debugstr_w(main_exe_name) );
833 TRACE( "starting Win16/DOS binary %s\n", debugstr_w(main_exe_name) );
834 CloseHandle( main_exe_file );
838 __wine_main_argv[0] = "winevdm.exe";
839 if (open_builtin_exe_file( winevdmW, error, sizeof(error), 0, &file_exists ))
841 MESSAGE( "wine: trying to run %s, cannot open builtin library for 'winevdm.exe': %s\n",
842 debugstr_w(main_exe_name), error );
845 MESSAGE( "wine: %s is an OS/2 binary, not supported\n", debugstr_w(main_exe_name) );
847 case BINARY_UNIX_EXE:
848 MESSAGE( "wine: %s is a Unix binary, not supported\n", debugstr_w(main_exe_name) );
850 case BINARY_UNIX_LIB:
852 DOS_FULL_NAME full_name;
854 TRACE( "starting Winelib app %s\n", debugstr_w(main_exe_name) );
855 CloseHandle( main_exe_file );
857 if (DOSFS_GetFullName( main_exe_name, TRUE, &full_name ) &&
858 wine_dlopen( full_name.long_name, RTLD_NOW, error, sizeof(error) ))
860 static const WCHAR soW[] = {'.','s','o',0};
861 if ((p = strrchrW( main_exe_name, '.' )) && !strcmpW( p, soW ))
864 /* update the unicode string */
865 RtlInitUnicodeString( &peb->ProcessParameters->ImagePathName, main_exe_name );
869 MESSAGE( "wine: could not load %s: %s\n", debugstr_w(main_exe_name), error );
875 /* build command line */
876 set_library_wargv( __wine_main_argv );
877 if (!build_command_line( __wine_main_wargv )) goto error;
879 stack_size = RtlImageNtHeader(peb->ImageBaseAddress)->OptionalHeader.SizeOfStackReserve;
881 /* allocate main thread stack */
882 if (!THREAD_InitStack( NtCurrentTeb(), stack_size )) goto error;
884 /* switch to the new stack */
885 wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
888 ExitProcess( GetLastError() );
892 /***********************************************************************
895 * Build an argv array from a command-line.
896 * 'reserved' is the number of args to reserve before the first one.
898 static char **build_argv( const WCHAR *cmdlineW, int reserved )
902 char *arg,*s,*d,*cmdline;
903 int in_quotes,bcount,len;
905 len = WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW, -1, NULL, 0, NULL, NULL );
906 if (!(cmdline = malloc(len))) return NULL;
907 WideCharToMultiByte( CP_UNIXCP, 0, cmdlineW, -1, cmdline, len, NULL, NULL );
914 if (*s=='\0' || ((*s==' ' || *s=='\t') && !in_quotes)) {
917 /* skip the remaining spaces */
918 while (*s==' ' || *s=='\t') {
925 } else if (*s=='\\') {
926 /* '\', count them */
928 } else if ((*s=='"') && ((bcount & 1)==0)) {
930 in_quotes=!in_quotes;
933 /* a regular character */
938 argv=malloc(argc*sizeof(*argv));
947 if ((*s==' ' || *s=='\t') && !in_quotes) {
948 /* Close the argument and copy it */
952 /* skip the remaining spaces */
955 } while (*s==' ' || *s=='\t');
957 /* Start with a new argument */
960 } else if (*s=='\\') {
964 } else if (*s=='"') {
966 if ((bcount & 1)==0) {
967 /* Preceeded by an even number of '\', this is half that
968 * number of '\', plus a '"' which we discard.
972 in_quotes=!in_quotes;
974 /* Preceeded by an odd number of '\', this is half that
975 * number of '\' followed by a '"'
983 /* a regular character */
998 /***********************************************************************
1001 * Allocate an environment string; helper for build_envp
1003 static char *alloc_env_string( const char *name, const char *value )
1005 char *ret = malloc( strlen(name) + strlen(value) + 1 );
1006 strcpy( ret, name );
1007 strcat( ret, value );
1011 /***********************************************************************
1014 * Build the environment of a new child process.
1016 static char **build_envp( const WCHAR *envW, const WCHAR *extra_envW )
1020 char *env, *extra_env = NULL;
1021 int count = 0, length;
1025 for (p = extra_envW; *p; count++) p += strlenW(p) + 1;
1027 length = WideCharToMultiByte( CP_UNIXCP, 0, extra_envW, p - extra_envW,
1028 NULL, 0, NULL, NULL );
1029 if ((extra_env = malloc( length )))
1030 WideCharToMultiByte( CP_UNIXCP, 0, extra_envW, p - extra_envW,
1031 extra_env, length, NULL, NULL );
1033 for (p = envW; *p; count++) p += strlenW(p) + 1;
1035 length = WideCharToMultiByte( CP_UNIXCP, 0, envW, p - envW, NULL, 0, NULL, NULL );
1036 if (!(env = malloc( length ))) return NULL;
1037 WideCharToMultiByte( CP_UNIXCP, 0, envW, p - envW, env, length, NULL, NULL );
1041 if ((envp = malloc( count * sizeof(*envp) )))
1043 char **envptr = envp;
1046 /* first the extra strings */
1047 if (extra_env) for (p = extra_env; *p; p += strlen(p) + 1) *envptr++ = p;
1048 /* then put PATH, HOME and WINEPREFIX from the unix env */
1049 if ((p = getenv("PATH"))) *envptr++ = alloc_env_string( "PATH=", p );
1050 if ((p = getenv("HOME"))) *envptr++ = alloc_env_string( "HOME=", p );
1051 if ((p = getenv("WINEPREFIX"))) *envptr++ = alloc_env_string( "WINEPREFIX=", p );
1052 /* now put the Windows environment strings */
1053 for (p = env; *p; p += strlen(p) + 1)
1055 if (!memcmp( p, "PATH=", 5 )) /* store PATH as WINEPATH */
1056 *envptr++ = alloc_env_string( "WINEPATH=", p + 5 );
1057 else if (memcmp( p, "HOME=", 5 ) &&
1058 memcmp( p, "WINEPATH=", 9 ) &&
1059 memcmp( p, "WINEPREFIX=", 11 )) *envptr++ = p;
1067 /***********************************************************************
1070 * Locate the Wine binary to exec for a new Win32 process.
1072 static void exec_wine_binary( char **argv, char **envp )
1074 const char *path, *pos, *ptr;
1076 /* first, try for a WINELOADER environment variable */
1077 argv[0] = getenv("WINELOADER");
1079 execve( argv[0], argv, envp );
1081 /* next, try bin directory */
1082 argv[0] = BINDIR "/wine";
1083 execve( argv[0], argv, envp );
1085 /* now try the path of argv0 of the current binary */
1086 if ((path = wine_get_argv0_path()))
1088 if (!(argv[0] = malloc( strlen(path) + sizeof("wine") ))) return;
1089 strcpy( argv[0], path );
1090 strcat( argv[0], "wine" );
1091 execve( argv[0], argv, envp );
1095 /* now search in the Unix path */
1096 if ((path = getenv( "PATH" )))
1098 if (!(argv[0] = malloc( strlen(path) + 6 ))) return;
1102 while (*pos == ':') pos++;
1104 if (!(ptr = strchr( pos, ':' ))) ptr = pos + strlen(pos);
1105 memcpy( argv[0], pos, ptr - pos );
1106 strcpy( argv[0] + (ptr - pos), "/wine" );
1107 execve( argv[0], argv, envp );
1115 /***********************************************************************
1118 * Fork and exec a new Unix binary, checking for errors.
1120 static int fork_and_exec( const char *filename, const WCHAR *cmdline,
1121 const WCHAR *env, const char *newdir )
1126 if (!env) env = GetEnvironmentStringsW();
1133 fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */
1134 if (!(pid = fork())) /* child */
1136 char **argv = build_argv( cmdline, 0 );
1137 char **envp = build_envp( env, NULL );
1140 /* Reset signals that we previously set to SIG_IGN */
1141 signal( SIGPIPE, SIG_DFL );
1142 signal( SIGCHLD, SIG_DFL );
1144 if (newdir) chdir(newdir);
1146 if (argv && envp) execve( filename, argv, envp );
1148 write( fd[1], &err, sizeof(err) );
1152 if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0)) /* exec failed */
1157 if (pid == -1) FILE_SetDosError();
1163 /***********************************************************************
1164 * create_user_params
1166 static RTL_USER_PROCESS_PARAMETERS *create_user_params( LPCWSTR filename, LPCWSTR cmdline,
1167 const STARTUPINFOW *startup )
1169 RTL_USER_PROCESS_PARAMETERS *params;
1170 UNICODE_STRING image_str, cmdline_str, desktop, title;
1172 WCHAR buffer[MAX_PATH];
1174 if (GetLongPathNameW( filename, buffer, MAX_PATH ))
1175 RtlInitUnicodeString( &image_str, buffer );
1177 RtlInitUnicodeString( &image_str, filename );
1179 RtlInitUnicodeString( &cmdline_str, cmdline );
1180 if (startup->lpDesktop) RtlInitUnicodeString( &desktop, startup->lpDesktop );
1181 if (startup->lpTitle) RtlInitUnicodeString( &title, startup->lpTitle );
1183 status = RtlCreateProcessParameters( ¶ms, &image_str, NULL, NULL, &cmdline_str, NULL,
1184 startup->lpTitle ? &title : NULL,
1185 startup->lpDesktop ? &desktop : NULL,
1187 if (status != STATUS_SUCCESS)
1189 SetLastError( RtlNtStatusToDosError(status) );
1193 params->Environment = NULL; /* we pass it through the Unix environment */
1194 params->hStdInput = startup->hStdInput;
1195 params->hStdOutput = startup->hStdOutput;
1196 params->hStdError = startup->hStdError;
1197 params->dwX = startup->dwX;
1198 params->dwY = startup->dwY;
1199 params->dwXSize = startup->dwXSize;
1200 params->dwYSize = startup->dwYSize;
1201 params->dwXCountChars = startup->dwXCountChars;
1202 params->dwYCountChars = startup->dwYCountChars;
1203 params->dwFillAttribute = startup->dwFillAttribute;
1204 params->dwFlags = startup->dwFlags;
1205 params->wShowWindow = startup->wShowWindow;
1210 /***********************************************************************
1213 * Create a new process. If hFile is a valid handle we have an exe
1214 * file, otherwise it is a Winelib app.
1216 static BOOL create_process( HANDLE hFile, LPCWSTR filename, LPWSTR cmd_line, LPWSTR env,
1217 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1218 BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
1219 LPPROCESS_INFORMATION info, LPCSTR unixdir )
1221 BOOL ret, success = FALSE;
1222 HANDLE process_info;
1223 RTL_USER_PROCESS_PARAMETERS *params;
1224 WCHAR *extra_env = NULL;
1233 env = GetEnvironmentStringsW();
1234 extra_env = DRIVE_BuildEnv();
1237 if (!(params = create_user_params( filename, cmd_line, startup )))
1239 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
1243 /* create the synchronization pipes */
1245 if (pipe( startfd ) == -1)
1248 RtlDestroyProcessParameters( params );
1249 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
1252 if (pipe( execfd ) == -1)
1255 close( startfd[0] );
1256 close( startfd[1] );
1257 RtlDestroyProcessParameters( params );
1258 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
1261 fcntl( execfd[1], F_SETFD, 1 ); /* set close on exec */
1263 /* create the child process */
1265 if (!(pid = fork())) /* child */
1267 char **argv = build_argv( cmd_line, 1 );
1268 char **envp = build_envp( env, extra_env );
1270 close( startfd[1] );
1273 /* wait for parent to tell us to start */
1274 if (read( startfd[0], &dummy, 1 ) != 1) _exit(1);
1276 close( startfd[0] );
1277 /* Reset signals that we previously set to SIG_IGN */
1278 signal( SIGPIPE, SIG_DFL );
1279 signal( SIGCHLD, SIG_DFL );
1281 if (unixdir) chdir(unixdir);
1283 if (argv && envp) exec_wine_binary( argv, envp );
1286 write( execfd[1], &err, sizeof(err) );
1290 /* this is the parent */
1292 close( startfd[0] );
1294 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
1297 close( startfd[1] );
1300 RtlDestroyProcessParameters( params );
1304 /* create the process on the server side */
1306 SERVER_START_REQ( new_process )
1308 req->inherit_all = inherit;
1309 req->create_flags = flags;
1310 req->unix_pid = pid;
1311 req->exe_file = hFile;
1312 if (startup->dwFlags & STARTF_USESTDHANDLES)
1314 req->hstdin = startup->hStdInput;
1315 req->hstdout = startup->hStdOutput;
1316 req->hstderr = startup->hStdError;
1320 req->hstdin = GetStdHandle( STD_INPUT_HANDLE );
1321 req->hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
1322 req->hstderr = GetStdHandle( STD_ERROR_HANDLE );
1325 if ((flags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS)) != 0)
1327 /* this is temporary (for console handles). We have no way to control that the handle is invalid in child process otherwise */
1328 if (is_console_handle(req->hstdin)) req->hstdin = INVALID_HANDLE_VALUE;
1329 if (is_console_handle(req->hstdout)) req->hstdout = INVALID_HANDLE_VALUE;
1330 if (is_console_handle(req->hstderr)) req->hstderr = INVALID_HANDLE_VALUE;
1334 if (is_console_handle(req->hstdin)) req->hstdin = console_handle_unmap(req->hstdin);
1335 if (is_console_handle(req->hstdout)) req->hstdout = console_handle_unmap(req->hstdout);
1336 if (is_console_handle(req->hstderr)) req->hstderr = console_handle_unmap(req->hstderr);
1339 wine_server_add_data( req, params, params->Size );
1340 ret = !wine_server_call_err( req );
1341 process_info = reply->info;
1345 RtlDestroyProcessParameters( params );
1348 close( startfd[1] );
1353 /* tell child to start and wait for it to exec */
1355 write( startfd[1], &dummy, 1 );
1356 close( startfd[1] );
1358 if (read( execfd[0], &err, sizeof(err) ) > 0) /* exec failed */
1363 CloseHandle( process_info );
1367 /* wait for the new process info to be ready */
1369 WaitForSingleObject( process_info, INFINITE );
1370 SERVER_START_REQ( get_new_process_info )
1372 req->info = process_info;
1373 req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle);
1374 req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle);
1375 if ((ret = !wine_server_call_err( req )))
1377 info->dwProcessId = (DWORD)reply->pid;
1378 info->dwThreadId = (DWORD)reply->tid;
1379 info->hProcess = reply->phandle;
1380 info->hThread = reply->thandle;
1381 success = reply->success;
1386 if (ret && !success) /* new process failed to start */
1389 if (GetExitCodeProcess( info->hProcess, &exitcode )) SetLastError( exitcode );
1390 CloseHandle( info->hThread );
1391 CloseHandle( info->hProcess );
1394 CloseHandle( process_info );
1399 /***********************************************************************
1400 * create_vdm_process
1402 * Create a new VDM process for a 16-bit or DOS application.
1404 static BOOL create_vdm_process( LPCWSTR filename, LPWSTR cmd_line, LPWSTR env,
1405 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1406 BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
1407 LPPROCESS_INFORMATION info, LPCSTR unixdir )
1409 static const WCHAR argsW[] = {'%','s',' ','-','-','a','p','p','-','n','a','m','e',' ','"','%','s','"',' ','%','s',0};
1412 LPWSTR new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
1413 (strlenW(filename) + strlenW(cmd_line) + 30) * sizeof(WCHAR) );
1417 SetLastError( ERROR_OUTOFMEMORY );
1420 sprintfW( new_cmd_line, argsW, winevdmW, filename, cmd_line );
1421 ret = create_process( 0, winevdmW, new_cmd_line, env, psa, tsa, inherit,
1422 flags, startup, info, unixdir );
1423 HeapFree( GetProcessHeap(), 0, new_cmd_line );
1428 /***********************************************************************
1429 * create_cmd_process
1431 * Create a new cmd shell process for a .BAT file.
1433 static BOOL create_cmd_process( LPCWSTR filename, LPWSTR cmd_line, LPVOID env,
1434 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1435 BOOL inherit, DWORD flags, LPSTARTUPINFOW startup,
1436 LPPROCESS_INFORMATION info, LPCWSTR cur_dir )
1439 static const WCHAR comspecW[] = {'C','O','M','S','P','E','C',0};
1440 static const WCHAR slashcW[] = {' ','/','c',' ',0};
1441 WCHAR comspec[MAX_PATH];
1445 if (!GetEnvironmentVariableW( comspecW, comspec, sizeof(comspec)/sizeof(WCHAR) ))
1447 if (!(newcmdline = HeapAlloc( GetProcessHeap(), 0,
1448 (strlenW(comspec) + 4 + strlenW(cmd_line) + 1) * sizeof(WCHAR))))
1451 strcpyW( newcmdline, comspec );
1452 strcatW( newcmdline, slashcW );
1453 strcatW( newcmdline, cmd_line );
1454 ret = CreateProcessW( comspec, newcmdline, psa, tsa, inherit,
1455 flags, env, cur_dir, startup, info );
1456 HeapFree( GetProcessHeap(), 0, newcmdline );
1461 /*************************************************************************
1464 * Helper for CreateProcess: retrieve the file name to load from the
1465 * app name and command line. Store the file name in buffer, and
1466 * return a possibly modified command line.
1467 * Also returns a handle to the opened file if it's a Windows binary.
1469 static LPWSTR get_file_name( LPCWSTR appname, LPWSTR cmdline, LPWSTR buffer,
1470 int buflen, HANDLE *handle )
1472 static const WCHAR quotesW[] = {'"','%','s','"',0};
1474 WCHAR *name, *pos, *ret = NULL;
1477 /* if we have an app name, everything is easy */
1481 /* use the unmodified app name as file name */
1482 lstrcpynW( buffer, appname, buflen );
1483 *handle = open_exe_file( buffer );
1484 if (!(ret = cmdline) || !cmdline[0])
1486 /* no command-line, create one */
1487 if ((ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(appname) + 3) * sizeof(WCHAR) )))
1488 sprintfW( ret, quotesW, appname );
1495 SetLastError( ERROR_INVALID_PARAMETER );
1499 /* first check for a quoted file name */
1501 if ((cmdline[0] == '"') && ((p = strchrW( cmdline + 1, '"' ))))
1503 int len = p - cmdline - 1;
1504 /* extract the quoted portion as file name */
1505 if (!(name = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
1506 memcpy( name, cmdline + 1, len * sizeof(WCHAR) );
1509 if (find_exe_file( name, buffer, buflen, handle ))
1510 ret = cmdline; /* no change necessary */
1514 /* now try the command-line word by word */
1516 if (!(name = HeapAlloc( GetProcessHeap(), 0, (strlenW(cmdline) + 1) * sizeof(WCHAR) )))
1523 do *pos++ = *p++; while (*p && *p != ' ');
1525 if (find_exe_file( name, buffer, buflen, handle ))
1532 if (!ret || !strchrW( name, ' ' )) goto done; /* no change necessary */
1534 /* now build a new command-line with quotes */
1536 if (!(ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(cmdline) + 3) * sizeof(WCHAR) )))
1538 sprintfW( ret, quotesW, name );
1542 HeapFree( GetProcessHeap(), 0, name );
1547 /**********************************************************************
1548 * CreateProcessA (KERNEL32.@)
1550 BOOL WINAPI CreateProcessA( LPCSTR app_name, LPSTR cmd_line, LPSECURITY_ATTRIBUTES process_attr,
1551 LPSECURITY_ATTRIBUTES thread_attr, BOOL inherit,
1552 DWORD flags, LPVOID env, LPCSTR cur_dir,
1553 LPSTARTUPINFOA startup_info, LPPROCESS_INFORMATION info )
1556 UNICODE_STRING app_nameW, cmd_lineW, cur_dirW, desktopW, titleW;
1559 if (app_name) RtlCreateUnicodeStringFromAsciiz( &app_nameW, app_name );
1560 else app_nameW.Buffer = NULL;
1561 if (cmd_line) RtlCreateUnicodeStringFromAsciiz( &cmd_lineW, cmd_line );
1562 else cmd_lineW.Buffer = NULL;
1563 if (cur_dir) RtlCreateUnicodeStringFromAsciiz( &cur_dirW, cur_dir );
1564 else cur_dirW.Buffer = NULL;
1565 if (startup_info->lpDesktop) RtlCreateUnicodeStringFromAsciiz( &desktopW, startup_info->lpDesktop );
1566 else desktopW.Buffer = NULL;
1567 if (startup_info->lpTitle) RtlCreateUnicodeStringFromAsciiz( &titleW, startup_info->lpTitle );
1568 else titleW.Buffer = NULL;
1570 memcpy( &infoW, startup_info, sizeof(infoW) );
1571 infoW.lpDesktop = desktopW.Buffer;
1572 infoW.lpTitle = titleW.Buffer;
1574 if (startup_info->lpReserved)
1575 FIXME("StartupInfo.lpReserved is used, please report (%s)\n",
1576 debugstr_a(startup_info->lpReserved));
1578 ret = CreateProcessW( app_nameW.Buffer, cmd_lineW.Buffer, process_attr, thread_attr,
1579 inherit, flags, env, cur_dirW.Buffer, &infoW, info );
1581 RtlFreeUnicodeString( &app_nameW );
1582 RtlFreeUnicodeString( &cmd_lineW );
1583 RtlFreeUnicodeString( &cur_dirW );
1584 RtlFreeUnicodeString( &desktopW );
1585 RtlFreeUnicodeString( &titleW );
1590 /**********************************************************************
1591 * CreateProcessW (KERNEL32.@)
1593 BOOL WINAPI CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIBUTES process_attr,
1594 LPSECURITY_ATTRIBUTES thread_attr, BOOL inherit, DWORD flags,
1595 LPVOID env, LPCWSTR cur_dir, LPSTARTUPINFOW startup_info,
1596 LPPROCESS_INFORMATION info )
1600 const char *unixdir = NULL;
1601 DOS_FULL_NAME full_dir;
1602 WCHAR name[MAX_PATH];
1603 WCHAR *tidy_cmdline, *p, *envW = env;
1605 /* Process the AppName and/or CmdLine to get module name and path */
1607 TRACE("app %s cmdline %s\n", debugstr_w(app_name), debugstr_w(cmd_line) );
1609 if (!(tidy_cmdline = get_file_name( app_name, cmd_line, name, sizeof(name), &hFile )))
1611 if (hFile == INVALID_HANDLE_VALUE) goto done;
1613 /* Warn if unsupported features are used */
1615 if (flags & (IDLE_PRIORITY_CLASS | HIGH_PRIORITY_CLASS | REALTIME_PRIORITY_CLASS |
1616 CREATE_NEW_PROCESS_GROUP | CREATE_SEPARATE_WOW_VDM | CREATE_SHARED_WOW_VDM |
1617 CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW |
1618 PROFILE_USER | PROFILE_KERNEL | PROFILE_SERVER))
1619 WARN("(%s,...): ignoring some flags in %lx\n", debugstr_w(name), flags);
1623 if (DOSFS_GetFullName( cur_dir, TRUE, &full_dir )) unixdir = full_dir.long_name;
1627 WCHAR buf[MAX_PATH];
1628 if (GetCurrentDirectoryW(MAX_PATH, buf))
1630 if (DOSFS_GetFullName( buf, TRUE, &full_dir )) unixdir = full_dir.long_name;
1634 if (env && !(flags & CREATE_UNICODE_ENVIRONMENT)) /* convert environment to unicode */
1639 while (*p) p += strlen(p) + 1;
1640 p++; /* final null */
1641 lenW = MultiByteToWideChar( CP_ACP, 0, env, p - (char*)env, NULL, 0 );
1642 envW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) );
1643 MultiByteToWideChar( CP_ACP, 0, env, p - (char*)env, envW, lenW );
1644 flags |= CREATE_UNICODE_ENVIRONMENT;
1647 info->hThread = info->hProcess = 0;
1648 info->dwProcessId = info->dwThreadId = 0;
1650 /* Determine executable type */
1652 if (!hFile) /* builtin exe */
1654 TRACE( "starting %s as Winelib app\n", debugstr_w(name) );
1655 retv = create_process( 0, name, tidy_cmdline, envW, process_attr, thread_attr,
1656 inherit, flags, startup_info, info, unixdir );
1660 switch( MODULE_GetBinaryType( hFile ))
1663 TRACE( "starting %s as Win32 binary\n", debugstr_w(name) );
1664 retv = create_process( hFile, name, tidy_cmdline, envW, process_attr, thread_attr,
1665 inherit, flags, startup_info, info, unixdir );
1669 TRACE( "starting %s as Win16/DOS binary\n", debugstr_w(name) );
1670 retv = create_vdm_process( name, tidy_cmdline, envW, process_attr, thread_attr,
1671 inherit, flags, startup_info, info, unixdir );
1674 FIXME( "%s is OS/2 binary, not supported\n", debugstr_w(name) );
1675 SetLastError( ERROR_BAD_EXE_FORMAT );
1678 TRACE( "not starting %s since it is a dll\n", debugstr_w(name) );
1679 SetLastError( ERROR_BAD_EXE_FORMAT );
1681 case BINARY_UNIX_LIB:
1682 TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_w(name) );
1683 retv = create_process( hFile, name, tidy_cmdline, envW, process_attr, thread_attr,
1684 inherit, flags, startup_info, info, unixdir );
1686 case BINARY_UNKNOWN:
1687 /* check for .com or .bat extension */
1688 if ((p = strrchrW( name, '.' )))
1690 if (!strcmpiW( p, comW ))
1692 TRACE( "starting %s as DOS binary\n", debugstr_w(name) );
1693 retv = create_vdm_process( name, tidy_cmdline, envW, process_attr, thread_attr,
1694 inherit, flags, startup_info, info, unixdir );
1697 if (!strcmpiW( p, batW ))
1699 TRACE( "starting %s as batch binary\n", debugstr_w(name) );
1700 retv = create_cmd_process( name, tidy_cmdline, envW, process_attr, thread_attr,
1701 inherit, flags, startup_info, info, cur_dir );
1706 case BINARY_UNIX_EXE:
1708 /* unknown file, try as unix executable */
1709 DOS_FULL_NAME full_name;
1711 TRACE( "starting %s as Unix binary\n", debugstr_w(name) );
1713 if (DOSFS_GetFullName( name, TRUE, &full_name ))
1714 retv = (fork_and_exec( full_name.long_name, tidy_cmdline, envW, unixdir ) != -1);
1718 CloseHandle( hFile );
1721 if (tidy_cmdline != cmd_line) HeapFree( GetProcessHeap(), 0, tidy_cmdline );
1722 if (envW != env) HeapFree( GetProcessHeap(), 0, envW );
1727 /***********************************************************************
1730 * Wrapper to call WaitForInputIdle USER function
1732 typedef DWORD (WINAPI *WaitForInputIdle_ptr)( HANDLE hProcess, DWORD dwTimeOut );
1734 static DWORD wait_input_idle( HANDLE process, DWORD timeout )
1736 HMODULE mod = GetModuleHandleA( "user32.dll" );
1739 WaitForInputIdle_ptr ptr = (WaitForInputIdle_ptr)GetProcAddress( mod, "WaitForInputIdle" );
1740 if (ptr) return ptr( process, timeout );
1746 /***********************************************************************
1747 * WinExec (KERNEL32.@)
1749 UINT WINAPI WinExec( LPCSTR lpCmdLine, UINT nCmdShow )
1751 PROCESS_INFORMATION info;
1752 STARTUPINFOA startup;
1756 memset( &startup, 0, sizeof(startup) );
1757 startup.cb = sizeof(startup);
1758 startup.dwFlags = STARTF_USESHOWWINDOW;
1759 startup.wShowWindow = nCmdShow;
1761 /* cmdline needs to be writeable for CreateProcess */
1762 if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(lpCmdLine)+1 ))) return 0;
1763 strcpy( cmdline, lpCmdLine );
1765 if (CreateProcessA( NULL, cmdline, NULL, NULL, FALSE,
1766 0, NULL, NULL, &startup, &info ))
1768 /* Give 30 seconds to the app to come up */
1769 if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
1770 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1772 /* Close off the handles */
1773 CloseHandle( info.hThread );
1774 CloseHandle( info.hProcess );
1776 else if ((ret = GetLastError()) >= 32)
1778 FIXME("Strange error set by CreateProcess: %d\n", ret );
1781 HeapFree( GetProcessHeap(), 0, cmdline );
1786 /**********************************************************************
1787 * LoadModule (KERNEL32.@)
1789 HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
1791 LOADPARAMS *params = (LOADPARAMS *)paramBlock;
1792 PROCESS_INFORMATION info;
1793 STARTUPINFOA startup;
1794 HINSTANCE hInstance;
1796 char filename[MAX_PATH];
1799 if (!name) return (HINSTANCE)ERROR_FILE_NOT_FOUND;
1801 if (!SearchPathA( NULL, name, ".exe", sizeof(filename), filename, NULL ) &&
1802 !SearchPathA( NULL, name, NULL, sizeof(filename), filename, NULL ))
1803 return (HINSTANCE)GetLastError();
1805 len = (BYTE)params->lpCmdLine[0];
1806 if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + len + 2 )))
1807 return (HINSTANCE)ERROR_NOT_ENOUGH_MEMORY;
1809 strcpy( cmdline, filename );
1810 p = cmdline + strlen(cmdline);
1812 memcpy( p, params->lpCmdLine + 1, len );
1815 memset( &startup, 0, sizeof(startup) );
1816 startup.cb = sizeof(startup);
1817 if (params->lpCmdShow)
1819 startup.dwFlags = STARTF_USESHOWWINDOW;
1820 startup.wShowWindow = params->lpCmdShow[1];
1823 if (CreateProcessA( filename, cmdline, NULL, NULL, FALSE, 0,
1824 params->lpEnvAddress, NULL, &startup, &info ))
1826 /* Give 30 seconds to the app to come up */
1827 if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
1828 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1829 hInstance = (HINSTANCE)33;
1830 /* Close off the handles */
1831 CloseHandle( info.hThread );
1832 CloseHandle( info.hProcess );
1834 else if ((hInstance = (HINSTANCE)GetLastError()) >= (HINSTANCE)32)
1836 FIXME("Strange error set by CreateProcess: %p\n", hInstance );
1837 hInstance = (HINSTANCE)11;
1840 HeapFree( GetProcessHeap(), 0, cmdline );
1845 /******************************************************************************
1846 * TerminateProcess (KERNEL32.@)
1848 BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
1850 NTSTATUS status = NtTerminateProcess( handle, exit_code );
1851 if (status) SetLastError( RtlNtStatusToDosError(status) );
1856 /***********************************************************************
1857 * ExitProcess (KERNEL32.@)
1859 void WINAPI ExitProcess( DWORD status )
1861 LdrShutdownProcess();
1862 SERVER_START_REQ( terminate_process )
1864 /* send the exit code to the server */
1865 req->handle = GetCurrentProcess();
1866 req->exit_code = status;
1867 wine_server_call( req );
1874 /***********************************************************************
1875 * GetExitCodeProcess [KERNEL32.@]
1877 * Gets termination status of specified process
1883 BOOL WINAPI GetExitCodeProcess(
1884 HANDLE hProcess, /* [in] handle to the process */
1885 LPDWORD lpExitCode) /* [out] address to receive termination status */
1888 SERVER_START_REQ( get_process_info )
1890 req->handle = hProcess;
1891 ret = !wine_server_call_err( req );
1892 if (ret && lpExitCode) *lpExitCode = reply->exit_code;
1899 /***********************************************************************
1900 * SetErrorMode (KERNEL32.@)
1902 UINT WINAPI SetErrorMode( UINT mode )
1904 UINT old = process_error_mode;
1905 process_error_mode = mode;
1910 /**********************************************************************
1911 * TlsAlloc [KERNEL32.@] Allocates a TLS index.
1913 * Allocates a thread local storage index
1916 * Success: TLS Index
1917 * Failure: 0xFFFFFFFF
1919 DWORD WINAPI TlsAlloc( void )
1923 RtlAcquirePebLock();
1924 index = RtlFindClearBitsAndSet( NtCurrentTeb()->Peb->TlsBitmap, 1, 0 );
1925 if (index != ~0UL) NtCurrentTeb()->TlsSlots[index] = 0; /* clear the value */
1926 else SetLastError( ERROR_NO_MORE_ITEMS );
1927 RtlReleasePebLock();
1932 /**********************************************************************
1933 * TlsFree [KERNEL32.@] Releases a TLS index.
1935 * Releases a thread local storage index, making it available for reuse
1941 BOOL WINAPI TlsFree(
1942 DWORD index) /* [in] TLS Index to free */
1946 RtlAcquirePebLock();
1947 ret = RtlAreBitsSet( NtCurrentTeb()->Peb->TlsBitmap, index, 1 );
1950 RtlClearBits( NtCurrentTeb()->Peb->TlsBitmap, index, 1 );
1951 NtSetInformationThread( GetCurrentThread(), ThreadZeroTlsCell, &index, sizeof(index) );
1953 else SetLastError( ERROR_INVALID_PARAMETER );
1954 RtlReleasePebLock();
1959 /**********************************************************************
1960 * TlsGetValue [KERNEL32.@] Gets value in a thread's TLS slot
1963 * Success: Value stored in calling thread's TLS slot for index
1964 * Failure: 0 and GetLastError returns NO_ERROR
1966 LPVOID WINAPI TlsGetValue(
1967 DWORD index) /* [in] TLS index to retrieve value for */
1969 if (index >= NtCurrentTeb()->Peb->TlsBitmap->SizeOfBitMap)
1971 SetLastError( ERROR_INVALID_PARAMETER );
1974 SetLastError( ERROR_SUCCESS );
1975 return NtCurrentTeb()->TlsSlots[index];
1979 /**********************************************************************
1980 * TlsSetValue [KERNEL32.@] Stores a value in the thread's TLS slot.
1986 BOOL WINAPI TlsSetValue(
1987 DWORD index, /* [in] TLS index to set value for */
1988 LPVOID value) /* [in] Value to be stored */
1990 if (index >= NtCurrentTeb()->Peb->TlsBitmap->SizeOfBitMap)
1992 SetLastError( ERROR_INVALID_PARAMETER );
1995 NtCurrentTeb()->TlsSlots[index] = value;
2000 /***********************************************************************
2001 * GetProcessFlags (KERNEL32.@)
2003 DWORD WINAPI GetProcessFlags( DWORD processid )
2005 IMAGE_NT_HEADERS *nt;
2008 if (processid && processid != GetCurrentProcessId()) return 0;
2010 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
2012 if (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
2013 flags |= PDB32_CONSOLE_PROC;
2015 if (!AreFileApisANSI()) flags |= PDB32_FILE_APIS_OEM;
2016 if (IsDebuggerPresent()) flags |= PDB32_DEBUGGED;
2021 /***********************************************************************
2022 * GetProcessDword (KERNEL.485)
2023 * GetProcessDword (KERNEL32.18)
2024 * 'Of course you cannot directly access Windows internal structures'
2026 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
2031 TRACE("(%ld, %d)\n", dwProcessID, offset );
2033 if (dwProcessID && dwProcessID != GetCurrentProcessId())
2035 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
2041 case GPD_APP_COMPAT_FLAGS:
2042 return GetAppCompatFlags16(0);
2043 case GPD_LOAD_DONE_EVENT:
2045 case GPD_HINSTANCE16:
2046 return GetTaskDS16();
2047 case GPD_WINDOWS_VERSION:
2048 return GetExeVersion16();
2050 return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
2052 return (DWORD)NtCurrentTeb()->Peb;
2053 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
2054 GetStartupInfoW(&siw);
2055 return (DWORD)siw.hStdOutput;
2056 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
2057 GetStartupInfoW(&siw);
2058 return (DWORD)siw.hStdInput;
2059 case GPD_STARTF_SHOWWINDOW:
2060 GetStartupInfoW(&siw);
2061 return siw.wShowWindow;
2062 case GPD_STARTF_SIZE:
2063 GetStartupInfoW(&siw);
2065 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
2067 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
2068 return MAKELONG( x, y );
2069 case GPD_STARTF_POSITION:
2070 GetStartupInfoW(&siw);
2072 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
2074 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
2075 return MAKELONG( x, y );
2076 case GPD_STARTF_FLAGS:
2077 GetStartupInfoW(&siw);
2082 return GetProcessFlags(0);
2084 return process_dword;
2086 ERR("Unknown offset %d\n", offset );
2091 /***********************************************************************
2092 * SetProcessDword (KERNEL.484)
2093 * 'Of course you cannot directly access Windows internal structures'
2095 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
2097 TRACE("(%ld, %d)\n", dwProcessID, offset );
2099 if (dwProcessID && dwProcessID != GetCurrentProcessId())
2101 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
2107 case GPD_APP_COMPAT_FLAGS:
2108 case GPD_LOAD_DONE_EVENT:
2109 case GPD_HINSTANCE16:
2110 case GPD_WINDOWS_VERSION:
2113 case GPD_STARTF_SHELLDATA:
2114 case GPD_STARTF_HOTKEY:
2115 case GPD_STARTF_SHOWWINDOW:
2116 case GPD_STARTF_SIZE:
2117 case GPD_STARTF_POSITION:
2118 case GPD_STARTF_FLAGS:
2121 ERR("Not allowed to modify offset %d\n", offset );
2124 process_dword = value;
2127 ERR("Unknown offset %d\n", offset );
2133 /***********************************************************************
2134 * ExitProcess (KERNEL.466)
2136 void WINAPI ExitProcess16( WORD status )
2139 ReleaseThunkLock( &count );
2140 ExitProcess( status );
2144 /*********************************************************************
2145 * OpenProcess (KERNEL32.@)
2147 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
2150 SERVER_START_REQ( open_process )
2153 req->access = access;
2154 req->inherit = inherit;
2155 if (!wine_server_call_err( req )) ret = reply->handle;
2162 /*********************************************************************
2163 * MapProcessHandle (KERNEL.483)
2165 DWORD WINAPI MapProcessHandle( HANDLE handle )
2168 SERVER_START_REQ( get_process_info )
2170 req->handle = handle;
2171 if (!wine_server_call_err( req )) ret = reply->pid;
2178 /*********************************************************************
2179 * CloseW32Handle (KERNEL.474)
2180 * CloseHandle (KERNEL32.@)
2182 BOOL WINAPI CloseHandle( HANDLE handle )
2186 /* stdio handles need special treatment */
2187 if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
2188 (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
2189 (handle == (HANDLE)STD_ERROR_HANDLE))
2190 handle = GetStdHandle( (DWORD)handle );
2192 if (is_console_handle(handle))
2193 return CloseConsoleHandle(handle);
2195 status = NtClose( handle );
2196 if (status) SetLastError( RtlNtStatusToDosError(status) );
2201 /*********************************************************************
2202 * GetHandleInformation (KERNEL32.@)
2204 BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
2207 SERVER_START_REQ( set_handle_info )
2209 req->handle = handle;
2213 ret = !wine_server_call_err( req );
2214 if (ret && flags) *flags = reply->old_flags;
2221 /*********************************************************************
2222 * SetHandleInformation (KERNEL32.@)
2224 BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
2227 SERVER_START_REQ( set_handle_info )
2229 req->handle = handle;
2233 ret = !wine_server_call_err( req );
2240 /*********************************************************************
2241 * DuplicateHandle (KERNEL32.@)
2243 BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
2244 HANDLE dest_process, HANDLE *dest,
2245 DWORD access, BOOL inherit, DWORD options )
2249 if (is_console_handle(source))
2251 /* FIXME: this test is not sufficient, we need to test process ids, not handles */
2252 if (source_process != dest_process ||
2253 source_process != GetCurrentProcess())
2255 SetLastError(ERROR_INVALID_PARAMETER);
2258 *dest = DuplicateConsoleHandle( source, access, inherit, options );
2259 return (*dest != INVALID_HANDLE_VALUE);
2261 status = NtDuplicateObject( source_process, source, dest_process, dest,
2262 access, inherit ? OBJ_INHERIT : 0, options );
2263 if (status) SetLastError( RtlNtStatusToDosError(status) );
2268 /***********************************************************************
2269 * ConvertToGlobalHandle (KERNEL.476)
2270 * ConvertToGlobalHandle (KERNEL32.@)
2272 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
2274 HANDLE ret = INVALID_HANDLE_VALUE;
2275 DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
2276 DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
2281 /***********************************************************************
2282 * SetHandleContext (KERNEL32.@)
2284 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context)
2286 FIXME("(%p,%ld), stub. In case this got called by WSOCK32/WS2_32: "
2287 "the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context);
2288 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2293 /***********************************************************************
2294 * GetHandleContext (KERNEL32.@)
2296 DWORD WINAPI GetHandleContext(HANDLE hnd)
2298 FIXME("(%p), stub. In case this got called by WSOCK32/WS2_32: "
2299 "the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd);
2300 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2305 /***********************************************************************
2306 * CreateSocketHandle (KERNEL32.@)
2308 HANDLE WINAPI CreateSocketHandle(void)
2310 FIXME("(), stub. In case this got called by WSOCK32/WS2_32: "
2311 "the external WINSOCK DLLs won't work with WINE, don't use them.\n");
2312 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2313 return INVALID_HANDLE_VALUE;
2317 /***********************************************************************
2318 * SetPriorityClass (KERNEL32.@)
2320 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
2323 SERVER_START_REQ( set_process_info )
2325 req->handle = hprocess;
2326 req->priority = priorityclass;
2327 req->mask = SET_PROCESS_INFO_PRIORITY;
2328 ret = !wine_server_call_err( req );
2335 /***********************************************************************
2336 * GetPriorityClass (KERNEL32.@)
2338 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
2341 SERVER_START_REQ( get_process_info )
2343 req->handle = hprocess;
2344 if (!wine_server_call_err( req )) ret = reply->priority;
2351 /***********************************************************************
2352 * SetProcessAffinityMask (KERNEL32.@)
2354 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
2357 SERVER_START_REQ( set_process_info )
2359 req->handle = hProcess;
2360 req->affinity = affmask;
2361 req->mask = SET_PROCESS_INFO_AFFINITY;
2362 ret = !wine_server_call_err( req );
2369 /**********************************************************************
2370 * GetProcessAffinityMask (KERNEL32.@)
2372 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
2373 LPDWORD lpProcessAffinityMask,
2374 LPDWORD lpSystemAffinityMask )
2377 SERVER_START_REQ( get_process_info )
2379 req->handle = hProcess;
2380 if (!wine_server_call_err( req ))
2382 if (lpProcessAffinityMask) *lpProcessAffinityMask = reply->process_affinity;
2383 if (lpSystemAffinityMask) *lpSystemAffinityMask = reply->system_affinity;
2392 /***********************************************************************
2393 * GetProcessVersion (KERNEL32.@)
2395 DWORD WINAPI GetProcessVersion( DWORD processid )
2397 IMAGE_NT_HEADERS *nt;
2399 if (processid && processid != GetCurrentProcessId())
2401 FIXME("should use ReadProcessMemory\n");
2404 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
2405 return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
2406 nt->OptionalHeader.MinorSubsystemVersion);
2411 /***********************************************************************
2412 * SetProcessWorkingSetSize [KERNEL32.@]
2413 * Sets the min/max working set sizes for a specified process.
2416 * hProcess [I] Handle to the process of interest
2417 * minset [I] Specifies minimum working set size
2418 * maxset [I] Specifies maximum working set size
2422 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
2425 FIXME("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
2426 if(( minset == (SIZE_T)-1) && (maxset == (SIZE_T)-1)) {
2427 /* Trim the working set to zero */
2428 /* Swap the process out of physical RAM */
2433 /***********************************************************************
2434 * GetProcessWorkingSetSize (KERNEL32.@)
2436 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess, PSIZE_T minset,
2439 FIXME("(%p,%p,%p): stub\n",hProcess,minset,maxset);
2440 /* 32 MB working set size */
2441 if (minset) *minset = 32*1024*1024;
2442 if (maxset) *maxset = 32*1024*1024;
2447 /***********************************************************************
2448 * SetProcessShutdownParameters (KERNEL32.@)
2450 BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
2452 FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
2453 shutdown_flags = flags;
2454 shutdown_priority = level;
2459 /***********************************************************************
2460 * GetProcessShutdownParameters (KERNEL32.@)
2463 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
2465 *lpdwLevel = shutdown_priority;
2466 *lpdwFlags = shutdown_flags;
2471 /***********************************************************************
2472 * GetProcessPriorityBoost (KERNEL32.@)
2474 BOOL WINAPI GetProcessPriorityBoost(HANDLE hprocess,PBOOL pDisablePriorityBoost)
2476 FIXME("(%p,%p): semi-stub\n", hprocess, pDisablePriorityBoost);
2478 /* Report that no boost is present.. */
2479 *pDisablePriorityBoost = FALSE;
2484 /***********************************************************************
2485 * SetProcessPriorityBoost (KERNEL32.@)
2487 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
2489 FIXME("(%p,%d): stub\n",hprocess,disableboost);
2490 /* Say we can do it. I doubt the program will notice that we don't. */
2495 /***********************************************************************
2496 * ReadProcessMemory (KERNEL32.@)
2498 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, SIZE_T size,
2499 SIZE_T *bytes_read )
2501 NTSTATUS status = NtReadVirtualMemory( process, addr, buffer, size, bytes_read );
2502 if (status) SetLastError( RtlNtStatusToDosError(status) );
2507 /***********************************************************************
2508 * WriteProcessMemory (KERNEL32.@)
2510 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPCVOID buffer, SIZE_T size,
2511 SIZE_T *bytes_written )
2513 NTSTATUS status = NtWriteVirtualMemory( process, addr, buffer, size, bytes_written );
2514 if (status) SetLastError( RtlNtStatusToDosError(status) );
2519 /****************************************************************************
2520 * FlushInstructionCache (KERNEL32.@)
2522 BOOL WINAPI FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize)
2524 if (GetVersion() & 0x80000000) return TRUE; /* not NT, always TRUE */
2525 FIXME("(%p,%p,0x%08lx): stub\n",hProcess, lpBaseAddress, dwSize);
2530 /******************************************************************
2531 * GetProcessIoCounters (KERNEL32.@)
2533 BOOL WINAPI GetProcessIoCounters(HANDLE hProcess, PIO_COUNTERS ioc)
2537 status = NtQueryInformationProcess(hProcess, ProcessIoCounters,
2538 ioc, sizeof(*ioc), NULL);
2539 if (status) SetLastError( RtlNtStatusToDosError(status) );
2543 /***********************************************************************
2544 * ProcessIdToSessionId (KERNEL32.@)
2545 * This function is available on Terminal Server 4SP4 and Windows 2000
2547 BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
2549 /* According to MSDN, if the calling process is not in a terminal
2550 * services environment, then the sessionid returned is zero.
2557 /***********************************************************************
2558 * RegisterServiceProcess (KERNEL.491)
2559 * RegisterServiceProcess (KERNEL32.@)
2561 * A service process calls this function to ensure that it continues to run
2562 * even after a user logged off.
2564 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
2566 /* I don't think that Wine needs to do anything in that function */
2567 return 1; /* success */
2571 /**************************************************************************
2572 * SetFileApisToOEM (KERNEL32.@)
2574 VOID WINAPI SetFileApisToOEM(void)
2576 oem_file_apis = TRUE;
2580 /**************************************************************************
2581 * SetFileApisToANSI (KERNEL32.@)
2583 VOID WINAPI SetFileApisToANSI(void)
2585 oem_file_apis = FALSE;
2589 /******************************************************************************
2590 * AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
2593 * TRUE: Set of file functions is using ANSI code page
2594 * FALSE: Set of file functions is using OEM code page
2596 BOOL WINAPI AreFileApisANSI(void)
2598 return !oem_file_apis;
2602 /***********************************************************************
2603 * GetTickCount (KERNEL32.@)
2605 * Returns the number of milliseconds, modulo 2^32, since the start
2606 * of the wineserver.
2608 DWORD WINAPI GetTickCount(void)
2611 gettimeofday( &t, NULL );
2612 return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks;
2616 /***********************************************************************
2617 * GetCurrentProcess (KERNEL32.@)
2619 #undef GetCurrentProcess
2620 HANDLE WINAPI GetCurrentProcess(void)
2622 return (HANDLE)0xffffffff;