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;
44 static PDB32
*PROCESS_PDBList
= NULL
;
45 static DWORD PROCESS_PDBList_Size
= 0;
47 /***********************************************************************
50 PDB32
*PROCESS_Current(void)
52 return THREAD_Current()->process
;
55 /***********************************************************************
58 * FIXME: This works only while running all processes in the same
59 * address space (or, at least, the initial process is mapped
60 * into all address spaces as is KERNEL32 in Windows 95)
63 PDB32
*PROCESS_Initial(void)
65 return PROCESS_IdToPDB( PROCESS_InitialProcessID
);
68 /***********************************************************************
71 * Get a process from a handle, incrementing the PDB refcount.
73 PDB32
*PROCESS_GetPtr( HANDLE32 handle
, DWORD access
, int *server_handle
)
75 return (PDB32
*)HANDLE_GetObjPtr( PROCESS_Current(), handle
,
76 K32OBJ_PROCESS
, access
, server_handle
);
80 /***********************************************************************
83 * Convert a process id to a PDB, making sure it is valid.
85 PDB32
*PROCESS_IdToPDB( DWORD id
)
89 if (!id
) return PROCESS_Current();
90 pdb
= PROCESS_ID_TO_PDB( id
);
91 if (!K32OBJ_IsValid( &pdb
->header
, K32OBJ_PROCESS
))
93 SetLastError( ERROR_INVALID_PARAMETER
);
101 /***********************************************************************
104 * Build the env DB for the initial process
106 static BOOL32
PROCESS_BuildEnvDB( PDB32
*pdb
)
108 /* Allocate the env DB (FIXME: should not be on the system heap) */
110 if (!(pdb
->env_db
= HeapAlloc(SystemHeap
,HEAP_ZERO_MEMORY
,sizeof(ENVDB
))))
112 InitializeCriticalSection( &pdb
->env_db
->section
);
114 /* Allocate startup info */
115 if (!(pdb
->env_db
->startup_info
=
116 HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(STARTUPINFO32A
) )))
119 /* Allocate the standard handles */
121 pdb
->env_db
->hStdin
= FILE_DupUnixHandle( 0 );
122 pdb
->env_db
->hStdout
= FILE_DupUnixHandle( 1 );
123 pdb
->env_db
->hStderr
= FILE_DupUnixHandle( 2 );
124 FILE_SetFileType( pdb
->env_db
->hStdin
, FILE_TYPE_CHAR
);
125 FILE_SetFileType( pdb
->env_db
->hStdout
, FILE_TYPE_CHAR
);
126 FILE_SetFileType( pdb
->env_db
->hStderr
, FILE_TYPE_CHAR
);
128 /* Build the command-line */
130 pdb
->env_db
->cmd_line
= HEAP_strdupA( SystemHeap
, 0, "kernel32" );
132 /* Build the environment strings */
134 return ENV_BuildEnvironment( pdb
);
138 /***********************************************************************
139 * PROCESS_InheritEnvDB
141 static BOOL32
PROCESS_InheritEnvDB( PDB32
*pdb
, LPCSTR cmd_line
, LPCSTR env
,
142 STARTUPINFO32A
*startup
)
144 if (!(pdb
->env_db
= HeapAlloc(pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(ENVDB
))))
146 InitializeCriticalSection( &pdb
->env_db
->section
);
148 /* Copy the parent environment */
150 if (!ENV_InheritEnvironment( pdb
, env
)) return FALSE
;
152 /* Copy the command line */
154 if (!(pdb
->env_db
->cmd_line
= HEAP_strdupA( pdb
->heap
, 0, cmd_line
)))
157 /* Remember startup info */
158 if (!(pdb
->env_db
->startup_info
=
159 HeapAlloc( pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(STARTUPINFO32A
) )))
161 *pdb
->env_db
->startup_info
= *startup
;
163 /* Inherit the standard handles */
164 if (pdb
->env_db
->startup_info
->dwFlags
& STARTF_USESTDHANDLES
)
166 pdb
->env_db
->hStdin
= pdb
->env_db
->startup_info
->hStdInput
;
167 pdb
->env_db
->hStdout
= pdb
->env_db
->startup_info
->hStdOutput
;
168 pdb
->env_db
->hStderr
= pdb
->env_db
->startup_info
->hStdError
;
172 pdb
->env_db
->hStdin
= pdb
->parent
->env_db
->hStdin
;
173 pdb
->env_db
->hStdout
= pdb
->parent
->env_db
->hStdout
;
174 pdb
->env_db
->hStderr
= pdb
->parent
->env_db
->hStderr
;
180 /***********************************************************************
181 * PROCESS_PDBList_Insert
182 * Insert this PDB into the global PDB list
185 static void PROCESS_PDBList_Insert (PDB32
*pdb
)
187 TRACE (process
, "Inserting PDB 0x%0lx, #%ld current\n",
188 PDB_TO_PROCESS_ID (pdb
), PROCESS_PDBList_Size
);
190 SYSTEM_LOCK (); /* FIXME: Do I need to worry about this ?
191 * I.e., could more than one process be
194 if (PROCESS_PDBList
== NULL
)
196 PROCESS_PDBList
= pdb
;
197 pdb
->list_next
= NULL
;
198 pdb
->list_prev
= NULL
;
202 PDB32
*first
= PROCESS_PDBList
, *last
= PROCESS_PDBList
;
203 if (first
->list_prev
) last
= first
->list_prev
;
205 PROCESS_PDBList
= pdb
;
206 pdb
->list_next
= first
;
207 pdb
->list_prev
= last
;
208 last
->list_next
= pdb
;
209 first
->list_prev
= pdb
;
211 PROCESS_PDBList_Size
++;
215 /***********************************************************************
216 * PROCESS_PDBList_Remove
217 * Remove this PDB from the global PDB list
220 static void PROCESS_PDBList_Remove (PDB32
*pdb
)
222 PDB32
*next
= pdb
->list_next
, *prev
= pdb
->list_prev
;
224 TRACE (process
, "Removing PDB 0x%0lx, #%ld current\n",
225 PDB_TO_PROCESS_ID (pdb
), PROCESS_PDBList_Size
);
231 next
->list_prev
= NULL
;
232 next
->list_next
= NULL
;
236 if (next
) next
->list_prev
= prev
;
237 if (prev
) prev
->list_next
= next
;
240 if (pdb
== PROCESS_PDBList
)
242 PROCESS_PDBList
= next
? next
: prev
;
244 PROCESS_PDBList_Size
--;
249 /***********************************************************************
250 * PROCESS_PDBList_Getsize
251 * Return the number of items in the global PDB list
254 int PROCESS_PDBList_Getsize ()
256 return PROCESS_PDBList_Size
;
259 /***********************************************************************
260 * PROCESS_PDBList_Getfirst
261 * Return the head of the PDB list
264 PDB32
* PROCESS_PDBList_Getfirst ()
266 return PROCESS_PDBList
;
269 /***********************************************************************
270 * PROCESS_PDBList_Getnext
271 * Return the "next" pdb as referenced from the argument.
272 * If at the end of the list, return NULL.
275 PDB32
* PROCESS_PDBList_Getnext (PDB32
*pdb
)
277 return (pdb
->list_next
!= PROCESS_PDBList
) ? pdb
->list_next
: NULL
;
280 /***********************************************************************
283 * Free a PDB and all associated storage.
285 static void PROCESS_FreePDB( PDB32
*pdb
)
289 * If this routine is called because PROCESS_CreatePDB fails, the
290 * following call to PROCESS_PDBList_Remove will probably screw
293 PROCESS_PDBList_Remove (pdb
);
294 pdb
->header
.type
= K32OBJ_UNKNOWN
;
295 if (pdb
->handle_table
) HANDLE_CloseAll( pdb
, NULL
);
296 ENV_FreeEnvironment( pdb
);
297 if (pdb
->heap
&& (pdb
->heap
!= pdb
->system_heap
)) HeapDestroy( pdb
->heap
);
298 if (pdb
->load_done_evt
) K32OBJ_DecCount( pdb
->load_done_evt
);
299 if (pdb
->event
) K32OBJ_DecCount( pdb
->event
);
300 DeleteCriticalSection( &pdb
->crit_section
);
301 HeapFree( SystemHeap
, 0, pdb
);
305 /***********************************************************************
308 * Allocate and fill a PDB structure.
309 * Runs in the context of the parent process.
311 static PDB32
*PROCESS_CreatePDB( PDB32
*parent
)
313 PDB32
*pdb
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(PDB32
) );
315 if (!pdb
) return NULL
;
316 pdb
->header
.type
= K32OBJ_PROCESS
;
317 pdb
->header
.refcount
= 1;
318 pdb
->exit_code
= 0x103; /* STILL_ACTIVE */
320 pdb
->running_threads
= 1;
321 pdb
->ring0_threads
= 1;
322 pdb
->system_heap
= SystemHeap
;
323 pdb
->parent
= parent
;
325 pdb
->priority
= 8; /* Normal */
326 pdb
->heap
= pdb
->system_heap
; /* will be changed later on */
328 InitializeCriticalSection( &pdb
->crit_section
);
330 /* Allocate the events */
332 if (!(pdb
->event
= EVENT_Create( TRUE
, FALSE
))) goto error
;
333 if (!(pdb
->load_done_evt
= EVENT_Create( TRUE
, FALSE
))) goto error
;
335 /* Create the handle table */
337 if (!HANDLE_CreateTable( pdb
, TRUE
)) goto error
;
339 PROCESS_PDBList_Insert (pdb
);
344 PROCESS_FreePDB( pdb
);
349 /***********************************************************************
352 BOOL32
PROCESS_Init(void)
357 /* Initialize virtual memory management */
358 if (!VIRTUAL_Init()) return FALSE
;
360 /* Create the system and SEGPTR heaps */
361 if (!(SystemHeap
= HeapCreate( HEAP_GROWABLE
, 0x10000, 0 ))) return FALSE
;
362 if (!(SegptrHeap
= HeapCreate( HEAP_WINE_SEGPTR
, 0, 0 ))) return FALSE
;
364 /* Create the initial process and thread structures */
365 if (!(pdb
= PROCESS_CreatePDB( NULL
))) return FALSE
;
366 if (!(thdb
= THREAD_Create( pdb
, 0, FALSE
, NULL
, NULL
, NULL
, NULL
))) return FALSE
;
367 thdb
->unix_pid
= getpid();
369 PROCESS_InitialProcessID
= PDB_TO_PROCESS_ID(pdb
);
371 /* Remember TEB selector of initial process for emergency use */
372 SYSLEVEL_EmergencyTeb
= thdb
->teb_sel
;
374 /* Create the environment DB of the first process */
375 if (!PROCESS_BuildEnvDB( pdb
)) return FALSE
;
377 /* Initialize the first thread */
378 if (CLIENT_InitThread()) return FALSE
;
384 /***********************************************************************
387 * Create a new process database and associated info.
389 PDB32
*PROCESS_Create( NE_MODULE
*pModule
, LPCSTR cmd_line
, LPCSTR env
,
390 HINSTANCE16 hInstance
, HINSTANCE16 hPrevInstance
,
391 STARTUPINFO32A
*startup
, PROCESS_INFORMATION
*info
)
394 int server_thandle
, server_phandle
;
397 PDB32
*parent
= PROCESS_Current();
398 PDB32
*pdb
= PROCESS_CreatePDB( parent
);
401 if (!pdb
) return NULL
;
402 info
->hThread
= info
->hProcess
= INVALID_HANDLE_VALUE32
;
404 /* Create the heap */
406 if (pModule
->module32
)
408 size
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfHeapReserve
;
409 commit
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfHeapCommit
;
415 pdb
->flags
|= PDB32_WIN16_PROC
; /* This is a Win16 process */
417 if (!(pdb
->heap
= HeapCreate( HEAP_GROWABLE
, size
, commit
))) goto error
;
418 pdb
->heap_list
= pdb
->heap
;
420 /* Inherit the env DB from the parent */
422 if (!PROCESS_InheritEnvDB( pdb
, cmd_line
, env
, startup
)) goto error
;
424 /* Create the main thread */
426 if (pModule
->module32
)
427 size
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfStackReserve
;
430 if (!(thdb
= THREAD_Create( pdb
, size
, FALSE
, &server_thandle
, &server_phandle
,
431 NULL
, NULL
))) goto error
;
432 if ((info
->hThread
= HANDLE_Alloc( parent
, &thdb
->header
, THREAD_ALL_ACCESS
,
433 FALSE
, server_thandle
)) == INVALID_HANDLE_VALUE32
)
435 if ((info
->hProcess
= HANDLE_Alloc( parent
, &pdb
->header
, PROCESS_ALL_ACCESS
,
436 FALSE
, server_phandle
)) == INVALID_HANDLE_VALUE32
)
438 info
->dwProcessId
= PDB_TO_PROCESS_ID(pdb
);
439 info
->dwThreadId
= THDB_TO_THREAD_ID(thdb
);
442 thdb
->unix_pid
= getpid(); /* FIXME: wrong here ... */
444 /* All Win16 'threads' have the same unix_pid, no matter by which thread
445 they were created ! */
446 pTask
= (TDB
*)GlobalLock16( parent
->task
);
447 thdb
->unix_pid
= pTask
? pTask
->thdb
->unix_pid
: THREAD_Current()->unix_pid
;
450 /* Create a Win16 task for this process */
452 if (startup
->dwFlags
& STARTF_USESHOWWINDOW
)
453 cmdShow
= startup
->wShowWindow
;
455 pdb
->task
= TASK_Create( thdb
, pModule
, hInstance
, hPrevInstance
, cmdShow
);
456 if (!pdb
->task
) goto error
;
459 /* Map system DLLs into this process (from initial process) */
460 /* FIXME: this is a hack */
461 pdb
->modref_list
= PROCESS_Initial()->modref_list
;
467 if (info
->hThread
!= INVALID_HANDLE_VALUE32
) CloseHandle( info
->hThread
);
468 if (info
->hProcess
!= INVALID_HANDLE_VALUE32
) CloseHandle( info
->hProcess
);
469 if (thdb
) K32OBJ_DecCount( &thdb
->header
);
470 PROCESS_FreePDB( pdb
);
475 /***********************************************************************
478 static BOOL32
PROCESS_Signaled( K32OBJ
*obj
, DWORD thread_id
)
480 PDB32
*pdb
= (PDB32
*)obj
;
481 assert( obj
->type
== K32OBJ_PROCESS
);
482 return K32OBJ_OPS( pdb
->event
)->signaled( pdb
->event
, thread_id
);
486 /***********************************************************************
489 * Wait on this object has been satisfied.
491 static BOOL32
PROCESS_Satisfied( K32OBJ
*obj
, DWORD thread_id
)
493 PDB32
*pdb
= (PDB32
*)obj
;
494 assert( obj
->type
== K32OBJ_PROCESS
);
495 return K32OBJ_OPS( pdb
->event
)->satisfied( pdb
->event
, thread_id
);
499 /***********************************************************************
502 * Add thread to object wait queue.
504 static void PROCESS_AddWait( K32OBJ
*obj
, DWORD thread_id
)
506 PDB32
*pdb
= (PDB32
*)obj
;
507 assert( obj
->type
== K32OBJ_PROCESS
);
508 return K32OBJ_OPS( pdb
->event
)->add_wait( pdb
->event
, thread_id
);
512 /***********************************************************************
515 * Remove thread from object wait queue.
517 static void PROCESS_RemoveWait( K32OBJ
*obj
, DWORD thread_id
)
519 PDB32
*pdb
= (PDB32
*)obj
;
520 assert( obj
->type
== K32OBJ_PROCESS
);
521 return K32OBJ_OPS( pdb
->event
)->remove_wait( pdb
->event
, thread_id
);
525 /***********************************************************************
528 static void PROCESS_Destroy( K32OBJ
*ptr
)
530 PDB32
*pdb
= (PDB32
*)ptr
;
531 assert( ptr
->type
== K32OBJ_PROCESS
);
533 /* Free everything */
535 ptr
->type
= K32OBJ_UNKNOWN
;
536 PROCESS_FreePDB( pdb
);
540 /***********************************************************************
541 * ExitProcess (KERNEL32.100)
543 void WINAPI
ExitProcess( DWORD status
)
545 PDB32
*pdb
= PROCESS_Current();
546 TDB
*pTask
= (TDB
*)GlobalLock16( pdb
->task
);
547 if ( pTask
) pTask
->nEvents
++;
549 if ( pTask
&& pTask
->thdb
!= THREAD_Current() )
550 ExitThread( status
);
553 /* FIXME: should kill all running threads of this process */
554 pdb
->exit_code
= status
;
555 EVENT_Set( pdb
->event
);
556 if (pdb
->console
) FreeConsole();
559 __RESTORE_ES
; /* Necessary for Pietrek's showseh example program */
560 TASK_KillCurrentTask( status
);
564 /******************************************************************************
565 * TerminateProcess (KERNEL32.684)
567 BOOL32 WINAPI
TerminateProcess( HANDLE32 handle
, DWORD exit_code
)
571 PDB32
*pdb
= PROCESS_GetPtr( handle
, PROCESS_TERMINATE
, &server_handle
);
572 if (!pdb
) return FALSE
;
573 ret
= !CLIENT_TerminateProcess( server_handle
, exit_code
);
574 K32OBJ_DecCount( &pdb
->header
);
578 /***********************************************************************
579 * GetCurrentProcess (KERNEL32.198)
581 HANDLE32 WINAPI
GetCurrentProcess(void)
583 return CURRENT_PROCESS_PSEUDOHANDLE
;
587 /*********************************************************************
588 * OpenProcess (KERNEL32.543)
590 HANDLE32 WINAPI
OpenProcess( DWORD access
, BOOL32 inherit
, DWORD id
)
593 PDB32
*pdb
= PROCESS_ID_TO_PDB(id
);
594 if (!K32OBJ_IsValid( &pdb
->header
, K32OBJ_PROCESS
))
596 SetLastError( ERROR_INVALID_HANDLE
);
599 if ((server_handle
= CLIENT_OpenProcess( pdb
->server_pid
, access
, inherit
)) == -1)
601 SetLastError( ERROR_INVALID_HANDLE
);
604 return HANDLE_Alloc( PROCESS_Current(), &pdb
->header
, access
,
605 inherit
, server_handle
);
609 /***********************************************************************
610 * GetCurrentProcessId (KERNEL32.199)
612 DWORD WINAPI
GetCurrentProcessId(void)
614 PDB32
*pdb
= PROCESS_Current();
615 return PDB_TO_PROCESS_ID( pdb
);
619 /***********************************************************************
620 * GetProcessHeap (KERNEL32.259)
622 HANDLE32 WINAPI
GetProcessHeap(void)
624 PDB32
*pdb
= PROCESS_Current();
625 return pdb
->heap
? pdb
->heap
: SystemHeap
;
629 /***********************************************************************
630 * GetThreadLocale (KERNEL32.295)
632 LCID WINAPI
GetThreadLocale(void)
634 return PROCESS_Current()->locale
;
638 /***********************************************************************
639 * SetPriorityClass (KERNEL32.503)
641 BOOL32 WINAPI
SetPriorityClass( HANDLE32 hprocess
, DWORD priorityclass
)
643 PDB32
*pdb
= PROCESS_GetPtr( hprocess
, PROCESS_SET_INFORMATION
, NULL
);
644 if (!pdb
) return FALSE
;
645 switch (priorityclass
)
647 case NORMAL_PRIORITY_CLASS
:
648 pdb
->priority
= 0x00000008;
650 case IDLE_PRIORITY_CLASS
:
651 pdb
->priority
= 0x00000004;
653 case HIGH_PRIORITY_CLASS
:
654 pdb
->priority
= 0x0000000d;
656 case REALTIME_PRIORITY_CLASS
:
657 pdb
->priority
= 0x00000018;
660 WARN(process
,"Unknown priority class %ld\n",priorityclass
);
663 K32OBJ_DecCount( &pdb
->header
);
668 /***********************************************************************
669 * GetPriorityClass (KERNEL32.250)
671 DWORD WINAPI
GetPriorityClass(HANDLE32 hprocess
)
673 PDB32
*pdb
= PROCESS_GetPtr( hprocess
, PROCESS_QUERY_INFORMATION
, NULL
);
677 switch (pdb
->priority
)
680 ret
= NORMAL_PRIORITY_CLASS
;
683 ret
= IDLE_PRIORITY_CLASS
;
686 ret
= HIGH_PRIORITY_CLASS
;
689 ret
= REALTIME_PRIORITY_CLASS
;
692 WARN(process
,"Unknown priority %ld\n",pdb
->priority
);
694 K32OBJ_DecCount( &pdb
->header
);
700 /***********************************************************************
701 * GetStdHandle (KERNEL32.276)
703 * FIXME: These should be allocated when a console is created, or inherited
706 HANDLE32 WINAPI
GetStdHandle( DWORD std_handle
)
710 PDB32
*pdb
= PROCESS_Current();
714 case STD_INPUT_HANDLE
:
715 if (pdb
->env_db
->hStdin
) return pdb
->env_db
->hStdin
;
718 case STD_OUTPUT_HANDLE
:
719 if (pdb
->env_db
->hStdout
) return pdb
->env_db
->hStdout
;
722 case STD_ERROR_HANDLE
:
723 if (pdb
->env_db
->hStderr
) return pdb
->env_db
->hStderr
;
727 SetLastError( ERROR_INVALID_PARAMETER
);
728 return INVALID_HANDLE_VALUE32
;
730 hFile
= FILE_DupUnixHandle( fd
);
731 if (hFile
!= HFILE_ERROR32
)
733 FILE_SetFileType( hFile
, FILE_TYPE_CHAR
);
736 case STD_INPUT_HANDLE
: pdb
->env_db
->hStdin
= hFile
; break;
737 case STD_OUTPUT_HANDLE
: pdb
->env_db
->hStdout
= hFile
; break;
738 case STD_ERROR_HANDLE
: pdb
->env_db
->hStderr
= hFile
; break;
745 /***********************************************************************
746 * SetStdHandle (KERNEL32.506)
748 BOOL32 WINAPI
SetStdHandle( DWORD std_handle
, HANDLE32 handle
)
750 PDB32
*pdb
= PROCESS_Current();
751 /* FIXME: should we close the previous handle? */
754 case STD_INPUT_HANDLE
:
755 pdb
->env_db
->hStdin
= handle
;
757 case STD_OUTPUT_HANDLE
:
758 pdb
->env_db
->hStdout
= handle
;
760 case STD_ERROR_HANDLE
:
761 pdb
->env_db
->hStderr
= handle
;
764 SetLastError( ERROR_INVALID_PARAMETER
);
768 /***********************************************************************
769 * GetProcessVersion (KERNEL32)
771 DWORD WINAPI
GetProcessVersion( DWORD processid
)
774 PDB32
*pdb
= PROCESS_IdToPDB( processid
);
777 if (!(pTask
= (TDB
*)GlobalLock16( pdb
->task
))) return 0;
778 return (pTask
->version
&0xff) | (((pTask
->version
>>8) & 0xff)<<16);
781 /***********************************************************************
782 * GetProcessFlags (KERNEL32)
784 DWORD WINAPI
GetProcessFlags( DWORD processid
)
786 PDB32
*pdb
= PROCESS_IdToPDB( processid
);
791 /***********************************************************************
792 * SetProcessWorkingSetSize [KERNEL32.662]
793 * Sets the min/max working set sizes for a specified process.
796 * hProcess [I] Handle to the process of interest
797 * minset [I] Specifies minimum working set size
798 * maxset [I] Specifies maximum working set size
802 BOOL32 WINAPI
SetProcessWorkingSetSize(HANDLE32 hProcess
,DWORD minset
,
805 FIXME(process
,"(0x%08x,%ld,%ld): stub - harmless\n",hProcess
,minset
,maxset
);
806 if(( minset
== -1) && (maxset
== -1)) {
807 /* Trim the working set to zero */
808 /* Swap the process out of physical RAM */
813 /***********************************************************************
814 * GetProcessWorkingSetSize (KERNEL32)
816 BOOL32 WINAPI
GetProcessWorkingSetSize(HANDLE32 hProcess
,LPDWORD minset
,
819 FIXME(process
,"(0x%08x,%p,%p): stub\n",hProcess
,minset
,maxset
);
820 /* 32 MB working set size */
821 if (minset
) *minset
= 32*1024*1024;
822 if (maxset
) *maxset
= 32*1024*1024;
826 /***********************************************************************
827 * SetProcessShutdownParameters (KERNEL32)
829 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
830 * Now tracks changes made (but does not act on these changes)
831 * NOTE: the definition for SHUTDOWN_NORETRY was done on guesswork.
832 * It really shouldn't be here, but I'll move it when it's been checked!
834 #define SHUTDOWN_NORETRY 1
835 extern unsigned int shutdown_noretry
= 0;
836 extern unsigned int shutdown_priority
= 0x280L
;
837 BOOL32 WINAPI
SetProcessShutdownParameters(DWORD level
,DWORD flags
)
839 if (flags
& SHUTDOWN_NORETRY
)
840 shutdown_noretry
= 1;
842 shutdown_noretry
= 0;
843 if (level
> 0x100L
&& level
< 0x3FFL
)
844 shutdown_priority
= level
;
847 ERR(process
,"invalid priority level 0x%08lx\n", level
);
854 /***********************************************************************
855 * GetProcessShutdownParameters (KERNEL32)
858 BOOL32 WINAPI
GetProcessShutdownParameters( LPDWORD lpdwLevel
,
861 (*lpdwLevel
) = shutdown_priority
;
862 (*lpdwFlags
) = (shutdown_noretry
* SHUTDOWN_NORETRY
);
865 /***********************************************************************
866 * SetProcessPriorityBoost (KERNEL32)
868 BOOL32 WINAPI
SetProcessPriorityBoost(HANDLE32 hprocess
,BOOL32 disableboost
)
870 FIXME(process
,"(%d,%d): stub\n",hprocess
,disableboost
);
871 /* Say we can do it. I doubt the program will notice that we don't. */
875 /***********************************************************************
876 * ReadProcessMemory (KERNEL32)
877 * FIXME: check this, if we ever run win32 binaries in different addressspaces
878 * ... and add a sizecheck
880 BOOL32 WINAPI
ReadProcessMemory( HANDLE32 hProcess
, LPCVOID lpBaseAddress
,
881 LPVOID lpBuffer
, DWORD nSize
,
882 LPDWORD lpNumberOfBytesRead
)
884 memcpy(lpBuffer
,lpBaseAddress
,nSize
);
885 if (lpNumberOfBytesRead
) *lpNumberOfBytesRead
= nSize
;
889 /***********************************************************************
890 * WriteProcessMemory (KERNEL32)
891 * FIXME: check this, if we ever run win32 binaries in different addressspaces
892 * ... and add a sizecheck
894 BOOL32 WINAPI
WriteProcessMemory(HANDLE32 hProcess
, LPVOID lpBaseAddress
,
895 LPVOID lpBuffer
, DWORD nSize
,
896 LPDWORD lpNumberOfBytesWritten
)
898 memcpy(lpBaseAddress
,lpBuffer
,nSize
);
899 if (lpNumberOfBytesWritten
) *lpNumberOfBytesWritten
= nSize
;
903 /***********************************************************************
904 * ConvertToGlobalHandle (KERNEL32)
906 HANDLE32 WINAPI
ConvertToGlobalHandle(HANDLE32 hSrc
)
908 HANDLE32 hProcessInit
, hDest
;
910 /* Get a handle to the initial process */
911 hProcessInit
= OpenProcess( PROCESS_ALL_ACCESS
, FALSE
, PROCESS_InitialProcessID
);
913 /* Duplicate the handle into the initial process */
914 if ( !DuplicateHandle( GetCurrentProcess(), hSrc
, hProcessInit
, &hDest
,
915 0, FALSE
, DUPLICATE_SAME_ACCESS
| DUPLICATE_CLOSE_SOURCE
) )
918 /* Close initial process handle */
919 CloseHandle( hProcessInit
);
921 /* Return obfuscated global handle */
922 return hDest
? HANDLE_LOCAL_TO_GLOBAL( hDest
) : 0;
925 /***********************************************************************
926 * RegisterServiceProcess (KERNEL, KERNEL32)
928 * A service process calls this function to ensure that it continues to run
929 * even after a user logged off.
931 DWORD WINAPI
RegisterServiceProcess(DWORD dwProcessId
, DWORD dwType
)
933 /* I don't think that Wine needs to do anything in that function */
934 return 1; /* success */
937 /***********************************************************************
938 * GetExitCodeProcess [KERNEL32.325]
940 * Gets termination status of specified process
947 * Should call SetLastError (but doesn't).
949 BOOL32 WINAPI
GetExitCodeProcess(
950 HANDLE32 hProcess
, /* [I] handle to the process */
951 LPDWORD lpExitCode
) /* [O] address to receive termination status */
955 struct get_process_info_reply info
;
957 if (!(process
= PROCESS_GetPtr( hProcess
, PROCESS_QUERY_INFORMATION
,
960 if (server_handle
!= -1)
962 CLIENT_GetProcessInfo( server_handle
, &info
);
963 if (lpExitCode
) *lpExitCode
= info
.exit_code
;
965 else if (lpExitCode
) *lpExitCode
= process
->exit_code
;
966 K32OBJ_DecCount( &process
->header
);
970 /***********************************************************************
971 * GetProcessHeaps [KERNEL32.376]
973 DWORD WINAPI
GetProcessHeaps(DWORD nrofheaps
,HANDLE32
*heaps
) {
974 FIXME(win32
,"(%ld,%p), incomplete implementation.\n",nrofheaps
,heaps
);
977 heaps
[0] = GetProcessHeap();
978 /* ... probably SystemHeap too ? */
981 /* number of available heaps */
985 /***********************************************************************
986 * PROCESS_SuspendOtherThreads
989 void PROCESS_SuspendOtherThreads(void)
996 pdb
= PROCESS_Current();
997 entry
= pdb
->thread_list
->next
;
1000 if (entry
->thread
!= THREAD_Current() && !THREAD_IsWin16(entry
->thread
))
1002 HANDLE32 handle
= HANDLE_Alloc( PROCESS_Current(),
1003 &entry
->thread
->header
,
1004 THREAD_ALL_ACCESS
, FALSE
, -1 );
1005 SuspendThread(handle
);
1006 CloseHandle(handle
);
1008 if (entry
== pdb
->thread_list
) break;
1009 entry
= entry
->next
;
1015 /***********************************************************************
1016 * PROCESS_ResumeOtherThreads
1019 void PROCESS_ResumeOtherThreads(void)
1022 THREAD_ENTRY
*entry
;
1026 pdb
= PROCESS_Current();
1027 entry
= pdb
->thread_list
->next
;
1030 if (entry
->thread
!= THREAD_Current() && !THREAD_IsWin16(entry
->thread
))
1032 HANDLE32 handle
= HANDLE_Alloc( PROCESS_Current(),
1033 &entry
->thread
->header
,
1034 THREAD_ALL_ACCESS
, FALSE
, -1 );
1035 ResumeThread(handle
);
1036 CloseHandle(handle
);
1038 if (entry
== pdb
->thread_list
) break;
1039 entry
= entry
->next
;