- Fixed resource functions to work directly from the HMODULE instead of
[wine] / scheduler / process.c
1 /*
2  * Win32 processes
3  *
4  * Copyright 1996, 1998 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include <ctype.h>
9 #include <errno.h>
10 #include <fcntl.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include "wine/winbase16.h"
16 #include "wine/exception.h"
17 #include "process.h"
18 #include "main.h"
19 #include "module.h"
20 #include "neexe.h"
21 #include "dosexe.h"
22 #include "file.h"
23 #include "global.h"
24 #include "heap.h"
25 #include "task.h"
26 #include "ldt.h"
27 #include "syslevel.h"
28 #include "thread.h"
29 #include "winerror.h"
30 #include "server.h"
31 #include "options.h"
32 #include "callback.h"
33 #include "debugtools.h"
34
35 DEFAULT_DEBUG_CHANNEL(process);
36 DECLARE_DEBUG_CHANNEL(relay);
37 DECLARE_DEBUG_CHANNEL(win32);
38
39
40 static ENVDB initial_envdb;
41 static STARTUPINFOA initial_startup;
42 static char **main_exe_argv;
43 static char *main_exe_name;
44 static HFILE main_exe_file = -1;
45
46
47 /***********************************************************************
48  *           PROCESS_IdToPDB
49  *
50  * Convert a process id to a PDB, making sure it is valid.
51  */
52 PDB *PROCESS_IdToPDB( DWORD pid )
53 {
54     if (!pid || pid == GetCurrentProcessId()) return PROCESS_Current();
55     return NULL;
56 }
57
58
59 /***********************************************************************
60  *           PROCESS_CallUserSignalProc
61  *
62  * FIXME:  Some of the signals aren't sent correctly!
63  *
64  * The exact meaning of the USER signals is undocumented, but this 
65  * should cover the basic idea:
66  *
67  * USIG_DLL_UNLOAD_WIN16
68  *     This is sent when a 16-bit module is unloaded.
69  *
70  * USIG_DLL_UNLOAD_WIN32
71  *     This is sent when a 32-bit module is unloaded.
72  *
73  * USIG_DLL_UNLOAD_ORPHANS
74  *     This is sent after the last Win3.1 module is unloaded,
75  *     to allow removal of orphaned menus.
76  *
77  * USIG_FAULT_DIALOG_PUSH
78  * USIG_FAULT_DIALOG_POP
79  *     These are called to allow USER to prepare for displaying a
80  *     fault dialog, even though the fault might have happened while
81  *     inside a USER critical section.
82  *
83  * USIG_THREAD_INIT
84  *     This is called from the context of a new thread, as soon as it
85  *     has started to run.
86  *
87  * USIG_THREAD_EXIT
88  *     This is called, still in its context, just before a thread is
89  *     about to terminate.
90  *
91  * USIG_PROCESS_CREATE
92  *     This is called, in the parent process context, after a new process
93  *     has been created.
94  *
95  * USIG_PROCESS_INIT
96  *     This is called in the new process context, just after the main thread
97  *     has started execution (after the main thread's USIG_THREAD_INIT has
98  *     been sent).
99  *
100  * USIG_PROCESS_LOADED
101  *     This is called after the executable file has been loaded into the
102  *     new process context.
103  *
104  * USIG_PROCESS_RUNNING
105  *     This is called immediately before the main entry point is called.
106  *
107  * USIG_PROCESS_EXIT
108  *     This is called in the context of a process that is about to
109  *     terminate (but before the last thread's USIG_THREAD_EXIT has
110  *     been sent).
111  *
112  * USIG_PROCESS_DESTROY
113  *     This is called after a process has terminated.
114  *
115  *
116  * The meaning of the dwFlags bits is as follows:
117  *
118  * USIG_FLAGS_WIN32
119  *     Current process is 32-bit.
120  *
121  * USIG_FLAGS_GUI
122  *     Current process is a (Win32) GUI process.
123  *
124  * USIG_FLAGS_FEEDBACK 
125  *     Current process needs 'feedback' (determined from the STARTUPINFO
126  *     flags STARTF_FORCEONFEEDBACK / STARTF_FORCEOFFFEEDBACK).
127  *
128  * USIG_FLAGS_FAULT
129  *     The signal is being sent due to a fault.
130  */
131 void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
132 {
133     DWORD flags = PROCESS_Current()->flags;
134     DWORD startup_flags = PROCESS_Current()->env_db->startup_info->dwFlags;
135     DWORD dwFlags = 0;
136
137     /* Determine dwFlags */
138
139     if ( !(flags & PDB32_WIN16_PROC) ) dwFlags |= USIG_FLAGS_WIN32;
140
141     if ( !(flags & PDB32_CONSOLE_PROC) ) dwFlags |= USIG_FLAGS_GUI;
142
143     if ( dwFlags & USIG_FLAGS_GUI )
144     {
145         /* Feedback defaults to ON */
146         if ( !(startup_flags & STARTF_FORCEOFFFEEDBACK) )
147             dwFlags |= USIG_FLAGS_FEEDBACK;
148     }
149     else
150     {
151         /* Feedback defaults to OFF */
152         if (startup_flags & STARTF_FORCEONFEEDBACK)
153             dwFlags |= USIG_FLAGS_FEEDBACK;
154     }
155
156     /* Convert module handle to 16-bit */
157
158     if ( HIWORD( hModule ) )
159         hModule = MapHModuleLS( hModule );
160
161     /* Call USER signal proc */
162
163     if ( Callout.UserSignalProc )
164     {
165         if ( uCode == USIG_THREAD_INIT || uCode == USIG_THREAD_EXIT )
166             Callout.UserSignalProc( uCode, GetCurrentThreadId(), dwFlags, hModule );
167         else
168             Callout.UserSignalProc( uCode, GetCurrentProcessId(), dwFlags, hModule );
169     }
170 }
171
172
173 /***********************************************************************
174  *           process_init
175  *
176  * Main process initialisation code
177  */
178 static BOOL process_init( char *argv[] )
179 {
180     struct init_process_request *req;
181     PDB *pdb = PROCESS_Current();
182
183     /* store the program name */
184     argv0 = argv[0];
185
186     /* Fill the initial process structure */
187     pdb->exit_code              = STILL_ACTIVE;
188     pdb->threads                = 1;
189     pdb->running_threads        = 1;
190     pdb->ring0_threads          = 1;
191     pdb->env_db                 = &initial_envdb;
192     pdb->group                  = pdb;
193     pdb->priority               = 8;  /* Normal */
194     pdb->winver                 = 0xffff; /* to be determined */
195     initial_envdb.startup_info  = &initial_startup;
196
197     /* Setup the server connection */
198     NtCurrentTeb()->socket = CLIENT_InitServer();
199     if (CLIENT_InitThread()) return FALSE;
200
201     /* Retrieve startup info from the server */
202     req = get_req_buffer();
203     req->ldt_copy  = ldt_copy;
204     req->ldt_flags = ldt_flags_copy;
205     req->ppid      = getppid();
206     if (server_call( REQ_INIT_PROCESS )) return FALSE;
207     main_exe_file               = req->exe_file;
208     if (req->filename[0]) main_exe_name = strdup( req->filename );
209     initial_startup.dwFlags     = req->start_flags;
210     initial_startup.wShowWindow = req->cmd_show;
211     initial_envdb.hStdin   = initial_startup.hStdInput  = req->hstdin;
212     initial_envdb.hStdout  = initial_startup.hStdOutput = req->hstdout;
213     initial_envdb.hStderr  = initial_startup.hStdError  = req->hstderr;
214
215     /* Remember TEB selector of initial process for emergency use */
216     SYSLEVEL_EmergencyTeb = NtCurrentTeb()->teb_sel;
217
218     /* Create the system and process heaps */
219     if (!HEAP_CreateSystemHeap()) return FALSE;
220     pdb->heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
221
222     /* Copy the parent environment */
223     if (!ENV_BuildEnvironment()) return FALSE;
224
225     /* Create the SEGPTR heap */
226     if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return FALSE;
227
228     /* Initialize the critical sections */
229     InitializeCriticalSection( &pdb->crit_section );
230     InitializeCriticalSection( &initial_envdb.section );
231
232     /* Initialize syslevel handling */
233     SYSLEVEL_Init();
234
235     /* Parse command line arguments */
236     OPTIONS_ParseOptions( argv );
237
238     return MAIN_MainInit();
239 }
240
241
242 /***********************************************************************
243  *           load_system_dlls
244  *
245  * Load system DLLs into the initial process (and initialize them)
246  */
247 static int load_system_dlls(void)
248 {
249     /* Get pointers to USER routines called by KERNEL */
250     THUNK_InitCallout();
251
252     /* Call FinalUserInit routine */
253     Callout.FinalUserInit16();
254
255     /* Note: The USIG_PROCESS_CREATE signal is supposed to be sent in the
256      *       context of the parent process.  Actually, the USER signal proc
257      *       doesn't really care about that, but it *does* require that the
258      *       startup parameters are correctly set up, so that GetProcessDword
259      *       works.  Furthermore, before calling the USER signal proc the 
260      *       16-bit stack must be set up, which it is only after TASK_Create
261      *       in the case of a 16-bit process. Thus, we send the signal here.
262      */
263     PROCESS_CallUserSignalProc( USIG_PROCESS_CREATE, 0 );
264     PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
265     PROCESS_CallUserSignalProc( USIG_PROCESS_INIT, 0 );
266     PROCESS_CallUserSignalProc( USIG_PROCESS_LOADED, 0 );
267
268     return 1;
269 }
270
271
272 /***********************************************************************
273  *           build_command_line
274  *
275  * Build the command-line of a process from the argv array.
276  */
277 static inline char *build_command_line( char **argv )
278 {
279     int len, quote;
280     char *cmdline, *p, **arg;
281
282     for (arg = argv, len = 0; *arg; arg++) len += strlen(*arg) + 1;
283     if ((quote = (strchr( argv[0], ' ' ) != NULL))) len += 2;
284     if (!(p = cmdline = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
285     arg = argv;
286     if (quote)
287     {
288         *p++ = '\"';
289         strcpy( p, *arg );
290         p += strlen(p);
291         *p++ = '\"';
292         *p++ = ' ';
293         arg++;
294     }
295     while (*arg)
296     {
297         strcpy( p, *arg );
298         p += strlen(p);
299         *p++ = ' ';
300         arg++;
301     }
302     if (p > cmdline) p--;  /* remove last space */
303     *p = 0;
304     return cmdline;
305 }
306
307
308 /***********************************************************************
309  *           start_process
310  *
311  * Startup routine of a new process. Runs on the new process stack.
312  */
313 static void start_process(void)
314 {
315     struct init_process_done_request *req = get_req_buffer();
316     int debugged, console_app;
317     UINT cmdShow = SW_SHOWNORMAL;
318     LPTHREAD_START_ROUTINE entry;
319     PDB *pdb = PROCESS_Current();
320     HMODULE module = pdb->exe_modref->module;
321
322     /* Increment EXE refcount */
323     pdb->exe_modref->refCount++;
324
325     /* build command line */
326     if (!(pdb->env_db->cmd_line = build_command_line( main_exe_argv ))) goto error;
327
328     /* Retrieve entry point address */
329     entry = (LPTHREAD_START_ROUTINE)((char*)module + PE_HEADER(module)->OptionalHeader.AddressOfEntryPoint);
330     console_app = (PE_HEADER(module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
331
332     if (console_app) pdb->flags |= PDB32_CONSOLE_PROC;
333
334     /* Signal the parent process to continue */
335     req->module = (void *)module;
336     req->entry  = entry;
337     req->name   = &pdb->exe_modref->filename;
338     req->gui    = !console_app;
339     server_call( REQ_INIT_PROCESS_DONE );
340     debugged = req->debugged;
341
342     /* Install signal handlers; this cannot be done before, since we cannot
343      * send exceptions to the debugger before the create process event that
344      * is sent by REQ_INIT_PROCESS_DONE */
345     if (!SIGNAL_Init()) goto error;
346
347     /* Load KERNEL (necessary for TASK_Create) */
348     if (!LoadLibraryA( "KERNEL32" )) goto error;
349
350     /* Create 16-bit task */
351     if (pdb->env_db->startup_info->dwFlags & STARTF_USESHOWWINDOW)
352         cmdShow = pdb->env_db->startup_info->wShowWindow;
353     if (!TASK_Create( (NE_MODULE *)GlobalLock16( MapHModuleLS(module) ), cmdShow,
354                       NtCurrentTeb(), NULL, 0 ))
355         goto error;
356
357     /* Load the system dlls */
358     if (!load_system_dlls()) goto error;
359
360     EnterCriticalSection( &pdb->crit_section );
361     PE_InitTls();
362     MODULE_DllProcessAttach( pdb->exe_modref, (LPVOID)1 );
363     LeaveCriticalSection( &pdb->crit_section );
364
365     /* Call UserSignalProc ( USIG_PROCESS_RUNNING ... ) only for non-GUI win32 apps */
366     if (console_app) PROCESS_CallUserSignalProc( USIG_PROCESS_RUNNING, 0 );
367
368     TRACE_(relay)( "Starting Win32 process (entryproc=%p)\n", entry );
369     if (debugged) DbgBreakPoint();
370     /* FIXME: should use _PEB as parameter for NT 3.5 programs !
371      * Dunno about other OSs */
372     ExitThread( entry(NULL) );
373
374  error:
375     ExitProcess( GetLastError() );
376 }
377
378
379 /***********************************************************************
380  *           PROCESS_Start
381  *
382  * Startup routine of a new Win32 process once the main module has been loaded.
383  * The filename is free'd by this routine.
384  */
385 static void PROCESS_Start( HMODULE main_module, HFILE hFile, LPSTR filename ) WINE_NORETURN;
386 static void PROCESS_Start( HMODULE main_module, HFILE hFile, LPSTR filename )
387 {
388     if (!filename)
389     {
390         /* if no explicit filename, use argv[0] */
391         if (!(filename = malloc( MAX_PATH ))) ExitProcess(1);
392         if (!GetLongPathNameA( full_argv0, filename, MAX_PATH ))
393             lstrcpynA( filename, full_argv0, MAX_PATH );
394     }
395
396     /* load main module */
397     if (PE_HEADER(main_module)->FileHeader.Characteristics & IMAGE_FILE_DLL)
398         ExitProcess( ERROR_BAD_EXE_FORMAT );
399
400     /* Create 32-bit MODREF */
401     if (!PE_CreateModule( main_module, filename, 0, hFile, FALSE ))
402         goto error;
403     free( filename );
404
405     /* allocate main thread stack */
406     if (!THREAD_InitStack( NtCurrentTeb(),
407                            PE_HEADER(main_module)->OptionalHeader.SizeOfStackReserve, TRUE ))
408         goto error;
409
410     /* switch to the new stack */
411     SYSDEPS_SwitchToThreadStack( start_process );
412
413  error:
414     ExitProcess( GetLastError() );
415 }
416
417
418 /***********************************************************************
419  *           PROCESS_InitWine
420  *
421  * Wine initialisation: load and start the main exe file.
422  */
423 void PROCESS_InitWine( int argc, char *argv[] )
424 {
425     DWORD type;
426
427     /* Initialize everything */
428     if (!process_init( argv )) exit(1);
429
430     main_exe_argv = ++argv;  /* remove argv[0] (wine itself) */
431
432     if (!main_exe_name)
433     {
434         char buffer[MAX_PATH];
435         if (!argv[0]) OPTIONS_Usage();
436
437         /* open the exe file */
438         if (!SearchPathA( NULL, argv[0], ".exe", sizeof(buffer), buffer, NULL ) &&
439             !SearchPathA( NULL, argv[0], NULL, sizeof(buffer), buffer, NULL ))
440         {
441             MESSAGE( "%s: cannot find '%s'\n", argv0, argv[0] );
442             goto error;
443         }
444         if (!(main_exe_name = strdup(buffer)))
445         {
446             MESSAGE( "%s: out of memory\n", argv0 );
447             ExitProcess(1);
448         }
449     }
450
451     if (main_exe_file == INVALID_HANDLE_VALUE)
452     {
453         if ((main_exe_file = CreateFileA( main_exe_name, GENERIC_READ, FILE_SHARE_READ,
454                                           NULL, OPEN_EXISTING, 0, -1 )) == INVALID_HANDLE_VALUE)
455         {
456             MESSAGE( "%s: cannot open '%s'\n", argv0, main_exe_name );
457             goto error;
458         }
459     }
460
461     if (!MODULE_GetBinaryType( main_exe_file, main_exe_name, &type ))
462     {
463         MESSAGE( "%s: unrecognized executable '%s'\n", argv0, main_exe_name );
464         goto error;
465     }
466
467     switch (type)
468     {
469     case SCS_32BIT_BINARY:
470         {
471             HMODULE main_module = PE_LoadImage( main_exe_file, main_exe_name, 0 );
472             if (main_module) PROCESS_Start( main_module, main_exe_file, main_exe_name );
473         }
474         break;
475
476     case SCS_WOW_BINARY:
477         {
478             HMODULE main_module;
479             /* create 32-bit module for main exe */
480             if (!(main_module = BUILTIN32_LoadExeModule())) goto error;
481             NtCurrentTeb()->tibflags &= ~TEBF_WIN32;
482             PROCESS_Current()->flags |= PDB32_WIN16_PROC;
483             SYSLEVEL_EnterWin16Lock();
484             PROCESS_Start( main_module, -1, NULL );
485         }
486         break;
487
488     case SCS_DOS_BINARY:
489         {
490             HMODULE main_module;
491             /* create 32-bit module for main exe */
492             if (!(main_module = BUILTIN32_LoadExeModule())) goto error;
493             NtCurrentTeb()->tibflags &= ~TEBF_WIN32;
494             if (!MZ_LoadImage( main_module, main_exe_file, main_exe_name )) goto error;
495             PROCESS_Start( main_module, main_exe_file, NULL );
496         }
497         break;
498
499     case SCS_PIF_BINARY:
500     case SCS_POSIX_BINARY:
501     case SCS_OS216_BINARY:
502     default:
503         MESSAGE( "%s: unrecognized executable '%s'\n", argv0, main_exe_name );
504         SetLastError( ERROR_BAD_FORMAT );
505         break;
506     }
507  error:
508     ExitProcess( GetLastError() );
509 }
510
511
512 /***********************************************************************
513  *           PROCESS_InitWinelib
514  *
515  * Initialisation of a new Winelib process.
516  */
517 void PROCESS_InitWinelib( int argc, char *argv[] )
518 {
519     HMODULE main_module;
520
521     if (!process_init( argv )) exit(1);
522
523     /* create 32-bit module for main exe */
524     if (!(main_module = BUILTIN32_LoadExeModule())) ExitProcess( GetLastError() );
525
526     main_exe_argv = argv;
527     PROCESS_Start( main_module, -1, NULL );
528 }
529
530
531 /***********************************************************************
532  *           build_argv
533  *
534  * Build an argv array from a command-line.
535  * The command-line is modified to insert nulls.
536  * 'reserved' is the number of args to reserve before the first one.
537  */
538 static char **build_argv( char *cmdline, int reserved )
539 {
540     char **argv;
541     int count = reserved + 1;
542     char *p = cmdline;
543
544     /* if first word is quoted store it as a single arg */
545     if (*cmdline == '\"')
546     {
547         if ((p = strchr( cmdline + 1, '\"' )))
548         {
549             p++;
550             count++;
551         }
552         else p = cmdline;
553     }
554     while (*p)
555     {
556         while (*p && isspace(*p)) p++;
557         if (!*p) break;
558         count++;
559         while (*p && !isspace(*p)) p++;
560     }
561
562     if ((argv = malloc( count * sizeof(*argv) )))
563     {
564         char **argvptr = argv + reserved;
565         p = cmdline;
566         if (*cmdline == '\"')
567         {
568             if ((p = strchr( cmdline + 1, '\"' )))
569             {
570                 *argvptr++ = cmdline + 1;
571                 *p++ = 0;
572             }
573             else p = cmdline;
574         }
575         while (*p)
576         {
577             while (*p && isspace(*p)) *p++ = 0;
578             if (!*p) break;
579             *argvptr++ = p;
580             while (*p && !isspace(*p)) p++;
581         }
582         *argvptr = 0;
583     }
584     return argv;
585 }
586
587
588 /***********************************************************************
589  *           build_envp
590  *
591  * Build the environment of a new child process.
592  */
593 static char **build_envp( const char *env )
594 {
595     const char *p;
596     char **envp;
597     int count;
598
599     for (p = env, count = 0; *p; count++) p += strlen(p) + 1;
600     count += 3;
601     if ((envp = malloc( count * sizeof(*envp) )))
602     {
603         extern char **environ;
604         char **envptr = envp;
605         char **unixptr = environ;
606         /* first put PATH, HOME and WINEPREFIX from the unix env */
607         for (unixptr = environ; unixptr && *unixptr; unixptr++)
608             if (!memcmp( *unixptr, "PATH=", 5 ) ||
609                 !memcmp( *unixptr, "HOME=", 5 ) ||
610                 !memcmp( *unixptr, "WINEPREFIX=", 11 )) *envptr++ = *unixptr;
611         /* now put the Windows environment strings */
612         for (p = env; *p; p += strlen(p) + 1)
613         {
614             if (memcmp( p, "PATH=", 5 ) &&
615                 memcmp( p, "HOME=", 5 ) &&
616                 memcmp( p, "WINEPREFIX=", 11 )) *envptr++ = (char *)p;
617         }
618         *envptr = 0;
619     }
620     return envp;
621 }
622
623
624 /***********************************************************************
625  *           find_wine_binary
626  *
627  * Locate the Wine binary to exec for a new Win32 process.
628  */
629 static void exec_wine_binary( char **argv, char **envp )
630 {
631     const char *path, *pos, *ptr;
632
633     /* first try bin directory */
634     argv[0] = BINDIR "/wine";
635     execve( argv[0], argv, envp );
636
637     /* now try the path of argv0 of the current binary */
638     if (!(argv[0] = malloc( strlen(full_argv0) + 6 ))) return;
639     if ((ptr = strrchr( full_argv0, '/' )))
640     {
641         memcpy( argv[0], full_argv0, ptr - full_argv0 );
642         strcpy( argv[0] + (ptr - full_argv0), "/wine" );
643         execve( argv[0], argv, envp );
644     }
645     free( argv[0] );
646
647     /* now search in the Unix path */
648     if ((path = getenv( "PATH" )))
649     {
650         if (!(argv[0] = malloc( strlen(path) + 6 ))) return;
651         pos = path;
652         for (;;)
653         {
654             while (*pos == ':') pos++;
655             if (!*pos) break;
656             if (!(ptr = strchr( pos, ':' ))) ptr = pos + strlen(pos);
657             memcpy( argv[0], pos, ptr - pos );
658             strcpy( argv[0] + (ptr - pos), "/wine" );
659             execve( argv[0], argv, envp );
660             pos = ptr;
661         }
662     }
663     free( argv[0] );
664
665     /* finally try the current directory */
666     argv[0] = "./wine";
667     execve( argv[0], argv, envp );
668 }
669
670
671 /***********************************************************************
672  *           fork_and_exec
673  *
674  * Fork and exec a new Unix process, checking for errors.
675  */
676 static int fork_and_exec( const char *filename, char *cmdline,
677                           const char *env, const char *newdir )
678 {
679     int fd[2];
680     int pid, err;
681
682     if (pipe(fd) == -1)
683     {
684         FILE_SetDosError();
685         return -1;
686     }
687     fcntl( fd[1], F_SETFD, 1 );  /* set close on exec */
688     if (!(pid = fork()))  /* child */
689     {
690         char **argv = build_argv( cmdline, filename ? 0 : 2 );
691         char **envp = build_envp( env );
692         close( fd[0] );
693
694         if (newdir) chdir(newdir);
695
696         if (argv && envp)
697         {
698             if (!filename)
699             {
700                 argv[1] = "--";
701                 exec_wine_binary( argv, envp );
702             }
703             else execve( filename, argv, envp );
704         }
705         err = errno;
706         write( fd[1], &err, sizeof(err) );
707         _exit(1);
708     }
709     close( fd[1] );
710     if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0))  /* exec failed */
711     {
712         errno = err;
713         pid = -1;
714     }
715     if (pid == -1) FILE_SetDosError();
716     close( fd[0] );
717     return pid;
718 }
719
720
721 /***********************************************************************
722  *           PROCESS_Create
723  *
724  * Create a new process. If hFile is a valid handle we have an exe
725  * file, and we exec a new copy of wine to load it; otherwise we
726  * simply exec the specified filename as a Unix process.
727  */
728 BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env, 
729                      LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
730                      BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
731                      LPPROCESS_INFORMATION info, LPCSTR lpCurrentDirectory )
732 {
733     int pid;
734     const char *unixfilename = NULL;
735     const char *unixdir = NULL;
736     DOS_FULL_NAME full_name;
737     HANDLE load_done_evt = -1;
738     struct new_process_request *req = get_req_buffer();
739     struct wait_process_request *wait_req = get_req_buffer();
740
741     info->hThread = info->hProcess = INVALID_HANDLE_VALUE;
742     
743     /* create the process on the server side */
744
745     req->inherit_all  = inherit;
746     req->create_flags = flags;
747     req->start_flags  = startup->dwFlags;
748     req->exe_file     = hFile;
749     if (startup->dwFlags & STARTF_USESTDHANDLES)
750     {
751         req->hstdin  = startup->hStdInput;
752         req->hstdout = startup->hStdOutput;
753         req->hstderr = startup->hStdError;
754     }
755     else
756     {
757         req->hstdin  = GetStdHandle( STD_INPUT_HANDLE );
758         req->hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
759         req->hstderr = GetStdHandle( STD_ERROR_HANDLE );
760     }
761     req->cmd_show = startup->wShowWindow;
762     req->alloc_fd = 0;
763
764     if (lpCurrentDirectory) {
765         if (DOSFS_GetFullName( lpCurrentDirectory, TRUE, &full_name ))
766             unixdir = full_name.long_name;
767     } else {
768         CHAR    buf[260];
769         if (GetCurrentDirectoryA(sizeof(buf),buf)) {
770             if (DOSFS_GetFullName( buf, TRUE, &full_name ))
771                 unixdir = full_name.long_name;
772         }
773     }
774
775     if (hFile == -1)  /* unix process */
776     {
777         unixfilename = filename;
778         if (DOSFS_GetFullName( filename, TRUE, &full_name )) unixfilename = full_name.long_name;
779         req->filename[0] = 0;
780     }
781     else  /* new wine process */
782     {
783         if (!GetLongPathNameA( filename, req->filename, server_remaining(req->filename) ))
784             lstrcpynA( req->filename, filename, server_remaining(req->filename) );
785     }
786     if (server_call( REQ_NEW_PROCESS )) return FALSE;
787
788     /* fork and execute */
789
790     pid = fork_and_exec( unixfilename, cmd_line, env ? env : GetEnvironmentStringsA(), unixdir );
791
792     wait_req->cancel   = (pid == -1);
793     wait_req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle);
794     wait_req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle);
795     wait_req->timeout  = 2000;
796     if (server_call( REQ_WAIT_PROCESS ) || (pid == -1)) goto error;
797     info->dwProcessId = (DWORD)wait_req->pid;
798     info->dwThreadId  = (DWORD)wait_req->tid;
799     info->hProcess    = wait_req->phandle;
800     info->hThread     = wait_req->thandle;
801     load_done_evt     = wait_req->event;
802
803     /* Wait until process is initialized (or initialization failed) */
804     if (load_done_evt != -1)
805     {
806         DWORD res;
807         HANDLE handles[2];
808
809         handles[0] = info->hProcess;
810         handles[1] = load_done_evt;
811         res = WaitForMultipleObjects( 2, handles, FALSE, INFINITE );
812         CloseHandle( load_done_evt );
813         if (res == STATUS_WAIT_0)  /* the process died */
814         {
815             DWORD exitcode;
816             if (GetExitCodeProcess( info->hProcess, &exitcode )) SetLastError( exitcode );
817             CloseHandle( info->hThread );
818             CloseHandle( info->hProcess );
819             return FALSE;
820         }
821     }
822     return TRUE;
823
824 error:
825     if (load_done_evt != -1) CloseHandle( load_done_evt );
826     if (info->hThread != INVALID_HANDLE_VALUE) CloseHandle( info->hThread );
827     if (info->hProcess != INVALID_HANDLE_VALUE) CloseHandle( info->hProcess );
828     return FALSE;
829 }
830
831
832 /***********************************************************************
833  *           ExitProcess   (KERNEL32.100)
834  */
835 void WINAPI ExitProcess( DWORD status )
836 {
837     struct terminate_process_request *req = get_req_buffer();
838
839     MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
840     /* send the exit code to the server */
841     req->handle    = GetCurrentProcess();
842     req->exit_code = status;
843     server_call( REQ_TERMINATE_PROCESS );
844     exit( status );
845 }
846
847 /***********************************************************************
848  *           ExitProcess16   (KERNEL.466)
849  */
850 void WINAPI ExitProcess16( WORD status )
851 {
852     SYSLEVEL_ReleaseWin16Lock();
853     ExitProcess( status );
854 }
855
856 /******************************************************************************
857  *           TerminateProcess   (KERNEL32.684)
858  */
859 BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
860 {
861     BOOL ret;
862     struct terminate_process_request *req = get_req_buffer();
863     req->handle    = handle;
864     req->exit_code = exit_code;
865     if ((ret = !server_call( REQ_TERMINATE_PROCESS )) && req->self) exit( exit_code );
866     return ret;
867 }
868
869
870 /***********************************************************************
871  *           GetProcessDword    (KERNEL32.18) (KERNEL.485)
872  * 'Of course you cannot directly access Windows internal structures'
873  */
874 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
875 {
876     PDB *process = PROCESS_IdToPDB( dwProcessID );
877     TDB *pTask;
878     DWORD x, y;
879
880     TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
881     if ( !process )
882     {
883         ERR("%d: process %lx not accessible\n", offset, dwProcessID);
884         return 0;
885     }
886
887     switch ( offset ) 
888     {
889     case GPD_APP_COMPAT_FLAGS:
890         pTask = (TDB *)GlobalLock16( GetCurrentTask() );
891         return pTask? pTask->compat_flags : 0;
892
893     case GPD_LOAD_DONE_EVENT:
894         return process->load_done_evt;
895
896     case GPD_HINSTANCE16:
897         pTask = (TDB *)GlobalLock16( GetCurrentTask() );
898         return pTask? pTask->hInstance : 0;
899
900     case GPD_WINDOWS_VERSION:
901         pTask = (TDB *)GlobalLock16( GetCurrentTask() );
902         return pTask? pTask->version : 0;
903
904     case GPD_THDB:
905         if ( process != PROCESS_Current() ) return 0;
906         return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
907
908     case GPD_PDB:
909         return (DWORD)process;
910
911     case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
912         return process->env_db->startup_info->hStdOutput;
913
914     case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
915         return process->env_db->startup_info->hStdInput;
916
917     case GPD_STARTF_SHOWWINDOW:
918         return process->env_db->startup_info->wShowWindow;
919
920     case GPD_STARTF_SIZE:
921         x = process->env_db->startup_info->dwXSize;
922         if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
923         y = process->env_db->startup_info->dwYSize;
924         if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
925         return MAKELONG( x, y );
926
927     case GPD_STARTF_POSITION:
928         x = process->env_db->startup_info->dwX;
929         if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
930         y = process->env_db->startup_info->dwY;
931         if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
932         return MAKELONG( x, y );
933
934     case GPD_STARTF_FLAGS:
935         return process->env_db->startup_info->dwFlags;
936
937     case GPD_PARENT:
938         return 0;
939
940     case GPD_FLAGS:
941         return process->flags;
942
943     case GPD_USERDATA:
944         return process->process_dword;
945
946     default:
947         ERR_(win32)("Unknown offset %d\n", offset );
948         return 0;
949     }
950 }
951
952 /***********************************************************************
953  *           SetProcessDword    (KERNEL.484)
954  * 'Of course you cannot directly access Windows internal structures'
955  */
956 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
957 {
958     PDB *process = PROCESS_IdToPDB( dwProcessID );
959
960     TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
961     if ( !process )
962     {
963         ERR("%d: process %lx not accessible\n", offset, dwProcessID);
964         return;
965     }
966
967     switch ( offset ) 
968     {
969     case GPD_APP_COMPAT_FLAGS:
970     case GPD_LOAD_DONE_EVENT:
971     case GPD_HINSTANCE16:
972     case GPD_WINDOWS_VERSION:
973     case GPD_THDB:
974     case GPD_PDB:
975     case GPD_STARTF_SHELLDATA:
976     case GPD_STARTF_HOTKEY:
977     case GPD_STARTF_SHOWWINDOW:
978     case GPD_STARTF_SIZE:
979     case GPD_STARTF_POSITION:
980     case GPD_STARTF_FLAGS:
981     case GPD_PARENT:
982     case GPD_FLAGS:
983         ERR_(win32)("Not allowed to modify offset %d\n", offset );
984         break;
985
986     case GPD_USERDATA:
987         process->process_dword = value; 
988         break;
989
990     default:
991         ERR_(win32)("Unknown offset %d\n", offset );
992         break;
993     }
994 }
995
996
997 /*********************************************************************
998  *           OpenProcess   (KERNEL32.543)
999  */
1000 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
1001 {
1002     HANDLE ret = 0;
1003     struct open_process_request *req = get_req_buffer();
1004
1005     req->pid     = (void *)id;
1006     req->access  = access;
1007     req->inherit = inherit;
1008     if (!server_call( REQ_OPEN_PROCESS )) ret = req->handle;
1009     return ret;
1010 }                             
1011
1012 /*********************************************************************
1013  *           MapProcessHandle   (KERNEL.483)
1014  */
1015 DWORD WINAPI MapProcessHandle( HANDLE handle )
1016 {
1017     DWORD ret = 0;
1018     struct get_process_info_request *req = get_req_buffer();
1019     req->handle = handle;
1020     if (!server_call( REQ_GET_PROCESS_INFO )) ret = (DWORD)req->pid;
1021     return ret;
1022 }
1023
1024 /***********************************************************************
1025  *           SetPriorityClass   (KERNEL32.503)
1026  */
1027 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
1028 {
1029     struct set_process_info_request *req = get_req_buffer();
1030     req->handle   = hprocess;
1031     req->priority = priorityclass;
1032     req->mask     = SET_PROCESS_INFO_PRIORITY;
1033     return !server_call( REQ_SET_PROCESS_INFO );
1034 }
1035
1036
1037 /***********************************************************************
1038  *           GetPriorityClass   (KERNEL32.250)
1039  */
1040 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
1041 {
1042     DWORD ret = 0;
1043     struct get_process_info_request *req = get_req_buffer();
1044     req->handle = hprocess;
1045     if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->priority;
1046     return ret;
1047 }
1048
1049
1050 /***********************************************************************
1051  *          SetProcessAffinityMask   (KERNEL32.662)
1052  */
1053 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
1054 {
1055     struct set_process_info_request *req = get_req_buffer();
1056     req->handle   = hProcess;
1057     req->affinity = affmask;
1058     req->mask     = SET_PROCESS_INFO_AFFINITY;
1059     return !server_call( REQ_SET_PROCESS_INFO );
1060 }
1061
1062 /**********************************************************************
1063  *          GetProcessAffinityMask    (KERNEL32.373)
1064  */
1065 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
1066                                       LPDWORD lpProcessAffinityMask,
1067                                       LPDWORD lpSystemAffinityMask )
1068 {
1069     BOOL ret = FALSE;
1070     struct get_process_info_request *req = get_req_buffer();
1071     req->handle = hProcess;
1072     if (!server_call( REQ_GET_PROCESS_INFO ))
1073     {
1074         if (lpProcessAffinityMask) *lpProcessAffinityMask = req->process_affinity;
1075         if (lpSystemAffinityMask) *lpSystemAffinityMask = req->system_affinity;
1076         ret = TRUE;
1077     }
1078     return ret;
1079 }
1080
1081
1082 /***********************************************************************
1083  *           GetStdHandle    (KERNEL32.276)
1084  */
1085 HANDLE WINAPI GetStdHandle( DWORD std_handle )
1086 {
1087     PDB *pdb = PROCESS_Current();
1088
1089     switch(std_handle)
1090     {
1091     case STD_INPUT_HANDLE:  return pdb->env_db->hStdin;
1092     case STD_OUTPUT_HANDLE: return pdb->env_db->hStdout;
1093     case STD_ERROR_HANDLE:  return pdb->env_db->hStderr;
1094     }
1095     SetLastError( ERROR_INVALID_PARAMETER );
1096     return INVALID_HANDLE_VALUE;
1097 }
1098
1099
1100 /***********************************************************************
1101  *           SetStdHandle    (KERNEL32.506)
1102  */
1103 BOOL WINAPI SetStdHandle( DWORD std_handle, HANDLE handle )
1104 {
1105     PDB *pdb = PROCESS_Current();
1106     /* FIXME: should we close the previous handle? */
1107     switch(std_handle)
1108     {
1109     case STD_INPUT_HANDLE:
1110         pdb->env_db->hStdin = handle;
1111         return TRUE;
1112     case STD_OUTPUT_HANDLE:
1113         pdb->env_db->hStdout = handle;
1114         return TRUE;
1115     case STD_ERROR_HANDLE:
1116         pdb->env_db->hStderr = handle;
1117         return TRUE;
1118     }
1119     SetLastError( ERROR_INVALID_PARAMETER );
1120     return FALSE;
1121 }
1122
1123 /***********************************************************************
1124  *           GetProcessVersion    (KERNEL32)
1125  */
1126 DWORD WINAPI GetProcessVersion( DWORD processid )
1127 {
1128     TDB *pTask;
1129     PDB *pdb = PROCESS_IdToPDB( processid );
1130
1131     if (!pdb) return 0;
1132     if (!(pTask = (TDB *)GlobalLock16( pdb->task ))) return 0;
1133     return (pTask->version&0xff) | (((pTask->version >>8) & 0xff)<<16);
1134 }
1135
1136 /***********************************************************************
1137  *           GetProcessFlags    (KERNEL32)
1138  */
1139 DWORD WINAPI GetProcessFlags( DWORD processid )
1140 {
1141     PDB *pdb = PROCESS_IdToPDB( processid );
1142     if (!pdb) return 0;
1143     return pdb->flags;
1144 }
1145
1146 /***********************************************************************
1147  *              SetProcessWorkingSetSize        [KERNEL32.662]
1148  * Sets the min/max working set sizes for a specified process.
1149  *
1150  * PARAMS
1151  *    hProcess [I] Handle to the process of interest
1152  *    minset   [I] Specifies minimum working set size
1153  *    maxset   [I] Specifies maximum working set size
1154  *
1155  * RETURNS  STD
1156  */
1157 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess,DWORD minset,
1158                                        DWORD maxset)
1159 {
1160     FIXME("(0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
1161     if(( minset == -1) && (maxset == -1)) {
1162         /* Trim the working set to zero */
1163         /* Swap the process out of physical RAM */
1164     }
1165     return TRUE;
1166 }
1167
1168 /***********************************************************************
1169  *           GetProcessWorkingSetSize    (KERNEL32)
1170  */
1171 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess,LPDWORD minset,
1172                                        LPDWORD maxset)
1173 {
1174         FIXME("(0x%08x,%p,%p): stub\n",hProcess,minset,maxset);
1175         /* 32 MB working set size */
1176         if (minset) *minset = 32*1024*1024;
1177         if (maxset) *maxset = 32*1024*1024;
1178         return TRUE;
1179 }
1180
1181 /***********************************************************************
1182  *           SetProcessShutdownParameters    (KERNEL32)
1183  *
1184  * CHANGED - James Sutherland (JamesSutherland@gmx.de)
1185  * Now tracks changes made (but does not act on these changes)
1186  * NOTE: the definition for SHUTDOWN_NORETRY was done on guesswork.
1187  * It really shouldn't be here, but I'll move it when it's been checked!
1188  */
1189 #define SHUTDOWN_NORETRY 1
1190 static unsigned int shutdown_noretry = 0;
1191 static unsigned int shutdown_priority = 0x280L;
1192 BOOL WINAPI SetProcessShutdownParameters(DWORD level,DWORD flags)
1193 {
1194     if (flags & SHUTDOWN_NORETRY)
1195       shutdown_noretry = 1;
1196     else
1197       shutdown_noretry = 0;
1198     if (level > 0x100L && level < 0x3FFL)
1199       shutdown_priority = level;
1200     else
1201       {
1202         ERR("invalid priority level 0x%08lx\n", level);
1203         return FALSE;
1204       }
1205     return TRUE;
1206 }
1207
1208
1209 /***********************************************************************
1210  * GetProcessShutdownParameters                 (KERNEL32)
1211  *
1212  */
1213 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel,
1214                                             LPDWORD lpdwFlags )
1215 {
1216   (*lpdwLevel) = shutdown_priority;
1217   (*lpdwFlags) = (shutdown_noretry * SHUTDOWN_NORETRY);
1218   return TRUE;
1219 }
1220 /***********************************************************************
1221  *           SetProcessPriorityBoost    (KERNEL32)
1222  */
1223 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
1224 {
1225     FIXME("(%d,%d): stub\n",hprocess,disableboost);
1226     /* Say we can do it. I doubt the program will notice that we don't. */
1227     return TRUE;
1228 }
1229
1230
1231 /***********************************************************************
1232  *           ReadProcessMemory                  (KERNEL32)
1233  */
1234 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, DWORD size,
1235                                LPDWORD bytes_read )
1236 {
1237     struct read_process_memory_request *req = get_req_buffer();
1238     unsigned int offset = (unsigned int)addr % sizeof(int);
1239     unsigned int max = server_remaining( req->data );  /* max length in one request */
1240     unsigned int pos;
1241
1242     if (bytes_read) *bytes_read = size;
1243
1244     /* first time, read total length to check for permissions */
1245     req->handle = process;
1246     req->addr   = (char *)addr - offset;
1247     req->len    = (size + offset + sizeof(int) - 1) / sizeof(int);
1248     if (server_call( REQ_READ_PROCESS_MEMORY )) goto error;
1249
1250     if (size <= max - offset)
1251     {
1252         memcpy( buffer, (char *)req->data + offset, size );
1253         return TRUE;
1254     }
1255
1256     /* now take care of the remaining data */
1257     memcpy( buffer, (char *)req->data + offset, max - offset );
1258     pos = max - offset;
1259     size -= pos;
1260     while (size)
1261     {
1262         if (max > size) max = size;
1263         req->handle = process;
1264         req->addr   = (char *)addr + pos;
1265         req->len    = (max + sizeof(int) - 1) / sizeof(int);
1266         if (server_call( REQ_READ_PROCESS_MEMORY )) goto error;
1267         memcpy( (char *)buffer + pos, (char *)req->data, max );
1268         size -= max;
1269         pos += max;
1270     }
1271     return TRUE;
1272
1273  error:
1274     if (bytes_read) *bytes_read = 0;
1275     return FALSE;
1276 }
1277
1278
1279 /***********************************************************************
1280  *           WriteProcessMemory                 (KERNEL32)
1281  */
1282 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPVOID buffer, DWORD size,
1283                                 LPDWORD bytes_written )
1284 {
1285     unsigned int first_offset, last_offset;
1286     struct write_process_memory_request *req = get_req_buffer();
1287     unsigned int max = server_remaining( req->data );  /* max length in one request */
1288     unsigned int pos, last_mask;
1289
1290     if (!size)
1291     {
1292         SetLastError( ERROR_INVALID_PARAMETER );
1293         return FALSE;
1294     }
1295     if (bytes_written) *bytes_written = size;
1296
1297     /* compute the mask for the first int */
1298     req->first_mask = ~0;
1299     first_offset = (unsigned int)addr % sizeof(int);
1300     memset( &req->first_mask, 0, first_offset );
1301
1302     /* compute the mask for the last int */
1303     last_offset = (size + first_offset) % sizeof(int);
1304     last_mask = 0;
1305     memset( &last_mask, 0xff, last_offset ? last_offset : sizeof(int) );
1306
1307     req->handle = process;
1308     req->addr = (char *)addr - first_offset;
1309     /* for the first request, use the total length */
1310     req->len = (size + first_offset + sizeof(int) - 1) / sizeof(int);
1311
1312     if (size + first_offset < max)  /* we can do it in one round */
1313     {
1314         memcpy( (char *)req->data + first_offset, buffer, size );
1315         req->last_mask = last_mask;
1316         if (server_call( REQ_WRITE_PROCESS_MEMORY )) goto error;
1317         return TRUE;
1318     }
1319
1320     /* needs multiple server calls */
1321
1322     memcpy( (char *)req->data + first_offset, buffer, max - first_offset );
1323     req->last_mask = ~0;
1324     if (server_call( REQ_WRITE_PROCESS_MEMORY )) goto error;
1325     pos = max - first_offset;
1326     size -= pos;
1327     while (size)
1328     {
1329         if (size <= max)  /* last one */
1330         {
1331             req->last_mask = last_mask;
1332             max = size;
1333         }
1334         req->handle = process;
1335         req->addr = (char *)addr + pos;
1336         req->len = (max + sizeof(int) - 1) / sizeof(int);
1337         req->first_mask = ~0;
1338         memcpy( req->data, (char *) buffer + pos, max );
1339         if (server_call( REQ_WRITE_PROCESS_MEMORY )) goto error;
1340         pos += max;
1341         size -= max;
1342     }
1343     return TRUE;
1344
1345  error:
1346     if (bytes_written) *bytes_written = 0;
1347     return FALSE;
1348
1349 }
1350
1351
1352 /***********************************************************************
1353  *           RegisterServiceProcess             (KERNEL, KERNEL32)
1354  *
1355  * A service process calls this function to ensure that it continues to run
1356  * even after a user logged off.
1357  */
1358 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
1359 {
1360         /* I don't think that Wine needs to do anything in that function */
1361         return 1; /* success */
1362 }
1363
1364 /***********************************************************************
1365  * GetExitCodeProcess [KERNEL32.325]
1366  *
1367  * Gets termination status of specified process
1368  * 
1369  * RETURNS
1370  *   Success: TRUE
1371  *   Failure: FALSE
1372  */
1373 BOOL WINAPI GetExitCodeProcess(
1374     HANDLE hProcess,  /* [I] handle to the process */
1375     LPDWORD lpExitCode) /* [O] address to receive termination status */
1376 {
1377     BOOL ret = FALSE;
1378     struct get_process_info_request *req = get_req_buffer();
1379     req->handle = hProcess;
1380     if (!server_call( REQ_GET_PROCESS_INFO ))
1381     {
1382         if (lpExitCode) *lpExitCode = req->exit_code;
1383         ret = TRUE;
1384     }
1385     return ret;
1386 }
1387
1388
1389 /***********************************************************************
1390  *           SetErrorMode   (KERNEL32.486)
1391  */
1392 UINT WINAPI SetErrorMode( UINT mode )
1393 {
1394     UINT old = PROCESS_Current()->error_mode;
1395     PROCESS_Current()->error_mode = mode;
1396     return old;
1397 }
1398
1399 /***********************************************************************
1400  *           GetCurrentProcess   (KERNEL32.198)
1401  */
1402 #undef GetCurrentProcess
1403 HANDLE WINAPI GetCurrentProcess(void)
1404 {
1405     return 0xffffffff;
1406 }