4 * Copyright 1996, 1998 Alexandre Julliard
11 #include "wine/winbase16.h"
27 #include "debugtools.h"
29 DECLARE_DEBUG_CHANNEL(process
)
30 DECLARE_DEBUG_CHANNEL(relay
)
31 DECLARE_DEBUG_CHANNEL(win32
)
34 /* The initial process PDB */
35 static PDB initial_pdb
;
37 static PDB
*PROCESS_First
= &initial_pdb
;
39 /* Pointer to debugger callback routine */
40 void (*TASK_AddTaskEntryBreakpoint
)( HTASK16 hTask
) = NULL
;
43 /***********************************************************************
46 void PROCESS_WalkProcess(void)
52 MESSAGE( " pid PDB #th modref module \n" );
55 if (pdb
== &initial_pdb
)
58 name
= (pdb
->exe_modref
) ? pdb
->exe_modref
->shortname
: "";
60 MESSAGE( " %8p %8p %5d %8p %s\n", pdb
->server_pid
, pdb
,
61 pdb
->threads
, pdb
->exe_modref
, name
);
67 /***********************************************************************
70 * FIXME: This works only while running all processes in the same
71 * address space (or, at least, the initial process is mapped
72 * into all address spaces as is KERNEL32 in Windows 95)
75 PDB
*PROCESS_Initial(void)
80 /***********************************************************************
83 * Check if a handle is to the current process
85 BOOL
PROCESS_IsCurrent( HANDLE handle
)
87 struct get_process_info_request
*req
= get_req_buffer();
89 return (!server_call( REQ_GET_PROCESS_INFO
) &&
90 (req
->pid
== PROCESS_Current()->server_pid
));
94 /***********************************************************************
97 * Convert a process id to a PDB, making sure it is valid.
99 PDB
*PROCESS_IdToPDB( DWORD id
)
103 if (!id
) return PROCESS_Current();
107 if ((DWORD
)pdb
->server_pid
== id
) return pdb
;
110 SetLastError( ERROR_INVALID_PARAMETER
);
115 /***********************************************************************
116 * PROCESS_CallUserSignalProc
118 * FIXME: Some of the signals aren't sent correctly!
120 * The exact meaning of the USER signals is undocumented, but this
121 * should cover the basic idea:
123 * USIG_DLL_UNLOAD_WIN16
124 * This is sent when a 16-bit module is unloaded.
126 * USIG_DLL_UNLOAD_WIN32
127 * This is sent when a 32-bit module is unloaded.
129 * USIG_DLL_UNLOAD_ORPHANS
130 * This is sent after the last Win3.1 module is unloaded,
131 * to allow removal of orphaned menus.
133 * USIG_FAULT_DIALOG_PUSH
134 * USIG_FAULT_DIALOG_POP
135 * These are called to allow USER to prepare for displaying a
136 * fault dialog, even though the fault might have happened while
137 * inside a USER critical section.
140 * This is called from the context of a new thread, as soon as it
141 * has started to run.
144 * This is called, still in its context, just before a thread is
145 * about to terminate.
147 * USIG_PROCESS_CREATE
148 * This is called, in the parent process context, after a new process
152 * This is called in the new process context, just after the main thread
153 * has started execution (after the main thread's USIG_THREAD_INIT has
156 * USIG_PROCESS_LOADED
157 * This is called after the executable file has been loaded into the
158 * new process context.
160 * USIG_PROCESS_RUNNING
161 * This is called immediately before the main entry point is called.
164 * This is called in the context of a process that is about to
165 * terminate (but before the last thread's USIG_THREAD_EXIT has
168 * USIG_PROCESS_DESTROY
169 * This is called after a process has terminated.
172 * The meaning of the dwFlags bits is as follows:
175 * Current process is 32-bit.
178 * Current process is a (Win32) GUI process.
180 * USIG_FLAGS_FEEDBACK
181 * Current process needs 'feedback' (determined from the STARTUPINFO
182 * flags STARTF_FORCEONFEEDBACK / STARTF_FORCEOFFFEEDBACK).
185 * The signal is being sent due to a fault.
187 static void PROCESS_CallUserSignalProcHelper( UINT uCode
, DWORD dwThreadOrProcessId
,
188 HMODULE hModule
, DWORD flags
, DWORD startup_flags
)
192 /* Determine dwFlags */
194 if ( !(flags
& PDB32_WIN16_PROC
) ) dwFlags
|= USIG_FLAGS_WIN32
;
196 if ( !(flags
& PDB32_CONSOLE_PROC
) ) dwFlags
|= USIG_FLAGS_GUI
;
198 if ( dwFlags
& USIG_FLAGS_GUI
)
200 /* Feedback defaults to ON */
201 if ( !(startup_flags
& STARTF_FORCEOFFFEEDBACK
) )
202 dwFlags
|= USIG_FLAGS_FEEDBACK
;
206 /* Feedback defaults to OFF */
207 if (startup_flags
& STARTF_FORCEONFEEDBACK
)
208 dwFlags
|= USIG_FLAGS_FEEDBACK
;
211 /* Convert module handle to 16-bit */
213 if ( HIWORD( hModule
) )
214 hModule
= MapHModuleLS( hModule
);
216 /* Call USER signal proc */
218 if ( Callout
.UserSignalProc
)
219 Callout
.UserSignalProc( uCode
, dwThreadOrProcessId
, dwFlags
, hModule
);
222 /* Call USER signal proc for the current thread/process */
223 void PROCESS_CallUserSignalProc( UINT uCode
, HMODULE hModule
)
225 DWORD dwThreadOrProcessId
;
227 /* Get thread or process ID */
228 if ( uCode
== USIG_THREAD_INIT
|| uCode
== USIG_THREAD_EXIT
)
229 dwThreadOrProcessId
= GetCurrentThreadId();
231 dwThreadOrProcessId
= GetCurrentProcessId();
233 PROCESS_CallUserSignalProcHelper( uCode
, dwThreadOrProcessId
, hModule
,
234 PROCESS_Current()->flags
,
235 PROCESS_Current()->env_db
->startup_info
->dwFlags
);
239 /***********************************************************************
240 * PROCESS_CreateEnvDB
242 * Create the env DB for a newly started process.
244 static BOOL
PROCESS_CreateEnvDB(void)
246 struct init_process_request
*req
= get_req_buffer();
247 STARTUPINFOA
*startup
;
250 PDB
*pdb
= PROCESS_Current();
252 /* Allocate the env DB */
254 if (!(env_db
= HeapAlloc( pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(ENVDB
) )))
256 pdb
->env_db
= env_db
;
257 InitializeCriticalSection( &env_db
->section
);
259 /* Allocate and fill the startup info */
260 if (!(startup
= HeapAlloc( pdb
->heap
, HEAP_ZERO_MEMORY
, sizeof(STARTUPINFOA
) )))
262 env_db
->startup_info
= startup
;
264 /* Retrieve startup info from the server */
266 if (server_call( REQ_INIT_PROCESS
)) return FALSE
;
267 startup
->dwFlags
= req
->start_flags
;
268 startup
->wShowWindow
= req
->cmd_show
;
269 env_db
->hStdin
= startup
->hStdInput
= req
->hstdin
;
270 env_db
->hStdout
= startup
->hStdOutput
= req
->hstdout
;
271 env_db
->hStderr
= startup
->hStdError
= req
->hstderr
;
272 lstrcpynA( cmd_line
, req
->cmdline
, sizeof(cmd_line
) );
274 /* Copy the parent environment */
276 if (!ENV_InheritEnvironment( pdb
, req
->env_ptr
)) return FALSE
;
278 /* Copy the command line */
280 if (!(pdb
->env_db
->cmd_line
= HEAP_strdupA( pdb
->heap
, 0, cmd_line
)))
287 /***********************************************************************
290 * Free a PDB and all associated storage.
292 void PROCESS_FreePDB( PDB
*pdb
)
294 PDB
**pptr
= &PROCESS_First
;
296 ENV_FreeEnvironment( pdb
);
297 while (*pptr
&& (*pptr
!= pdb
)) pptr
= &(*pptr
)->next
;
298 if (*pptr
) *pptr
= pdb
->next
;
299 if (pdb
->heap
&& (pdb
->heap
!= pdb
->system_heap
)) HeapDestroy( pdb
->heap
);
300 HeapFree( SystemHeap
, 0, pdb
);
304 /***********************************************************************
307 * Allocate and fill a PDB structure.
308 * Runs in the context of the parent process.
310 static PDB
*PROCESS_CreatePDB( PDB
*parent
, BOOL inherit
)
312 PDB
*pdb
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(PDB
) );
314 if (!pdb
) return NULL
;
315 pdb
->exit_code
= 0x103; /* STILL_ACTIVE */
317 pdb
->running_threads
= 1;
318 pdb
->ring0_threads
= 1;
319 pdb
->system_heap
= SystemHeap
;
320 pdb
->parent
= parent
;
322 pdb
->priority
= 8; /* Normal */
323 pdb
->heap
= pdb
->system_heap
; /* will be changed later on */
324 pdb
->next
= PROCESS_First
;
325 pdb
->winver
= 0xffff; /* to be determined */
331 /***********************************************************************
334 BOOL
PROCESS_Init(void)
339 /* Start the server */
340 server_fd
= CLIENT_InitServer();
342 /* Fill the initial process structure */
343 initial_pdb
.exit_code
= 0x103; /* STILL_ACTIVE */
344 initial_pdb
.threads
= 1;
345 initial_pdb
.running_threads
= 1;
346 initial_pdb
.ring0_threads
= 1;
347 initial_pdb
.group
= &initial_pdb
;
348 initial_pdb
.priority
= 8; /* Normal */
349 initial_pdb
.flags
= PDB32_WIN16_PROC
;
350 initial_pdb
.winver
= 0xffff; /* to be determined */
352 /* Initialize virtual memory management */
353 if (!VIRTUAL_Init()) return FALSE
;
355 /* Create the initial thread structure and socket pair */
356 if (!(teb
= THREAD_CreateInitialThread( &initial_pdb
, server_fd
))) return FALSE
;
358 /* Remember TEB selector of initial process for emergency use */
359 SYSLEVEL_EmergencyTeb
= teb
->teb_sel
;
361 /* Create the system heap */
362 if (!(SystemHeap
= HeapCreate( HEAP_GROWABLE
, 0x10000, 0 ))) return FALSE
;
363 initial_pdb
.system_heap
= initial_pdb
.heap
= SystemHeap
;
365 /* Create the environment DB of the first process */
366 if (!PROCESS_CreateEnvDB()) return FALSE
;
368 /* Create the SEGPTR heap */
369 if (!(SegptrHeap
= HeapCreate( HEAP_WINE_SEGPTR
, 0, 0 ))) return FALSE
;
371 /* Initialize the first process critical section */
372 InitializeCriticalSection( &initial_pdb
.crit_section
);
378 /***********************************************************************
381 * Startup routine of a new process. Called in the context of the new process.
383 void PROCESS_Start(void)
386 LPTHREAD_START_ROUTINE entry
= NULL
;
387 PDB
*pdb
= PROCESS_Current();
388 NE_MODULE
*pModule
= NE_GetPtr( pdb
->module
);
389 OFSTRUCT
*ofs
= (OFSTRUCT
*)((char*)(pModule
) + (pModule
)->fileinfo
);
390 IMAGE_OPTIONAL_HEADER
*header
= !pModule
->module32
? NULL
:
391 &PE_HEADER(pModule
->module32
)->OptionalHeader
;
393 /* Get process type */
394 enum { PROC_DOS
, PROC_WIN16
, PROC_WIN32
} type
;
395 if ( pdb
->flags
& PDB32_DOS_PROC
)
397 else if ( pdb
->flags
& PDB32_WIN16_PROC
)
402 /* Initialize the critical section */
403 InitializeCriticalSection( &pdb
->crit_section
);
405 /* Create the heap */
406 if (!(pdb
->heap
= HeapCreate( HEAP_GROWABLE
,
407 header
? header
->SizeOfHeapReserve
: 0x10000,
408 header
? header
->SizeOfHeapCommit
: 0 )))
410 pdb
->heap_list
= pdb
->heap
;
412 /* Create the environment db */
413 if (!PROCESS_CreateEnvDB()) goto error
;
415 /* Create a task for this process */
416 if (pdb
->env_db
->startup_info
->dwFlags
& STARTF_USESHOWWINDOW
)
417 cmdShow
= pdb
->env_db
->startup_info
->wShowWindow
;
418 if (!TASK_Create( pModule
, cmdShow
))
421 /* Perform Win16 specific process initialization */
422 if ( type
== PROC_WIN16
)
423 if ( !NE_InitProcess( pModule
) )
426 /* Note: The USIG_PROCESS_CREATE signal is supposed to be sent in the
427 * context of the parent process. Actually, the USER signal proc
428 * doesn't really care about that, but it *does* require that the
429 * startup parameters are correctly set up, so that GetProcessDword
430 * works. Furthermore, before calling the USER signal proc the
431 * 16-bit stack must be set up, which it is only after TASK_Create
432 * in the case of a 16-bit process. Thus, we send the signal here.
435 /* Load USER32.DLL before calling UserSignalProc (relay debugging!) */
436 LoadLibraryA( "USER32.DLL" );
438 PROCESS_CallUserSignalProc( USIG_PROCESS_CREATE
, 0 );
440 PROCESS_CallUserSignalProc( USIG_THREAD_INIT
, 0 ); /* for initial thread */
442 PROCESS_CallUserSignalProc( USIG_PROCESS_INIT
, 0 );
444 /* Signal the parent process to continue */
445 SetEvent( pdb
->load_done_evt
);
446 CloseHandle( pdb
->load_done_evt
);
447 pdb
->load_done_evt
= INVALID_HANDLE_VALUE
;
449 /* Perform Win32 specific process initialization */
450 if ( type
== PROC_WIN32
)
452 /* Send the debug event to the debugger */
453 entry
= (LPTHREAD_START_ROUTINE
)RVA_PTR(pModule
->module32
,
454 OptionalHeader
.AddressOfEntryPoint
);
455 if (pdb
->flags
& PDB32_DEBUGGED
)
456 DEBUG_SendCreateProcessEvent( -1 /*FIXME*/, pModule
->module32
, entry
);
458 /* Create 32-bit MODREF */
459 if (!PE_CreateModule( pModule
->module32
, ofs
, 0, FALSE
)) goto error
;
461 /* Increment EXE refcount */
462 assert( pdb
->exe_modref
);
463 pdb
->exe_modref
->refCount
++;
465 /* Initialize thread-local storage */
469 PROCESS_CallUserSignalProc( USIG_PROCESS_LOADED
, 0 ); /* FIXME: correct location? */
471 if ( (pdb
->flags
& PDB32_CONSOLE_PROC
) || (pdb
->flags
& PDB32_DOS_PROC
) )
474 if ( type
== PROC_WIN32
)
476 EnterCriticalSection( &pdb
->crit_section
);
477 MODULE_DllProcessAttach( pdb
->exe_modref
, (LPVOID
)1 );
478 LeaveCriticalSection( &pdb
->crit_section
);
481 /* If requested, add entry point breakpoint */
482 if ( TASK_AddTaskEntryBreakpoint
)
483 TASK_AddTaskEntryBreakpoint( pdb
->task
);
485 /* Now call the entry point */
486 PROCESS_CallUserSignalProc( USIG_PROCESS_RUNNING
, 0 );
491 TRACE_(relay
)( "Starting DOS process\n" );
493 ERR_(relay
)( "DOSVM_Enter returned; should not happen!\n" );
497 TRACE_(relay
)( "Starting Win16 process\n" );
499 ERR_(relay
)( "TASK_CallToStart returned; should not happen!\n" );
503 TRACE_(relay
)( "Starting Win32 process (entryproc=%p)\n", entry
);
504 ExitProcess( entry(NULL
) );
508 ExitProcess( GetLastError() );
512 /***********************************************************************
515 * Create a new process database and associated info.
517 PDB
*PROCESS_Create( NE_MODULE
*pModule
, LPCSTR cmd_line
, LPCSTR env
,
518 LPSECURITY_ATTRIBUTES psa
, LPSECURITY_ATTRIBUTES tsa
,
519 BOOL inherit
, DWORD flags
, STARTUPINFOA
*startup
,
520 PROCESS_INFORMATION
*info
)
522 HANDLE handles
[2], load_done_evt
= INVALID_HANDLE_VALUE
;
523 DWORD exitcode
, size
;
526 struct new_process_request
*req
= get_req_buffer();
528 PDB
*parent
= PROCESS_Current();
529 PDB
*pdb
= PROCESS_CreatePDB( parent
, inherit
);
531 if (!pdb
) return NULL
;
532 info
->hThread
= info
->hProcess
= INVALID_HANDLE_VALUE
;
534 /* Create the process on the server side */
536 req
->inherit
= (psa
&& (psa
->nLength
>= sizeof(*psa
)) && psa
->bInheritHandle
);
537 req
->inherit_all
= inherit
;
538 req
->create_flags
= flags
;
539 req
->start_flags
= startup
->dwFlags
;
540 if (startup
->dwFlags
& STARTF_USESTDHANDLES
)
542 req
->hstdin
= startup
->hStdInput
;
543 req
->hstdout
= startup
->hStdOutput
;
544 req
->hstderr
= startup
->hStdError
;
548 req
->hstdin
= GetStdHandle( STD_INPUT_HANDLE
);
549 req
->hstdout
= GetStdHandle( STD_OUTPUT_HANDLE
);
550 req
->hstderr
= GetStdHandle( STD_ERROR_HANDLE
);
552 req
->cmd_show
= startup
->wShowWindow
;
553 req
->env_ptr
= (void*)env
; /* FIXME: hack */
554 lstrcpynA( req
->cmdline
, cmd_line
, server_remaining(req
->cmdline
) );
555 if (server_call( REQ_NEW_PROCESS
)) goto error
;
556 pdb
->server_pid
= req
->pid
;
557 info
->hProcess
= req
->handle
;
558 info
->dwProcessId
= (DWORD
)pdb
->server_pid
;
560 if ((flags
& DEBUG_PROCESS
) ||
561 ((parent
->flags
& PDB32_DEBUGGED
) && !(flags
& DEBUG_ONLY_THIS_PROCESS
)))
562 pdb
->flags
|= PDB32_DEBUGGED
;
564 if (pModule
->module32
) /* Win32 process */
566 IMAGE_OPTIONAL_HEADER
*header
= &PE_HEADER(pModule
->module32
)->OptionalHeader
;
567 size
= header
->SizeOfStackReserve
;
568 if (header
->Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_CUI
)
569 pdb
->flags
|= PDB32_CONSOLE_PROC
;
570 alloc_stack16
= TRUE
;
572 else if (!pModule
->dos_image
) /* Win16 process */
574 alloc_stack16
= FALSE
;
576 pdb
->flags
|= PDB32_WIN16_PROC
;
578 else /* DOS process */
580 alloc_stack16
= FALSE
;
582 pdb
->flags
|= PDB32_DOS_PROC
;
585 /* Create the main thread */
587 if (!(teb
= THREAD_Create( pdb
, 0L, size
, alloc_stack16
, tsa
, &server_thandle
)))
589 info
->hThread
= server_thandle
;
590 info
->dwThreadId
= (DWORD
)teb
->tid
;
591 teb
->startup
= PROCESS_Start
;
593 /* Create the load-done event */
594 load_done_evt
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
595 DuplicateHandle( GetCurrentProcess(), load_done_evt
,
596 info
->hProcess
, &pdb
->load_done_evt
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
598 /* Pass module to new process (FIXME: hack) */
599 pdb
->module
= pModule
->self
;
600 SYSDEPS_SpawnThread( teb
);
602 /* Wait until process is initialized (or initialization failed) */
603 handles
[0] = info
->hProcess
;
604 handles
[1] = load_done_evt
;
606 switch ( WaitForMultipleObjects( 2, handles
, FALSE
, INFINITE
) )
609 ERR_(process
)( "WaitForMultipleObjects failed\n" );
613 /* Child initialization code returns error condition as exitcode */
614 if ( GetExitCodeProcess( info
->hProcess
, &exitcode
) )
615 SetLastError( exitcode
);
619 /* Get 16-bit task up and running */
620 if ( pdb
->flags
& PDB32_WIN16_PROC
)
622 /* Post event to start the task */
623 PostEvent16( pdb
->task
);
625 /* If we ourselves are a 16-bit task, we Yield() directly. */
626 if ( parent
->flags
& PDB32_WIN16_PROC
)
632 CloseHandle( load_done_evt
);
633 load_done_evt
= INVALID_HANDLE_VALUE
;
638 if (load_done_evt
!= INVALID_HANDLE_VALUE
) CloseHandle( load_done_evt
);
639 if (info
->hThread
!= INVALID_HANDLE_VALUE
) CloseHandle( info
->hThread
);
640 if (info
->hProcess
!= INVALID_HANDLE_VALUE
) CloseHandle( info
->hProcess
);
641 PROCESS_FreePDB( pdb
);
646 /***********************************************************************
647 * ExitProcess (KERNEL32.100)
649 void WINAPI
ExitProcess( DWORD status
)
651 EnterCriticalSection( &PROCESS_Current()->crit_section
);
652 MODULE_DllProcessDetach( TRUE
, (LPVOID
)1 );
653 LeaveCriticalSection( &PROCESS_Current()->crit_section
);
656 TerminateProcess( GetCurrentProcess(), status
);
659 /***********************************************************************
660 * ExitProcess16 (KERNEL.466)
662 void WINAPI
ExitProcess16( WORD status
)
664 SYSLEVEL_ReleaseWin16Lock();
665 ExitProcess( status
);
668 /******************************************************************************
669 * TerminateProcess (KERNEL32.684)
671 BOOL WINAPI
TerminateProcess( HANDLE handle
, DWORD exit_code
)
673 struct terminate_process_request
*req
= get_req_buffer();
674 req
->handle
= handle
;
675 req
->exit_code
= exit_code
;
676 return !server_call( REQ_TERMINATE_PROCESS
);
680 /***********************************************************************
681 * GetProcessDword (KERNEL32.18) (KERNEL.485)
682 * 'Of course you cannot directly access Windows internal structures'
684 DWORD WINAPI
GetProcessDword( DWORD dwProcessID
, INT offset
)
686 PDB
*process
= PROCESS_IdToPDB( dwProcessID
);
690 TRACE_(win32
)("(%ld, %d)\n", dwProcessID
, offset
);
691 if ( !process
) return 0;
695 case GPD_APP_COMPAT_FLAGS
:
696 pTask
= (TDB
*)GlobalLock16( process
->task
);
697 return pTask
? pTask
->compat_flags
: 0;
699 case GPD_LOAD_DONE_EVENT
:
700 return process
->load_done_evt
;
702 case GPD_HINSTANCE16
:
703 pTask
= (TDB
*)GlobalLock16( process
->task
);
704 return pTask
? pTask
->hInstance
: 0;
706 case GPD_WINDOWS_VERSION
:
707 pTask
= (TDB
*)GlobalLock16( process
->task
);
708 return pTask
? pTask
->version
: 0;
711 if ( process
!= PROCESS_Current() ) return 0;
712 return (DWORD
)NtCurrentTeb() - 0x10 /* FIXME */;
715 return (DWORD
)process
;
717 case GPD_STARTF_SHELLDATA
: /* return stdoutput handle from startupinfo ??? */
718 return process
->env_db
->startup_info
->hStdOutput
;
720 case GPD_STARTF_HOTKEY
: /* return stdinput handle from startupinfo ??? */
721 return process
->env_db
->startup_info
->hStdInput
;
723 case GPD_STARTF_SHOWWINDOW
:
724 return process
->env_db
->startup_info
->wShowWindow
;
726 case GPD_STARTF_SIZE
:
727 x
= process
->env_db
->startup_info
->dwXSize
;
728 if ( x
== CW_USEDEFAULT
) x
= CW_USEDEFAULT16
;
729 y
= process
->env_db
->startup_info
->dwYSize
;
730 if ( y
== CW_USEDEFAULT
) y
= CW_USEDEFAULT16
;
731 return MAKELONG( x
, y
);
733 case GPD_STARTF_POSITION
:
734 x
= process
->env_db
->startup_info
->dwX
;
735 if ( x
== CW_USEDEFAULT
) x
= CW_USEDEFAULT16
;
736 y
= process
->env_db
->startup_info
->dwY
;
737 if ( y
== CW_USEDEFAULT
) y
= CW_USEDEFAULT16
;
738 return MAKELONG( x
, y
);
740 case GPD_STARTF_FLAGS
:
741 return process
->env_db
->startup_info
->dwFlags
;
744 return (DWORD
)process
->parent
->server_pid
;
747 return process
->flags
;
750 return process
->process_dword
;
753 ERR_(win32
)("Unknown offset %d\n", offset
);
758 /***********************************************************************
759 * SetProcessDword (KERNEL.484)
760 * 'Of course you cannot directly access Windows internal structures'
762 void WINAPI
SetProcessDword( DWORD dwProcessID
, INT offset
, DWORD value
)
764 PDB
*process
= PROCESS_IdToPDB( dwProcessID
);
766 TRACE_(win32
)("(%ld, %d)\n", dwProcessID
, offset
);
767 if ( !process
) return;
771 case GPD_APP_COMPAT_FLAGS
:
772 case GPD_LOAD_DONE_EVENT
:
773 case GPD_HINSTANCE16
:
774 case GPD_WINDOWS_VERSION
:
777 case GPD_STARTF_SHELLDATA
:
778 case GPD_STARTF_HOTKEY
:
779 case GPD_STARTF_SHOWWINDOW
:
780 case GPD_STARTF_SIZE
:
781 case GPD_STARTF_POSITION
:
782 case GPD_STARTF_FLAGS
:
785 ERR_(win32
)("Not allowed to modify offset %d\n", offset
);
789 process
->process_dword
= value
;
793 ERR_(win32
)("Unknown offset %d\n", offset
);
799 /***********************************************************************
800 * GetCurrentProcess (KERNEL32.198)
802 HANDLE WINAPI
GetCurrentProcess(void)
804 return CURRENT_PROCESS_PSEUDOHANDLE
;
808 /*********************************************************************
809 * OpenProcess (KERNEL32.543)
811 HANDLE WINAPI
OpenProcess( DWORD access
, BOOL inherit
, DWORD id
)
814 struct open_process_request
*req
= get_req_buffer();
816 req
->pid
= (void *)id
;
817 req
->access
= access
;
818 req
->inherit
= inherit
;
819 if (!server_call( REQ_OPEN_PROCESS
)) ret
= req
->handle
;
823 /*********************************************************************
824 * MapProcessHandle (KERNEL.483)
826 DWORD WINAPI
MapProcessHandle( HANDLE handle
)
829 struct get_process_info_request
*req
= get_req_buffer();
830 req
->handle
= handle
;
831 if (!server_call( REQ_GET_PROCESS_INFO
)) ret
= (DWORD
)req
->pid
;
835 /***********************************************************************
836 * GetCurrentProcessId (KERNEL32.199)
838 DWORD WINAPI
GetCurrentProcessId(void)
840 return (DWORD
)PROCESS_Current()->server_pid
;
844 /***********************************************************************
845 * GetProcessHeap (KERNEL32.259)
847 HANDLE WINAPI
GetProcessHeap(void)
849 PDB
*pdb
= PROCESS_Current();
850 return pdb
->heap
? pdb
->heap
: SystemHeap
;
854 /***********************************************************************
855 * GetThreadLocale (KERNEL32.295)
857 LCID WINAPI
GetThreadLocale(void)
859 return PROCESS_Current()->locale
;
863 /***********************************************************************
864 * SetPriorityClass (KERNEL32.503)
866 BOOL WINAPI
SetPriorityClass( HANDLE hprocess
, DWORD priorityclass
)
868 struct set_process_info_request
*req
= get_req_buffer();
869 req
->handle
= hprocess
;
870 req
->priority
= priorityclass
;
871 req
->mask
= SET_PROCESS_INFO_PRIORITY
;
872 return !server_call( REQ_SET_PROCESS_INFO
);
876 /***********************************************************************
877 * GetPriorityClass (KERNEL32.250)
879 DWORD WINAPI
GetPriorityClass(HANDLE hprocess
)
882 struct get_process_info_request
*req
= get_req_buffer();
883 req
->handle
= hprocess
;
884 if (!server_call( REQ_GET_PROCESS_INFO
)) ret
= req
->priority
;
889 /***********************************************************************
890 * SetProcessAffinityMask (KERNEL32.662)
892 BOOL WINAPI
SetProcessAffinityMask( HANDLE hProcess
, DWORD affmask
)
894 struct set_process_info_request
*req
= get_req_buffer();
895 req
->handle
= hProcess
;
896 req
->affinity
= affmask
;
897 req
->mask
= SET_PROCESS_INFO_AFFINITY
;
898 return !server_call( REQ_SET_PROCESS_INFO
);
901 /**********************************************************************
902 * GetProcessAffinityMask (KERNEL32.373)
904 BOOL WINAPI
GetProcessAffinityMask( HANDLE hProcess
,
905 LPDWORD lpProcessAffinityMask
,
906 LPDWORD lpSystemAffinityMask
)
909 struct get_process_info_request
*req
= get_req_buffer();
910 req
->handle
= hProcess
;
911 if (!server_call( REQ_GET_PROCESS_INFO
))
913 if (lpProcessAffinityMask
) *lpProcessAffinityMask
= req
->process_affinity
;
914 if (lpSystemAffinityMask
) *lpSystemAffinityMask
= req
->system_affinity
;
921 /***********************************************************************
922 * GetStdHandle (KERNEL32.276)
924 HANDLE WINAPI
GetStdHandle( DWORD std_handle
)
926 PDB
*pdb
= PROCESS_Current();
930 case STD_INPUT_HANDLE
: return pdb
->env_db
->hStdin
;
931 case STD_OUTPUT_HANDLE
: return pdb
->env_db
->hStdout
;
932 case STD_ERROR_HANDLE
: return pdb
->env_db
->hStderr
;
934 SetLastError( ERROR_INVALID_PARAMETER
);
935 return INVALID_HANDLE_VALUE
;
939 /***********************************************************************
940 * SetStdHandle (KERNEL32.506)
942 BOOL WINAPI
SetStdHandle( DWORD std_handle
, HANDLE handle
)
944 PDB
*pdb
= PROCESS_Current();
945 /* FIXME: should we close the previous handle? */
948 case STD_INPUT_HANDLE
:
949 pdb
->env_db
->hStdin
= handle
;
951 case STD_OUTPUT_HANDLE
:
952 pdb
->env_db
->hStdout
= handle
;
954 case STD_ERROR_HANDLE
:
955 pdb
->env_db
->hStderr
= handle
;
958 SetLastError( ERROR_INVALID_PARAMETER
);
962 /***********************************************************************
963 * GetProcessVersion (KERNEL32)
965 DWORD WINAPI
GetProcessVersion( DWORD processid
)
968 PDB
*pdb
= PROCESS_IdToPDB( processid
);
971 if (!(pTask
= (TDB
*)GlobalLock16( pdb
->task
))) return 0;
972 return (pTask
->version
&0xff) | (((pTask
->version
>>8) & 0xff)<<16);
975 /***********************************************************************
976 * GetProcessFlags (KERNEL32)
978 DWORD WINAPI
GetProcessFlags( DWORD processid
)
980 PDB
*pdb
= PROCESS_IdToPDB( processid
);
985 /***********************************************************************
986 * SetProcessWorkingSetSize [KERNEL32.662]
987 * Sets the min/max working set sizes for a specified process.
990 * hProcess [I] Handle to the process of interest
991 * minset [I] Specifies minimum working set size
992 * maxset [I] Specifies maximum working set size
996 BOOL WINAPI
SetProcessWorkingSetSize(HANDLE hProcess
,DWORD minset
,
999 FIXME_(process
)("(0x%08x,%ld,%ld): stub - harmless\n",hProcess
,minset
,maxset
);
1000 if(( minset
== -1) && (maxset
== -1)) {
1001 /* Trim the working set to zero */
1002 /* Swap the process out of physical RAM */
1007 /***********************************************************************
1008 * GetProcessWorkingSetSize (KERNEL32)
1010 BOOL WINAPI
GetProcessWorkingSetSize(HANDLE hProcess
,LPDWORD minset
,
1013 FIXME_(process
)("(0x%08x,%p,%p): stub\n",hProcess
,minset
,maxset
);
1014 /* 32 MB working set size */
1015 if (minset
) *minset
= 32*1024*1024;
1016 if (maxset
) *maxset
= 32*1024*1024;
1020 /***********************************************************************
1021 * SetProcessShutdownParameters (KERNEL32)
1023 * CHANGED - James Sutherland (JamesSutherland@gmx.de)
1024 * Now tracks changes made (but does not act on these changes)
1025 * NOTE: the definition for SHUTDOWN_NORETRY was done on guesswork.
1026 * It really shouldn't be here, but I'll move it when it's been checked!
1028 #define SHUTDOWN_NORETRY 1
1029 static unsigned int shutdown_noretry
= 0;
1030 static unsigned int shutdown_priority
= 0x280L
;
1031 BOOL WINAPI
SetProcessShutdownParameters(DWORD level
,DWORD flags
)
1033 if (flags
& SHUTDOWN_NORETRY
)
1034 shutdown_noretry
= 1;
1036 shutdown_noretry
= 0;
1037 if (level
> 0x100L
&& level
< 0x3FFL
)
1038 shutdown_priority
= level
;
1041 ERR_(process
)("invalid priority level 0x%08lx\n", level
);
1048 /***********************************************************************
1049 * GetProcessShutdownParameters (KERNEL32)
1052 BOOL WINAPI
GetProcessShutdownParameters( LPDWORD lpdwLevel
,
1055 (*lpdwLevel
) = shutdown_priority
;
1056 (*lpdwFlags
) = (shutdown_noretry
* SHUTDOWN_NORETRY
);
1059 /***********************************************************************
1060 * SetProcessPriorityBoost (KERNEL32)
1062 BOOL WINAPI
SetProcessPriorityBoost(HANDLE hprocess
,BOOL disableboost
)
1064 FIXME_(process
)("(%d,%d): stub\n",hprocess
,disableboost
);
1065 /* Say we can do it. I doubt the program will notice that we don't. */
1069 /***********************************************************************
1070 * ReadProcessMemory (KERNEL32)
1071 * FIXME: check this, if we ever run win32 binaries in different addressspaces
1072 * ... and add a sizecheck
1074 BOOL WINAPI
ReadProcessMemory( HANDLE hProcess
, LPCVOID lpBaseAddress
,
1075 LPVOID lpBuffer
, DWORD nSize
,
1076 LPDWORD lpNumberOfBytesRead
)
1078 memcpy(lpBuffer
,lpBaseAddress
,nSize
);
1079 if (lpNumberOfBytesRead
) *lpNumberOfBytesRead
= nSize
;
1083 /***********************************************************************
1084 * WriteProcessMemory (KERNEL32)
1085 * FIXME: check this, if we ever run win32 binaries in different addressspaces
1086 * ... and add a sizecheck
1088 BOOL WINAPI
WriteProcessMemory(HANDLE hProcess
, LPVOID lpBaseAddress
,
1089 LPVOID lpBuffer
, DWORD nSize
,
1090 LPDWORD lpNumberOfBytesWritten
)
1092 memcpy(lpBaseAddress
,lpBuffer
,nSize
);
1093 if (lpNumberOfBytesWritten
) *lpNumberOfBytesWritten
= nSize
;
1097 /***********************************************************************
1098 * RegisterServiceProcess (KERNEL, KERNEL32)
1100 * A service process calls this function to ensure that it continues to run
1101 * even after a user logged off.
1103 DWORD WINAPI
RegisterServiceProcess(DWORD dwProcessId
, DWORD dwType
)
1105 /* I don't think that Wine needs to do anything in that function */
1106 return 1; /* success */
1109 /***********************************************************************
1110 * GetExitCodeProcess [KERNEL32.325]
1112 * Gets termination status of specified process
1118 BOOL WINAPI
GetExitCodeProcess(
1119 HANDLE hProcess
, /* [I] handle to the process */
1120 LPDWORD lpExitCode
) /* [O] address to receive termination status */
1123 struct get_process_info_request
*req
= get_req_buffer();
1124 req
->handle
= hProcess
;
1125 if (!server_call( REQ_GET_PROCESS_INFO
))
1127 if (lpExitCode
) *lpExitCode
= req
->exit_code
;
1134 /***********************************************************************
1135 * GetProcessHeaps [KERNEL32.376]
1137 DWORD WINAPI
GetProcessHeaps(DWORD nrofheaps
,HANDLE
*heaps
) {
1138 FIXME_(win32
)("(%ld,%p), incomplete implementation.\n",nrofheaps
,heaps
);
1141 heaps
[0] = GetProcessHeap();
1142 /* ... probably SystemHeap too ? */
1145 /* number of available heaps */
1150 /***********************************************************************
1151 * SetErrorMode (KERNEL32.486)
1153 UINT WINAPI
SetErrorMode( UINT mode
)
1155 UINT old
= PROCESS_Current()->error_mode
;
1156 PROCESS_Current()->error_mode
= mode
;