4 * Copyright 1996, 1998 Alexandre Julliard
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 */
40 PROCESS_Destroy
/* destroy */
43 static DWORD PROCESS_InitialProcessID
= 0;
46 /***********************************************************************
49 PDB32
*PROCESS_Current(void)
51 return THREAD_Current()->process
;
54 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
82 * Convert a process id to a PDB, making sure it is valid.
84 PDB32
*PROCESS_IdToPDB( DWORD id
)
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
);
100 /***********************************************************************
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
))))
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
) )))
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
))))
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
)))
156 /* Remember startup info */
157 if (!(pdb
->env_db
->startup_info
=
158 HeapAlloc( pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(STARTUPINFO32A
) )))
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
;
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
;
180 /***********************************************************************
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 /***********************************************************************
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 */
213 pdb
->running_threads
= 1;
214 pdb
->ring0_threads
= 1;
215 pdb
->system_heap
= SystemHeap
;
216 pdb
->parent
= parent
;
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
;
235 PROCESS_FreePDB( pdb
);
240 /***********************************************************************
243 BOOL32
PROCESS_Init(void)
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
;
275 /***********************************************************************
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
)
285 int server_thandle
, server_phandle
;
288 PDB32
*parent
= PROCESS_Current();
289 PDB32
*pdb
= PROCESS_CreatePDB( parent
);
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
;
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
;
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
)
326 if ((info
->hProcess
= HANDLE_Alloc( parent
, &pdb
->header
, PROCESS_ALL_ACCESS
,
327 FALSE
, server_phandle
)) == INVALID_HANDLE_VALUE32
)
329 info
->dwProcessId
= PDB_TO_PROCESS_ID(pdb
);
330 info
->dwThreadId
= THDB_TO_THREAD_ID(thdb
);
333 thdb
->unix_pid
= getpid(); /* FIXME: wrong here ... */
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
;
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
;
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
);
360 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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
);
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();
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
)
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
);
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
)
478 PDB32
*pdb
= PROCESS_ID_TO_PDB(id
);
479 if (!K32OBJ_IsValid( &pdb
->header
, K32OBJ_PROCESS
))
481 SetLastError( ERROR_INVALID_HANDLE
);
484 if ((server_handle
= CLIENT_OpenProcess( pdb
->server_pid
, access
, inherit
)) == -1)
486 SetLastError( ERROR_INVALID_HANDLE
);
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;
535 case IDLE_PRIORITY_CLASS
:
536 pdb
->priority
= 0x00000004;
538 case HIGH_PRIORITY_CLASS
:
539 pdb
->priority
= 0x0000000d;
541 case REALTIME_PRIORITY_CLASS
:
542 pdb
->priority
= 0x00000018;
545 WARN(process
,"Unknown priority class %ld\n",priorityclass
);
548 K32OBJ_DecCount( &pdb
->header
);
553 /***********************************************************************
554 * GetPriorityClass (KERNEL32.250)
556 DWORD WINAPI
GetPriorityClass(HANDLE32 hprocess
)
558 PDB32
*pdb
= PROCESS_GetPtr( hprocess
, PROCESS_QUERY_INFORMATION
, NULL
);
562 switch (pdb
->priority
)
565 ret
= NORMAL_PRIORITY_CLASS
;
568 ret
= IDLE_PRIORITY_CLASS
;
571 ret
= HIGH_PRIORITY_CLASS
;
574 ret
= REALTIME_PRIORITY_CLASS
;
577 WARN(process
,"Unknown priority %ld\n",pdb
->priority
);
579 K32OBJ_DecCount( &pdb
->header
);
585 /***********************************************************************
586 * GetStdHandle (KERNEL32.276)
588 * FIXME: These should be allocated when a console is created, or inherited
591 HANDLE32 WINAPI
GetStdHandle( DWORD std_handle
)
595 PDB32
*pdb
= PROCESS_Current();
599 case STD_INPUT_HANDLE
:
600 if (pdb
->env_db
->hStdin
) return pdb
->env_db
->hStdin
;
603 case STD_OUTPUT_HANDLE
:
604 if (pdb
->env_db
->hStdout
) return pdb
->env_db
->hStdout
;
607 case STD_ERROR_HANDLE
:
608 if (pdb
->env_db
->hStderr
) return pdb
->env_db
->hStderr
;
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
);
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;
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? */
639 case STD_INPUT_HANDLE
:
640 pdb
->env_db
->hStdin
= handle
;
642 case STD_OUTPUT_HANDLE
:
643 pdb
->env_db
->hStdout
= handle
;
645 case STD_ERROR_HANDLE
:
646 pdb
->env_db
->hStderr
= handle
;
649 SetLastError( ERROR_INVALID_PARAMETER
);
653 /***********************************************************************
654 * GetProcessVersion (KERNEL32)
656 DWORD WINAPI
GetProcessVersion( DWORD processid
)
659 PDB32
*pdb
= PROCESS_IdToPDB( processid
);
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
);
676 /***********************************************************************
677 * SetProcessWorkingSetSize [KERNEL32.662]
678 * Sets the min/max working set sizes for a specified process.
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
687 BOOL32 WINAPI
SetProcessWorkingSetSize(HANDLE32 hProcess
,DWORD minset
,
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 */
698 /***********************************************************************
699 * GetProcessWorkingSetSize (KERNEL32)
701 BOOL32 WINAPI
GetProcessWorkingSetSize(HANDLE32 hProcess
,LPDWORD minset
,
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;
711 /***********************************************************************
712 * SetProcessShutdownParameters (KERNEL32)
714 BOOL32 WINAPI
SetProcessShutdownParameters(DWORD level
,DWORD flags
)
716 FIXME(process
,"(%ld,0x%08lx): stub\n",level
,flags
);
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. */
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
;
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
;
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
) )
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
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 */
810 struct get_process_info_reply info
;
812 if (!(process
= PROCESS_GetPtr( hProcess
, PROCESS_QUERY_INFORMATION
,
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
);
825 /***********************************************************************
826 * GetProcessHeaps [KERNEL32.376]
828 DWORD WINAPI
GetProcessHeaps(DWORD nrofheaps
,HANDLE32
*heaps
) {
829 FIXME(win32
,"(%ld,%p), incomplete implementation.\n",nrofheaps
,heaps
);
832 heaps
[0] = GetProcessHeap();
833 /* ... probably SystemHeap too ? */
836 /* number of available heaps */
840 /***********************************************************************
841 * PROCESS_SuspendOtherThreads
844 void PROCESS_SuspendOtherThreads(void)
851 pdb
= PROCESS_Current();
852 entry
= pdb
->thread_list
->next
;
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
);
863 if (entry
== pdb
->thread_list
) break;
870 /***********************************************************************
871 * PROCESS_ResumeOtherThreads
874 void PROCESS_ResumeOtherThreads(void)
881 pdb
= PROCESS_Current();
882 entry
= pdb
->thread_list
->next
;
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
);
893 if (entry
== pdb
->thread_list
) break;
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
);
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
);