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