Added .spec entry for KERNEL.RegisterServiceProcess.
[wine/multimedia.git] / scheduler / process.c
blobcc3dc64c83b8f7ad0f9baadafed7e97697d15336
1 /*
2 * Win32 processes
4 * Copyright 1996, 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include "process.h"
12 #include "module.h"
13 #include "file.h"
14 #include "global.h"
15 #include "heap.h"
16 #include "task.h"
17 #include "ldt.h"
18 #include "syslevel.h"
19 #include "thread.h"
20 #include "winerror.h"
21 #include "pe_image.h"
22 #include "task.h"
23 #include "server.h"
24 #include "debug.h"
26 static BOOL32 PROCESS_Signaled( K32OBJ *obj, DWORD thread_id );
27 static BOOL32 PROCESS_Satisfied( K32OBJ *obj, DWORD thread_id );
28 static void PROCESS_AddWait( K32OBJ *obj, DWORD thread_id );
29 static void PROCESS_RemoveWait( K32OBJ *obj, DWORD thread_id );
30 static void PROCESS_Destroy( K32OBJ *obj );
32 const K32OBJ_OPS PROCESS_Ops =
34 PROCESS_Signaled, /* signaled */
35 PROCESS_Satisfied, /* satisfied */
36 PROCESS_AddWait, /* add_wait */
37 PROCESS_RemoveWait, /* remove_wait */
38 NULL, /* read */
39 NULL, /* write */
40 PROCESS_Destroy /* destroy */
43 static DWORD PROCESS_InitialProcessID = 0;
46 /***********************************************************************
47 * PROCESS_Current
49 PDB32 *PROCESS_Current(void)
51 return THREAD_Current()->process;
54 /***********************************************************************
55 * PROCESS_Initial
57 * FIXME: This works only while running all processes in the same
58 * address space (or, at least, the initial process is mapped
59 * into all address spaces as is KERNEL32 in Windows 95)
62 PDB32 *PROCESS_Initial(void)
64 return PROCESS_IdToPDB( PROCESS_InitialProcessID );
67 /***********************************************************************
68 * PROCESS_GetPtr
70 * Get a process from a handle, incrementing the PDB refcount.
72 PDB32 *PROCESS_GetPtr( HANDLE32 handle, DWORD access, int *server_handle )
74 return (PDB32 *)HANDLE_GetObjPtr( PROCESS_Current(), handle,
75 K32OBJ_PROCESS, access, server_handle );
79 /***********************************************************************
80 * PROCESS_IdToPDB
82 * Convert a process id to a PDB, making sure it is valid.
84 PDB32 *PROCESS_IdToPDB( DWORD id )
86 PDB32 *pdb;
88 if (!id) return PROCESS_Current();
89 pdb = PROCESS_ID_TO_PDB( id );
90 if (!K32OBJ_IsValid( &pdb->header, K32OBJ_PROCESS ))
92 SetLastError( ERROR_INVALID_PARAMETER );
93 return NULL;
95 return pdb;
100 /***********************************************************************
101 * PROCESS_BuildEnvDB
103 * Build the env DB for the initial process
105 static BOOL32 PROCESS_BuildEnvDB( PDB32 *pdb )
107 /* Allocate the env DB (FIXME: should not be on the system heap) */
109 if (!(pdb->env_db = HeapAlloc(SystemHeap,HEAP_ZERO_MEMORY,sizeof(ENVDB))))
110 return FALSE;
111 InitializeCriticalSection( &pdb->env_db->section );
113 /* Allocate startup info */
114 if (!(pdb->env_db->startup_info =
115 HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(STARTUPINFO32A) )))
116 return FALSE;
118 /* Allocate the standard handles */
120 pdb->env_db->hStdin = FILE_DupUnixHandle( 0 );
121 pdb->env_db->hStdout = FILE_DupUnixHandle( 1 );
122 pdb->env_db->hStderr = FILE_DupUnixHandle( 2 );
123 FILE_SetFileType( pdb->env_db->hStdin, FILE_TYPE_CHAR );
124 FILE_SetFileType( pdb->env_db->hStdout, FILE_TYPE_CHAR );
125 FILE_SetFileType( pdb->env_db->hStderr, FILE_TYPE_CHAR );
127 /* Build the command-line */
129 pdb->env_db->cmd_line = HEAP_strdupA( SystemHeap, 0, "kernel32" );
131 /* Build the environment strings */
133 return ENV_BuildEnvironment( pdb );
137 /***********************************************************************
138 * PROCESS_InheritEnvDB
140 static BOOL32 PROCESS_InheritEnvDB( PDB32 *pdb, LPCSTR cmd_line, LPCSTR env,
141 STARTUPINFO32A *startup )
143 if (!(pdb->env_db = HeapAlloc(pdb->heap, HEAP_ZERO_MEMORY, sizeof(ENVDB))))
144 return FALSE;
145 InitializeCriticalSection( &pdb->env_db->section );
147 /* Copy the parent environment */
149 if (!ENV_InheritEnvironment( pdb, env )) return FALSE;
151 /* Copy the command line */
153 if (!(pdb->env_db->cmd_line = HEAP_strdupA( pdb->heap, 0, cmd_line )))
154 return FALSE;
156 /* Remember startup info */
157 if (!(pdb->env_db->startup_info =
158 HeapAlloc( pdb->heap, HEAP_ZERO_MEMORY, sizeof(STARTUPINFO32A) )))
159 return FALSE;
160 *pdb->env_db->startup_info = *startup;
162 /* Inherit the standard handles */
163 if (pdb->env_db->startup_info->dwFlags & STARTF_USESTDHANDLES)
165 pdb->env_db->hStdin = pdb->env_db->startup_info->hStdInput;
166 pdb->env_db->hStdout = pdb->env_db->startup_info->hStdOutput;
167 pdb->env_db->hStderr = pdb->env_db->startup_info->hStdError;
169 else
171 pdb->env_db->hStdin = pdb->parent->env_db->hStdin;
172 pdb->env_db->hStdout = pdb->parent->env_db->hStdout;
173 pdb->env_db->hStderr = pdb->parent->env_db->hStderr;
176 return TRUE;
180 /***********************************************************************
181 * PROCESS_FreePDB
183 * Free a PDB and all associated storage.
185 static void PROCESS_FreePDB( PDB32 *pdb )
187 pdb->header.type = K32OBJ_UNKNOWN;
188 if (pdb->handle_table) HANDLE_CloseAll( pdb, NULL );
189 ENV_FreeEnvironment( pdb );
190 if (pdb->heap && (pdb->heap != pdb->system_heap)) HeapDestroy( pdb->heap );
191 if (pdb->load_done_evt) K32OBJ_DecCount( pdb->load_done_evt );
192 if (pdb->event) K32OBJ_DecCount( pdb->event );
193 DeleteCriticalSection( &pdb->crit_section );
194 HeapFree( SystemHeap, 0, pdb );
198 /***********************************************************************
199 * PROCESS_CreatePDB
201 * Allocate and fill a PDB structure.
202 * Runs in the context of the parent process.
204 static PDB32 *PROCESS_CreatePDB( PDB32 *parent )
206 PDB32 *pdb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(PDB32) );
208 if (!pdb) return NULL;
209 pdb->header.type = K32OBJ_PROCESS;
210 pdb->header.refcount = 1;
211 pdb->exit_code = 0x103; /* STILL_ACTIVE */
212 pdb->threads = 1;
213 pdb->running_threads = 1;
214 pdb->ring0_threads = 1;
215 pdb->system_heap = SystemHeap;
216 pdb->parent = parent;
217 pdb->group = pdb;
218 pdb->priority = 8; /* Normal */
219 pdb->heap = pdb->system_heap; /* will be changed later on */
221 InitializeCriticalSection( &pdb->crit_section );
223 /* Allocate the events */
225 if (!(pdb->event = EVENT_Create( TRUE, FALSE ))) goto error;
226 if (!(pdb->load_done_evt = EVENT_Create( TRUE, FALSE ))) goto error;
228 /* Create the handle table */
230 if (!HANDLE_CreateTable( pdb, TRUE )) goto error;
232 return pdb;
234 error:
235 PROCESS_FreePDB( pdb );
236 return NULL;
240 /***********************************************************************
241 * PROCESS_Init
243 BOOL32 PROCESS_Init(void)
245 PDB32 *pdb;
246 THDB *thdb;
248 /* Initialize virtual memory management */
249 if (!VIRTUAL_Init()) return FALSE;
251 /* Create the system and SEGPTR heaps */
252 if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE;
253 if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return FALSE;
255 /* Create the initial process and thread structures */
256 if (!(pdb = PROCESS_CreatePDB( NULL ))) return FALSE;
257 if (!(thdb = THREAD_Create( pdb, 0, TRUE, NULL, NULL, NULL, NULL ))) return FALSE;
258 thdb->unix_pid = getpid();
260 PROCESS_InitialProcessID = PDB_TO_PROCESS_ID(pdb);
262 /* Remember TEB selector of initial process for emergency use */
263 SYSLEVEL_EmergencyTeb = thdb->teb_sel;
265 /* Create the environment DB of the first process */
266 if (!PROCESS_BuildEnvDB( pdb )) return FALSE;
268 /* Initialize the first thread */
269 if (CLIENT_InitThread()) return FALSE;
271 return TRUE;
275 /***********************************************************************
276 * PROCESS_Create
278 * Create a new process database and associated info.
280 PDB32 *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env,
281 HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance,
282 STARTUPINFO32A *startup, PROCESS_INFORMATION *info )
284 DWORD size, commit;
285 int server_thandle, server_phandle;
286 UINT32 cmdShow = 0;
287 THDB *thdb = NULL;
288 PDB32 *parent = PROCESS_Current();
289 PDB32 *pdb = PROCESS_CreatePDB( parent );
290 TDB *pTask;
292 if (!pdb) return NULL;
293 info->hThread = info->hProcess = INVALID_HANDLE_VALUE32;
295 /* Create the heap */
297 if (pModule->module32)
299 size = PE_HEADER(pModule->module32)->OptionalHeader.SizeOfHeapReserve;
300 commit = PE_HEADER(pModule->module32)->OptionalHeader.SizeOfHeapCommit;
302 else
304 size = 0x10000;
305 commit = 0;
306 pdb->flags |= PDB32_WIN16_PROC; /* This is a Win16 process */
308 if (!(pdb->heap = HeapCreate( HEAP_GROWABLE, size, commit ))) goto error;
309 pdb->heap_list = pdb->heap;
311 /* Inherit the env DB from the parent */
313 if (!PROCESS_InheritEnvDB( pdb, cmd_line, env, startup )) goto error;
315 /* Create the main thread */
317 if (pModule->module32)
318 size = PE_HEADER(pModule->module32)->OptionalHeader.SizeOfStackReserve;
319 else
320 size = 0;
321 if (!(thdb = THREAD_Create( pdb, size, FALSE, &server_thandle, &server_phandle,
322 NULL, NULL ))) goto error;
323 if ((info->hThread = HANDLE_Alloc( parent, &thdb->header, THREAD_ALL_ACCESS,
324 FALSE, server_thandle )) == INVALID_HANDLE_VALUE32)
325 goto error;
326 if ((info->hProcess = HANDLE_Alloc( parent, &pdb->header, PROCESS_ALL_ACCESS,
327 FALSE, server_phandle )) == INVALID_HANDLE_VALUE32)
328 goto error;
329 info->dwProcessId = PDB_TO_PROCESS_ID(pdb);
330 info->dwThreadId = THDB_TO_THREAD_ID(thdb);
332 #if 0
333 thdb->unix_pid = getpid(); /* FIXME: wrong here ... */
334 #else
335 /* All Win16 'threads' have the same unix_pid, no matter by which thread
336 they were created ! */
337 pTask = (TDB *)GlobalLock16( parent->task );
338 thdb->unix_pid = pTask? pTask->thdb->unix_pid : THREAD_Current()->unix_pid;
339 #endif
341 /* Create a Win16 task for this process */
343 if (startup->dwFlags & STARTF_USESHOWWINDOW)
344 cmdShow = startup->wShowWindow;
346 pdb->task = TASK_Create( thdb, pModule, hInstance, hPrevInstance, cmdShow);
347 if (!pdb->task) goto error;
349 return pdb;
351 error:
352 if (info->hThread != INVALID_HANDLE_VALUE32) CloseHandle( info->hThread );
353 if (info->hProcess != INVALID_HANDLE_VALUE32) CloseHandle( info->hProcess );
354 if (thdb) K32OBJ_DecCount( &thdb->header );
355 PROCESS_FreePDB( pdb );
356 return NULL;
360 /***********************************************************************
361 * PROCESS_Signaled
363 static BOOL32 PROCESS_Signaled( K32OBJ *obj, DWORD thread_id )
365 PDB32 *pdb = (PDB32 *)obj;
366 assert( obj->type == K32OBJ_PROCESS );
367 return K32OBJ_OPS( pdb->event )->signaled( pdb->event, thread_id );
371 /***********************************************************************
372 * PROCESS_Satisfied
374 * Wait on this object has been satisfied.
376 static BOOL32 PROCESS_Satisfied( K32OBJ *obj, DWORD thread_id )
378 PDB32 *pdb = (PDB32 *)obj;
379 assert( obj->type == K32OBJ_PROCESS );
380 return K32OBJ_OPS( pdb->event )->satisfied( pdb->event, thread_id );
384 /***********************************************************************
385 * PROCESS_AddWait
387 * Add thread to object wait queue.
389 static void PROCESS_AddWait( K32OBJ *obj, DWORD thread_id )
391 PDB32 *pdb = (PDB32 *)obj;
392 assert( obj->type == K32OBJ_PROCESS );
393 return K32OBJ_OPS( pdb->event )->add_wait( pdb->event, thread_id );
397 /***********************************************************************
398 * PROCESS_RemoveWait
400 * Remove thread from object wait queue.
402 static void PROCESS_RemoveWait( K32OBJ *obj, DWORD thread_id )
404 PDB32 *pdb = (PDB32 *)obj;
405 assert( obj->type == K32OBJ_PROCESS );
406 return K32OBJ_OPS( pdb->event )->remove_wait( pdb->event, thread_id );
410 /***********************************************************************
411 * PROCESS_Destroy
413 static void PROCESS_Destroy( K32OBJ *ptr )
415 PDB32 *pdb = (PDB32 *)ptr;
416 assert( ptr->type == K32OBJ_PROCESS );
418 /* Free everything */
420 ptr->type = K32OBJ_UNKNOWN;
421 PROCESS_FreePDB( pdb );
425 /***********************************************************************
426 * ExitProcess (KERNEL32.100)
428 void WINAPI ExitProcess( DWORD status )
430 PDB32 *pdb = PROCESS_Current();
431 TDB *pTask = (TDB *)GlobalLock16( pdb->task );
432 if ( pTask ) pTask->nEvents++;
434 if ( pTask && pTask->thdb != THREAD_Current() )
435 ExitThread( status );
437 SYSTEM_LOCK();
438 /* FIXME: should kill all running threads of this process */
439 pdb->exit_code = status;
440 EVENT_Set( pdb->event );
441 if (pdb->console) FreeConsole();
442 SYSTEM_UNLOCK();
444 __RESTORE_ES; /* Necessary for Pietrek's showseh example program */
445 TASK_KillCurrentTask( status );
449 /******************************************************************************
450 * TerminateProcess (KERNEL32.684)
452 BOOL32 WINAPI TerminateProcess( HANDLE32 handle, DWORD exit_code )
454 int server_handle;
455 BOOL32 ret;
456 PDB32 *pdb = PROCESS_GetPtr( handle, PROCESS_TERMINATE, &server_handle );
457 if (!pdb) return FALSE;
458 ret = !CLIENT_TerminateProcess( server_handle, exit_code );
459 K32OBJ_DecCount( &pdb->header );
460 return ret;
463 /***********************************************************************
464 * GetCurrentProcess (KERNEL32.198)
466 HANDLE32 WINAPI GetCurrentProcess(void)
468 return CURRENT_PROCESS_PSEUDOHANDLE;
472 /*********************************************************************
473 * OpenProcess (KERNEL32.543)
475 HANDLE32 WINAPI OpenProcess( DWORD access, BOOL32 inherit, DWORD id )
477 int server_handle;
478 PDB32 *pdb = PROCESS_ID_TO_PDB(id);
479 if (!K32OBJ_IsValid( &pdb->header, K32OBJ_PROCESS ))
481 SetLastError( ERROR_INVALID_HANDLE );
482 return 0;
484 if ((server_handle = CLIENT_OpenProcess( pdb->server_pid, access, inherit )) == -1)
486 SetLastError( ERROR_INVALID_HANDLE );
487 return 0;
489 return HANDLE_Alloc( PROCESS_Current(), &pdb->header, access,
490 inherit, server_handle );
494 /***********************************************************************
495 * GetCurrentProcessId (KERNEL32.199)
497 DWORD WINAPI GetCurrentProcessId(void)
499 PDB32 *pdb = PROCESS_Current();
500 return PDB_TO_PROCESS_ID( pdb );
504 /***********************************************************************
505 * GetProcessHeap (KERNEL32.259)
507 HANDLE32 WINAPI GetProcessHeap(void)
509 PDB32 *pdb = PROCESS_Current();
510 return pdb->heap ? pdb->heap : SystemHeap;
514 /***********************************************************************
515 * GetThreadLocale (KERNEL32.295)
517 LCID WINAPI GetThreadLocale(void)
519 return PROCESS_Current()->locale;
523 /***********************************************************************
524 * SetPriorityClass (KERNEL32.503)
526 BOOL32 WINAPI SetPriorityClass( HANDLE32 hprocess, DWORD priorityclass )
528 PDB32 *pdb = PROCESS_GetPtr( hprocess, PROCESS_SET_INFORMATION, NULL );
529 if (!pdb) return FALSE;
530 switch (priorityclass)
532 case NORMAL_PRIORITY_CLASS:
533 pdb->priority = 0x00000008;
534 break;
535 case IDLE_PRIORITY_CLASS:
536 pdb->priority = 0x00000004;
537 break;
538 case HIGH_PRIORITY_CLASS:
539 pdb->priority = 0x0000000d;
540 break;
541 case REALTIME_PRIORITY_CLASS:
542 pdb->priority = 0x00000018;
543 break;
544 default:
545 WARN(process,"Unknown priority class %ld\n",priorityclass);
546 break;
548 K32OBJ_DecCount( &pdb->header );
549 return TRUE;
553 /***********************************************************************
554 * GetPriorityClass (KERNEL32.250)
556 DWORD WINAPI GetPriorityClass(HANDLE32 hprocess)
558 PDB32 *pdb = PROCESS_GetPtr( hprocess, PROCESS_QUERY_INFORMATION, NULL );
559 DWORD ret = 0;
560 if (pdb)
562 switch (pdb->priority)
564 case 0x00000008:
565 ret = NORMAL_PRIORITY_CLASS;
566 break;
567 case 0x00000004:
568 ret = IDLE_PRIORITY_CLASS;
569 break;
570 case 0x0000000d:
571 ret = HIGH_PRIORITY_CLASS;
572 break;
573 case 0x00000018:
574 ret = REALTIME_PRIORITY_CLASS;
575 break;
576 default:
577 WARN(process,"Unknown priority %ld\n",pdb->priority);
579 K32OBJ_DecCount( &pdb->header );
581 return ret;
585 /***********************************************************************
586 * GetStdHandle (KERNEL32.276)
588 * FIXME: These should be allocated when a console is created, or inherited
589 * from the parent.
591 HANDLE32 WINAPI GetStdHandle( DWORD std_handle )
593 HFILE32 hFile;
594 int fd;
595 PDB32 *pdb = PROCESS_Current();
597 switch(std_handle)
599 case STD_INPUT_HANDLE:
600 if (pdb->env_db->hStdin) return pdb->env_db->hStdin;
601 fd = 0;
602 break;
603 case STD_OUTPUT_HANDLE:
604 if (pdb->env_db->hStdout) return pdb->env_db->hStdout;
605 fd = 1;
606 break;
607 case STD_ERROR_HANDLE:
608 if (pdb->env_db->hStderr) return pdb->env_db->hStderr;
609 fd = 2;
610 break;
611 default:
612 SetLastError( ERROR_INVALID_PARAMETER );
613 return INVALID_HANDLE_VALUE32;
615 hFile = FILE_DupUnixHandle( fd );
616 if (hFile != HFILE_ERROR32)
618 FILE_SetFileType( hFile, FILE_TYPE_CHAR );
619 switch(std_handle)
621 case STD_INPUT_HANDLE: pdb->env_db->hStdin = hFile; break;
622 case STD_OUTPUT_HANDLE: pdb->env_db->hStdout = hFile; break;
623 case STD_ERROR_HANDLE: pdb->env_db->hStderr = hFile; break;
626 return hFile;
630 /***********************************************************************
631 * SetStdHandle (KERNEL32.506)
633 BOOL32 WINAPI SetStdHandle( DWORD std_handle, HANDLE32 handle )
635 PDB32 *pdb = PROCESS_Current();
636 /* FIXME: should we close the previous handle? */
637 switch(std_handle)
639 case STD_INPUT_HANDLE:
640 pdb->env_db->hStdin = handle;
641 return TRUE;
642 case STD_OUTPUT_HANDLE:
643 pdb->env_db->hStdout = handle;
644 return TRUE;
645 case STD_ERROR_HANDLE:
646 pdb->env_db->hStderr = handle;
647 return TRUE;
649 SetLastError( ERROR_INVALID_PARAMETER );
650 return FALSE;
653 /***********************************************************************
654 * GetProcessVersion (KERNEL32)
656 DWORD WINAPI GetProcessVersion( DWORD processid )
658 TDB *pTask;
659 PDB32 *pdb = PROCESS_IdToPDB( processid );
661 if (!pdb) return 0;
662 if (!(pTask = (TDB *)GlobalLock16( pdb->task ))) return 0;
663 return (pTask->version&0xff) | (((pTask->version >>8) & 0xff)<<16);
666 /***********************************************************************
667 * GetProcessFlags (KERNEL32)
669 DWORD WINAPI GetProcessFlags( DWORD processid )
671 PDB32 *pdb = PROCESS_IdToPDB( processid );
672 if (!pdb) return 0;
673 return pdb->flags;
676 /***********************************************************************
677 * SetProcessWorkingSetSize [KERNEL32.662]
678 * Sets the min/max working set sizes for a specified process.
680 * PARAMS
681 * hProcess [I] Handle to the process of interest
682 * minset [I] Specifies minimum working set size
683 * maxset [I] Specifies maximum working set size
685 * RETURNS STD
687 BOOL32 WINAPI SetProcessWorkingSetSize(HANDLE32 hProcess,DWORD minset,
688 DWORD maxset)
690 FIXME(process,"(0x%08x,%ld,%ld): stub - harmless\n",hProcess,minset,maxset);
691 if(( minset == -1) && (maxset == -1)) {
692 /* Trim the working set to zero */
693 /* Swap the process out of physical RAM */
695 return TRUE;
698 /***********************************************************************
699 * GetProcessWorkingSetSize (KERNEL32)
701 BOOL32 WINAPI GetProcessWorkingSetSize(HANDLE32 hProcess,LPDWORD minset,
702 LPDWORD maxset)
704 FIXME(process,"(0x%08x,%p,%p): stub\n",hProcess,minset,maxset);
705 /* 32 MB working set size */
706 if (minset) *minset = 32*1024*1024;
707 if (maxset) *maxset = 32*1024*1024;
708 return TRUE;
711 /***********************************************************************
712 * SetProcessShutdownParameters (KERNEL32)
714 BOOL32 WINAPI SetProcessShutdownParameters(DWORD level,DWORD flags)
716 FIXME(process,"(%ld,0x%08lx): stub\n",level,flags);
717 return TRUE;
720 /***********************************************************************
721 * SetProcessPriorityBoost (KERNEL32)
723 BOOL32 WINAPI SetProcessPriorityBoost(HANDLE32 hprocess,BOOL32 disableboost)
725 FIXME(process,"(%d,%d): stub\n",hprocess,disableboost);
726 /* Say we can do it. I doubt the program will notice that we don't. */
727 return TRUE;
730 /***********************************************************************
731 * ReadProcessMemory (KERNEL32)
732 * FIXME: check this, if we ever run win32 binaries in different addressspaces
733 * ... and add a sizecheck
735 BOOL32 WINAPI ReadProcessMemory( HANDLE32 hProcess, LPCVOID lpBaseAddress,
736 LPVOID lpBuffer, DWORD nSize,
737 LPDWORD lpNumberOfBytesRead )
739 memcpy(lpBuffer,lpBaseAddress,nSize);
740 if (lpNumberOfBytesRead) *lpNumberOfBytesRead = nSize;
741 return TRUE;
744 /***********************************************************************
745 * WriteProcessMemory (KERNEL32)
746 * FIXME: check this, if we ever run win32 binaries in different addressspaces
747 * ... and add a sizecheck
749 BOOL32 WINAPI WriteProcessMemory(HANDLE32 hProcess, LPVOID lpBaseAddress,
750 LPVOID lpBuffer, DWORD nSize,
751 LPDWORD lpNumberOfBytesWritten )
753 memcpy(lpBaseAddress,lpBuffer,nSize);
754 if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = nSize;
755 return TRUE;
758 /***********************************************************************
759 * ConvertToGlobalHandle (KERNEL32)
761 HANDLE32 WINAPI ConvertToGlobalHandle(HANDLE32 hSrc)
763 HANDLE32 hProcessInit, hDest;
765 /* Get a handle to the initial process */
766 hProcessInit = OpenProcess( PROCESS_ALL_ACCESS, FALSE, PROCESS_InitialProcessID );
768 /* Duplicate the handle into the initial process */
769 if ( !DuplicateHandle( GetCurrentProcess(), hSrc, hProcessInit, &hDest,
770 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE ) )
771 hDest = 0;
773 /* Close initial process handle */
774 CloseHandle( hProcessInit );
776 /* Return obfuscated global handle */
777 return hDest? HANDLE_LOCAL_TO_GLOBAL( hDest ) : 0;
780 /***********************************************************************
781 * RegisterServiceProcess (KERNEL, KERNEL32)
783 * A service process calls this function to ensure that it continues to run
784 * even after a user logged off.
786 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
788 /* I don't think that Wine needs to do anything in that function */
789 return 1; /* success */
792 /***********************************************************************
793 * GetExitCodeProcess [KERNEL32.325]
795 * Gets termination status of specified process
797 * RETURNS
798 * Success: TRUE
799 * Failure: FALSE
801 * FIXME
802 * Should call SetLastError (but doesn't).
804 BOOL32 WINAPI GetExitCodeProcess(
805 HANDLE32 hProcess, /* [I] handle to the process */
806 LPDWORD lpExitCode) /* [O] address to receive termination status */
808 PDB32 *process;
809 int server_handle;
810 struct get_process_info_reply info;
812 if (!(process = PROCESS_GetPtr( hProcess, PROCESS_QUERY_INFORMATION,
813 &server_handle )))
814 return FALSE;
815 if (server_handle != -1)
817 CLIENT_GetProcessInfo( server_handle, &info );
818 if (lpExitCode) *lpExitCode = info.exit_code;
820 else if (lpExitCode) *lpExitCode = process->exit_code;
821 K32OBJ_DecCount( &process->header );
822 return TRUE;
825 /***********************************************************************
826 * GetProcessHeaps [KERNEL32.376]
828 DWORD WINAPI GetProcessHeaps(DWORD nrofheaps,HANDLE32 *heaps) {
829 FIXME(win32,"(%ld,%p), incomplete implementation.\n",nrofheaps,heaps);
831 if (nrofheaps) {
832 heaps[0] = GetProcessHeap();
833 /* ... probably SystemHeap too ? */
834 return 1;
836 /* number of available heaps */
837 return 1;
840 /***********************************************************************
841 * PROCESS_SuspendOtherThreads
844 void PROCESS_SuspendOtherThreads(void)
846 PDB32 *pdb;
847 THREAD_ENTRY *entry;
849 SYSTEM_LOCK();
851 pdb = PROCESS_Current();
852 entry = pdb->thread_list->next;
853 for (;;)
855 if (entry->thread != THREAD_Current() && !THREAD_IsWin16(entry->thread))
857 HANDLE32 handle = HANDLE_Alloc( PROCESS_Current(),
858 &entry->thread->header,
859 THREAD_ALL_ACCESS, FALSE, -1 );
860 SuspendThread(handle);
861 CloseHandle(handle);
863 if (entry == pdb->thread_list) break;
864 entry = entry->next;
867 SYSTEM_UNLOCK();
870 /***********************************************************************
871 * PROCESS_ResumeOtherThreads
874 void PROCESS_ResumeOtherThreads(void)
876 PDB32 *pdb;
877 THREAD_ENTRY *entry;
879 SYSTEM_LOCK();
881 pdb = PROCESS_Current();
882 entry = pdb->thread_list->next;
883 for (;;)
885 if (entry->thread != THREAD_Current() && !THREAD_IsWin16(entry->thread))
887 HANDLE32 handle = HANDLE_Alloc( PROCESS_Current(),
888 &entry->thread->header,
889 THREAD_ALL_ACCESS, FALSE, -1 );
890 ResumeThread(handle);
891 CloseHandle(handle);
893 if (entry == pdb->thread_list) break;
894 entry = entry->next;
897 SYSTEM_UNLOCK();
900 BOOL32 WINAPI Process32First(HANDLE32 hSnapshot, LPPROCESSENTRY32 lppe)
902 FIXME (process, "(0x%08lx,0x%08lx), stub!\n", hSnapshot, lppe);
903 SetLastError (ERROR_NO_MORE_FILES);
904 return FALSE;
907 BOOL32 WINAPI Process32Next(HANDLE32 hSnapshot, LPPROCESSENTRY32 lppe)
909 FIXME (process, "(0x%08lx,0x%08lx), stub!\n", hSnapshot, lppe);
910 SetLastError (ERROR_NO_MORE_FILES);
911 return FALSE;