More verbose error messages when application load fails.
[wine/dcerpc.git] / scheduler / process.c
blobefb9848bdb5961b65196d72d6500811e200b2de5
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 "thread.h"
23 #include "winerror.h"
24 #include "server.h"
25 #include "options.h"
26 #include "callback.h"
27 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(process);
30 DECLARE_DEBUG_CHANNEL(relay);
31 DECLARE_DEBUG_CHANNEL(win32);
33 struct _ENVDB;
35 /* Win32 process database */
36 typedef struct _PDB
38 LONG header[2]; /* 00 Kernel object header */
39 HMODULE module; /* 08 Main exe module (NT) */
40 void *event; /* 0c Pointer to an event object (unused) */
41 DWORD exit_code; /* 10 Process exit code */
42 DWORD unknown2; /* 14 Unknown */
43 HANDLE heap; /* 18 Default process heap */
44 HANDLE mem_context; /* 1c Process memory context */
45 DWORD flags; /* 20 Flags */
46 void *pdb16; /* 24 DOS PSP */
47 WORD PSP_sel; /* 28 Selector to DOS PSP */
48 WORD imte; /* 2a IMTE for the process module */
49 WORD threads; /* 2c Number of threads */
50 WORD running_threads; /* 2e Number of running threads */
51 WORD free_lib_count; /* 30 Recursion depth of FreeLibrary calls */
52 WORD ring0_threads; /* 32 Number of ring 0 threads */
53 HANDLE system_heap; /* 34 System heap to allocate handles */
54 HTASK task; /* 38 Win16 task */
55 void *mem_map_files; /* 3c Pointer to mem-mapped files */
56 struct _ENVDB *env_db; /* 40 Environment database */
57 void *handle_table; /* 44 Handle table */
58 struct _PDB *parent; /* 48 Parent process */
59 void *modref_list; /* 4c MODREF list */
60 void *thread_list; /* 50 List of threads */
61 void *debuggee_CB; /* 54 Debuggee context block */
62 void *local_heap_free; /* 58 Head of local heap free list */
63 DWORD unknown4; /* 5c Unknown */
64 CRITICAL_SECTION crit_section; /* 60 Critical section */
65 DWORD unknown5[3]; /* 78 Unknown */
66 void *console; /* 84 Console */
67 DWORD tls_bits[2]; /* 88 TLS in-use bits */
68 DWORD process_dword; /* 90 Unknown */
69 struct _PDB *group; /* 94 Process group */
70 void *exe_modref; /* 98 MODREF for the process EXE */
71 void *top_filter; /* 9c Top exception filter */
72 DWORD priority; /* a0 Priority level */
73 HANDLE heap_list; /* a4 Head of process heap list */
74 void *heap_handles; /* a8 Head of heap handles list */
75 DWORD unknown6; /* ac Unknown */
76 void *console_provider; /* b0 Console provider (??) */
77 WORD env_selector; /* b4 Selector to process environment */
78 WORD error_mode; /* b6 Error mode */
79 HANDLE load_done_evt; /* b8 Event for process loading done */
80 void *UTState; /* bc Head of Univeral Thunk list */
81 DWORD unknown8; /* c0 Unknown (NT) */
82 LCID locale; /* c4 Locale to be queried by GetThreadLocale (NT) */
83 } PDB;
85 PDB current_process;
87 /* Process flags */
88 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
89 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
90 #define PDB32_DOS_PROC 0x0010 /* Dos process */
91 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
92 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
93 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
95 static char **main_exe_argv;
96 static char main_exe_name[MAX_PATH];
97 static HANDLE main_exe_file;
99 unsigned int server_startticks;
101 /* memory/environ.c */
102 extern struct _ENVDB *ENV_BuildEnvironment(void);
103 extern BOOL ENV_BuildCommandLine( char **argv );
104 extern STARTUPINFOA current_startupinfo;
106 extern BOOL MAIN_MainInit(void);
109 /***********************************************************************
110 * PROCESS_CallUserSignalProc
112 * FIXME: Some of the signals aren't sent correctly!
114 * The exact meaning of the USER signals is undocumented, but this
115 * should cover the basic idea:
117 * USIG_DLL_UNLOAD_WIN16
118 * This is sent when a 16-bit module is unloaded.
120 * USIG_DLL_UNLOAD_WIN32
121 * This is sent when a 32-bit module is unloaded.
123 * USIG_DLL_UNLOAD_ORPHANS
124 * This is sent after the last Win3.1 module is unloaded,
125 * to allow removal of orphaned menus.
127 * USIG_FAULT_DIALOG_PUSH
128 * USIG_FAULT_DIALOG_POP
129 * These are called to allow USER to prepare for displaying a
130 * fault dialog, even though the fault might have happened while
131 * inside a USER critical section.
133 * USIG_THREAD_INIT
134 * This is called from the context of a new thread, as soon as it
135 * has started to run.
137 * USIG_THREAD_EXIT
138 * This is called, still in its context, just before a thread is
139 * about to terminate.
141 * USIG_PROCESS_CREATE
142 * This is called, in the parent process context, after a new process
143 * has been created.
145 * USIG_PROCESS_INIT
146 * This is called in the new process context, just after the main thread
147 * has started execution (after the main thread's USIG_THREAD_INIT has
148 * been sent).
150 * USIG_PROCESS_LOADED
151 * This is called after the executable file has been loaded into the
152 * new process context.
154 * USIG_PROCESS_RUNNING
155 * This is called immediately before the main entry point is called.
157 * USIG_PROCESS_EXIT
158 * This is called in the context of a process that is about to
159 * terminate (but before the last thread's USIG_THREAD_EXIT has
160 * been sent).
162 * USIG_PROCESS_DESTROY
163 * This is called after a process has terminated.
166 * The meaning of the dwFlags bits is as follows:
168 * USIG_FLAGS_WIN32
169 * Current process is 32-bit.
171 * USIG_FLAGS_GUI
172 * Current process is a (Win32) GUI process.
174 * USIG_FLAGS_FEEDBACK
175 * Current process needs 'feedback' (determined from the STARTUPINFO
176 * flags STARTF_FORCEONFEEDBACK / STARTF_FORCEOFFFEEDBACK).
178 * USIG_FLAGS_FAULT
179 * The signal is being sent due to a fault.
181 void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
183 DWORD flags = current_process.flags;
184 DWORD startup_flags = current_startupinfo.dwFlags;
185 DWORD dwFlags = 0;
187 /* Determine dwFlags */
189 if ( !(flags & PDB32_WIN16_PROC) ) dwFlags |= USIG_FLAGS_WIN32;
191 if ( !(flags & PDB32_CONSOLE_PROC) ) dwFlags |= USIG_FLAGS_GUI;
193 if ( dwFlags & USIG_FLAGS_GUI )
195 /* Feedback defaults to ON */
196 if ( !(startup_flags & STARTF_FORCEOFFFEEDBACK) )
197 dwFlags |= USIG_FLAGS_FEEDBACK;
199 else
201 /* Feedback defaults to OFF */
202 if (startup_flags & STARTF_FORCEONFEEDBACK)
203 dwFlags |= USIG_FLAGS_FEEDBACK;
206 /* Convert module handle to 16-bit */
208 if ( HIWORD( hModule ) )
209 hModule = MapHModuleLS( hModule );
211 /* Call USER signal proc */
213 if ( Callout.UserSignalProc )
215 if ( uCode == USIG_THREAD_INIT || uCode == USIG_THREAD_EXIT )
216 Callout.UserSignalProc( uCode, GetCurrentThreadId(), dwFlags, hModule );
217 else
218 Callout.UserSignalProc( uCode, GetCurrentProcessId(), dwFlags, hModule );
223 /***********************************************************************
224 * process_init
226 * Main process initialisation code
228 static BOOL process_init( char *argv[] )
230 BOOL ret;
232 /* store the program name */
233 argv0 = argv[0];
234 main_exe_argv = argv;
236 /* Fill the initial process structure */
237 current_process.exit_code = STILL_ACTIVE;
238 current_process.threads = 1;
239 current_process.running_threads = 1;
240 current_process.ring0_threads = 1;
241 current_process.group = &current_process;
242 current_process.priority = 8; /* Normal */
244 /* Setup the server connection */
245 NtCurrentTeb()->socket = CLIENT_InitServer();
246 if (CLIENT_InitThread()) return FALSE;
248 /* Retrieve startup info from the server */
249 SERVER_START_REQ
251 struct init_process_request *req = server_alloc_req( sizeof(*req),
252 sizeof(main_exe_name)-1 );
254 req->ldt_copy = &wine_ldt_copy;
255 req->ppid = getppid();
256 if ((ret = !server_call( REQ_INIT_PROCESS )))
258 size_t len = server_data_size( req );
259 memcpy( main_exe_name, server_data_ptr(req), len );
260 main_exe_name[len] = 0;
261 main_exe_file = req->exe_file;
262 current_startupinfo.dwFlags = req->start_flags;
263 server_startticks = req->server_start;
264 current_startupinfo.wShowWindow = req->cmd_show;
265 current_startupinfo.hStdInput = req->hstdin;
266 current_startupinfo.hStdOutput = req->hstdout;
267 current_startupinfo.hStdError = req->hstderr;
268 SetStdHandle( STD_INPUT_HANDLE, current_startupinfo.hStdInput );
269 SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
270 SetStdHandle( STD_ERROR_HANDLE, current_startupinfo.hStdError );
273 SERVER_END_REQ;
274 if (!ret) return FALSE;
276 /* Create the system and process heaps */
277 if (!HEAP_CreateSystemHeap()) return FALSE;
278 current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
280 /* Copy the parent environment */
281 if (!(current_process.env_db = ENV_BuildEnvironment())) return FALSE;
283 /* Parse command line arguments */
284 OPTIONS_ParseOptions( argv );
286 return MAIN_MainInit();
290 /***********************************************************************
291 * start_process
293 * Startup routine of a new process. Runs on the new process stack.
295 static void start_process(void)
297 int debugged, console_app;
298 LPTHREAD_START_ROUTINE entry;
299 WINE_MODREF *wm;
301 /* build command line */
302 if (!ENV_BuildCommandLine( main_exe_argv )) goto error;
304 /* create 32-bit module for main exe */
305 if (!(current_process.module = BUILTIN32_LoadExeModule( current_process.module ))) goto error;
307 /* use original argv[0] as name for the main module */
308 if (!main_exe_name[0])
310 if (!GetLongPathNameA( full_argv0, main_exe_name, sizeof(main_exe_name) ))
311 lstrcpynA( main_exe_name, full_argv0, sizeof(main_exe_name) );
314 /* Retrieve entry point address */
315 entry = (LPTHREAD_START_ROUTINE)((char*)current_process.module +
316 PE_HEADER(current_process.module)->OptionalHeader.AddressOfEntryPoint);
317 console_app = (PE_HEADER(current_process.module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
318 if (console_app) current_process.flags |= PDB32_CONSOLE_PROC;
320 /* Signal the parent process to continue */
321 SERVER_START_REQ
323 struct init_process_done_request *req = server_alloc_req( sizeof(*req), 0 );
324 req->module = (void *)current_process.module;
325 req->entry = entry;
326 req->name = main_exe_name;
327 req->exe_file = main_exe_file;
328 req->gui = !console_app;
329 server_call( REQ_INIT_PROCESS_DONE );
330 debugged = req->debugged;
332 SERVER_END_REQ;
334 /* Install signal handlers; this cannot be done before, since we cannot
335 * send exceptions to the debugger before the create process event that
336 * is sent by REQ_INIT_PROCESS_DONE */
337 if (!SIGNAL_Init()) goto error;
339 /* create the main modref and load dependencies */
340 if (!(wm = PE_CreateModule( current_process.module, main_exe_name, 0, 0, FALSE )))
341 goto error;
342 wm->refCount++;
344 RtlAcquirePebLock();
345 PE_InitTls();
346 MODULE_DllProcessAttach( NULL, (LPVOID)1 );
347 RtlReleasePebLock();
349 /* Get pointers to USER routines called by KERNEL */
350 THUNK_InitCallout();
352 /* Call FinalUserInit routine */
353 if (Callout.FinalUserInit16) Callout.FinalUserInit16();
355 /* Note: The USIG_PROCESS_CREATE signal is supposed to be sent in the
356 * context of the parent process. Actually, the USER signal proc
357 * doesn't really care about that, but it *does* require that the
358 * startup parameters are correctly set up, so that GetProcessDword
359 * works. Furthermore, before calling the USER signal proc the
360 * 16-bit stack must be set up, which it is only after TASK_Create
361 * in the case of a 16-bit process. Thus, we send the signal here.
363 PROCESS_CallUserSignalProc( USIG_PROCESS_CREATE, 0 );
364 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
365 PROCESS_CallUserSignalProc( USIG_PROCESS_INIT, 0 );
366 PROCESS_CallUserSignalProc( USIG_PROCESS_LOADED, 0 );
367 /* Call UserSignalProc ( USIG_PROCESS_RUNNING ... ) only for non-GUI win32 apps */
368 if (console_app) PROCESS_CallUserSignalProc( USIG_PROCESS_RUNNING, 0 );
370 TRACE_(relay)( "Starting Win32 process %s (entryproc=%p)\n", main_exe_name, entry );
371 if (debugged) DbgBreakPoint();
372 /* FIXME: should use _PEB as parameter for NT 3.5 programs !
373 * Dunno about other OSs */
374 SetLastError(0); /* clear error code */
375 ExitThread( entry(NULL) );
377 error:
378 ExitProcess( GetLastError() );
382 /***********************************************************************
383 * open_winelib_app
385 * Try to open the Winelib app .so file based on argv[0] or WINEPRELOAD.
387 void *open_winelib_app( char *argv[] )
389 void *ret = NULL;
390 char *tmp;
391 const char *name;
392 char errStr[100];
394 if ((name = getenv( "WINEPRELOAD" )))
396 if (!(ret = wine_dll_load_main_exe( name, 0, errStr, sizeof(errStr) )))
398 MESSAGE( "%s: could not load '%s' as specified in the WINEPRELOAD environment variable: %s\n",
399 argv[0], name, errStr );
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), errStr, sizeof(errStr) );
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: %s\n",
426 argv[0], tmp, errStr );
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[], LPSTR win16_exe_name, HANDLE *win16_exe_file )
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, 0)) == 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 strcpy( win16_exe_name, main_exe_name );
487 main_exe_name[0] = 0;
488 *win16_exe_file = main_exe_file;
489 main_exe_file = 0;
490 _EnterWin16Lock();
492 found:
493 /* allocate main thread stack */
494 if (!THREAD_InitStack( NtCurrentTeb(), stack_size, TRUE )) goto error;
496 /* switch to the new stack */
497 SYSDEPS_SwitchToThreadStack( start_process );
499 error:
500 ExitProcess( GetLastError() );
504 /***********************************************************************
505 * PROCESS_InitWinelib
507 * Initialisation of a new Winelib process.
509 void PROCESS_InitWinelib( int argc, char *argv[] )
511 if (!process_init( argv )) exit(1);
513 /* allocate main thread stack */
514 if (!THREAD_InitStack( NtCurrentTeb(), 0, TRUE )) ExitProcess( GetLastError() );
516 /* switch to the new stack */
517 SYSDEPS_SwitchToThreadStack( start_process );
521 /***********************************************************************
522 * build_argv
524 * Build an argv array from a command-line.
525 * The command-line is modified to insert nulls.
526 * 'reserved' is the number of args to reserve before the first one.
528 static char **build_argv( char *cmdline, int reserved )
530 char **argv;
531 int count = reserved + 1;
532 char *p = cmdline;
534 /* if first word is quoted store it as a single arg */
535 if (*cmdline == '\"')
537 if ((p = strchr( cmdline + 1, '\"' )))
539 p++;
540 count++;
542 else p = cmdline;
544 while (*p)
546 while (*p && isspace(*p)) p++;
547 if (!*p) break;
548 count++;
549 while (*p && !isspace(*p)) p++;
552 if ((argv = malloc( count * sizeof(*argv) )))
554 char **argvptr = argv + reserved;
555 p = cmdline;
556 if (*cmdline == '\"')
558 if ((p = strchr( cmdline + 1, '\"' )))
560 *argvptr++ = cmdline + 1;
561 *p++ = 0;
563 else p = cmdline;
565 while (*p)
567 while (*p && isspace(*p)) *p++ = 0;
568 if (!*p) break;
569 *argvptr++ = p;
570 while (*p && !isspace(*p)) p++;
572 *argvptr = 0;
574 return argv;
578 /***********************************************************************
579 * build_envp
581 * Build the environment of a new child process.
583 static char **build_envp( const char *env, const char *extra_env )
585 const char *p;
586 char **envp;
587 int count = 0;
589 if (extra_env) for (p = extra_env; *p; count++) p += strlen(p) + 1;
590 for (p = env; *p; count++) p += strlen(p) + 1;
591 count += 3;
593 if ((envp = malloc( count * sizeof(*envp) )))
595 extern char **environ;
596 char **envptr = envp;
597 char **unixptr = environ;
598 /* first the extra strings */
599 if (extra_env) for (p = extra_env; *p; p += strlen(p) + 1) *envptr++ = (char *)p;
600 /* then put PATH, HOME and WINEPREFIX from the unix env */
601 for (unixptr = environ; unixptr && *unixptr; unixptr++)
602 if (!memcmp( *unixptr, "PATH=", 5 ) ||
603 !memcmp( *unixptr, "HOME=", 5 ) ||
604 !memcmp( *unixptr, "WINEPREFIX=", 11 )) *envptr++ = *unixptr;
605 /* now put the Windows environment strings */
606 for (p = env; *p; p += strlen(p) + 1)
608 if (memcmp( p, "PATH=", 5 ) &&
609 memcmp( p, "HOME=", 5 ) &&
610 memcmp( p, "WINEPRELOAD=", 12 ) &&
611 memcmp( p, "WINEPREFIX=", 11 )) *envptr++ = (char *)p;
613 *envptr = 0;
615 return envp;
619 /***********************************************************************
620 * exec_wine_binary
622 * Locate the Wine binary to exec for a new Win32 process.
624 static void exec_wine_binary( char **argv, char **envp )
626 const char *path, *pos, *ptr;
628 /* first, try for a WINELOADER environment variable */
629 argv[0] = getenv("WINELOADER");
630 if (argv[0])
631 execve( argv[0], argv, envp );
633 /* next, try bin directory */
634 argv[0] = BINDIR "/wine";
635 execve( argv[0], argv, envp );
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, '/' )))
641 memcpy( argv[0], full_argv0, ptr - full_argv0 );
642 strcpy( argv[0] + (ptr - full_argv0), "/wine" );
643 execve( argv[0], argv, envp );
645 free( argv[0] );
647 /* now search in the Unix path */
648 if ((path = getenv( "PATH" )))
650 if (!(argv[0] = malloc( strlen(path) + 6 ))) return;
651 pos = path;
652 for (;;)
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;
663 free( argv[0] );
665 /* finally try the current directory */
666 argv[0] = "./wine";
667 execve( argv[0], argv, envp );
671 /***********************************************************************
672 * fork_and_exec
674 * Fork and exec a new Unix process, checking for errors.
676 static int fork_and_exec( const char *filename, char *cmdline,
677 const char *env, const char *newdir )
679 int fd[2];
680 int pid, err;
681 char *extra_env = NULL;
683 if (!env)
685 env = GetEnvironmentStringsA();
686 extra_env = DRIVE_BuildEnv();
689 if (pipe(fd) == -1)
691 FILE_SetDosError();
692 return -1;
694 fcntl( fd[1], F_SETFD, 1 ); /* set close on exec */
695 if (!(pid = fork())) /* child */
697 char **argv = build_argv( cmdline, filename ? 0 : 2 );
698 char **envp = build_envp( env, extra_env );
699 close( fd[0] );
701 if (newdir) chdir(newdir);
703 if (argv && envp)
705 if (!filename)
707 argv[1] = "--";
708 exec_wine_binary( argv, envp );
710 else execve( filename, argv, envp );
712 err = errno;
713 write( fd[1], &err, sizeof(err) );
714 _exit(1);
716 close( fd[1] );
717 if ((pid != -1) && (read( fd[0], &err, sizeof(err) ) > 0)) /* exec failed */
719 errno = err;
720 pid = -1;
722 if (pid == -1) FILE_SetDosError();
723 close( fd[0] );
724 if (extra_env) HeapFree( GetProcessHeap(), 0, extra_env );
725 return pid;
729 /***********************************************************************
730 * PROCESS_Create
732 * Create a new process. If hFile is a valid handle we have an exe
733 * file, and we exec a new copy of wine to load it; otherwise we
734 * simply exec the specified filename as a Unix process.
736 BOOL PROCESS_Create( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
737 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
738 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
739 LPPROCESS_INFORMATION info, LPCSTR lpCurrentDirectory )
741 BOOL ret;
742 int pid;
743 const char *unixfilename = NULL;
744 const char *unixdir = NULL;
745 DOS_FULL_NAME full_dir, full_name;
746 HANDLE load_done_evt = 0;
747 HANDLE process_info;
749 info->hThread = info->hProcess = 0;
751 if (lpCurrentDirectory)
753 if (DOSFS_GetFullName( lpCurrentDirectory, TRUE, &full_dir ))
754 unixdir = full_dir.long_name;
756 else
758 char buf[MAX_PATH];
759 if (GetCurrentDirectoryA(sizeof(buf),buf))
761 if (DOSFS_GetFullName( buf, TRUE, &full_dir ))
762 unixdir = full_dir.long_name;
766 /* create the process on the server side */
768 SERVER_START_REQ
770 struct new_process_request *req = server_alloc_req( sizeof(*req), MAX_PATH );
771 req->inherit_all = inherit;
772 req->create_flags = flags;
773 req->start_flags = startup->dwFlags;
774 req->exe_file = hFile;
775 if (startup->dwFlags & STARTF_USESTDHANDLES)
777 req->hstdin = startup->hStdInput;
778 req->hstdout = startup->hStdOutput;
779 req->hstderr = startup->hStdError;
781 else
783 req->hstdin = GetStdHandle( STD_INPUT_HANDLE );
784 req->hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
785 req->hstderr = GetStdHandle( STD_ERROR_HANDLE );
787 req->cmd_show = startup->wShowWindow;
789 if (!hFile) /* unix process */
791 unixfilename = filename;
792 if (DOSFS_GetFullName( filename, TRUE, &full_name ))
793 unixfilename = full_name.long_name;
794 lstrcpynA( server_data_ptr(req), unixfilename, MAX_PATH );
796 else /* new wine process */
798 if (!GetLongPathNameA( filename, server_data_ptr(req), MAX_PATH ))
799 lstrcpynA( server_data_ptr(req), filename, MAX_PATH );
801 ret = !server_call( REQ_NEW_PROCESS );
802 process_info = req->info;
804 SERVER_END_REQ;
805 if (!ret) return FALSE;
807 /* fork and execute */
809 pid = fork_and_exec( unixfilename, cmd_line, env, unixdir );
811 /* wait for the new process info to be ready */
813 ret = FALSE;
814 if ((pid != -1) && (WaitForSingleObject( process_info, 2000 ) == STATUS_WAIT_0))
816 SERVER_START_REQ
818 struct get_new_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
819 req->info = process_info;
820 req->pinherit = (psa && (psa->nLength >= sizeof(*psa)) && psa->bInheritHandle);
821 req->tinherit = (tsa && (tsa->nLength >= sizeof(*tsa)) && tsa->bInheritHandle);
822 if ((ret = !server_call( REQ_GET_NEW_PROCESS_INFO )))
824 info->dwProcessId = (DWORD)req->pid;
825 info->dwThreadId = (DWORD)req->tid;
826 info->hProcess = req->phandle;
827 info->hThread = req->thandle;
828 load_done_evt = req->event;
831 SERVER_END_REQ;
833 CloseHandle( process_info );
834 if (!ret) goto error;
836 /* Wait until process is initialized (or initialization failed) */
837 if (load_done_evt)
839 DWORD res;
840 HANDLE handles[2];
842 handles[0] = info->hProcess;
843 handles[1] = load_done_evt;
844 res = WaitForMultipleObjects( 2, handles, FALSE, INFINITE );
845 CloseHandle( load_done_evt );
846 if (res == STATUS_WAIT_0) /* the process died */
848 DWORD exitcode;
849 if (GetExitCodeProcess( info->hProcess, &exitcode )) SetLastError( exitcode );
850 CloseHandle( info->hThread );
851 CloseHandle( info->hProcess );
852 return FALSE;
855 return TRUE;
857 error:
858 if (load_done_evt) CloseHandle( load_done_evt );
859 if (info->hThread) CloseHandle( info->hThread );
860 if (info->hProcess) CloseHandle( info->hProcess );
861 return FALSE;
865 /***********************************************************************
866 * ExitProcess (KERNEL32.100)
868 void WINAPI ExitProcess( DWORD status )
870 MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
871 SERVER_START_REQ
873 struct terminate_process_request *req = server_alloc_req( sizeof(*req), 0 );
874 /* send the exit code to the server */
875 req->handle = GetCurrentProcess();
876 req->exit_code = status;
877 server_call( REQ_TERMINATE_PROCESS );
879 SERVER_END_REQ;
880 exit( status );
883 /***********************************************************************
884 * ExitProcess16 (KERNEL.466)
886 void WINAPI ExitProcess16( WORD status )
888 DWORD count;
889 ReleaseThunkLock( &count );
890 ExitProcess( status );
893 /******************************************************************************
894 * TerminateProcess (KERNEL32.684)
896 BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
898 NTSTATUS status = NtTerminateProcess( handle, exit_code );
899 if (status) SetLastError( RtlNtStatusToDosError(status) );
900 return !status;
904 /***********************************************************************
905 * GetProcessDword (KERNEL32.18) (KERNEL.485)
906 * 'Of course you cannot directly access Windows internal structures'
908 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
910 DWORD x, y;
912 TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
914 if (dwProcessID && dwProcessID != GetCurrentProcessId())
916 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
917 return 0;
920 switch ( offset )
922 case GPD_APP_COMPAT_FLAGS:
923 return GetAppCompatFlags16(0);
925 case GPD_LOAD_DONE_EVENT:
926 return current_process.load_done_evt;
928 case GPD_HINSTANCE16:
929 return GetTaskDS16();
931 case GPD_WINDOWS_VERSION:
932 return GetExeVersion16();
934 case GPD_THDB:
935 return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
937 case GPD_PDB:
938 return (DWORD)&current_process;
940 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
941 return current_startupinfo.hStdOutput;
943 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
944 return current_startupinfo.hStdInput;
946 case GPD_STARTF_SHOWWINDOW:
947 return current_startupinfo.wShowWindow;
949 case GPD_STARTF_SIZE:
950 x = current_startupinfo.dwXSize;
951 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
952 y = current_startupinfo.dwYSize;
953 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
954 return MAKELONG( x, y );
956 case GPD_STARTF_POSITION:
957 x = current_startupinfo.dwX;
958 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
959 y = current_startupinfo.dwY;
960 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
961 return MAKELONG( x, y );
963 case GPD_STARTF_FLAGS:
964 return current_startupinfo.dwFlags;
966 case GPD_PARENT:
967 return 0;
969 case GPD_FLAGS:
970 return current_process.flags;
972 case GPD_USERDATA:
973 return current_process.process_dword;
975 default:
976 ERR_(win32)("Unknown offset %d\n", offset );
977 return 0;
981 /***********************************************************************
982 * SetProcessDword (KERNEL.484)
983 * 'Of course you cannot directly access Windows internal structures'
985 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
987 TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
989 if (dwProcessID && dwProcessID != GetCurrentProcessId())
991 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
992 return;
995 switch ( offset )
997 case GPD_APP_COMPAT_FLAGS:
998 case GPD_LOAD_DONE_EVENT:
999 case GPD_HINSTANCE16:
1000 case GPD_WINDOWS_VERSION:
1001 case GPD_THDB:
1002 case GPD_PDB:
1003 case GPD_STARTF_SHELLDATA:
1004 case GPD_STARTF_HOTKEY:
1005 case GPD_STARTF_SHOWWINDOW:
1006 case GPD_STARTF_SIZE:
1007 case GPD_STARTF_POSITION:
1008 case GPD_STARTF_FLAGS:
1009 case GPD_PARENT:
1010 case GPD_FLAGS:
1011 ERR_(win32)("Not allowed to modify offset %d\n", offset );
1012 break;
1014 case GPD_USERDATA:
1015 current_process.process_dword = value;
1016 break;
1018 default:
1019 ERR_(win32)("Unknown offset %d\n", offset );
1020 break;
1025 /*********************************************************************
1026 * OpenProcess (KERNEL32.543)
1028 HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id )
1030 HANDLE ret = 0;
1031 SERVER_START_REQ
1033 struct open_process_request *req = server_alloc_req( sizeof(*req), 0 );
1035 req->pid = (void *)id;
1036 req->access = access;
1037 req->inherit = inherit;
1038 if (!server_call( REQ_OPEN_PROCESS )) ret = req->handle;
1040 SERVER_END_REQ;
1041 return ret;
1044 /*********************************************************************
1045 * MapProcessHandle (KERNEL.483)
1047 DWORD WINAPI MapProcessHandle( HANDLE handle )
1049 DWORD ret = 0;
1050 SERVER_START_REQ
1052 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1053 req->handle = handle;
1054 if (!server_call( REQ_GET_PROCESS_INFO )) ret = (DWORD)req->pid;
1056 SERVER_END_REQ;
1057 return ret;
1060 /***********************************************************************
1061 * SetPriorityClass (KERNEL32.503)
1063 BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass )
1065 BOOL ret;
1066 SERVER_START_REQ
1068 struct set_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1069 req->handle = hprocess;
1070 req->priority = priorityclass;
1071 req->mask = SET_PROCESS_INFO_PRIORITY;
1072 ret = !server_call( REQ_SET_PROCESS_INFO );
1074 SERVER_END_REQ;
1075 return ret;
1079 /***********************************************************************
1080 * GetPriorityClass (KERNEL32.250)
1082 DWORD WINAPI GetPriorityClass(HANDLE hprocess)
1084 DWORD ret = 0;
1085 SERVER_START_REQ
1087 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1088 req->handle = hprocess;
1089 if (!server_call( REQ_GET_PROCESS_INFO )) ret = req->priority;
1091 SERVER_END_REQ;
1092 return ret;
1096 /***********************************************************************
1097 * SetProcessAffinityMask (KERNEL32.662)
1099 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask )
1101 BOOL ret;
1102 SERVER_START_REQ
1104 struct set_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1105 req->handle = hProcess;
1106 req->affinity = affmask;
1107 req->mask = SET_PROCESS_INFO_AFFINITY;
1108 ret = !server_call( REQ_SET_PROCESS_INFO );
1110 SERVER_END_REQ;
1111 return ret;
1114 /**********************************************************************
1115 * GetProcessAffinityMask (KERNEL32.373)
1117 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
1118 LPDWORD lpProcessAffinityMask,
1119 LPDWORD lpSystemAffinityMask )
1121 BOOL ret = FALSE;
1122 SERVER_START_REQ
1124 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1125 req->handle = hProcess;
1126 if (!server_call( REQ_GET_PROCESS_INFO ))
1128 if (lpProcessAffinityMask) *lpProcessAffinityMask = req->process_affinity;
1129 if (lpSystemAffinityMask) *lpSystemAffinityMask = req->system_affinity;
1130 ret = TRUE;
1133 SERVER_END_REQ;
1134 return ret;
1138 /***********************************************************************
1139 * GetProcessVersion (KERNEL32)
1141 DWORD WINAPI GetProcessVersion( DWORD processid )
1143 IMAGE_NT_HEADERS *nt;
1145 if (processid && processid != GetCurrentProcessId())
1147 FIXME("should use ReadProcessMemory\n");
1148 return 0;
1150 if ((nt = RtlImageNtHeader( current_process.module )))
1151 return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
1152 nt->OptionalHeader.MinorSubsystemVersion);
1153 return 0;
1156 /***********************************************************************
1157 * GetProcessFlags (KERNEL32)
1159 DWORD WINAPI GetProcessFlags( DWORD processid )
1161 if (processid && processid != GetCurrentProcessId()) return 0;
1162 return current_process.flags;
1166 /***********************************************************************
1167 * SetProcessWorkingSetSize [KERNEL32.662]
1168 * Sets the min/max working set sizes for a specified process.
1170 * PARAMS
1171 * hProcess [I] Handle to the process of interest
1172 * minset [I] Specifies minimum working set size
1173 * maxset [I] Specifies maximum working set size
1175 * RETURNS STD
1177 BOOL WINAPI SetProcessWorkingSetSize(HANDLE hProcess,DWORD minset,
1178 DWORD maxset)
1180 FIXME("(0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
1181 if(( minset == (DWORD)-1) && (maxset == (DWORD)-1)) {
1182 /* Trim the working set to zero */
1183 /* Swap the process out of physical RAM */
1185 return TRUE;
1188 /***********************************************************************
1189 * GetProcessWorkingSetSize (KERNEL32)
1191 BOOL WINAPI GetProcessWorkingSetSize(HANDLE hProcess,LPDWORD minset,
1192 LPDWORD maxset)
1194 FIXME("(0x%08x,%p,%p): stub\n",hProcess,minset,maxset);
1195 /* 32 MB working set size */
1196 if (minset) *minset = 32*1024*1024;
1197 if (maxset) *maxset = 32*1024*1024;
1198 return TRUE;
1201 /***********************************************************************
1202 * SetProcessShutdownParameters (KERNEL32)
1204 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
1205 * Now tracks changes made (but does not act on these changes)
1207 static DWORD shutdown_flags = 0;
1208 static DWORD shutdown_priority = 0x280;
1210 BOOL WINAPI SetProcessShutdownParameters(DWORD level, DWORD flags)
1212 FIXME("(%08lx, %08lx): partial stub.\n", level, flags);
1213 shutdown_flags = flags;
1214 shutdown_priority = level;
1215 return TRUE;
1219 /***********************************************************************
1220 * GetProcessShutdownParameters (KERNEL32)
1223 BOOL WINAPI GetProcessShutdownParameters( LPDWORD lpdwLevel, LPDWORD lpdwFlags )
1225 *lpdwLevel = shutdown_priority;
1226 *lpdwFlags = shutdown_flags;
1227 return TRUE;
1231 /***********************************************************************
1232 * SetProcessPriorityBoost (KERNEL32)
1234 BOOL WINAPI SetProcessPriorityBoost(HANDLE hprocess,BOOL disableboost)
1236 FIXME("(%d,%d): stub\n",hprocess,disableboost);
1237 /* Say we can do it. I doubt the program will notice that we don't. */
1238 return TRUE;
1242 /***********************************************************************
1243 * ReadProcessMemory (KERNEL32)
1245 BOOL WINAPI ReadProcessMemory( HANDLE process, LPCVOID addr, LPVOID buffer, DWORD size,
1246 LPDWORD bytes_read )
1248 unsigned int offset = (unsigned int)addr % sizeof(int);
1249 unsigned int pos = 0, len, max;
1250 int res;
1252 if (bytes_read) *bytes_read = size;
1254 /* first time, read total length to check for permissions */
1255 len = (size + offset + sizeof(int) - 1) / sizeof(int);
1256 max = min( REQUEST_MAX_VAR_SIZE, len * sizeof(int) );
1258 for (;;)
1260 SERVER_START_REQ
1262 struct read_process_memory_request *req = server_alloc_req( sizeof(*req), max );
1263 req->handle = process;
1264 req->addr = (char *)addr + pos - offset;
1265 req->len = len;
1266 if (!(res = server_call( REQ_READ_PROCESS_MEMORY )))
1268 size_t result = server_data_size( req );
1269 if (result > size + offset) result = size + offset;
1270 memcpy( (char *)buffer + pos, server_data_ptr(req) + offset, result - offset );
1271 size -= result - offset;
1272 pos += result - offset;
1275 SERVER_END_REQ;
1276 if (res)
1278 if (bytes_read) *bytes_read = 0;
1279 return FALSE;
1281 if (!size) return TRUE;
1282 max = min( REQUEST_MAX_VAR_SIZE, size );
1283 len = (max + sizeof(int) - 1) / sizeof(int);
1284 offset = 0;
1289 /***********************************************************************
1290 * WriteProcessMemory (KERNEL32)
1292 BOOL WINAPI WriteProcessMemory( HANDLE process, LPVOID addr, LPVOID buffer, DWORD size,
1293 LPDWORD bytes_written )
1295 unsigned int first_offset, last_offset;
1296 unsigned int pos = 0, len, max, first_mask, last_mask;
1297 int res;
1299 if (!size)
1301 SetLastError( ERROR_INVALID_PARAMETER );
1302 return FALSE;
1304 if (bytes_written) *bytes_written = size;
1306 /* compute the mask for the first int */
1307 first_mask = ~0;
1308 first_offset = (unsigned int)addr % sizeof(int);
1309 memset( &first_mask, 0, first_offset );
1311 /* compute the mask for the last int */
1312 last_offset = (size + first_offset) % sizeof(int);
1313 last_mask = 0;
1314 memset( &last_mask, 0xff, last_offset ? last_offset : sizeof(int) );
1316 /* for the first request, use the total length */
1317 len = (size + first_offset + sizeof(int) - 1) / sizeof(int);
1318 max = min( REQUEST_MAX_VAR_SIZE, len * sizeof(int) );
1320 for (;;)
1322 SERVER_START_REQ
1324 struct write_process_memory_request *req = server_alloc_req( sizeof(*req), max );
1325 req->handle = process;
1326 req->addr = (char *)addr - first_offset + pos;
1327 req->len = len;
1328 req->first_mask = (!pos) ? first_mask : ~0;
1329 if (size + first_offset <= max) /* last round */
1331 req->last_mask = last_mask;
1332 max = size + first_offset;
1334 else req->last_mask = ~0;
1336 memcpy( (char *)server_data_ptr(req) + first_offset, (char *)buffer + pos,
1337 max - first_offset );
1338 if (!(res = server_call( REQ_WRITE_PROCESS_MEMORY )))
1340 pos += max - first_offset;
1341 size -= max - first_offset;
1344 SERVER_END_REQ;
1345 if (res)
1347 if (bytes_written) *bytes_written = 0;
1348 return FALSE;
1350 if (!size) return TRUE;
1351 first_offset = 0;
1352 len = min( size + sizeof(int) - 1, REQUEST_MAX_VAR_SIZE ) / sizeof(int);
1353 max = len * sizeof(int);
1358 /***********************************************************************
1359 * RegisterServiceProcess (KERNEL, KERNEL32)
1361 * A service process calls this function to ensure that it continues to run
1362 * even after a user logged off.
1364 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
1366 /* I don't think that Wine needs to do anything in that function */
1367 return 1; /* success */
1370 /***********************************************************************
1371 * GetExitCodeProcess [KERNEL32.325]
1373 * Gets termination status of specified process
1375 * RETURNS
1376 * Success: TRUE
1377 * Failure: FALSE
1379 BOOL WINAPI GetExitCodeProcess(
1380 HANDLE hProcess, /* [in] handle to the process */
1381 LPDWORD lpExitCode) /* [out] address to receive termination status */
1383 BOOL ret;
1384 SERVER_START_REQ
1386 struct get_process_info_request *req = server_alloc_req( sizeof(*req), 0 );
1387 req->handle = hProcess;
1388 ret = !server_call( REQ_GET_PROCESS_INFO );
1389 if (ret && lpExitCode) *lpExitCode = req->exit_code;
1391 SERVER_END_REQ;
1392 return ret;
1396 /***********************************************************************
1397 * SetErrorMode (KERNEL32.486)
1399 UINT WINAPI SetErrorMode( UINT mode )
1401 UINT old = current_process.error_mode;
1402 current_process.error_mode = mode;
1403 return old;
1407 /**********************************************************************
1408 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
1410 * Allocates a thread local storage index
1412 * RETURNS
1413 * Success: TLS Index
1414 * Failure: 0xFFFFFFFF
1416 DWORD WINAPI TlsAlloc( void )
1418 DWORD i, mask, ret = 0;
1419 DWORD *bits = current_process.tls_bits;
1420 RtlAcquirePebLock();
1421 if (*bits == 0xffffffff)
1423 bits++;
1424 ret = 32;
1425 if (*bits == 0xffffffff)
1427 RtlReleasePebLock();
1428 SetLastError( ERROR_NO_MORE_ITEMS );
1429 return 0xffffffff;
1432 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
1433 *bits |= mask;
1434 RtlReleasePebLock();
1435 return ret + i;
1439 /**********************************************************************
1440 * TlsFree [KERNEL32.531] Releases a TLS index.
1442 * Releases a thread local storage index, making it available for reuse
1444 * RETURNS
1445 * Success: TRUE
1446 * Failure: FALSE
1448 BOOL WINAPI TlsFree(
1449 DWORD index) /* [in] TLS Index to free */
1451 DWORD mask = (1 << (index & 31));
1452 DWORD *bits = current_process.tls_bits;
1453 if (index >= 64)
1455 SetLastError( ERROR_INVALID_PARAMETER );
1456 return FALSE;
1458 if (index >= 32) bits++;
1459 RtlAcquirePebLock();
1460 if (!(*bits & mask)) /* already free? */
1462 RtlReleasePebLock();
1463 SetLastError( ERROR_INVALID_PARAMETER );
1464 return FALSE;
1466 *bits &= ~mask;
1467 NtCurrentTeb()->tls_array[index] = 0;
1468 /* FIXME: should zero all other thread values */
1469 RtlReleasePebLock();
1470 return TRUE;
1474 /**********************************************************************
1475 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
1477 * RETURNS
1478 * Success: Value stored in calling thread's TLS slot for index
1479 * Failure: 0 and GetLastError returns NO_ERROR
1481 LPVOID WINAPI TlsGetValue(
1482 DWORD index) /* [in] TLS index to retrieve value for */
1484 if (index >= 64)
1486 SetLastError( ERROR_INVALID_PARAMETER );
1487 return NULL;
1489 SetLastError( ERROR_SUCCESS );
1490 return NtCurrentTeb()->tls_array[index];
1494 /**********************************************************************
1495 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
1497 * RETURNS
1498 * Success: TRUE
1499 * Failure: FALSE
1501 BOOL WINAPI TlsSetValue(
1502 DWORD index, /* [in] TLS index to set value for */
1503 LPVOID value) /* [in] Value to be stored */
1505 if (index >= 64)
1507 SetLastError( ERROR_INVALID_PARAMETER );
1508 return FALSE;
1510 NtCurrentTeb()->tls_array[index] = value;
1511 return TRUE;
1515 /***********************************************************************
1516 * GetCurrentProcess (KERNEL32.198)
1518 #undef GetCurrentProcess
1519 HANDLE WINAPI GetCurrentProcess(void)
1521 return 0xffffffff;