Added a more truthful message about what really is wrong.
[wine/multimedia.git] / scheduler / process.c
blob7ce442434434ccd73cc25273560d9ed208688222
1 /*
2 * Win32 processes
4 * Copyright 1996, 1998 Alexandre Julliard
5 */
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 "wine/library.h"
18 #include "drive.h"
19 #include "module.h"
20 #include "file.h"
21 #include "heap.h"
22 #include "task.h"
23 #include "thread.h"
24 #include "winerror.h"
25 #include "server.h"
26 #include "options.h"
27 #include "callback.h"
28 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(process);
31 DECLARE_DEBUG_CHANNEL(relay);
32 DECLARE_DEBUG_CHANNEL(win32);
34 struct _ENVDB;
36 /* Win32 process database */
37 typedef struct _PDB
39 LONG header[2]; /* 00 Kernel object header */
40 HMODULE module; /* 08 Main exe module (NT) */
41 void *event; /* 0c Pointer to an event object (unused) */
42 DWORD exit_code; /* 10 Process exit code */
43 DWORD unknown2; /* 14 Unknown */
44 HANDLE heap; /* 18 Default process heap */
45 HANDLE mem_context; /* 1c Process memory context */
46 DWORD flags; /* 20 Flags */
47 void *pdb16; /* 24 DOS PSP */
48 WORD PSP_sel; /* 28 Selector to DOS PSP */
49 WORD imte; /* 2a IMTE for the process module */
50 WORD threads; /* 2c Number of threads */
51 WORD running_threads; /* 2e Number of running threads */
52 WORD free_lib_count; /* 30 Recursion depth of FreeLibrary calls */
53 WORD ring0_threads; /* 32 Number of ring 0 threads */
54 HANDLE system_heap; /* 34 System heap to allocate handles */
55 HTASK task; /* 38 Win16 task */
56 void *mem_map_files; /* 3c Pointer to mem-mapped files */
57 struct _ENVDB *env_db; /* 40 Environment database */
58 void *handle_table; /* 44 Handle table */
59 struct _PDB *parent; /* 48 Parent process */
60 void *modref_list; /* 4c MODREF list */
61 void *thread_list; /* 50 List of threads */
62 void *debuggee_CB; /* 54 Debuggee context block */
63 void *local_heap_free; /* 58 Head of local heap free list */
64 DWORD unknown4; /* 5c Unknown */
65 CRITICAL_SECTION crit_section; /* 60 Critical section */
66 DWORD unknown5[3]; /* 78 Unknown */
67 void *console; /* 84 Console */
68 DWORD tls_bits[2]; /* 88 TLS in-use bits */
69 DWORD process_dword; /* 90 Unknown */
70 struct _PDB *group; /* 94 Process group */
71 void *exe_modref; /* 98 MODREF for the process EXE */
72 void *top_filter; /* 9c Top exception filter */
73 DWORD priority; /* a0 Priority level */
74 HANDLE heap_list; /* a4 Head of process heap list */
75 void *heap_handles; /* a8 Head of heap handles list */
76 DWORD unknown6; /* ac Unknown */
77 void *console_provider; /* b0 Console provider (??) */
78 WORD env_selector; /* b4 Selector to process environment */
79 WORD error_mode; /* b6 Error mode */
80 HANDLE load_done_evt; /* b8 Event for process loading done */
81 void *UTState; /* bc Head of Univeral Thunk list */
82 DWORD unknown8; /* c0 Unknown (NT) */
83 LCID locale; /* c4 Locale to be queried by GetThreadLocale (NT) */
84 } PDB;
86 PDB current_process;
88 /* Process flags */
89 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
90 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
91 #define PDB32_DOS_PROC 0x0010 /* Dos process */
92 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
93 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
94 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
96 static char **main_exe_argv;
97 static char main_exe_name[MAX_PATH];
98 static HANDLE main_exe_file;
100 unsigned int server_startticks;
102 /* memory/environ.c */
103 extern struct _ENVDB *ENV_BuildEnvironment(void);
104 extern BOOL ENV_BuildCommandLine( char **argv );
105 extern STARTUPINFOA current_startupinfo;
107 extern BOOL MAIN_MainInit(void);
110 /***********************************************************************
111 * PROCESS_CallUserSignalProc
113 * FIXME: Some of the signals aren't sent correctly!
115 * The exact meaning of the USER signals is undocumented, but this
116 * should cover the basic idea:
118 * USIG_DLL_UNLOAD_WIN16
119 * This is sent when a 16-bit module is unloaded.
121 * USIG_DLL_UNLOAD_WIN32
122 * This is sent when a 32-bit module is unloaded.
124 * USIG_DLL_UNLOAD_ORPHANS
125 * This is sent after the last Win3.1 module is unloaded,
126 * to allow removal of orphaned menus.
128 * USIG_FAULT_DIALOG_PUSH
129 * USIG_FAULT_DIALOG_POP
130 * These are called to allow USER to prepare for displaying a
131 * fault dialog, even though the fault might have happened while
132 * inside a USER critical section.
134 * USIG_THREAD_INIT
135 * This is called from the context of a new thread, as soon as it
136 * has started to run.
138 * USIG_THREAD_EXIT
139 * This is called, still in its context, just before a thread is
140 * about to terminate.
142 * USIG_PROCESS_CREATE
143 * This is called, in the parent process context, after a new process
144 * has been created.
146 * USIG_PROCESS_INIT
147 * This is called in the new process context, just after the main thread
148 * has started execution (after the main thread's USIG_THREAD_INIT has
149 * been sent).
151 * USIG_PROCESS_LOADED
152 * This is called after the executable file has been loaded into the
153 * new process context.
155 * USIG_PROCESS_RUNNING
156 * This is called immediately before the main entry point is called.
158 * USIG_PROCESS_EXIT
159 * This is called in the context of a process that is about to
160 * terminate (but before the last thread's USIG_THREAD_EXIT has
161 * been sent).
163 * USIG_PROCESS_DESTROY
164 * This is called after a process has terminated.
167 * The meaning of the dwFlags bits is as follows:
169 * USIG_FLAGS_WIN32
170 * Current process is 32-bit.
172 * USIG_FLAGS_GUI
173 * Current process is a (Win32) GUI process.
175 * USIG_FLAGS_FEEDBACK
176 * Current process needs 'feedback' (determined from the STARTUPINFO
177 * flags STARTF_FORCEONFEEDBACK / STARTF_FORCEOFFFEEDBACK).
179 * USIG_FLAGS_FAULT
180 * The signal is being sent due to a fault.
182 void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
184 DWORD flags = current_process.flags;
185 DWORD startup_flags = current_startupinfo.dwFlags;
186 DWORD dwFlags = 0;
188 /* Determine dwFlags */
190 if ( !(flags & PDB32_WIN16_PROC) ) dwFlags |= USIG_FLAGS_WIN32;
192 if ( !(flags & PDB32_CONSOLE_PROC) ) dwFlags |= USIG_FLAGS_GUI;
194 if ( dwFlags & USIG_FLAGS_GUI )
196 /* Feedback defaults to ON */
197 if ( !(startup_flags & STARTF_FORCEOFFFEEDBACK) )
198 dwFlags |= USIG_FLAGS_FEEDBACK;
200 else
202 /* Feedback defaults to OFF */
203 if (startup_flags & STARTF_FORCEONFEEDBACK)
204 dwFlags |= USIG_FLAGS_FEEDBACK;
207 /* Convert module handle to 16-bit */
209 if ( HIWORD( hModule ) )
210 hModule = MapHModuleLS( hModule );
212 /* Call USER signal proc */
214 if ( Callout.UserSignalProc )
216 if ( uCode == USIG_THREAD_INIT || uCode == USIG_THREAD_EXIT )
217 Callout.UserSignalProc( uCode, GetCurrentThreadId(), dwFlags, hModule );
218 else
219 Callout.UserSignalProc( uCode, GetCurrentProcessId(), dwFlags, hModule );
224 /***********************************************************************
225 * process_init
227 * Main process initialisation code
229 static BOOL process_init( char *argv[] )
231 BOOL ret;
233 /* store the program name */
234 argv0 = argv[0];
235 main_exe_argv = argv;
237 /* Fill the initial process structure */
238 current_process.exit_code = STILL_ACTIVE;
239 current_process.threads = 1;
240 current_process.running_threads = 1;
241 current_process.ring0_threads = 1;
242 current_process.group = &current_process;
243 current_process.priority = 8; /* Normal */
245 /* Setup the server connection */
246 NtCurrentTeb()->socket = CLIENT_InitServer();
247 if (CLIENT_InitThread()) return FALSE;
249 /* Retrieve startup info from the server */
250 SERVER_START_REQ
252 struct init_process_request *req = server_alloc_req( sizeof(*req),
253 sizeof(main_exe_name)-1 );
255 req->ldt_copy = &wine_ldt_copy;
256 req->ppid = getppid();
257 if ((ret = !server_call( REQ_INIT_PROCESS )))
259 size_t len = server_data_size( req );
260 memcpy( main_exe_name, server_data_ptr(req), len );
261 main_exe_name[len] = 0;
262 main_exe_file = req->exe_file;
263 current_startupinfo.dwFlags = req->start_flags;
264 server_startticks = req->server_start;
265 current_startupinfo.wShowWindow = req->cmd_show;
266 current_startupinfo.hStdInput = req->hstdin;
267 current_startupinfo.hStdOutput = req->hstdout;
268 current_startupinfo.hStdError = req->hstderr;
269 SetStdHandle( STD_INPUT_HANDLE, current_startupinfo.hStdInput );
270 SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
271 SetStdHandle( STD_ERROR_HANDLE, current_startupinfo.hStdError );
274 SERVER_END_REQ;
275 if (!ret) return FALSE;
277 /* Create the system and process heaps */
278 if (!HEAP_CreateSystemHeap()) return FALSE;
279 current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
281 /* Copy the parent environment */
282 if (!(current_process.env_db = ENV_BuildEnvironment())) return FALSE;
284 /* Parse command line arguments */
285 OPTIONS_ParseOptions( argv );
287 return MAIN_MainInit();
291 /***********************************************************************
292 * start_process
294 * Startup routine of a new process. Runs on the new process stack.
296 static void start_process(void)
298 int debugged, console_app;
299 LPTHREAD_START_ROUTINE entry;
300 WINE_MODREF *wm;
302 /* build command line */
303 if (!ENV_BuildCommandLine( main_exe_argv )) goto error;
305 /* create 32-bit module for main exe */
306 if (!(current_process.module = BUILTIN32_LoadExeModule( current_process.module ))) goto error;
308 /* use original argv[0] as name for the main module */
309 if (!main_exe_name[0])
311 if (!GetLongPathNameA( full_argv0, main_exe_name, sizeof(main_exe_name) ))
312 lstrcpynA( main_exe_name, full_argv0, sizeof(main_exe_name) );
315 /* Retrieve entry point address */
316 entry = (LPTHREAD_START_ROUTINE)((char*)current_process.module +
317 PE_HEADER(current_process.module)->OptionalHeader.AddressOfEntryPoint);
318 console_app = (PE_HEADER(current_process.module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
319 if (console_app) current_process.flags |= PDB32_CONSOLE_PROC;
321 /* Signal the parent process to continue */
322 SERVER_START_REQ
324 struct init_process_done_request *req = server_alloc_req( sizeof(*req), 0 );
325 req->module = (void *)current_process.module;
326 req->entry = entry;
327 req->name = main_exe_name;
328 req->exe_file = main_exe_file;
329 req->gui = !console_app;
330 server_call( REQ_INIT_PROCESS_DONE );
331 debugged = req->debugged;
333 SERVER_END_REQ;
335 /* Install signal handlers; this cannot be done before, since we cannot
336 * send exceptions to the debugger before the create process event that
337 * is sent by REQ_INIT_PROCESS_DONE */
338 if (!SIGNAL_Init()) goto error;
340 /* create the main modref and load dependencies */
341 if (!(wm = PE_CreateModule( current_process.module, main_exe_name, 0, 0, FALSE )))
342 goto error;
343 wm->refCount++;
345 RtlAcquirePebLock();
346 PE_InitTls();
347 MODULE_DllProcessAttach( NULL, (LPVOID)1 );
348 RtlReleasePebLock();
350 /* Get pointers to USER routines called by KERNEL */
351 THUNK_InitCallout();
353 /* Call FinalUserInit routine */
354 if (Callout.FinalUserInit16) Callout.FinalUserInit16();
356 /* Note: The USIG_PROCESS_CREATE signal is supposed to be sent in the
357 * context of the parent process. Actually, the USER signal proc
358 * doesn't really care about that, but it *does* require that the
359 * startup parameters are correctly set up, so that GetProcessDword
360 * works. Furthermore, before calling the USER signal proc the
361 * 16-bit stack must be set up, which it is only after TASK_Create
362 * in the case of a 16-bit process. Thus, we send the signal here.
364 PROCESS_CallUserSignalProc( USIG_PROCESS_CREATE, 0 );
365 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
366 PROCESS_CallUserSignalProc( USIG_PROCESS_INIT, 0 );
367 PROCESS_CallUserSignalProc( USIG_PROCESS_LOADED, 0 );
368 /* Call UserSignalProc ( USIG_PROCESS_RUNNING ... ) only for non-GUI win32 apps */
369 if (console_app) PROCESS_CallUserSignalProc( USIG_PROCESS_RUNNING, 0 );
371 TRACE_(relay)( "Starting Win32 process %s (entryproc=%p)\n", main_exe_name, entry );
372 if (debugged) DbgBreakPoint();
373 /* FIXME: should use _PEB as parameter for NT 3.5 programs !
374 * Dunno about other OSs */
375 SetLastError(0); /* clear error code */
376 ExitThread( entry(NULL) );
378 error:
379 ExitProcess( GetLastError() );
383 /***********************************************************************
384 * open_winelib_app
386 * Try to open the Winelib app .so file based on argv[0] or WINEPRELOAD.
388 void *open_winelib_app( char *argv[] )
390 void *ret = NULL;
391 char *tmp;
392 const char *name;
394 if ((name = getenv( "WINEPRELOAD" )))
396 if (!(ret = wine_dll_load_main_exe( name, 0 )))
398 MESSAGE( "%s: could not load '%s' as specified in the WINEPRELOAD environment variable\n",
399 argv[0], name );
400 ExitProcess(1);
403 else
405 const char *argv0 = main_exe_name;
406 if (!*argv0)
408 /* if argv[0] is "wine", don't try to load anything */
409 argv0 = argv[0];
410 if (!(name = strrchr( argv0, '/' ))) name = argv0;
411 else name++;
412 if (!strcmp( name, "wine" )) return NULL;
415 /* now try argv[0] with ".so" appended */
416 if ((tmp = HeapAlloc( GetProcessHeap(), 0, strlen(argv0) + 4 )))
418 strcpy( tmp, argv0 );
419 strcat( tmp, ".so" );
420 /* search in PATH only if there was no '/' in argv[0] */
421 ret = wine_dll_load_main_exe( tmp, (name == argv0) );
422 if (!ret && !argv[1])
424 /* if no argv[1], this will be better than displaying usage */
425 MESSAGE( "%s: could not load library '%s' as Winelib application\n",
426 argv[0], tmp );
427 ExitProcess(1);
429 HeapFree( GetProcessHeap(), 0, tmp );
432 return ret;
435 /***********************************************************************
436 * PROCESS_InitWine
438 * Wine initialisation: load and start the main exe file.
440 void PROCESS_InitWine( int argc, char *argv[] )
442 DWORD stack_size = 0;
444 /* Initialize everything */
445 if (!process_init( argv )) exit(1);
447 if (open_winelib_app( argv )) goto found; /* try to open argv[0] as a winelib app */
449 main_exe_argv = ++argv; /* remove argv[0] (wine itself) */
451 if (!main_exe_name[0])
453 if (!argv[0]) OPTIONS_Usage();
455 /* open the exe file */
456 if (!SearchPathA( NULL, argv[0], ".exe", sizeof(main_exe_name), main_exe_name, NULL ) &&
457 !SearchPathA( NULL, argv[0], NULL, sizeof(main_exe_name), main_exe_name, NULL ))
459 MESSAGE( "%s: cannot find '%s'\n", argv0, argv[0] );
460 goto error;
464 if (!main_exe_file)
466 if ((main_exe_file = CreateFileA( main_exe_name, GENERIC_READ, FILE_SHARE_READ,
467 NULL, OPEN_EXISTING, 0, -1 )) == INVALID_HANDLE_VALUE)
469 MESSAGE( "%s: cannot open '%s'\n", argv0, main_exe_name );
470 goto error;
474 /* first try Win32 format; this will fail if the file is not a PE binary */
475 if ((current_process.module = PE_LoadImage( main_exe_file, main_exe_name, 0 )))
477 if (PE_HEADER(current_process.module)->FileHeader.Characteristics & IMAGE_FILE_DLL)
478 ExitProcess( ERROR_BAD_EXE_FORMAT );
479 stack_size = PE_HEADER(current_process.module)->OptionalHeader.SizeOfStackReserve;
480 goto found;
483 /* it must be 16-bit or DOS format */
484 NtCurrentTeb()->tibflags &= ~TEBF_WIN32;
485 current_process.flags |= PDB32_WIN16_PROC;
486 main_exe_name[0] = 0;
487 CloseHandle( main_exe_file );
488 main_exe_file = 0;
489 _EnterWin16Lock();
491 found:
492 /* allocate main thread stack */
493 if (!THREAD_InitStack( NtCurrentTeb(), stack_size, TRUE )) goto error;
495 /* switch to the new stack */
496 SYSDEPS_SwitchToThreadStack( start_process );
498 error:
499 ExitProcess( GetLastError() );
503 /***********************************************************************
504 * PROCESS_InitWinelib
506 * Initialisation of a new Winelib process.
508 void PROCESS_InitWinelib( int argc, char *argv[] )
510 if (!process_init( argv )) exit(1);
512 /* allocate main thread stack */
513 if (!THREAD_InitStack( NtCurrentTeb(), 0, TRUE )) ExitProcess( GetLastError() );
515 /* switch to the new stack */
516 SYSDEPS_SwitchToThreadStack( start_process );
520 /***********************************************************************
521 * build_argv
523 * Build an argv array from a command-line.
524 * The command-line is modified to insert nulls.
525 * 'reserved' is the number of args to reserve before the first one.
527 static char **build_argv( char *cmdline, int reserved )
529 char **argv;
530 int count = reserved + 1;
531 char *p = cmdline;
533 /* if first word is quoted store it as a single arg */
534 if (*cmdline == '\"')
536 if ((p = strchr( cmdline + 1, '\"' )))
538 p++;
539 count++;
541 else p = cmdline;
543 while (*p)
545 while (*p && isspace(*p)) p++;
546 if (!*p) break;
547 count++;
548 while (*p && !isspace(*p)) p++;
551 if ((argv = malloc( count * sizeof(*argv) )))
553 char **argvptr = argv + reserved;
554 p = cmdline;
555 if (*cmdline == '\"')
557 if ((p = strchr( cmdline + 1, '\"' )))
559 *argvptr++ = cmdline + 1;
560 *p++ = 0;
562 else p = cmdline;
564 while (*p)
566 while (*p && isspace(*p)) *p++ = 0;
567 if (!*p) break;
568 *argvptr++ = p;
569 while (*p && !isspace(*p)) p++;
571 *argvptr = 0;
573 return argv;
577 /***********************************************************************
578 * build_envp
580 * Build the environment of a new child process.
582 static char **build_envp( const char *env, const char *extra_env )
584 const char *p;
585 char **envp;
586 int count = 0;
588 if (extra_env) for (p = extra_env; *p; count++) p += strlen(p) + 1;
589 for (p = env; *p; count++) p += strlen(p) + 1;
590 count += 3;
592 if ((envp = malloc( count * sizeof(*envp) )))
594 extern char **environ;
595 char **envptr = envp;
596 char **unixptr = environ;
597 /* first the extra strings */
598 if (extra_env) for (p = extra_env; *p; p += strlen(p) + 1) *envptr++ = (char *)p;
599 /* then put PATH, HOME and WINEPREFIX from the unix env */
600 for (unixptr = environ; unixptr && *unixptr; unixptr++)
601 if (!memcmp( *unixptr, "PATH=", 5 ) ||
602 !memcmp( *unixptr, "HOME=", 5 ) ||
603 !memcmp( *unixptr, "WINEPREFIX=", 11 )) *envptr++ = *unixptr;
604 /* now put the Windows environment strings */
605 for (p = env; *p; p += strlen(p) + 1)
607 if (memcmp( p, "PATH=", 5 ) &&
608 memcmp( p, "HOME=", 5 ) &&
609 memcmp( p, "WINEPRELOAD=", 12 ) &&
610 memcmp( p, "WINEPREFIX=", 11 )) *envptr++ = (char *)p;
612 *envptr = 0;
614 return envp;
618 /***********************************************************************
619 * exec_wine_binary
621 * Locate the Wine binary to exec for a new Win32 process.
623 static void exec_wine_binary( char **argv, char **envp )
625 const char *path, *pos, *ptr;
627 /* first, try for a WINELOADER environment variable */
628 argv[0] = getenv("WINELOADER");
629 if (argv[0])
630 execve( argv[0], argv, envp );
632 /* next, try bin directory */
633 argv[0] = BINDIR "/wine";
634 execve( argv[0], argv, envp );
636 /* now try the path of argv0 of the current binary */
637 if (!(argv[0] = malloc( strlen(full_argv0) + 6 ))) return;
638 if ((ptr = strrchr( full_argv0, '/' )))
640 memcpy( argv[0], full_argv0, ptr - full_argv0 );
641 strcpy( argv[0] + (ptr - full_argv0), "/wine" );
642 execve( argv[0], argv, envp );
644 free( argv[0] );
646 /* now search in the Unix path */
647 if ((path = getenv( "PATH" )))
649 if (!(argv[0] = malloc( strlen(path) + 6 ))) return;
650 pos = path;
651 for (;;)
653 while (*pos == ':') pos++;
654 if (!*pos) break;
655 if (!(ptr = strchr( pos, ':' ))) ptr = pos + strlen(pos);
656 memcpy( argv[0], pos, ptr - pos );
657 strcpy( argv[0] + (ptr - pos), "/wine" );
658 execve( argv[0], argv, envp );
659 pos = ptr;
662 free( argv[0] );
664 /* finally try the current directory */
665 argv[0] = "./wine";
666 execve( argv[0], argv, envp );
670 /***********************************************************************
671 * fork_and_exec
673 * Fork and exec a new Unix process, checking for errors.
675 static int fork_and_exec( const char *filename, char *cmdline,
676 const char *env, const char *newdir )
678 int fd[2];
679 int pid, err;
680 char *extra_env = NULL;
682 if (!env)
684 env = GetEnvironmentStringsA();
685 extra_env = DRIVE_BuildEnv();
688 if (pipe(fd) == -1)
690 FILE_SetDosError();
691 return -1;
693 fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */
694 if (!(pid = fork())) /* child */
696 char **argv = build_argv( cmdline, filename ? 0 : 2 );
697 char **envp = build_envp( env, extra_env );
698 close( fd[0] );
700 if (newdir) chdir(newdir);
702 if (argv && envp)
704 if (!filename)
706 argv[1] = "--";
707 exec_wine_binary( argv, envp );
709 else execve( filename, argv, envp );
711 err = errno;
712 write( fd[1], &err, sizeof(err) );
713 _exit(1);
715 close( fd[1] );
716 if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0)) /* exec failed */
718 errno = err;
719 pid = -1;
721 if (pid == -1) FILE_SetDosError();
722 close( fd[0] );
723 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
724 return pid;
728 /***********************************************************************
729 * PROCESS_Create
731 * Create a new process. If hFile is a valid handle we have an exe
732 * file, and we exec a new copy of wine to load it; otherwise we
733 * simply exec the specified filename as a Unix process.
735 BOOL PROCESS_Create( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
736 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
737 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
738 LPPROCESS_INFORMATION info, LPCSTR lpCurrentDirectory )
740 BOOL ret;
741 int pid;
742 const char *unixfilename = NULL;
743 const char *unixdir = NULL;
744 DOS_FULL_NAME full_dir, full_name;
745 HANDLE load_done_evt = 0;
747 info->hThread = info->hProcess = 0;
749 if (lpCurrentDirectory)
751 if (DOSFS_GetFullName( lpCurrentDirectory, TRUE, &full_dir ))
752 unixdir = full_dir.long_name;
754 else
756 char buf[MAX_PATH];
757 if (GetCurrentDirectoryA(sizeof(buf),buf))
759 if (DOSFS_GetFullName( buf, TRUE, &full_dir ))
760 unixdir = full_dir.long_name;
764 /* create the process on the server side */
766 SERVER_START_REQ
768 struct new_process_request *req = server_alloc_req( sizeof(*req), MAX_PATH );
769 req->inherit_all = inherit;
770 req->create_flags = flags;
771 req->start_flags = startup->dwFlags;
772 req->exe_file = hFile;
773 if (startup->dwFlags & STARTF_USESTDHANDLES)
775 req->hstdin = startup->hStdInput;
776 req->hstdout = startup->hStdOutput;
777 req->hstderr = startup->hStdError;
779 else
781 req->hstdin = GetStdHandle( STD_INPUT_HANDLE );
782 req->hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
783 req->hstderr = GetStdHandle( STD_ERROR_HANDLE );
785 req->cmd_show = startup->wShowWindow;
787 if (!hFile) /* unix process */
789 unixfilename = filename;
790 if (DOSFS_GetFullName( filename, TRUE, &full_name ))
791 unixfilename = full_name.long_name;
792 lstrcpynA( server_data_ptr(req), unixfilename, MAX_PATH );
794 else /* new wine process */
796 if (!GetLongPathNameA( filename, server_data_ptr(req), MAX_PATH ))
797 lstrcpynA( server_data_ptr(req), filename, MAX_PATH );
799 ret = !server_call( REQ_NEW_PROCESS );
801 SERVER_END_REQ;
802 if (!ret) return FALSE;
804 /* fork and execute */
806 pid = fork_and_exec( unixfilename, cmd_line, env, unixdir );
808 SERVER_START_REQ
810 struct wait_process_request *req = server_alloc_req( sizeof(*req), 0 );
811 req->cancel = (pid == -1);
812 req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle);
813 req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle);
814 req->timeout = 2000;
815 if ((ret = !server_call( REQ_WAIT_PROCESS )) && (pid != -1))
817 info->dwProcessId = (DWORD)req->pid;
818 info->dwThreadId = (DWORD)req->tid;
819 info->hProcess = req->phandle;
820 info->hThread = req->thandle;
821 load_done_evt = req->event;
824 SERVER_END_REQ;
825 if (!ret || (pid == -1)) goto error;
827 /* Wait until process is initialized (or initialization failed) */
828 if (load_done_evt)
830 DWORD res;
831 HANDLE handles[2];
833 handles[0] = info->hProcess;
834 handles[1] = load_done_evt;
835 res = WaitForMultipleObjects( 2, handles, FALSE, INFINITE );
836 CloseHandle( load_done_evt );
837 if (res == STATUS_WAIT_0) /* the process died */
839 DWORD exitcode;
840 if (GetExitCodeProcess( info->hProcess, &exitcode )) SetLastError( exitcode );
841 CloseHandle( info->hThread );
842 CloseHandle( info->hProcess );
843 return FALSE;
846 return TRUE;
848 error:
849 if (load_done_evt) CloseHandle( load_done_evt );
850 if (info->hThread) CloseHandle( info->hThread );
851 if (info->hProcess) CloseHandle( info->hProcess );
852 return FALSE;
856 /***********************************************************************
857 * ExitProcess (KERNEL32.100)
859 void WINAPI ExitProcess( DWORD status )
861 MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
862 SERVER_START_REQ
864 struct terminate_process_request *req = server_alloc_req( sizeof(*req), 0 );
865 /* send the exit code to the server */
866 req->handle = GetCurrentProcess();
867 req->exit_code = status;
868 server_call( REQ_TERMINATE_PROCESS );
870 SERVER_END_REQ;
871 exit( status );
874 /***********************************************************************
875 * ExitProcess16 (KERNEL.466)
877 void WINAPI ExitProcess16( WORD status )
879 DWORD count;
880 ReleaseThunkLock( &count );
881 ExitProcess( status );
884 /******************************************************************************
885 * TerminateProcess (KERNEL32.684)
887 BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
889 NTSTATUS status = NtTerminateProcess( handle, exit_code );
890 if (status) SetLastError( RtlNtStatusToDosError(status) );
891 return !status;
895 /***********************************************************************
896 * GetProcessDword (KERNEL32.18) (KERNEL.485)
897 * 'Of course you cannot directly access Windows internal structures'
899 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
901 TDB *pTask;
902 DWORD x, y;
904 TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
906 if (dwProcessID && dwProcessID != GetCurrentProcessId())
908 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
909 return 0;
912 switch ( offset )
914 case GPD_APP_COMPAT_FLAGS:
915 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
916 return pTask? pTask->compat_flags : 0;
918 case GPD_LOAD_DONE_EVENT:
919 return current_process.load_done_evt;
921 case GPD_HINSTANCE16:
922 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
923 return pTask? pTask->hInstance : 0;
925 case GPD_WINDOWS_VERSION:
926 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
927 return pTask? pTask->version : 0;
929 case GPD_THDB:
930 return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
932 case GPD_PDB:
933 return (DWORD)&current_process;
935 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
936 return current_startupinfo.hStdOutput;
938 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
939 return current_startupinfo.hStdInput;
941 case GPD_STARTF_SHOWWINDOW:
942 return current_startupinfo.wShowWindow;
944 case GPD_STARTF_SIZE:
945 x = current_startupinfo.dwXSize;
946 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
947 y = current_startupinfo.dwYSize;
948 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
949 return MAKELONG( x, y );
951 case GPD_STARTF_POSITION:
952 x = current_startupinfo.dwX;
953 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
954 y = current_startupinfo.dwY;
955 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
956 return MAKELONG( x, y );
958 case GPD_STARTF_FLAGS:
959 return current_startupinfo.dwFlags;
961 case GPD_PARENT:
962 return 0;
964 case GPD_FLAGS:
965 return current_process.flags;
967 case GPD_USERDATA:
968 return current_process.process_dword;
970 default:
971 ERR_(win32)("Unknown offset %d\n", offset );
972 return 0;
976 /***********************************************************************
977 * SetProcessDword (KERNEL.484)
978 * 'Of course you cannot directly access Windows internal structures'
980 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
982 TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
984 if (dwProcessID && dwProcessID != GetCurrentProcessId())
986 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
987 return;
990 switch ( offset )
992 case GPD_APP_COMPAT_FLAGS:
993 case GPD_LOAD_DONE_EVENT:
994 case GPD_HINSTANCE16:
995 case GPD_WINDOWS_VERSION:
996 case GPD_THDB:
997 case GPD_PDB:
998 case GPD_STARTF_SHELLDATA:
999 case GPD_STARTF_HOTKEY:
1000 case GPD_STARTF_SHOWWINDOW:
1001 case GPD_STARTF_SIZE:
1002 case GPD_STARTF_POSITION:
1003 case GPD_STARTF_FLAGS:
1004 case GPD_PARENT:
1005 case GPD_FLAGS:
1006 ERR_(win32)("Not allowed to modify offset %d\n", offset );
1007 break;
1009 case GPD_USERDATA:
1010 current_process.process_dword = value;
1011 break;
1013 default:
1014 ERR_(win32)("Unknown offset %d\n", offset );
1015 break;
1020 /*********************************************************************
1021 * OpenProcess (KERNEL32.543)
1023 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
1025 HANDLE ret = 0;
1026 SERVER_START_REQ
1028 struct open_process_request *req = server_alloc_req( sizeof(*req), 0 );
1030 req->pid = (void *)id;
1031 req->access = access;
1032 req->inherit = inherit;
1033 if (!server_call( REQ_OPEN_PROCESS )) ret = req->handle;
1035 SERVER_END_REQ;
1036 return ret;
1039 /*********************************************************************
1040 * MapProcessHandle (KERNEL.483)
1042 DWORD WINAPI MapProcessHandle( HANDLE handle )
1044 DWORD ret = 0;
1045 SERVER_START_REQ
1047 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1048 req->handle = handle;
1049 if (!server_call( REQ_GET_PROCESS_INFO )) ret = (DWORD)req->pid;
1051 SERVER_END_REQ;
1052 return ret;
1055 /***********************************************************************
1056 * SetPriorityClass (KERNEL32.503)
1058 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
1060 BOOL ret;
1061 SERVER_START_REQ
1063 struct set_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1064 req->handle = hprocess;
1065 req->priority = priorityclass;
1066 req->mask = SET_PROCESS_INFO_PRIORITY;
1067 ret = !server_call( REQ_SET_PROCESS_INFO );
1069 SERVER_END_REQ;
1070 return ret;
1074 /***********************************************************************
1075 * GetPriorityClass (KERNEL32.250)
1077 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
1079 DWORD ret = 0;
1080 SERVER_START_REQ
1082 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1083 req->handle = hprocess;
1084 if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->priority;
1086 SERVER_END_REQ;
1087 return ret;
1091 /***********************************************************************
1092 * SetProcessAffinityMask (KERNEL32.662)
1094 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
1096 BOOL ret;
1097 SERVER_START_REQ
1099 struct set_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1100 req->handle = hProcess;
1101 req->affinity = affmask;
1102 req->mask = SET_PROCESS_INFO_AFFINITY;
1103 ret = !server_call( REQ_SET_PROCESS_INFO );
1105 SERVER_END_REQ;
1106 return ret;
1109 /**********************************************************************
1110 * GetProcessAffinityMask (KERNEL32.373)
1112 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
1113 LPDWORD lpProcessAffinityMask,
1114 LPDWORD lpSystemAffinityMask )
1116 BOOL ret = FALSE;
1117 SERVER_START_REQ
1119 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1120 req->handle = hProcess;
1121 if (!server_call( REQ_GET_PROCESS_INFO ))
1123 if (lpProcessAffinityMask) *lpProcessAffinityMask = req->process_affinity;
1124 if (lpSystemAffinityMask) *lpSystemAffinityMask = req->system_affinity;
1125 ret = TRUE;
1128 SERVER_END_REQ;
1129 return ret;
1133 /***********************************************************************
1134 * GetProcessVersion (KERNEL32)
1136 DWORD WINAPI GetProcessVersion( DWORD processid )
1138 IMAGE_NT_HEADERS *nt;
1140 if (processid && processid != GetCurrentProcessId())
1142 FIXME("should use ReadProcessMemory\n");
1143 return 0;
1145 if ((nt = RtlImageNtHeader( current_process.module )))
1146 return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
1147 nt->OptionalHeader.MinorSubsystemVersion);
1148 return 0;
1151 /***********************************************************************
1152 * GetProcessFlags (KERNEL32)
1154 DWORD WINAPI GetProcessFlags( DWORD processid )
1156 if (processid && processid != GetCurrentProcessId()) return 0;
1157 return current_process.flags;
1161 /***********************************************************************
1162 * SetProcessWorkingSetSize [KERNEL32.662]
1163 * Sets the min/max working set sizes for a specified process.
1165 * PARAMS
1166 * hProcess [I] Handle to the process of interest
1167 * minset [I] Specifies minimum working set size
1168 * maxset [I] Specifies maximum working set size
1170 * RETURNS STD
1172 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess,DWORD minset,
1173 DWORD maxset)
1175 FIXME("(0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
1176 if(( minset == (DWORD)-1) && (maxset == (DWORD)-1)) {
1177 /* Trim the working set to zero */
1178 /* Swap the process out of physical RAM */
1180 return TRUE;
1183 /***********************************************************************
1184 * GetProcessWorkingSetSize (KERNEL32)
1186 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess,LPDWORD minset,
1187 LPDWORD maxset)
1189 FIXME("(0x%08x,%p,%p): stub\n",hProcess,minset,maxset);
1190 /* 32 MB working set size */
1191 if (minset) *minset = 32*1024*1024;
1192 if (maxset) *maxset = 32*1024*1024;
1193 return TRUE;
1196 /***********************************************************************
1197 * SetProcessShutdownParameters (KERNEL32)
1199 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
1200 * Now tracks changes made (but does not act on these changes)
1202 static DWORD shutdown_flags = 0;
1203 static DWORD shutdown_priority = 0x280;
1205 BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
1207 FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
1208 shutdown_flags = flags;
1209 shutdown_priority = level;
1210 return TRUE;
1214 /***********************************************************************
1215 * GetProcessShutdownParameters (KERNEL32)
1218 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
1220 *lpdwLevel = shutdown_priority;
1221 *lpdwFlags = shutdown_flags;
1222 return TRUE;
1226 /***********************************************************************
1227 * SetProcessPriorityBoost (KERNEL32)
1229 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
1231 FIXME("(%d,%d): stub\n",hprocess,disableboost);
1232 /* Say we can do it. I doubt the program will notice that we don't. */
1233 return TRUE;
1237 /***********************************************************************
1238 * ReadProcessMemory (KERNEL32)
1240 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, DWORD size,
1241 LPDWORD bytes_read )
1243 unsigned int offset = (unsigned int)addr % sizeof(int);
1244 unsigned int pos = 0, len, max;
1245 int res;
1247 if (bytes_read) *bytes_read = size;
1249 /* first time, read total length to check for permissions */
1250 len = (size + offset + sizeof(int) - 1) / sizeof(int);
1251 max = min( REQUEST_MAX_VAR_SIZE, len * sizeof(int) );
1253 for (;;)
1255 SERVER_START_REQ
1257 struct read_process_memory_request *req = server_alloc_req( sizeof(*req), max );
1258 req->handle = process;
1259 req->addr = (char *)addr + pos - offset;
1260 req->len = len;
1261 if (!(res = server_call( REQ_READ_PROCESS_MEMORY )))
1263 size_t result = server_data_size( req );
1264 if (result > size + offset) result = size + offset;
1265 memcpy( (char *)buffer + pos, server_data_ptr(req) + offset, result - offset );
1266 size -= result - offset;
1267 pos += result - offset;
1270 SERVER_END_REQ;
1271 if (res)
1273 if (bytes_read) *bytes_read = 0;
1274 return FALSE;
1276 if (!size) return TRUE;
1277 max = min( REQUEST_MAX_VAR_SIZE, size );
1278 len = (max + sizeof(int) - 1) / sizeof(int);
1279 offset = 0;
1284 /***********************************************************************
1285 * WriteProcessMemory (KERNEL32)
1287 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPVOID buffer, DWORD size,
1288 LPDWORD bytes_written )
1290 unsigned int first_offset, last_offset;
1291 unsigned int pos = 0, len, max, first_mask, last_mask;
1292 int res;
1294 if (!size)
1296 SetLastError( ERROR_INVALID_PARAMETER );
1297 return FALSE;
1299 if (bytes_written) *bytes_written = size;
1301 /* compute the mask for the first int */
1302 first_mask = ~0;
1303 first_offset = (unsigned int)addr % sizeof(int);
1304 memset( &first_mask, 0, first_offset );
1306 /* compute the mask for the last int */
1307 last_offset = (size + first_offset) % sizeof(int);
1308 last_mask = 0;
1309 memset( &last_mask, 0xff, last_offset ? last_offset : sizeof(int) );
1311 /* for the first request, use the total length */
1312 len = (size + first_offset + sizeof(int) - 1) / sizeof(int);
1313 max = min( REQUEST_MAX_VAR_SIZE, len * sizeof(int) );
1315 for (;;)
1317 SERVER_START_REQ
1319 struct write_process_memory_request *req = server_alloc_req( sizeof(*req), max );
1320 req->handle = process;
1321 req->addr = (char *)addr - first_offset + pos;
1322 req->len = len;
1323 req->first_mask = (!pos) ? first_mask : ~0;
1324 if (size + first_offset <= max) /* last round */
1326 req->last_mask = last_mask;
1327 max = size + first_offset;
1329 else req->last_mask = ~0;
1331 memcpy( (char *)server_data_ptr(req) + first_offset, (char *)buffer + pos,
1332 max - first_offset );
1333 if (!(res = server_call( REQ_WRITE_PROCESS_MEMORY )))
1335 pos += max - first_offset;
1336 size -= max - first_offset;
1339 SERVER_END_REQ;
1340 if (res)
1342 if (bytes_written) *bytes_written = 0;
1343 return FALSE;
1345 if (!size) return TRUE;
1346 first_offset = 0;
1347 len = min( size + sizeof(int) - 1, REQUEST_MAX_VAR_SIZE ) / sizeof(int);
1348 max = len * sizeof(int);
1353 /***********************************************************************
1354 * RegisterServiceProcess (KERNEL, KERNEL32)
1356 * A service process calls this function to ensure that it continues to run
1357 * even after a user logged off.
1359 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
1361 /* I don't think that Wine needs to do anything in that function */
1362 return 1; /* success */
1365 /***********************************************************************
1366 * GetExitCodeProcess [KERNEL32.325]
1368 * Gets termination status of specified process
1370 * RETURNS
1371 * Success: TRUE
1372 * Failure: FALSE
1374 BOOL WINAPI GetExitCodeProcess(
1375 HANDLE hProcess, /* [in] handle to the process */
1376 LPDWORD lpExitCode) /* [out] address to receive termination status */
1378 BOOL ret;
1379 SERVER_START_REQ
1381 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1382 req->handle = hProcess;
1383 ret = !server_call( REQ_GET_PROCESS_INFO );
1384 if (ret && lpExitCode) *lpExitCode = req->exit_code;
1386 SERVER_END_REQ;
1387 return ret;
1391 /***********************************************************************
1392 * SetErrorMode (KERNEL32.486)
1394 UINT WINAPI SetErrorMode( UINT mode )
1396 UINT old = current_process.error_mode;
1397 current_process.error_mode = mode;
1398 return old;
1402 /**********************************************************************
1403 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
1405 * Allocates a thread local storage index
1407 * RETURNS
1408 * Success: TLS Index
1409 * Failure: 0xFFFFFFFF
1411 DWORD WINAPI TlsAlloc( void )
1413 DWORD i, mask, ret = 0;
1414 DWORD *bits = current_process.tls_bits;
1415 RtlAcquirePebLock();
1416 if (*bits == 0xffffffff)
1418 bits++;
1419 ret = 32;
1420 if (*bits == 0xffffffff)
1422 RtlReleasePebLock();
1423 SetLastError( ERROR_NO_MORE_ITEMS );
1424 return 0xffffffff;
1427 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
1428 *bits |= mask;
1429 RtlReleasePebLock();
1430 return ret + i;
1434 /**********************************************************************
1435 * TlsFree [KERNEL32.531] Releases a TLS index.
1437 * Releases a thread local storage index, making it available for reuse
1439 * RETURNS
1440 * Success: TRUE
1441 * Failure: FALSE
1443 BOOL WINAPI TlsFree(
1444 DWORD index) /* [in] TLS Index to free */
1446 DWORD mask = (1 << (index & 31));
1447 DWORD *bits = current_process.tls_bits;
1448 if (index >= 64)
1450 SetLastError( ERROR_INVALID_PARAMETER );
1451 return FALSE;
1453 if (index >= 32) bits++;
1454 RtlAcquirePebLock();
1455 if (!(*bits & mask)) /* already free? */
1457 RtlReleasePebLock();
1458 SetLastError( ERROR_INVALID_PARAMETER );
1459 return FALSE;
1461 *bits &= ~mask;
1462 NtCurrentTeb()->tls_array[index] = 0;
1463 /* FIXME: should zero all other thread values */
1464 RtlReleasePebLock();
1465 return TRUE;
1469 /**********************************************************************
1470 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
1472 * RETURNS
1473 * Success: Value stored in calling thread's TLS slot for index
1474 * Failure: 0 and GetLastError returns NO_ERROR
1476 LPVOID WINAPI TlsGetValue(
1477 DWORD index) /* [in] TLS index to retrieve value for */
1479 if (index >= 64)
1481 SetLastError( ERROR_INVALID_PARAMETER );
1482 return NULL;
1484 SetLastError( ERROR_SUCCESS );
1485 return NtCurrentTeb()->tls_array[index];
1489 /**********************************************************************
1490 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
1492 * RETURNS
1493 * Success: TRUE
1494 * Failure: FALSE
1496 BOOL WINAPI TlsSetValue(
1497 DWORD index, /* [in] TLS index to set value for */
1498 LPVOID value) /* [in] Value to be stored */
1500 if (index >= 64)
1502 SetLastError( ERROR_INVALID_PARAMETER );
1503 return FALSE;
1505 NtCurrentTeb()->tls_array[index] = value;
1506 return TRUE;
1510 /***********************************************************************
1511 * GetCurrentProcess (KERNEL32.198)
1513 #undef GetCurrentProcess
1514 HANDLE WINAPI GetCurrentProcess(void)
1516 return 0xffffffff;