4 * Copyright 1996, 1998 Alexandre Julliard
28 /* The initial process PDB */
29 static PDB initial_pdb
;
31 static PDB
*PROCESS_First
= &initial_pdb
;
33 /***********************************************************************
36 PDB
*PROCESS_Current(void)
38 return THREAD_Current()->process
;
41 /***********************************************************************
44 * FIXME: This works only while running all processes in the same
45 * address space (or, at least, the initial process is mapped
46 * into all address spaces as is KERNEL32 in Windows 95)
49 PDB
*PROCESS_Initial(void)
54 /***********************************************************************
57 * Retrieve information about a process
59 static BOOL
PROCESS_QueryInfo( HANDLE handle
,
60 struct get_process_info_reply
*reply
)
62 struct get_process_info_request req
;
64 CLIENT_SendRequest( REQ_GET_PROCESS_INFO
, -1, 1, &req
, sizeof(req
) );
65 return !CLIENT_WaitSimpleReply( reply
, sizeof(*reply
), NULL
);
68 /***********************************************************************
71 * Check if a handle is to the current process
73 BOOL
PROCESS_IsCurrent( HANDLE handle
)
75 struct get_process_info_reply reply
;
76 return (PROCESS_QueryInfo( handle
, &reply
) &&
77 (reply
.pid
== PROCESS_Current()->server_pid
));
81 /***********************************************************************
84 * Convert a process id to a PDB, making sure it is valid.
86 PDB
*PROCESS_IdToPDB( DWORD id
)
90 if (!id
) return PROCESS_Current();
94 if ((DWORD
)pdb
->server_pid
== id
) return pdb
;
97 SetLastError( ERROR_INVALID_PARAMETER
);
103 /***********************************************************************
106 * Build the env DB for the initial process
108 static BOOL
PROCESS_BuildEnvDB( PDB
*pdb
)
110 /* Allocate the env DB (FIXME: should not be on the system heap) */
112 if (!(pdb
->env_db
= HeapAlloc(SystemHeap
,HEAP_ZERO_MEMORY
,sizeof(ENVDB
))))
114 InitializeCriticalSection( &pdb
->env_db
->section
);
116 /* Allocate startup info */
117 if (!(pdb
->env_db
->startup_info
=
118 HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(STARTUPINFOA
) )))
121 /* Allocate the standard handles */
123 pdb
->env_db
->hStdin
= FILE_DupUnixHandle( 0, GENERIC_READ
);
124 pdb
->env_db
->hStdout
= FILE_DupUnixHandle( 1, GENERIC_WRITE
);
125 pdb
->env_db
->hStderr
= FILE_DupUnixHandle( 2, GENERIC_WRITE
);
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 BOOL
PROCESS_InheritEnvDB( PDB
*pdb
, LPCSTR cmd_line
, LPCSTR env
,
141 BOOL inherit_handles
, STARTUPINFOA
*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(STARTUPINFOA
) )))
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 if (inherit_handles
)
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
;
175 /* else will be done later on in PROCESS_Create */
181 /***********************************************************************
182 * PROCESS_CreateEnvDB
184 * Create the env DB for a newly started process.
186 static BOOL
PROCESS_CreateEnvDB(void)
188 struct init_process_request req
;
189 struct init_process_reply reply
;
190 STARTUPINFOA
*startup
;
192 PDB
*pdb
= PROCESS_Current();
194 /* Retrieve startup info from the server */
197 CLIENT_SendRequest( REQ_INIT_PROCESS
, -1, 1, &req
, sizeof(req
) );
198 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) return FALSE
;
200 /* Allocate the env DB */
202 if (!(env_db
= HeapAlloc( pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(ENVDB
) )))
204 pdb
->env_db
= env_db
;
205 InitializeCriticalSection( &env_db
->section
);
207 /* Allocate and fill the startup info */
208 if (!(startup
= HeapAlloc( pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(STARTUPINFOA
) )))
210 pdb
->env_db
->startup_info
= startup
;
211 startup
->dwFlags
= reply
.start_flags
;
212 pdb
->env_db
->hStdin
= startup
->hStdInput
= reply
.hstdin
;
213 pdb
->env_db
->hStdout
= startup
->hStdOutput
= reply
.hstdout
;
214 pdb
->env_db
->hStderr
= startup
->hStdError
= reply
.hstderr
;
217 /* Copy the parent environment */
219 if (!ENV_InheritEnvironment( pdb
, env
)) return FALSE
;
221 /* Copy the command line */
223 if (!(pdb
->env_db
->cmd_line
= HEAP_strdupA( pdb
->heap
, 0, cmd_line
)))
230 /***********************************************************************
233 * Free a PDB and all associated storage.
235 void PROCESS_FreePDB( PDB
*pdb
)
237 PDB
**pptr
= &PROCESS_First
;
239 ENV_FreeEnvironment( pdb
);
240 while (*pptr
&& (*pptr
!= pdb
)) pptr
= &(*pptr
)->next
;
241 if (*pptr
) *pptr
= pdb
->next
;
242 if (pdb
->heap
&& (pdb
->heap
!= pdb
->system_heap
)) HeapDestroy( pdb
->heap
);
243 HeapFree( SystemHeap
, 0, pdb
);
247 /***********************************************************************
250 * Allocate and fill a PDB structure.
251 * Runs in the context of the parent process.
253 static PDB
*PROCESS_CreatePDB( PDB
*parent
, BOOL inherit
)
255 PDB
*pdb
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(PDB
) );
257 if (!pdb
) return NULL
;
258 pdb
->exit_code
= 0x103; /* STILL_ACTIVE */
260 pdb
->running_threads
= 1;
261 pdb
->ring0_threads
= 1;
262 pdb
->system_heap
= SystemHeap
;
263 pdb
->parent
= parent
;
265 pdb
->priority
= 8; /* Normal */
266 pdb
->heap
= pdb
->system_heap
; /* will be changed later on */
267 pdb
->next
= PROCESS_First
;
273 /***********************************************************************
276 BOOL
PROCESS_Init(void)
281 /* Start the server */
282 server_fd
= CLIENT_InitServer();
284 /* Fill the initial process structure */
285 initial_pdb
.exit_code
= 0x103; /* STILL_ACTIVE */
286 initial_pdb
.threads
= 1;
287 initial_pdb
.running_threads
= 1;
288 initial_pdb
.ring0_threads
= 1;
289 initial_pdb
.group
= &initial_pdb
;
290 initial_pdb
.priority
= 8; /* Normal */
291 initial_pdb
.flags
= PDB32_WIN16_PROC
;
293 /* Initialize virtual memory management */
294 if (!VIRTUAL_Init()) return FALSE
;
296 /* Create the initial thread structure and socket pair */
297 if (!(thdb
= THREAD_CreateInitialThread( &initial_pdb
, server_fd
))) return FALSE
;
299 /* Remember TEB selector of initial process for emergency use */
300 SYSLEVEL_EmergencyTeb
= thdb
->teb_sel
;
302 /* Create the system heap */
303 if (!(SystemHeap
= HeapCreate( HEAP_GROWABLE
, 0x10000, 0 ))) return FALSE
;
304 initial_pdb
.system_heap
= initial_pdb
.heap
= SystemHeap
;
306 /* Create the environment DB of the first process */
307 if (!PROCESS_BuildEnvDB( &initial_pdb
)) return FALSE
;
309 /* Create the SEGPTR heap */
310 if (!(SegptrHeap
= HeapCreate( HEAP_WINE_SEGPTR
, 0, 0 ))) return FALSE
;
312 /* Initialize the first process critical section */
313 InitializeCriticalSection( &initial_pdb
.crit_section
);
319 /***********************************************************************
322 * Startup routine of a new process. Called in the context of the new process.
324 void PROCESS_Start(void)
328 LPTHREAD_START_ROUTINE entry
;
329 THDB
*thdb
= THREAD_Current();
330 PDB
*pdb
= thdb
->process
;
331 TDB
*pTask
= (TDB
*)GlobalLock16( pdb
->task
);
332 NE_MODULE
*pModule
= NE_GetPtr( pTask
->hModule
);
333 OFSTRUCT
*ofs
= (OFSTRUCT
*)((char*)(pModule
) + (pModule
)->fileinfo
);
336 /* Initialize the critical section */
338 InitializeCriticalSection( &pdb
->crit_section
);
340 /* Create the heap */
342 size
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfHeapReserve
;
343 commit
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfHeapCommit
;
344 if (!(pdb
->heap
= HeapCreate( HEAP_GROWABLE
, size
, commit
))) goto error
;
345 pdb
->heap_list
= pdb
->heap
;
347 /* Create the environment db */
349 if (!PROCESS_CreateEnvDB()) goto error
;
351 if (pdb
->env_db
->startup_info
->dwFlags
& STARTF_USESHOWWINDOW
)
352 cmdShow
= pdb
->env_db
->startup_info
->wShowWindow
;
353 if (!TASK_Create( thdb
, pModule
, 0, 0, cmdShow
)) goto error
;
357 /* Map system DLLs into this process (from initial process) */
358 /* FIXME: this is a hack */
359 pdb
->modref_list
= PROCESS_Initial()->modref_list
;
361 /* Create 32-bit MODREF */
362 if (!PE_CreateModule( pModule
->module32
, ofs
, 0, FALSE
)) goto error
;
364 /* Initialize thread-local storage */
368 if (PE_HEADER(pModule
->module32
)->OptionalHeader
.Subsystem
==IMAGE_SUBSYSTEM_WINDOWS_CUI
)
371 /* Now call the entry point */
373 MODULE_InitializeDLLs( 0, DLL_PROCESS_ATTACH
, (LPVOID
)-1 );
374 entry
= (LPTHREAD_START_ROUTINE
)RVA_PTR(pModule
->module32
,
375 OptionalHeader
.AddressOfEntryPoint
);
376 TRACE(relay
, "(entryproc=%p)\n", entry
);
377 ExitProcess( entry(NULL
) );
384 /***********************************************************************
387 * Create a new process database and associated info.
389 PDB
*PROCESS_Create( NE_MODULE
*pModule
, LPCSTR cmd_line
, LPCSTR env
,
390 HINSTANCE16 hInstance
, HINSTANCE16 hPrevInstance
,
391 LPSECURITY_ATTRIBUTES psa
, LPSECURITY_ATTRIBUTES tsa
,
392 BOOL inherit
, STARTUPINFOA
*startup
,
393 PROCESS_INFORMATION
*info
)
397 struct new_process_request req
;
398 struct new_process_reply reply
;
401 PDB
*parent
= PROCESS_Current();
402 PDB
*pdb
= PROCESS_CreatePDB( parent
, inherit
);
404 if (!pdb
) return NULL
;
405 info
->hThread
= info
->hProcess
= INVALID_HANDLE_VALUE
;
407 /* Create the process on the server side */
409 req
.inherit
= (psa
&& (psa
->nLength
>= sizeof(*psa
)) && psa
->bInheritHandle
);
410 req
.inherit_all
= inherit
;
411 req
.start_flags
= startup
->dwFlags
;
412 if (startup
->dwFlags
& STARTF_USESTDHANDLES
)
414 req
.hstdin
= startup
->hStdInput
;
415 req
.hstdout
= startup
->hStdOutput
;
416 req
.hstderr
= startup
->hStdError
;
420 req
.hstdin
= GetStdHandle( STD_INPUT_HANDLE
);
421 req
.hstdout
= GetStdHandle( STD_OUTPUT_HANDLE
);
422 req
.hstderr
= GetStdHandle( STD_ERROR_HANDLE
);
424 CLIENT_SendRequest( REQ_NEW_PROCESS
, -1, 2,
425 &req
, sizeof(req
), cmd_line
, strlen(cmd_line
) + 1 );
426 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) goto error
;
427 pdb
->server_pid
= reply
.pid
;
428 info
->hProcess
= reply
.handle
;
429 info
->dwProcessId
= (DWORD
)pdb
->server_pid
;
431 /* Initialize the critical section */
433 InitializeCriticalSection( &pdb
->crit_section
);
435 /* Create the heap */
437 if (pModule
->module32
)
439 size
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfHeapReserve
;
440 commit
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfHeapCommit
;
446 pdb
->flags
|= PDB32_WIN16_PROC
; /* This is a Win16 process */
448 if (!(pdb
->heap
= HeapCreate( HEAP_GROWABLE
, size
, commit
))) goto error
;
449 pdb
->heap_list
= pdb
->heap
;
451 /* Inherit the env DB from the parent */
453 if (!PROCESS_InheritEnvDB( pdb
, cmd_line
, env
, inherit
, startup
)) goto error
;
455 /* Create the main thread */
457 if (pModule
->module32
)
458 size
= PE_HEADER(pModule
->module32
)->OptionalHeader
.SizeOfStackReserve
;
461 if (!(thdb
= THREAD_Create( pdb
, 0L, size
, hInstance
== 0, tsa
, &server_thandle
)))
463 info
->hThread
= server_thandle
;
464 info
->dwThreadId
= (DWORD
)thdb
->server_tid
;
465 thdb
->startup
= PROCESS_Start
;
467 /* Duplicate the standard handles */
469 if ((!(pdb
->env_db
->startup_info
->dwFlags
& STARTF_USESTDHANDLES
)) && !inherit
)
471 DuplicateHandle( GetCurrentProcess(), pdb
->parent
->env_db
->hStdin
,
472 info
->hProcess
, &pdb
->env_db
->hStdin
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
473 DuplicateHandle( GetCurrentProcess(), pdb
->parent
->env_db
->hStdout
,
474 info
->hProcess
, &pdb
->env_db
->hStdout
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
475 DuplicateHandle( GetCurrentProcess(), pdb
->parent
->env_db
->hStderr
,
476 info
->hProcess
, &pdb
->env_db
->hStderr
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
479 /* Create a Win16 task for this process */
481 if (startup
->dwFlags
& STARTF_USESHOWWINDOW
)
482 cmdShow
= startup
->wShowWindow
;
484 if ( !TASK_Create( thdb
, pModule
, hInstance
, hPrevInstance
, cmdShow
) )
488 /* Map system DLLs into this process (from initial process) */
489 /* FIXME: this is a hack */
490 pdb
->modref_list
= PROCESS_Initial()->modref_list
;
495 TASK_StartTask( pdb
->task
);
500 if (info
->hThread
!= INVALID_HANDLE_VALUE
) CloseHandle( info
->hThread
);
501 if (info
->hProcess
!= INVALID_HANDLE_VALUE
) CloseHandle( info
->hProcess
);
502 PROCESS_FreePDB( pdb
);
507 /***********************************************************************
508 * ExitProcess (KERNEL32.100)
510 void WINAPI
ExitProcess( DWORD status
)
512 MODULE_InitializeDLLs( 0, DLL_PROCESS_DETACH
, NULL
);
514 if ( THREAD_IsWin16( THREAD_Current() ) )
515 TASK_KillCurrentTask( status
);
518 TerminateProcess( GetCurrentProcess(), status
);
522 /******************************************************************************
523 * TerminateProcess (KERNEL32.684)
525 BOOL WINAPI
TerminateProcess( HANDLE handle
, DWORD exit_code
)
527 struct terminate_process_request req
;
529 req
.exit_code
= exit_code
;
530 CLIENT_SendRequest( REQ_TERMINATE_PROCESS
, -1, 1, &req
, sizeof(req
) );
531 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
534 /***********************************************************************
535 * GetCurrentProcess (KERNEL32.198)
537 HANDLE WINAPI
GetCurrentProcess(void)
539 return CURRENT_PROCESS_PSEUDOHANDLE
;
543 /*********************************************************************
544 * OpenProcess (KERNEL32.543)
546 HANDLE WINAPI
OpenProcess( DWORD access
, BOOL inherit
, DWORD id
)
548 struct open_process_request req
;
549 struct open_process_reply reply
;
551 req
.pid
= (void *)id
;
553 req
.inherit
= inherit
;
554 CLIENT_SendRequest( REQ_OPEN_PROCESS
, -1, 1, &req
, sizeof(req
) );
555 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) return 0;
560 /***********************************************************************
561 * GetCurrentProcessId (KERNEL32.199)
563 DWORD WINAPI
GetCurrentProcessId(void)
565 return (DWORD
)PROCESS_Current()->server_pid
;
569 /***********************************************************************
570 * GetProcessHeap (KERNEL32.259)
572 HANDLE WINAPI
GetProcessHeap(void)
574 PDB
*pdb
= PROCESS_Current();
575 return pdb
->heap
? pdb
->heap
: SystemHeap
;
579 /***********************************************************************
580 * GetThreadLocale (KERNEL32.295)
582 LCID WINAPI
GetThreadLocale(void)
584 return PROCESS_Current()->locale
;
588 /***********************************************************************
589 * SetPriorityClass (KERNEL32.503)
591 BOOL WINAPI
SetPriorityClass( HANDLE hprocess
, DWORD priorityclass
)
593 struct set_process_info_request req
;
594 req
.handle
= hprocess
;
595 req
.priority
= priorityclass
;
596 req
.mask
= SET_PROCESS_INFO_PRIORITY
;
597 CLIENT_SendRequest( REQ_SET_PROCESS_INFO
, -1, 1, &req
, sizeof(req
) );
598 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
602 /***********************************************************************
603 * GetPriorityClass (KERNEL32.250)
605 DWORD WINAPI
GetPriorityClass(HANDLE hprocess
)
607 struct get_process_info_reply reply
;
608 if (!PROCESS_QueryInfo( hprocess
, &reply
)) return 0;
609 return reply
.priority
;
613 /***********************************************************************
614 * SetProcessAffinityMask (KERNEL32.662)
616 BOOL WINAPI
SetProcessAffinityMask( HANDLE hProcess
, DWORD affmask
)
618 struct set_process_info_request req
;
619 req
.handle
= hProcess
;
620 req
.affinity
= affmask
;
621 req
.mask
= SET_PROCESS_INFO_AFFINITY
;
622 CLIENT_SendRequest( REQ_SET_PROCESS_INFO
, -1, 1, &req
, sizeof(req
) );
623 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
626 /**********************************************************************
627 * GetProcessAffinityMask (KERNEL32.373)
629 BOOL WINAPI
GetProcessAffinityMask( HANDLE hProcess
,
630 LPDWORD lpProcessAffinityMask
,
631 LPDWORD lpSystemAffinityMask
)
633 struct get_process_info_reply reply
;
634 if (!PROCESS_QueryInfo( hProcess
, &reply
)) return FALSE
;
635 if (lpProcessAffinityMask
) *lpProcessAffinityMask
= reply
.process_affinity
;
636 if (lpSystemAffinityMask
) *lpSystemAffinityMask
= reply
.system_affinity
;
641 /***********************************************************************
642 * GetStdHandle (KERNEL32.276)
644 HANDLE WINAPI
GetStdHandle( DWORD std_handle
)
646 PDB
*pdb
= PROCESS_Current();
650 case STD_INPUT_HANDLE
: return pdb
->env_db
->hStdin
;
651 case STD_OUTPUT_HANDLE
: return pdb
->env_db
->hStdout
;
652 case STD_ERROR_HANDLE
: return pdb
->env_db
->hStderr
;
654 SetLastError( ERROR_INVALID_PARAMETER
);
655 return INVALID_HANDLE_VALUE
;
659 /***********************************************************************
660 * SetStdHandle (KERNEL32.506)
662 BOOL WINAPI
SetStdHandle( DWORD std_handle
, HANDLE handle
)
664 PDB
*pdb
= PROCESS_Current();
665 /* FIXME: should we close the previous handle? */
668 case STD_INPUT_HANDLE
:
669 pdb
->env_db
->hStdin
= handle
;
671 case STD_OUTPUT_HANDLE
:
672 pdb
->env_db
->hStdout
= handle
;
674 case STD_ERROR_HANDLE
:
675 pdb
->env_db
->hStderr
= handle
;
678 SetLastError( ERROR_INVALID_PARAMETER
);
682 /***********************************************************************
683 * GetProcessVersion (KERNEL32)
685 DWORD WINAPI
GetProcessVersion( DWORD processid
)
688 PDB
*pdb
= PROCESS_IdToPDB( processid
);
691 if (!(pTask
= (TDB
*)GlobalLock16( pdb
->task
))) return 0;
692 return (pTask
->version
&0xff) | (((pTask
->version
>>8) & 0xff)<<16);
695 /***********************************************************************
696 * GetProcessFlags (KERNEL32)
698 DWORD WINAPI
GetProcessFlags( DWORD processid
)
700 PDB
*pdb
= PROCESS_IdToPDB( processid
);
705 /***********************************************************************
706 * SetProcessWorkingSetSize [KERNEL32.662]
707 * Sets the min/max working set sizes for a specified process.
710 * hProcess [I] Handle to the process of interest
711 * minset [I] Specifies minimum working set size
712 * maxset [I] Specifies maximum working set size
716 BOOL WINAPI
SetProcessWorkingSetSize(HANDLE hProcess
,DWORD minset
,
719 FIXME(process
,"(0x%08x,%ld,%ld): stub - harmless\n",hProcess
,minset
,maxset
);
720 if(( minset
== -1) && (maxset
== -1)) {
721 /* Trim the working set to zero */
722 /* Swap the process out of physical RAM */
727 /***********************************************************************
728 * GetProcessWorkingSetSize (KERNEL32)
730 BOOL WINAPI
GetProcessWorkingSetSize(HANDLE hProcess
,LPDWORD minset
,
733 FIXME(process
,"(0x%08x,%p,%p): stub\n",hProcess
,minset
,maxset
);
734 /* 32 MB working set size */
735 if (minset
) *minset
= 32*1024*1024;
736 if (maxset
) *maxset
= 32*1024*1024;
740 /***********************************************************************
741 * SetProcessShutdownParameters (KERNEL32)
743 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
744 * Now tracks changes made (but does not act on these changes)
745 * NOTE: the definition for SHUTDOWN_NORETRY was done on guesswork.
746 * It really shouldn't be here, but I'll move it when it's been checked!
748 #define SHUTDOWN_NORETRY 1
749 static unsigned int shutdown_noretry
= 0;
750 static unsigned int shutdown_priority
= 0x280L
;
751 BOOL WINAPI
SetProcessShutdownParameters(DWORD level
,DWORD flags
)
753 if (flags
& SHUTDOWN_NORETRY
)
754 shutdown_noretry
= 1;
756 shutdown_noretry
= 0;
757 if (level
> 0x100L
&& level
< 0x3FFL
)
758 shutdown_priority
= level
;
761 ERR(process
,"invalid priority level 0x%08lx\n", level
);
768 /***********************************************************************
769 * GetProcessShutdownParameters (KERNEL32)
772 BOOL WINAPI
GetProcessShutdownParameters( LPDWORD lpdwLevel
,
775 (*lpdwLevel
) = shutdown_priority
;
776 (*lpdwFlags
) = (shutdown_noretry
* SHUTDOWN_NORETRY
);
779 /***********************************************************************
780 * SetProcessPriorityBoost (KERNEL32)
782 BOOL WINAPI
SetProcessPriorityBoost(HANDLE hprocess
,BOOL disableboost
)
784 FIXME(process
,"(%d,%d): stub\n",hprocess
,disableboost
);
785 /* Say we can do it. I doubt the program will notice that we don't. */
789 /***********************************************************************
790 * ReadProcessMemory (KERNEL32)
791 * FIXME: check this, if we ever run win32 binaries in different addressspaces
792 * ... and add a sizecheck
794 BOOL WINAPI
ReadProcessMemory( HANDLE hProcess
, LPCVOID lpBaseAddress
,
795 LPVOID lpBuffer
, DWORD nSize
,
796 LPDWORD lpNumberOfBytesRead
)
798 memcpy(lpBuffer
,lpBaseAddress
,nSize
);
799 if (lpNumberOfBytesRead
) *lpNumberOfBytesRead
= nSize
;
803 /***********************************************************************
804 * WriteProcessMemory (KERNEL32)
805 * FIXME: check this, if we ever run win32 binaries in different addressspaces
806 * ... and add a sizecheck
808 BOOL WINAPI
WriteProcessMemory(HANDLE hProcess
, LPVOID lpBaseAddress
,
809 LPVOID lpBuffer
, DWORD nSize
,
810 LPDWORD lpNumberOfBytesWritten
)
812 memcpy(lpBaseAddress
,lpBuffer
,nSize
);
813 if (lpNumberOfBytesWritten
) *lpNumberOfBytesWritten
= nSize
;
817 /***********************************************************************
818 * RegisterServiceProcess (KERNEL, KERNEL32)
820 * A service process calls this function to ensure that it continues to run
821 * even after a user logged off.
823 DWORD WINAPI
RegisterServiceProcess(DWORD dwProcessId
, DWORD dwType
)
825 /* I don't think that Wine needs to do anything in that function */
826 return 1; /* success */
829 /***********************************************************************
830 * GetExitCodeProcess [KERNEL32.325]
832 * Gets termination status of specified process
838 BOOL WINAPI
GetExitCodeProcess(
839 HANDLE hProcess
, /* [I] handle to the process */
840 LPDWORD lpExitCode
) /* [O] address to receive termination status */
842 struct get_process_info_reply reply
;
843 if (!PROCESS_QueryInfo( hProcess
, &reply
)) return FALSE
;
844 if (lpExitCode
) *lpExitCode
= reply
.exit_code
;
849 /***********************************************************************
850 * GetProcessHeaps [KERNEL32.376]
852 DWORD WINAPI
GetProcessHeaps(DWORD nrofheaps
,HANDLE
*heaps
) {
853 FIXME(win32
,"(%ld,%p), incomplete implementation.\n",nrofheaps
,heaps
);
856 heaps
[0] = GetProcessHeap();
857 /* ... probably SystemHeap too ? */
860 /* number of available heaps */
864 /***********************************************************************
865 * PROCESS_SuspendOtherThreads
868 void PROCESS_SuspendOtherThreads(void)
876 pdb
= PROCESS_Current();
877 entry
= pdb
->thread_list
->next
;
880 if (entry
->thread
!= THREAD_Current() && !THREAD_IsWin16(entry
->thread
))
882 HANDLE handle
= HANDLE_Alloc( PROCESS_Current(),
883 &entry
->thread
->header
,
884 THREAD_ALL_ACCESS
, FALSE
, -1 );
885 SuspendThread(handle
);
888 if (entry
== pdb
->thread_list
) break;
896 /***********************************************************************
897 * PROCESS_ResumeOtherThreads
900 void PROCESS_ResumeOtherThreads(void)
908 pdb
= PROCESS_Current();
909 entry
= pdb
->thread_list
->next
;
912 if (entry
->thread
!= THREAD_Current() && !THREAD_IsWin16(entry
->thread
))
914 HANDLE handle
= HANDLE_Alloc( PROCESS_Current(),
915 &entry
->thread
->header
,
916 THREAD_ALL_ACCESS
, FALSE
, -1 );
917 ResumeThread(handle
);
920 if (entry
== pdb
->thread_list
) break;