Moved the wine server client-side support to dlls/ntdll. Removed a
[wine/wine-kai.git] / dlls / kernel / process.c
blobf01730fc144898d9dd03e7e8ca55e6cd4af26ec8
1 /*
2 * Win32 processes
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <ctype.h>
26 #include <errno.h>
27 #include <locale.h>
28 #include <signal.h>
29 #include <stdio.h>
31 #include "wine/winbase16.h"
32 #include "wine/winuser16.h"
33 #include "ntstatus.h"
34 #include "thread.h"
35 #include "drive.h"
36 #include "file.h"
37 #include "heap.h"
38 #include "module.h"
39 #include "options.h"
40 #include "kernel_private.h"
41 #include "wine/server.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(process);
45 WINE_DECLARE_DEBUG_CHANNEL(server);
46 WINE_DECLARE_DEBUG_CHANNEL(relay);
47 WINE_DECLARE_DEBUG_CHANNEL(snoop);
49 /* Win32 process database */
50 typedef struct _PDB
52 LONG header[2]; /* 00 Kernel object header */
53 HMODULE module; /* 08 Main exe module (NT) */
54 PPEB_LDR_DATA LdrData; /* 0c Pointer to loader information */
55 RTL_USER_PROCESS_PARAMETERS *ProcessParameters; /* 10 Process parameters */
56 DWORD unknown2; /* 14 Unknown */
57 HANDLE heap; /* 18 Default process heap */
58 HANDLE mem_context; /* 1c Process memory context */
59 DWORD flags; /* 20 Flags */
60 void *pdb16; /* 24 DOS PSP */
61 WORD PSP_sel; /* 28 Selector to DOS PSP */
62 WORD imte; /* 2a IMTE for the process module */
63 WORD threads; /* 2c Number of threads */
64 WORD running_threads; /* 2e Number of running threads */
65 WORD free_lib_count; /* 30 Recursion depth of FreeLibrary calls */
66 WORD ring0_threads; /* 32 Number of ring 0 threads */
67 HANDLE system_heap; /* 34 System heap to allocate handles */
68 HTASK task; /* 38 Win16 task */
69 void *mem_map_files; /* 3c Pointer to mem-mapped files */
70 struct _ENVDB *env_db; /* 40 Environment database */
71 void *handle_table; /* 44 Handle table */
72 struct _PDB *parent; /* 48 Parent process */
73 void *modref_list; /* 4c MODREF list */
74 void *thread_list; /* 50 List of threads */
75 void *debuggee_CB; /* 54 Debuggee context block */
76 void *local_heap_free; /* 58 Head of local heap free list */
77 DWORD unknown4; /* 5c Unknown */
78 CRITICAL_SECTION crit_section; /* 60 Critical section */
79 DWORD unknown5[3]; /* 78 Unknown */
80 void *console; /* 84 Console */
81 DWORD tls_bits[2]; /* 88 TLS in-use bits */
82 DWORD process_dword; /* 90 Unknown */
83 struct _PDB *group; /* 94 Process group */
84 void *exe_modref; /* 98 MODREF for the process EXE */
85 void *top_filter; /* 9c Top exception filter */
86 DWORD priority; /* a0 Priority level */
87 HANDLE heap_list; /* a4 Head of process heap list */
88 void *heap_handles; /* a8 Head of heap handles list */
89 DWORD unknown6; /* ac Unknown */
90 void *console_provider; /* b0 Console provider (??) */
91 WORD env_selector; /* b4 Selector to process environment */
92 WORD error_mode; /* b6 Error mode */
93 HANDLE load_done_evt; /* b8 Event for process loading done */
94 void *UTState; /* bc Head of Univeral Thunk list */
95 DWORD unknown8; /* c0 Unknown (NT) */
96 LCID locale; /* c4 Locale to be queried by GetThreadLocale (NT) */
97 } PDB;
99 PDB current_process;
101 static RTL_USER_PROCESS_PARAMETERS process_pmts;
102 static PEB_LDR_DATA process_ldr;
104 static char main_exe_name[MAX_PATH];
105 static char *main_exe_name_ptr = main_exe_name;
106 static HANDLE main_exe_file;
107 static DWORD shutdown_flags = 0;
108 static DWORD shutdown_priority = 0x280;
109 static DWORD process_dword;
110 static BOOL oem_file_apis;
112 extern unsigned int server_startticks;
113 int main_create_flags = 0;
115 /* Process flags */
116 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
117 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
118 #define PDB32_DOS_PROC 0x0010 /* Dos process */
119 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
120 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
121 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
123 /* dlls/ntdll/env.c */
124 extern BOOL init_user_process_pmts( size_t, char*, size_t );
125 extern BOOL build_command_line( char **argv );
127 extern void RELAY_InitDebugLists(void);
128 extern void SHELL_LoadRegistry(void);
129 extern void VERSION_Init( const char *appname );
131 /***********************************************************************
132 * get_basename
134 inline static const char *get_basename( const char *name )
136 char *p;
138 if ((p = strrchr( name, '/' ))) name = p + 1;
139 if ((p = strrchr( name, '\\' ))) name = p + 1;
140 return name;
144 /***********************************************************************
145 * open_builtin_exe_file
147 * Open an exe file for a builtin exe.
149 static void *open_builtin_exe_file( const char *name, char *error, int error_size,
150 int test_only, int *file_exists )
152 char exename[MAX_PATH], *p;
153 const char *basename = get_basename(name);
155 if (strlen(basename) >= sizeof(exename)) return NULL;
156 strcpy( exename, basename );
157 for (p = exename; *p; p++) *p = FILE_tolower(*p);
158 return wine_dll_load_main_exe( exename, error, error_size, test_only, file_exists );
162 /***********************************************************************
163 * open_exe_file
165 * Open a specific exe file, taking load order into account.
166 * Returns the file handle or 0 for a builtin exe.
168 static HANDLE open_exe_file( const char *name )
170 enum loadorder_type loadorder[LOADORDER_NTYPES];
171 char buffer[MAX_PATH];
172 HANDLE handle;
173 int i, file_exists;
175 TRACE("looking for %s\n", debugstr_a(name) );
177 if ((handle = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
178 NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
180 /* file doesn't exist, check for builtin */
181 if (!FILE_contains_path( name )) goto error;
182 if (!MODULE_GetBuiltinPath( name, "", buffer, sizeof(buffer) )) goto error;
183 name = buffer;
186 MODULE_GetLoadOrder( loadorder, name, TRUE );
188 for(i = 0; i < LOADORDER_NTYPES; i++)
190 if (loadorder[i] == LOADORDER_INVALID) break;
191 switch(loadorder[i])
193 case LOADORDER_DLL:
194 TRACE( "Trying native exe %s\n", debugstr_a(name) );
195 if (handle != INVALID_HANDLE_VALUE) return handle;
196 break;
197 case LOADORDER_BI:
198 TRACE( "Trying built-in exe %s\n", debugstr_a(name) );
199 open_builtin_exe_file( name, NULL, 0, 1, &file_exists );
200 if (file_exists)
202 if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
203 return 0;
205 default:
206 break;
209 if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
211 error:
212 SetLastError( ERROR_FILE_NOT_FOUND );
213 return INVALID_HANDLE_VALUE;
217 /***********************************************************************
218 * find_exe_file
220 * Open an exe file, and return the full name and file handle.
221 * Returns FALSE if file could not be found.
222 * If file exists but cannot be opened, returns TRUE and set handle to INVALID_HANDLE_VALUE.
223 * If file is a builtin exe, returns TRUE and sets handle to 0.
225 static BOOL find_exe_file( const char *name, char *buffer, int buflen, HANDLE *handle )
227 enum loadorder_type loadorder[LOADORDER_NTYPES];
228 int i, file_exists;
230 TRACE("looking for %s\n", debugstr_a(name) );
232 if (!SearchPathA( NULL, name, ".exe", buflen, buffer, NULL ) &&
233 !MODULE_GetBuiltinPath( name, ".exe", buffer, buflen ))
235 /* no builtin found, try native without extension in case it is a Unix app */
237 if (SearchPathA( NULL, name, NULL, buflen, buffer, NULL ))
239 TRACE( "Trying native/Unix binary %s\n", debugstr_a(buffer) );
240 if ((*handle = CreateFileA( buffer, GENERIC_READ, FILE_SHARE_READ,
241 NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
242 return TRUE;
244 return FALSE;
247 MODULE_GetLoadOrder( loadorder, buffer, TRUE );
249 for(i = 0; i < LOADORDER_NTYPES; i++)
251 if (loadorder[i] == LOADORDER_INVALID) break;
252 switch(loadorder[i])
254 case LOADORDER_DLL:
255 TRACE( "Trying native exe %s\n", debugstr_a(buffer) );
256 if ((*handle = CreateFileA( buffer, GENERIC_READ, FILE_SHARE_READ,
257 NULL, OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE)
258 return TRUE;
259 if (GetLastError() != ERROR_FILE_NOT_FOUND) return TRUE;
260 break;
261 case LOADORDER_BI:
262 TRACE( "Trying built-in exe %s\n", debugstr_a(buffer) );
263 open_builtin_exe_file( buffer, NULL, 0, 1, &file_exists );
264 if (file_exists)
266 *handle = 0;
267 return TRUE;
269 break;
270 default:
271 break;
274 SetLastError( ERROR_FILE_NOT_FOUND );
275 return FALSE;
279 /***********************************************************************
280 * process_init
282 * Main process initialisation code
284 static BOOL process_init( char *argv[] )
286 BOOL ret;
287 size_t info_size = 0;
289 setbuf(stdout,NULL);
290 setbuf(stderr,NULL);
291 setlocale(LC_CTYPE,"");
293 /* store the program name */
294 argv0 = argv[0];
296 /* Fill the initial process structure */
297 current_process.threads = 1;
298 current_process.running_threads = 1;
299 current_process.ring0_threads = 1;
300 current_process.group = &current_process;
301 current_process.priority = 8; /* Normal */
302 current_process.ProcessParameters = &process_pmts;
303 current_process.LdrData = &process_ldr;
304 InitializeListHead(&process_ldr.InLoadOrderModuleList);
305 InitializeListHead(&process_ldr.InMemoryOrderModuleList);
306 InitializeListHead(&process_ldr.InInitializationOrderModuleList);
308 /* Setup the server connection */
309 wine_server_init_thread();
311 /* Retrieve startup info from the server */
312 SERVER_START_REQ( init_process )
314 req->ldt_copy = &wine_ldt_copy;
315 if ((ret = !wine_server_call_err( req )))
317 main_exe_file = reply->exe_file;
318 main_create_flags = reply->create_flags;
319 info_size = reply->info_size;
320 server_startticks = reply->server_start;
321 process_pmts.hStdInput = reply->hstdin;
322 process_pmts.hStdOutput = reply->hstdout;
323 process_pmts.hStdError = reply->hstderr;
326 SERVER_END_REQ;
327 if (!ret) return FALSE;
329 /* Create the process heap */
330 current_process.heap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL );
332 if (info_size == 0)
334 /* This is wine specific: we have no parent (we're started from unix)
335 * so, create a simple console with bare handles to unix stdio
336 * input & output streams (aka simple console)
338 wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, TRUE, &process_pmts.hStdInput );
339 wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, &process_pmts.hStdOutput );
340 wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, TRUE, &process_pmts.hStdError );
342 else
344 /* convert value from server:
345 * + 0 => INVALID_HANDLE_VALUE
346 * + console handle need to be mapped
348 if (!process_pmts.hStdInput)
349 process_pmts.hStdInput = INVALID_HANDLE_VALUE;
350 else if (VerifyConsoleIoHandle(console_handle_map(process_pmts.hStdInput)))
351 process_pmts.hStdInput = console_handle_map(process_pmts.hStdInput);
352 if (!process_pmts.hStdOutput)
353 process_pmts.hStdOutput = INVALID_HANDLE_VALUE;
354 else if (VerifyConsoleIoHandle(console_handle_map(process_pmts.hStdOutput)))
355 process_pmts.hStdOutput = console_handle_map(process_pmts.hStdOutput);
356 if (!process_pmts.hStdError)
357 process_pmts.hStdError = INVALID_HANDLE_VALUE;
358 else if (VerifyConsoleIoHandle(console_handle_map(process_pmts.hStdError)))
359 process_pmts.hStdError = console_handle_map(process_pmts.hStdError);
362 /* Copy the parent environment */
363 if (!init_user_process_pmts( info_size, main_exe_name, sizeof(main_exe_name) ))
364 return FALSE;
366 /* Parse command line arguments */
367 OPTIONS_ParseOptions( !info_size ? argv : NULL );
369 /* <hack: to be changed later on> */
370 process_pmts.CurrentDirectoryName.Length = 3 * sizeof(WCHAR);
371 process_pmts.CurrentDirectoryName.MaximumLength = RtlGetLongestNtPathLength() * sizeof(WCHAR);
372 process_pmts.CurrentDirectoryName.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, process_pmts.CurrentDirectoryName.MaximumLength);
373 process_pmts.CurrentDirectoryName.Buffer[0] = 'C';
374 process_pmts.CurrentDirectoryName.Buffer[1] = ':';
375 process_pmts.CurrentDirectoryName.Buffer[2] = '\\';
376 process_pmts.CurrentDirectoryName.Buffer[3] = '\0';
377 /* </hack: to be changed later on> */
379 /* initialise DOS drives */
380 if (!DRIVE_Init()) return FALSE;
382 /* initialise DOS directories */
383 if (!DIR_Init()) return FALSE;
385 /* registry initialisation */
386 SHELL_LoadRegistry();
388 /* global boot finished, the rest is process-local */
389 SERVER_START_REQ( boot_done )
391 req->debug_level = TRACE_ON(server);
392 wine_server_call( req );
394 SERVER_END_REQ;
396 if (TRACE_ON(relay) || TRACE_ON(snoop)) RELAY_InitDebugLists();
398 return TRUE;
402 /***********************************************************************
403 * start_process
405 * Startup routine of a new process. Runs on the new process stack.
407 static void start_process( void *arg )
409 __TRY
411 LPTHREAD_START_ROUTINE entry;
412 HANDLE main_file = main_exe_file;
413 IMAGE_NT_HEADERS *nt;
414 PEB *peb = NtCurrentTeb()->Peb;
416 if (main_file)
418 UINT drive_type = GetDriveTypeA( main_exe_name );
419 /* don't keep the file handle open on removable media */
420 if (drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_CDROM) main_file = 0;
423 /* Retrieve entry point address */
424 nt = RtlImageNtHeader( peb->ImageBaseAddress );
425 entry = (LPTHREAD_START_ROUTINE)((char*)peb->ImageBaseAddress +
426 nt->OptionalHeader.AddressOfEntryPoint);
428 /* Install signal handlers; this cannot be done before, since we cannot
429 * send exceptions to the debugger before the create process event that
430 * is sent by REQ_INIT_PROCESS_DONE.
431 * We do need the handlers in place by the time the request is over, so
432 * we set them up here. If we segfault between here and the server call
433 * something is very wrong... */
434 if (!SIGNAL_Init()) goto error;
436 /* Signal the parent process to continue */
437 SERVER_START_REQ( init_process_done )
439 req->module = peb->ImageBaseAddress;
440 req->module_size = nt->OptionalHeader.SizeOfImage;
441 req->entry = entry;
442 /* API requires a double indirection */
443 req->name = &main_exe_name_ptr;
444 req->exe_file = main_file;
445 req->gui = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CUI);
446 wine_server_add_data( req, main_exe_name, strlen(main_exe_name) );
447 wine_server_call( req );
448 peb->BeingDebugged = reply->debugged;
450 SERVER_END_REQ;
452 /* create the main modref and load dependencies */
453 if (!PE_CreateModule( peb->ImageBaseAddress, main_exe_name, 0, 0, FALSE )) goto error;
455 if (main_exe_file) CloseHandle( main_exe_file ); /* we no longer need it */
457 MODULE_DllProcessAttach( NULL, (LPVOID)1 );
459 if (TRACE_ON(relay))
460 DPRINTF( "%04lx:Starting process %s (entryproc=%p)\n",
461 GetCurrentThreadId(), main_exe_name, entry );
462 if (peb->BeingDebugged) DbgBreakPoint();
463 SetLastError(0); /* clear error code */
464 ExitThread( entry( NtCurrentTeb()->Peb ) );
466 error:
467 ExitProcess( GetLastError() );
469 __EXCEPT(UnhandledExceptionFilter)
471 TerminateThread( GetCurrentThread(), GetExceptionCode() );
473 __ENDTRY
477 /***********************************************************************
478 * __wine_process_init
480 * Wine initialisation: load and start the main exe file.
482 void __wine_process_init( int argc, char *argv[] )
484 char error[1024], *p;
485 DWORD stack_size = 0;
486 int file_exists;
488 /* Initialize everything */
489 if (!process_init( argv )) exit(1);
491 argv++; /* remove argv[0] (wine itself) */
493 TRACE( "starting process name=%s file=%p argv[0]=%s\n",
494 debugstr_a(main_exe_name), main_exe_file, debugstr_a(argv[0]) );
496 if (!main_exe_name[0])
498 if (!argv[0]) OPTIONS_Usage();
500 if (!find_exe_file( argv[0], main_exe_name, sizeof(main_exe_name), &main_exe_file ))
502 MESSAGE( "%s: cannot find '%s'\n", argv0, argv[0] );
503 ExitProcess(1);
505 if (main_exe_file == INVALID_HANDLE_VALUE)
507 MESSAGE( "%s: cannot open '%s'\n", argv0, main_exe_name );
508 ExitProcess(1);
512 if (!main_exe_file) /* no file handle -> Winelib app */
514 TRACE( "starting Winelib app %s\n", debugstr_a(main_exe_name) );
515 if (open_builtin_exe_file( main_exe_name, error, sizeof(error), 0, &file_exists ))
516 goto found;
517 MESSAGE( "%s: cannot open builtin library for '%s': %s\n", argv0, main_exe_name, error );
518 ExitProcess(1);
520 VERSION_Init( main_exe_name );
522 switch( MODULE_GetBinaryType( main_exe_file ))
524 case BINARY_PE_EXE:
525 TRACE( "starting Win32 binary %s\n", debugstr_a(main_exe_name) );
526 if ((current_process.module = PE_LoadImage( main_exe_file, main_exe_name, 0 ))) goto found;
527 MESSAGE( "%s: could not load '%s' as Win32 binary\n", argv0, main_exe_name );
528 ExitProcess(1);
529 case BINARY_PE_DLL:
530 MESSAGE( "%s: '%s' is a DLL, not an executable\n", argv0, main_exe_name );
531 ExitProcess(1);
532 case BINARY_UNKNOWN:
533 /* check for .com extension */
534 if (!(p = strrchr( main_exe_name, '.' )) || FILE_strcasecmp( p, ".com" ))
536 MESSAGE( "%s: cannot determine executable type for '%s'\n", argv0, main_exe_name );
537 ExitProcess(1);
539 /* fall through */
540 case BINARY_WIN16:
541 case BINARY_DOS:
542 TRACE( "starting Win16/DOS binary %s\n", debugstr_a(main_exe_name) );
543 CloseHandle( main_exe_file );
544 main_exe_file = 0;
545 argv--;
546 argv[0] = "winevdm.exe";
547 if (open_builtin_exe_file( "winevdm.exe", error, sizeof(error), 0, &file_exists ))
548 goto found;
549 MESSAGE( "%s: trying to run '%s', cannot open builtin library for 'winevdm.exe': %s\n",
550 argv0, main_exe_name, error );
551 ExitProcess(1);
552 case BINARY_OS216:
553 MESSAGE( "%s: '%s' is an OS/2 binary, not supported\n", argv0, main_exe_name );
554 ExitProcess(1);
555 case BINARY_UNIX_EXE:
556 MESSAGE( "%s: '%s' is a Unix binary, not supported\n", argv0, main_exe_name );
557 ExitProcess(1);
558 case BINARY_UNIX_LIB:
560 DOS_FULL_NAME full_name;
561 const char *name = main_exe_name;
562 UNICODE_STRING nameW;
564 TRACE( "starting Winelib app %s\n", debugstr_a(main_exe_name) );
565 RtlCreateUnicodeStringFromAsciiz(&nameW, name);
566 if (DOSFS_GetFullName( nameW.Buffer, TRUE, &full_name )) name = full_name.long_name;
567 RtlFreeUnicodeString(&nameW);
568 CloseHandle( main_exe_file );
569 main_exe_file = 0;
570 if (wine_dlopen( name, RTLD_NOW, error, sizeof(error) ))
572 if ((p = strrchr( main_exe_name, '.' )) && !strcmp( p, ".so" )) *p = 0;
573 goto found;
575 MESSAGE( "%s: could not load '%s': %s\n", argv0, main_exe_name, error );
576 ExitProcess(1);
580 found:
581 /* build command line */
582 if (!build_command_line( argv )) goto error;
584 /* create 32-bit module for main exe */
585 if (!(current_process.module = BUILTIN32_LoadExeModule( current_process.module ))) goto error;
586 stack_size = RtlImageNtHeader(current_process.module)->OptionalHeader.SizeOfStackReserve;
588 /* allocate main thread stack */
589 if (!THREAD_InitStack( NtCurrentTeb(), stack_size )) goto error;
591 /* switch to the new stack */
592 wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
594 error:
595 ExitProcess( GetLastError() );
599 /***********************************************************************
600 * build_argv
602 * Build an argv array from a command-line.
603 * The command-line is modified to insert nulls.
604 * 'reserved' is the number of args to reserve before the first one.
606 static char **build_argv( char *cmdline, int reserved )
608 int argc;
609 char** argv;
610 char *arg,*s,*d;
611 int in_quotes,bcount;
613 argc=reserved+1;
614 bcount=0;
615 in_quotes=0;
616 s=cmdline;
617 while (1) {
618 if (*s=='\0' || ((*s==' ' || *s=='\t') && !in_quotes)) {
619 /* space */
620 argc++;
621 /* skip the remaining spaces */
622 while (*s==' ' || *s=='\t') {
623 s++;
625 if (*s=='\0')
626 break;
627 bcount=0;
628 continue;
629 } else if (*s=='\\') {
630 /* '\', count them */
631 bcount++;
632 } else if ((*s=='"') && ((bcount & 1)==0)) {
633 /* unescaped '"' */
634 in_quotes=!in_quotes;
635 bcount=0;
636 } else {
637 /* a regular character */
638 bcount=0;
640 s++;
642 argv=malloc(argc*sizeof(*argv));
643 if (!argv)
644 return NULL;
646 arg=d=s=cmdline;
647 bcount=0;
648 in_quotes=0;
649 argc=reserved;
650 while (*s) {
651 if ((*s==' ' || *s=='\t') && !in_quotes) {
652 /* Close the argument and copy it */
653 *d=0;
654 argv[argc++]=arg;
656 /* skip the remaining spaces */
657 do {
658 s++;
659 } while (*s==' ' || *s=='\t');
661 /* Start with a new argument */
662 arg=d=s;
663 bcount=0;
664 } else if (*s=='\\') {
665 /* '\\' */
666 *d++=*s++;
667 bcount++;
668 } else if (*s=='"') {
669 /* '"' */
670 if ((bcount & 1)==0) {
671 /* Preceeded by an even number of '\', this is half that
672 * number of '\', plus a '"' which we discard.
674 d-=bcount/2;
675 s++;
676 in_quotes=!in_quotes;
677 } else {
678 /* Preceeded by an odd number of '\', this is half that
679 * number of '\' followed by a '"'
681 d=d-bcount/2-1;
682 *d++='"';
683 s++;
685 bcount=0;
686 } else {
687 /* a regular character */
688 *d++=*s++;
689 bcount=0;
692 if (*arg) {
693 *d='\0';
694 argv[argc++]=arg;
696 argv[argc]=NULL;
698 return argv;
702 /***********************************************************************
703 * build_envp
705 * Build the environment of a new child process.
707 static char **build_envp( const char *env, const char *extra_env )
709 const char *p;
710 char **envp;
711 int count = 0;
713 if (extra_env) for (p = extra_env; *p; count++) p += strlen(p) + 1;
714 for (p = env; *p; count++) p += strlen(p) + 1;
715 count += 3;
717 if ((envp = malloc( count * sizeof(*envp) )))
719 extern char **environ;
720 char **envptr = envp;
721 char **unixptr = environ;
722 /* first the extra strings */
723 if (extra_env) for (p = extra_env; *p; p += strlen(p) + 1) *envptr++ = (char *)p;
724 /* then put PATH, HOME and WINEPREFIX from the unix env */
725 for (unixptr = environ; unixptr && *unixptr; unixptr++)
726 if (!memcmp( *unixptr, "PATH=", 5 ) ||
727 !memcmp( *unixptr, "HOME=", 5 ) ||
728 !memcmp( *unixptr, "WINEPREFIX=", 11 )) *envptr++ = *unixptr;
729 /* now put the Windows environment strings */
730 for (p = env; *p; p += strlen(p) + 1)
732 if (!memcmp( p, "PATH=", 5 )) /* store PATH as WINEPATH */
734 char *winepath = malloc( strlen(p) + 5 );
735 strcpy( winepath, "WINE" );
736 strcpy( winepath + 4, p );
737 *envptr++ = winepath;
739 else if (memcmp( p, "HOME=", 5 ) &&
740 memcmp( p, "WINEPATH=", 9 ) &&
741 memcmp( p, "WINEPREFIX=", 11 )) *envptr++ = (char *)p;
743 *envptr = 0;
745 return envp;
749 /***********************************************************************
750 * exec_wine_binary
752 * Locate the Wine binary to exec for a new Win32 process.
754 static void exec_wine_binary( char **argv, char **envp )
756 const char *path, *pos, *ptr;
758 /* first, try for a WINELOADER environment variable */
759 argv[0] = getenv("WINELOADER");
760 if (argv[0])
761 execve( argv[0], argv, envp );
763 /* next, try bin directory */
764 argv[0] = BINDIR "/wine";
765 execve( argv[0], argv, envp );
767 /* now try the path of argv0 of the current binary */
768 if (!(argv[0] = malloc( strlen(full_argv0) + 6 ))) return;
769 if ((ptr = strrchr( full_argv0, '/' )))
771 memcpy( argv[0], full_argv0, ptr - full_argv0 );
772 strcpy( argv[0] + (ptr - full_argv0), "/wine" );
773 execve( argv[0], argv, envp );
775 free( argv[0] );
777 /* now search in the Unix path */
778 if ((path = getenv( "PATH" )))
780 if (!(argv[0] = malloc( strlen(path) + 6 ))) return;
781 pos = path;
782 for (;;)
784 while (*pos == ':') pos++;
785 if (!*pos) break;
786 if (!(ptr = strchr( pos, ':' ))) ptr = pos + strlen(pos);
787 memcpy( argv[0], pos, ptr - pos );
788 strcpy( argv[0] + (ptr - pos), "/wine" );
789 execve( argv[0], argv, envp );
790 pos = ptr;
793 free( argv[0] );
797 /***********************************************************************
798 * fork_and_exec
800 * Fork and exec a new Unix binary, checking for errors.
802 static int fork_and_exec( const char *filename, char *cmdline,
803 const char *env, const char *newdir )
805 int fd[2];
806 int pid, err;
808 if (!env) env = GetEnvironmentStringsA();
810 if (pipe(fd) == -1)
812 FILE_SetDosError();
813 return -1;
815 fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */
816 if (!(pid = fork())) /* child */
818 char **argv = build_argv( cmdline, 0 );
819 char **envp = build_envp( env, NULL );
820 close( fd[0] );
822 /* Reset signals that we previously set to SIG_IGN */
823 signal( SIGPIPE, SIG_DFL );
824 signal( SIGCHLD, SIG_DFL );
826 if (newdir) chdir(newdir);
828 if (argv && envp) execve( filename, argv, envp );
829 err = errno;
830 write( fd[1], &err, sizeof(err) );
831 _exit(1);
833 close( fd[1] );
834 if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0)) /* exec failed */
836 errno = err;
837 pid = -1;
839 if (pid == -1) FILE_SetDosError();
840 close( fd[0] );
841 return pid;
845 /***********************************************************************
846 * create_process
848 * Create a new process. If hFile is a valid handle we have an exe
849 * file, otherwise it is a Winelib app.
851 static BOOL create_process( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
852 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
853 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
854 LPPROCESS_INFORMATION info, LPCSTR unixdir )
856 BOOL ret, success = FALSE;
857 HANDLE process_info;
858 startup_info_t startup_info;
859 char *extra_env = NULL;
860 int startfd[2];
861 int execfd[2];
862 pid_t pid;
863 int err;
864 char dummy = 0;
866 if (!env)
868 env = GetEnvironmentStringsA();
869 extra_env = DRIVE_BuildEnv();
872 /* create the synchronization pipes */
874 if (pipe( startfd ) == -1)
876 FILE_SetDosError();
877 return FALSE;
879 if (pipe( execfd ) == -1)
881 close( startfd[0] );
882 close( startfd[1] );
883 FILE_SetDosError();
884 return FALSE;
886 fcntl( execfd[1], F_SETFD, 1 ); /* set close on exec */
888 /* create the child process */
890 if (!(pid = fork())) /* child */
892 char **argv = build_argv( cmd_line, 1 );
893 char **envp = build_envp( env, extra_env );
895 close( startfd[1] );
896 close( execfd[0] );
898 /* wait for parent to tell us to start */
899 if (read( startfd[0], &dummy, 1 ) != 1) _exit(1);
901 close( startfd[0] );
902 /* Reset signals that we previously set to SIG_IGN */
903 signal( SIGPIPE, SIG_DFL );
904 signal( SIGCHLD, SIG_DFL );
906 if (unixdir) chdir(unixdir);
908 if (argv && envp) exec_wine_binary( argv, envp );
910 err = errno;
911 write( execfd[1], &err, sizeof(err) );
912 _exit(1);
915 /* this is the parent */
917 close( startfd[0] );
918 close( execfd[1] );
919 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
920 if (pid == -1)
922 close( startfd[1] );
923 close( execfd[0] );
924 FILE_SetDosError();
925 return FALSE;
928 /* fill the startup info structure */
930 startup_info.size = sizeof(startup_info);
931 /* startup_info.filename_len is set below */
932 startup_info.cmdline_len = cmd_line ? strlen(cmd_line) : 0;
933 startup_info.desktop_len = startup->lpDesktop ? strlen(startup->lpDesktop) : 0;
934 startup_info.title_len = startup->lpTitle ? strlen(startup->lpTitle) : 0;
935 startup_info.x = startup->dwX;
936 startup_info.y = startup->dwY;
937 startup_info.cx = startup->dwXSize;
938 startup_info.cy = startup->dwYSize;
939 startup_info.x_chars = startup->dwXCountChars;
940 startup_info.y_chars = startup->dwYCountChars;
941 startup_info.attribute = startup->dwFillAttribute;
942 startup_info.cmd_show = startup->wShowWindow;
943 startup_info.flags = startup->dwFlags;
945 /* create the process on the server side */
947 SERVER_START_REQ( new_process )
949 char buf[MAX_PATH];
950 LPCSTR nameptr;
952 req->inherit_all = inherit;
953 req->create_flags = flags;
954 req->unix_pid = pid;
955 req->exe_file = hFile;
956 if (startup->dwFlags & STARTF_USESTDHANDLES)
958 req->hstdin = startup->hStdInput;
959 req->hstdout = startup->hStdOutput;
960 req->hstderr = startup->hStdError;
962 else
964 req->hstdin = GetStdHandle( STD_INPUT_HANDLE );
965 req->hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
966 req->hstderr = GetStdHandle( STD_ERROR_HANDLE );
969 if ((flags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS)) != 0)
971 /* this is temporary (for console handles). We have no way to control that the handle is invalid in child process otherwise */
972 if (is_console_handle(req->hstdin)) req->hstdin = INVALID_HANDLE_VALUE;
973 if (is_console_handle(req->hstdout)) req->hstdout = INVALID_HANDLE_VALUE;
974 if (is_console_handle(req->hstderr)) req->hstderr = INVALID_HANDLE_VALUE;
976 else
978 if (is_console_handle(req->hstdin)) req->hstdin = console_handle_unmap(req->hstdin);
979 if (is_console_handle(req->hstdout)) req->hstdout = console_handle_unmap(req->hstdout);
980 if (is_console_handle(req->hstderr)) req->hstderr = console_handle_unmap(req->hstderr);
983 if (GetLongPathNameA( filename, buf, MAX_PATH ))
984 nameptr = buf;
985 else
986 nameptr = filename;
988 startup_info.filename_len = strlen(nameptr);
989 wine_server_add_data( req, &startup_info, sizeof(startup_info) );
990 wine_server_add_data( req, nameptr, startup_info.filename_len );
991 wine_server_add_data( req, cmd_line, startup_info.cmdline_len );
992 wine_server_add_data( req, startup->lpDesktop, startup_info.desktop_len );
993 wine_server_add_data( req, startup->lpTitle, startup_info.title_len );
995 ret = !wine_server_call_err( req );
996 process_info = reply->info;
998 SERVER_END_REQ;
1000 if (!ret)
1002 close( startfd[1] );
1003 close( execfd[0] );
1004 return FALSE;
1007 /* tell child to start and wait for it to exec */
1009 write( startfd[1], &dummy, 1 );
1010 close( startfd[1] );
1012 if (read( execfd[0], &err, sizeof(err) ) > 0) /* exec failed */
1014 errno = err;
1015 FILE_SetDosError();
1016 close( execfd[0] );
1017 CloseHandle( process_info );
1018 return FALSE;
1021 /* wait for the new process info to be ready */
1023 WaitForSingleObject( process_info, INFINITE );
1024 SERVER_START_REQ( get_new_process_info )
1026 req->info = process_info;
1027 req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle);
1028 req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle);
1029 if ((ret = !wine_server_call_err( req )))
1031 info->dwProcessId = (DWORD)reply->pid;
1032 info->dwThreadId = (DWORD)reply->tid;
1033 info->hProcess = reply->phandle;
1034 info->hThread = reply->thandle;
1035 success = reply->success;
1038 SERVER_END_REQ;
1040 if (ret && !success) /* new process failed to start */
1042 DWORD exitcode;
1043 if (GetExitCodeProcess( info->hProcess, &exitcode )) SetLastError( exitcode );
1044 CloseHandle( info->hThread );
1045 CloseHandle( info->hProcess );
1046 ret = FALSE;
1048 CloseHandle( process_info );
1049 return ret;
1053 /***********************************************************************
1054 * create_vdm_process
1056 * Create a new VDM process for a 16-bit or DOS application.
1058 static BOOL create_vdm_process( LPCSTR filename, LPSTR cmd_line, LPCSTR env,
1059 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1060 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
1061 LPPROCESS_INFORMATION info, LPCSTR unixdir )
1063 BOOL ret;
1064 LPSTR new_cmd_line = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + strlen(cmd_line) + 30 );
1066 if (!new_cmd_line)
1068 SetLastError( ERROR_OUTOFMEMORY );
1069 return FALSE;
1071 sprintf( new_cmd_line, "winevdm.exe --app-name \"%s\" %s", filename, cmd_line );
1072 ret = create_process( 0, "winevdm.exe", new_cmd_line, env, psa, tsa, inherit,
1073 flags, startup, info, unixdir );
1074 HeapFree( GetProcessHeap(), 0, new_cmd_line );
1075 return ret;
1079 /*************************************************************************
1080 * get_file_name
1082 * Helper for CreateProcess: retrieve the file name to load from the
1083 * app name and command line. Store the file name in buffer, and
1084 * return a possibly modified command line.
1085 * Also returns a handle to the opened file if it's a Windows binary.
1087 static LPSTR get_file_name( LPCSTR appname, LPSTR cmdline, LPSTR buffer,
1088 int buflen, HANDLE *handle )
1090 char *name, *pos, *ret = NULL;
1091 const char *p;
1093 /* if we have an app name, everything is easy */
1095 if (appname)
1097 /* use the unmodified app name as file name */
1098 lstrcpynA( buffer, appname, buflen );
1099 *handle = open_exe_file( buffer );
1100 if (!(ret = cmdline) || !cmdline[0])
1102 /* no command-line, create one */
1103 if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(appname) + 3 )))
1104 sprintf( ret, "\"%s\"", appname );
1106 return ret;
1109 if (!cmdline)
1111 SetLastError( ERROR_INVALID_PARAMETER );
1112 return NULL;
1115 /* first check for a quoted file name */
1117 if ((cmdline[0] == '"') && ((p = strchr( cmdline + 1, '"' ))))
1119 int len = p - cmdline - 1;
1120 /* extract the quoted portion as file name */
1121 if (!(name = HeapAlloc( GetProcessHeap(), 0, len + 1 ))) return NULL;
1122 memcpy( name, cmdline + 1, len );
1123 name[len] = 0;
1125 if (find_exe_file( name, buffer, buflen, handle ))
1126 ret = cmdline; /* no change necessary */
1127 goto done;
1130 /* now try the command-line word by word */
1132 if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(cmdline) + 1 ))) return NULL;
1133 pos = name;
1134 p = cmdline;
1136 while (*p)
1138 do *pos++ = *p++; while (*p && *p != ' ');
1139 *pos = 0;
1140 if (find_exe_file( name, buffer, buflen, handle ))
1142 ret = cmdline;
1143 break;
1147 if (!ret || !strchr( name, ' ' )) goto done; /* no change necessary */
1149 /* now build a new command-line with quotes */
1151 if (!(ret = HeapAlloc( GetProcessHeap(), 0, strlen(cmdline) + 3 ))) goto done;
1152 sprintf( ret, "\"%s\"%s", name, p );
1154 done:
1155 HeapFree( GetProcessHeap(), 0, name );
1156 return ret;
1160 /**********************************************************************
1161 * CreateProcessA (KERNEL32.@)
1163 BOOL WINAPI CreateProcessA( LPCSTR app_name, LPSTR cmd_line, LPSECURITY_ATTRIBUTES process_attr,
1164 LPSECURITY_ATTRIBUTES thread_attr, BOOL inherit,
1165 DWORD flags, LPVOID env, LPCSTR cur_dir,
1166 LPSTARTUPINFOA startup_info, LPPROCESS_INFORMATION info )
1168 BOOL retv = FALSE;
1169 HANDLE hFile = 0;
1170 const char *unixdir = NULL;
1171 DOS_FULL_NAME full_dir;
1172 char name[MAX_PATH];
1173 LPSTR tidy_cmdline;
1174 char *p;
1176 /* Process the AppName and/or CmdLine to get module name and path */
1178 TRACE("app %s cmdline %s\n", debugstr_a(app_name), debugstr_a(cmd_line) );
1180 if (!(tidy_cmdline = get_file_name( app_name, cmd_line, name, sizeof(name), &hFile )))
1181 return FALSE;
1182 if (hFile == INVALID_HANDLE_VALUE) goto done;
1184 /* Warn if unsupported features are used */
1186 if (flags & NORMAL_PRIORITY_CLASS)
1187 FIXME("(%s,...): NORMAL_PRIORITY_CLASS ignored\n", name);
1188 if (flags & IDLE_PRIORITY_CLASS)
1189 FIXME("(%s,...): IDLE_PRIORITY_CLASS ignored\n", name);
1190 if (flags & HIGH_PRIORITY_CLASS)
1191 FIXME("(%s,...): HIGH_PRIORITY_CLASS ignored\n", name);
1192 if (flags & REALTIME_PRIORITY_CLASS)
1193 FIXME("(%s,...): REALTIME_PRIORITY_CLASS ignored\n", name);
1194 if (flags & CREATE_NEW_PROCESS_GROUP)
1195 FIXME("(%s,...): CREATE_NEW_PROCESS_GROUP ignored\n", name);
1196 if (flags & CREATE_UNICODE_ENVIRONMENT)
1197 FIXME("(%s,...): CREATE_UNICODE_ENVIRONMENT ignored\n", name);
1198 if (flags & CREATE_SEPARATE_WOW_VDM)
1199 FIXME("(%s,...): CREATE_SEPARATE_WOW_VDM ignored\n", name);
1200 if (flags & CREATE_SHARED_WOW_VDM)
1201 FIXME("(%s,...): CREATE_SHARED_WOW_VDM ignored\n", name);
1202 if (flags & CREATE_DEFAULT_ERROR_MODE)
1203 FIXME("(%s,...): CREATE_DEFAULT_ERROR_MODE ignored\n", name);
1204 if (flags & CREATE_NO_WINDOW)
1205 FIXME("(%s,...): CREATE_NO_WINDOW ignored\n", name);
1206 if (flags & PROFILE_USER)
1207 FIXME("(%s,...): PROFILE_USER ignored\n", name);
1208 if (flags & PROFILE_KERNEL)
1209 FIXME("(%s,...): PROFILE_KERNEL ignored\n", name);
1210 if (flags & PROFILE_SERVER)
1211 FIXME("(%s,...): PROFILE_SERVER ignored\n", name);
1212 if (startup_info->lpDesktop)
1213 FIXME("(%s,...): startup_info->lpDesktop %s ignored\n",
1214 name, debugstr_a(startup_info->lpDesktop));
1215 if (startup_info->dwFlags & STARTF_RUNFULLSCREEN)
1216 FIXME("(%s,...): STARTF_RUNFULLSCREEN ignored\n", name);
1217 if (startup_info->dwFlags & STARTF_FORCEONFEEDBACK)
1218 FIXME("(%s,...): STARTF_FORCEONFEEDBACK ignored\n", name);
1219 if (startup_info->dwFlags & STARTF_FORCEOFFFEEDBACK)
1220 FIXME("(%s,...): STARTF_FORCEOFFFEEDBACK ignored\n", name);
1221 if (startup_info->dwFlags & STARTF_USEHOTKEY)
1222 FIXME("(%s,...): STARTF_USEHOTKEY ignored\n", name);
1224 if (cur_dir)
1226 UNICODE_STRING cur_dirW;
1227 RtlCreateUnicodeStringFromAsciiz(&cur_dirW, cur_dir);
1228 if (DOSFS_GetFullName( cur_dirW.Buffer, TRUE, &full_dir ))
1229 unixdir = full_dir.long_name;
1230 RtlFreeUnicodeString(&cur_dirW);
1232 else
1234 WCHAR buf[MAX_PATH];
1235 if (GetCurrentDirectoryW(MAX_PATH, buf))
1237 if (DOSFS_GetFullName( buf, TRUE, &full_dir )) unixdir = full_dir.long_name;
1241 info->hThread = info->hProcess = 0;
1242 info->dwProcessId = info->dwThreadId = 0;
1244 /* Determine executable type */
1246 if (!hFile) /* builtin exe */
1248 TRACE( "starting %s as Winelib app\n", debugstr_a(name) );
1249 retv = create_process( 0, name, tidy_cmdline, env, process_attr, thread_attr,
1250 inherit, flags, startup_info, info, unixdir );
1251 goto done;
1254 switch( MODULE_GetBinaryType( hFile ))
1256 case BINARY_PE_EXE:
1257 TRACE( "starting %s as Win32 binary\n", debugstr_a(name) );
1258 retv = create_process( hFile, name, tidy_cmdline, env, process_attr, thread_attr,
1259 inherit, flags, startup_info, info, unixdir );
1260 break;
1261 case BINARY_WIN16:
1262 case BINARY_DOS:
1263 TRACE( "starting %s as Win16/DOS binary\n", debugstr_a(name) );
1264 retv = create_vdm_process( name, tidy_cmdline, env, process_attr, thread_attr,
1265 inherit, flags, startup_info, info, unixdir );
1266 break;
1267 case BINARY_OS216:
1268 FIXME( "%s is OS/2 binary, not supported\n", debugstr_a(name) );
1269 SetLastError( ERROR_BAD_EXE_FORMAT );
1270 break;
1271 case BINARY_PE_DLL:
1272 TRACE( "not starting %s since it is a dll\n", debugstr_a(name) );
1273 SetLastError( ERROR_BAD_EXE_FORMAT );
1274 break;
1275 case BINARY_UNIX_LIB:
1276 TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_a(name) );
1277 retv = create_process( hFile, name, tidy_cmdline, env, process_attr, thread_attr,
1278 inherit, flags, startup_info, info, unixdir );
1279 break;
1280 case BINARY_UNKNOWN:
1281 /* check for .com or .bat extension */
1282 if ((p = strrchr( name, '.' )))
1284 if (!FILE_strcasecmp( p, ".com" ))
1286 TRACE( "starting %s as DOS binary\n", debugstr_a(name) );
1287 retv = create_vdm_process( name, tidy_cmdline, env, process_attr, thread_attr,
1288 inherit, flags, startup_info, info, unixdir );
1289 break;
1291 if (!FILE_strcasecmp( p, ".bat" ))
1293 char comspec[MAX_PATH];
1294 if (GetEnvironmentVariableA("COMSPEC", comspec, sizeof(comspec)))
1296 char *newcmdline;
1297 if ((newcmdline = HeapAlloc( GetProcessHeap(), 0,
1298 strlen(comspec) + 4 + strlen(tidy_cmdline) + 1)))
1300 sprintf( newcmdline, "%s /c %s", comspec, tidy_cmdline);
1301 TRACE( "starting %s as batch binary: %s\n",
1302 debugstr_a(name), debugstr_a(newcmdline) );
1303 retv = CreateProcessA( comspec, newcmdline, process_attr, thread_attr,
1304 inherit, flags, env, cur_dir, startup_info, info );
1305 HeapFree( GetProcessHeap(), 0, newcmdline );
1306 break;
1311 /* fall through */
1312 case BINARY_UNIX_EXE:
1314 /* unknown file, try as unix executable */
1315 UNICODE_STRING nameW;
1316 DOS_FULL_NAME full_name;
1317 const char *unixfilename = name;
1319 TRACE( "starting %s as Unix binary\n", debugstr_a(name) );
1321 RtlCreateUnicodeStringFromAsciiz(&nameW, name);
1322 if (DOSFS_GetFullName( nameW.Buffer, TRUE, &full_name )) unixfilename = full_name.long_name;
1323 RtlFreeUnicodeString(&nameW);
1324 retv = (fork_and_exec( unixfilename, tidy_cmdline, env, unixdir ) != -1);
1326 break;
1328 CloseHandle( hFile );
1330 done:
1331 if (tidy_cmdline != cmd_line) HeapFree( GetProcessHeap(), 0, tidy_cmdline );
1332 return retv;
1336 /**********************************************************************
1337 * CreateProcessW (KERNEL32.@)
1338 * NOTES
1339 * lpReserved is not converted
1341 BOOL WINAPI CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIBUTES process_attr,
1342 LPSECURITY_ATTRIBUTES thread_attr, BOOL inherit, DWORD flags,
1343 LPVOID env, LPCWSTR cur_dir, LPSTARTUPINFOW startup_info,
1344 LPPROCESS_INFORMATION info )
1346 BOOL ret;
1347 STARTUPINFOA StartupInfoA;
1349 LPSTR app_nameA = HEAP_strdupWtoA (GetProcessHeap(),0,app_name);
1350 LPSTR cmd_lineA = HEAP_strdupWtoA (GetProcessHeap(),0,cmd_line);
1351 LPSTR cur_dirA = HEAP_strdupWtoA (GetProcessHeap(),0,cur_dir);
1353 memcpy (&StartupInfoA, startup_info, sizeof(STARTUPINFOA));
1354 StartupInfoA.lpDesktop = HEAP_strdupWtoA (GetProcessHeap(),0,startup_info->lpDesktop);
1355 StartupInfoA.lpTitle = HEAP_strdupWtoA (GetProcessHeap(),0,startup_info->lpTitle);
1357 TRACE("(%s,%s,...)\n", debugstr_w(app_name), debugstr_w(cmd_line));
1359 if (startup_info->lpReserved)
1360 FIXME("StartupInfo.lpReserved is used, please report (%s)\n",
1361 debugstr_w(startup_info->lpReserved));
1363 ret = CreateProcessA( app_nameA, cmd_lineA, process_attr, thread_attr,
1364 inherit, flags, env, cur_dirA, &StartupInfoA, info );
1366 HeapFree( GetProcessHeap(), 0, cur_dirA );
1367 HeapFree( GetProcessHeap(), 0, cmd_lineA );
1368 HeapFree( GetProcessHeap(), 0, StartupInfoA.lpDesktop );
1369 HeapFree( GetProcessHeap(), 0, StartupInfoA.lpTitle );
1371 return ret;
1375 /***********************************************************************
1376 * wait_input_idle
1378 * Wrapper to call WaitForInputIdle USER function
1380 typedef DWORD (WINAPI *WaitForInputIdle_ptr)( HANDLE hProcess, DWORD dwTimeOut );
1382 static DWORD wait_input_idle( HANDLE process, DWORD timeout )
1384 HMODULE mod = GetModuleHandleA( "user32.dll" );
1385 if (mod)
1387 WaitForInputIdle_ptr ptr = (WaitForInputIdle_ptr)GetProcAddress( mod, "WaitForInputIdle" );
1388 if (ptr) return ptr( process, timeout );
1390 return 0;
1394 /***********************************************************************
1395 * WinExec (KERNEL32.@)
1397 UINT WINAPI WinExec( LPCSTR lpCmdLine, UINT nCmdShow )
1399 PROCESS_INFORMATION info;
1400 STARTUPINFOA startup;
1401 char *cmdline;
1402 UINT ret;
1404 memset( &startup, 0, sizeof(startup) );
1405 startup.cb = sizeof(startup);
1406 startup.dwFlags = STARTF_USESHOWWINDOW;
1407 startup.wShowWindow = nCmdShow;
1409 /* cmdline needs to be writeable for CreateProcess */
1410 if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(lpCmdLine)+1 ))) return 0;
1411 strcpy( cmdline, lpCmdLine );
1413 if (CreateProcessA( NULL, cmdline, NULL, NULL, FALSE,
1414 0, NULL, NULL, &startup, &info ))
1416 /* Give 30 seconds to the app to come up */
1417 if (wait_input_idle( info.hProcess, 30000 ) == 0xFFFFFFFF)
1418 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1419 ret = 33;
1420 /* Close off the handles */
1421 CloseHandle( info.hThread );
1422 CloseHandle( info.hProcess );
1424 else if ((ret = GetLastError()) >= 32)
1426 FIXME("Strange error set by CreateProcess: %d\n", ret );
1427 ret = 11;
1429 HeapFree( GetProcessHeap(), 0, cmdline );
1430 return ret;
1434 /**********************************************************************
1435 * LoadModule (KERNEL32.@)
1437 HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
1439 LOADPARAMS *params = (LOADPARAMS *)paramBlock;
1440 PROCESS_INFORMATION info;
1441 STARTUPINFOA startup;
1442 HINSTANCE hInstance;
1443 LPSTR cmdline, p;
1444 char filename[MAX_PATH];
1445 BYTE len;
1447 if (!name) return (HINSTANCE)ERROR_FILE_NOT_FOUND;
1449 if (!SearchPathA( NULL, name, ".exe", sizeof(filename), filename, NULL ) &&
1450 !SearchPathA( NULL, name, NULL, sizeof(filename), filename, NULL ))
1451 return (HINSTANCE)GetLastError();
1453 len = (BYTE)params->lpCmdLine[0];
1454 if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + len + 2 )))
1455 return (HINSTANCE)ERROR_NOT_ENOUGH_MEMORY;
1457 strcpy( cmdline, filename );
1458 p = cmdline + strlen(cmdline);
1459 *p++ = ' ';
1460 memcpy( p, params->lpCmdLine + 1, len );
1461 p[len] = 0;
1463 memset( &startup, 0, sizeof(startup) );
1464 startup.cb = sizeof(startup);
1465 if (params->lpCmdShow)
1467 startup.dwFlags = STARTF_USESHOWWINDOW;
1468 startup.wShowWindow = params->lpCmdShow[1];
1471 if (CreateProcessA( filename, cmdline, NULL, NULL, FALSE, 0,
1472 params->lpEnvAddress, NULL, &startup, &info ))
1474 /* Give 30 seconds to the app to come up */
1475 if (wait_input_idle( info.hProcess, 30000 ) == 0xFFFFFFFF )
1476 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1477 hInstance = (HINSTANCE)33;
1478 /* Close off the handles */
1479 CloseHandle( info.hThread );
1480 CloseHandle( info.hProcess );
1482 else if ((hInstance = (HINSTANCE)GetLastError()) >= (HINSTANCE)32)
1484 FIXME("Strange error set by CreateProcess: %p\n", hInstance );
1485 hInstance = (HINSTANCE)11;
1488 HeapFree( GetProcessHeap(), 0, cmdline );
1489 return hInstance;
1493 /******************************************************************************
1494 * TerminateProcess (KERNEL32.@)
1496 BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
1498 NTSTATUS status = NtTerminateProcess( handle, exit_code );
1499 if (status) SetLastError( RtlNtStatusToDosError(status) );
1500 return !status;
1504 /***********************************************************************
1505 * GetExitCodeProcess [KERNEL32.@]
1507 * Gets termination status of specified process
1509 * RETURNS
1510 * Success: TRUE
1511 * Failure: FALSE
1513 BOOL WINAPI GetExitCodeProcess(
1514 HANDLE hProcess, /* [in] handle to the process */
1515 LPDWORD lpExitCode) /* [out] address to receive termination status */
1517 BOOL ret;
1518 SERVER_START_REQ( get_process_info )
1520 req->handle = hProcess;
1521 ret = !wine_server_call_err( req );
1522 if (ret && lpExitCode) *lpExitCode = reply->exit_code;
1524 SERVER_END_REQ;
1525 return ret;
1529 /***********************************************************************
1530 * SetErrorMode (KERNEL32.@)
1532 UINT WINAPI SetErrorMode( UINT mode )
1534 UINT old = current_process.error_mode;
1535 current_process.error_mode = mode;
1536 return old;
1540 /**********************************************************************
1541 * TlsAlloc [KERNEL32.@] Allocates a TLS index.
1543 * Allocates a thread local storage index
1545 * RETURNS
1546 * Success: TLS Index
1547 * Failure: 0xFFFFFFFF
1549 DWORD WINAPI TlsAlloc( void )
1551 DWORD i, mask, ret = 0;
1552 DWORD *bits = current_process.tls_bits;
1553 RtlAcquirePebLock();
1554 if (*bits == 0xffffffff)
1556 bits++;
1557 ret = 32;
1558 if (*bits == 0xffffffff)
1560 RtlReleasePebLock();
1561 SetLastError( ERROR_NO_MORE_ITEMS );
1562 return 0xffffffff;
1565 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
1566 *bits |= mask;
1567 RtlReleasePebLock();
1568 NtCurrentTeb()->TlsSlots[ret+i] = 0; /* clear the value */
1569 return ret + i;
1573 /**********************************************************************
1574 * TlsFree [KERNEL32.@] Releases a TLS index.
1576 * Releases a thread local storage index, making it available for reuse
1578 * RETURNS
1579 * Success: TRUE
1580 * Failure: FALSE
1582 BOOL WINAPI TlsFree(
1583 DWORD index) /* [in] TLS Index to free */
1585 DWORD mask = (1 << (index & 31));
1586 DWORD *bits = current_process.tls_bits;
1587 if (index >= 64)
1589 SetLastError( ERROR_INVALID_PARAMETER );
1590 return FALSE;
1592 if (index >= 32) bits++;
1593 RtlAcquirePebLock();
1594 if (!(*bits & mask)) /* already free? */
1596 RtlReleasePebLock();
1597 SetLastError( ERROR_INVALID_PARAMETER );
1598 return FALSE;
1600 *bits &= ~mask;
1601 NtSetInformationThread( GetCurrentThread(), ThreadZeroTlsCell, &index, sizeof(index) );
1602 RtlReleasePebLock();
1603 return TRUE;
1607 /**********************************************************************
1608 * TlsGetValue [KERNEL32.@] Gets value in a thread's TLS slot
1610 * RETURNS
1611 * Success: Value stored in calling thread's TLS slot for index
1612 * Failure: 0 and GetLastError returns NO_ERROR
1614 LPVOID WINAPI TlsGetValue(
1615 DWORD index) /* [in] TLS index to retrieve value for */
1617 if (index >= 64)
1619 SetLastError( ERROR_INVALID_PARAMETER );
1620 return NULL;
1622 SetLastError( ERROR_SUCCESS );
1623 return NtCurrentTeb()->TlsSlots[index];
1627 /**********************************************************************
1628 * TlsSetValue [KERNEL32.@] Stores a value in the thread's TLS slot.
1630 * RETURNS
1631 * Success: TRUE
1632 * Failure: FALSE
1634 BOOL WINAPI TlsSetValue(
1635 DWORD index, /* [in] TLS index to set value for */
1636 LPVOID value) /* [in] Value to be stored */
1638 if (index >= 64)
1640 SetLastError( ERROR_INVALID_PARAMETER );
1641 return FALSE;
1643 NtCurrentTeb()->TlsSlots[index] = value;
1644 return TRUE;
1648 /***********************************************************************
1649 * GetProcessFlags (KERNEL32.@)
1651 DWORD WINAPI GetProcessFlags( DWORD processid )
1653 IMAGE_NT_HEADERS *nt;
1654 DWORD flags = 0;
1656 if (processid && processid != GetCurrentProcessId()) return 0;
1658 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
1660 if (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
1661 flags |= PDB32_CONSOLE_PROC;
1663 if (!AreFileApisANSI()) flags |= PDB32_FILE_APIS_OEM;
1664 if (IsDebuggerPresent()) flags |= PDB32_DEBUGGED;
1665 return flags;
1669 /***********************************************************************
1670 * GetProcessDword (KERNEL.485)
1671 * GetProcessDword (KERNEL32.18)
1672 * 'Of course you cannot directly access Windows internal structures'
1674 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
1676 DWORD x, y;
1677 STARTUPINFOW siw;
1679 TRACE("(%ld, %d)\n", dwProcessID, offset );
1681 if (dwProcessID && dwProcessID != GetCurrentProcessId())
1683 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
1684 return 0;
1687 switch ( offset )
1689 case GPD_APP_COMPAT_FLAGS:
1690 return GetAppCompatFlags16(0);
1691 case GPD_LOAD_DONE_EVENT:
1692 return 0;
1693 case GPD_HINSTANCE16:
1694 return GetTaskDS16();
1695 case GPD_WINDOWS_VERSION:
1696 return GetExeVersion16();
1697 case GPD_THDB:
1698 return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
1699 case GPD_PDB:
1700 return (DWORD)NtCurrentTeb()->Peb;
1701 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
1702 GetStartupInfoW(&siw);
1703 return (DWORD)siw.hStdOutput;
1704 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
1705 GetStartupInfoW(&siw);
1706 return (DWORD)siw.hStdInput;
1707 case GPD_STARTF_SHOWWINDOW:
1708 GetStartupInfoW(&siw);
1709 return siw.wShowWindow;
1710 case GPD_STARTF_SIZE:
1711 GetStartupInfoW(&siw);
1712 x = siw.dwXSize;
1713 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
1714 y = siw.dwYSize;
1715 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
1716 return MAKELONG( x, y );
1717 case GPD_STARTF_POSITION:
1718 GetStartupInfoW(&siw);
1719 x = siw.dwX;
1720 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
1721 y = siw.dwY;
1722 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
1723 return MAKELONG( x, y );
1724 case GPD_STARTF_FLAGS:
1725 GetStartupInfoW(&siw);
1726 return siw.dwFlags;
1727 case GPD_PARENT:
1728 return 0;
1729 case GPD_FLAGS:
1730 return GetProcessFlags(0);
1731 case GPD_USERDATA:
1732 return process_dword;
1733 default:
1734 ERR("Unknown offset %d\n", offset );
1735 return 0;
1739 /***********************************************************************
1740 * SetProcessDword (KERNEL.484)
1741 * 'Of course you cannot directly access Windows internal structures'
1743 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
1745 TRACE("(%ld, %d)\n", dwProcessID, offset );
1747 if (dwProcessID && dwProcessID != GetCurrentProcessId())
1749 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
1750 return;
1753 switch ( offset )
1755 case GPD_APP_COMPAT_FLAGS:
1756 case GPD_LOAD_DONE_EVENT:
1757 case GPD_HINSTANCE16:
1758 case GPD_WINDOWS_VERSION:
1759 case GPD_THDB:
1760 case GPD_PDB:
1761 case GPD_STARTF_SHELLDATA:
1762 case GPD_STARTF_HOTKEY:
1763 case GPD_STARTF_SHOWWINDOW:
1764 case GPD_STARTF_SIZE:
1765 case GPD_STARTF_POSITION:
1766 case GPD_STARTF_FLAGS:
1767 case GPD_PARENT:
1768 case GPD_FLAGS:
1769 ERR("Not allowed to modify offset %d\n", offset );
1770 break;
1771 case GPD_USERDATA:
1772 process_dword = value;
1773 break;
1774 default:
1775 ERR("Unknown offset %d\n", offset );
1776 break;
1781 /***********************************************************************
1782 * ExitProcess (KERNEL.466)
1784 void WINAPI ExitProcess16( WORD status )
1786 DWORD count;
1787 ReleaseThunkLock( &count );
1788 ExitProcess( status );
1792 /*********************************************************************
1793 * OpenProcess (KERNEL32.@)
1795 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
1797 HANDLE ret = 0;
1798 SERVER_START_REQ( open_process )
1800 req->pid = id;
1801 req->access = access;
1802 req->inherit = inherit;
1803 if (!wine_server_call_err( req )) ret = reply->handle;
1805 SERVER_END_REQ;
1806 return ret;
1810 /*********************************************************************
1811 * MapProcessHandle (KERNEL.483)
1813 DWORD WINAPI MapProcessHandle( HANDLE handle )
1815 DWORD ret = 0;
1816 SERVER_START_REQ( get_process_info )
1818 req->handle = handle;
1819 if (!wine_server_call_err( req )) ret = reply->pid;
1821 SERVER_END_REQ;
1822 return ret;
1826 /***********************************************************************
1827 * SetPriorityClass (KERNEL32.@)
1829 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
1831 BOOL ret;
1832 SERVER_START_REQ( set_process_info )
1834 req->handle = hprocess;
1835 req->priority = priorityclass;
1836 req->mask = SET_PROCESS_INFO_PRIORITY;
1837 ret = !wine_server_call_err( req );
1839 SERVER_END_REQ;
1840 return ret;
1844 /***********************************************************************
1845 * GetPriorityClass (KERNEL32.@)
1847 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
1849 DWORD ret = 0;
1850 SERVER_START_REQ( get_process_info )
1852 req->handle = hprocess;
1853 if (!wine_server_call_err( req )) ret = reply->priority;
1855 SERVER_END_REQ;
1856 return ret;
1860 /***********************************************************************
1861 * SetProcessAffinityMask (KERNEL32.@)
1863 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
1865 BOOL ret;
1866 SERVER_START_REQ( set_process_info )
1868 req->handle = hProcess;
1869 req->affinity = affmask;
1870 req->mask = SET_PROCESS_INFO_AFFINITY;
1871 ret = !wine_server_call_err( req );
1873 SERVER_END_REQ;
1874 return ret;
1878 /**********************************************************************
1879 * GetProcessAffinityMask (KERNEL32.@)
1881 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
1882 LPDWORD lpProcessAffinityMask,
1883 LPDWORD lpSystemAffinityMask )
1885 BOOL ret = FALSE;
1886 SERVER_START_REQ( get_process_info )
1888 req->handle = hProcess;
1889 if (!wine_server_call_err( req ))
1891 if (lpProcessAffinityMask) *lpProcessAffinityMask = reply->process_affinity;
1892 if (lpSystemAffinityMask) *lpSystemAffinityMask = reply->system_affinity;
1893 ret = TRUE;
1896 SERVER_END_REQ;
1897 return ret;
1901 /***********************************************************************
1902 * GetProcessVersion (KERNEL32.@)
1904 DWORD WINAPI GetProcessVersion( DWORD processid )
1906 IMAGE_NT_HEADERS *nt;
1908 if (processid && processid != GetCurrentProcessId())
1910 FIXME("should use ReadProcessMemory\n");
1911 return 0;
1913 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
1914 return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
1915 nt->OptionalHeader.MinorSubsystemVersion);
1916 return 0;
1920 /***********************************************************************
1921 * SetProcessWorkingSetSize [KERNEL32.@]
1922 * Sets the min/max working set sizes for a specified process.
1924 * PARAMS
1925 * hProcess [I] Handle to the process of interest
1926 * minset [I] Specifies minimum working set size
1927 * maxset [I] Specifies maximum working set size
1929 * RETURNS STD
1931 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess, SIZE_T minset,
1932 SIZE_T maxset)
1934 FIXME("(%p,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
1935 if(( minset == (SIZE_T)-1) && (maxset == (SIZE_T)-1)) {
1936 /* Trim the working set to zero */
1937 /* Swap the process out of physical RAM */
1939 return TRUE;
1942 /***********************************************************************
1943 * GetProcessWorkingSetSize (KERNEL32.@)
1945 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess, PSIZE_T minset,
1946 PSIZE_T maxset)
1948 FIXME("(%p,%p,%p): stub\n",hProcess,minset,maxset);
1949 /* 32 MB working set size */
1950 if (minset) *minset = 32*1024*1024;
1951 if (maxset) *maxset = 32*1024*1024;
1952 return TRUE;
1956 /***********************************************************************
1957 * SetProcessShutdownParameters (KERNEL32.@)
1959 BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
1961 FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
1962 shutdown_flags = flags;
1963 shutdown_priority = level;
1964 return TRUE;
1968 /***********************************************************************
1969 * GetProcessShutdownParameters (KERNEL32.@)
1972 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
1974 *lpdwLevel = shutdown_priority;
1975 *lpdwFlags = shutdown_flags;
1976 return TRUE;
1980 /***********************************************************************
1981 * GetProcessPriorityBoost (KERNEL32.@)
1983 BOOL WINAPI GetProcessPriorityBoost(HANDLE hprocess,PBOOL pDisablePriorityBoost)
1985 FIXME("(%p,%p): semi-stub\n", hprocess, pDisablePriorityBoost);
1987 /* Report that no boost is present.. */
1988 *pDisablePriorityBoost = FALSE;
1990 return TRUE;
1993 /***********************************************************************
1994 * SetProcessPriorityBoost (KERNEL32.@)
1996 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
1998 FIXME("(%p,%d): stub\n",hprocess,disableboost);
1999 /* Say we can do it. I doubt the program will notice that we don't. */
2000 return TRUE;
2004 /***********************************************************************
2005 * ReadProcessMemory (KERNEL32.@)
2007 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, SIZE_T size,
2008 SIZE_T *bytes_read )
2010 NTSTATUS status = NtReadVirtualMemory( process, addr, buffer, size, bytes_read );
2011 if (status) SetLastError( RtlNtStatusToDosError(status) );
2012 return !status;
2016 /***********************************************************************
2017 * WriteProcessMemory (KERNEL32.@)
2019 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPCVOID buffer, SIZE_T size,
2020 SIZE_T *bytes_written )
2022 NTSTATUS status = NtWriteVirtualMemory( process, addr, buffer, size, bytes_written );
2023 if (status) SetLastError( RtlNtStatusToDosError(status) );
2024 return !status;
2028 /***********************************************************************
2029 * ProcessIdToSessionId (KERNEL32.@)
2030 * This function is available on Terminal Server 4SP4 and Windows 2000
2032 BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
2034 /* According to MSDN, if the calling process is not in a terminal
2035 * services environment, then the sessionid returned is zero.
2037 *sessionid_ptr = 0;
2038 return TRUE;
2042 /***********************************************************************
2043 * RegisterServiceProcess (KERNEL.491)
2044 * RegisterServiceProcess (KERNEL32.@)
2046 * A service process calls this function to ensure that it continues to run
2047 * even after a user logged off.
2049 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
2051 /* I don't think that Wine needs to do anything in that function */
2052 return 1; /* success */
2056 /**************************************************************************
2057 * SetFileApisToOEM (KERNEL32.@)
2059 VOID WINAPI SetFileApisToOEM(void)
2061 oem_file_apis = TRUE;
2065 /**************************************************************************
2066 * SetFileApisToANSI (KERNEL32.@)
2068 VOID WINAPI SetFileApisToANSI(void)
2070 oem_file_apis = FALSE;
2074 /******************************************************************************
2075 * AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
2077 * RETURNS
2078 * TRUE: Set of file functions is using ANSI code page
2079 * FALSE: Set of file functions is using OEM code page
2081 BOOL WINAPI AreFileApisANSI(void)
2083 return !oem_file_apis;
2087 /***********************************************************************
2088 * GetCurrentProcess (KERNEL32.@)
2090 #undef GetCurrentProcess
2091 HANDLE WINAPI GetCurrentProcess(void)
2093 return (HANDLE)0xffffffff;