diff --git a/include/process.h b/include/process.h index 7ad864eed40..249d16f9ae9 100644 --- a/include/process.h +++ b/include/process.h @@ -94,10 +94,11 @@ typedef struct _PDB void *server_pid; /* Server id for this process */ HANDLE *dos_handles; /* Handles mapping DOS -> Win32 */ struct _PDB *next; /* List reference - list of PDB's */ - WORD winver; /* Windows version figured out by VERSION_GetVersion */ + WORD winver; /* Windows version figured out by VERSION_GetVersion */ struct _SERVICETABLE *service_table; /* Service table for service thread */ HANDLE idle_event; /* event to signal, when the process is idle */ HANDLE16 main_queue; /* main message queue of the process */ + HFILE exe_file; /* handle to main exe file */ } PDB; /* Process flags */ @@ -157,10 +158,9 @@ extern void ENV_FreeEnvironment( PDB *pdb ); /* scheduler/process.c */ extern BOOL PROCESS_Init( BOOL win32 ); extern BOOL PROCESS_IsCurrent( HANDLE handle ); -extern PDB *PROCESS_Initial(void); extern PDB *PROCESS_IdToPDB( DWORD id ); extern void PROCESS_CallUserSignalProc( UINT uCode, DWORD dwThreadId, HMODULE hModule ); -extern PDB *PROCESS_Create( struct _NE_MODULE *pModule, +extern PDB *PROCESS_Create( struct _NE_MODULE *pModule, HFILE hFile, LPCSTR cmd_line, LPCSTR env, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, BOOL inherit, DWORD flags, diff --git a/include/server.h b/include/server.h index c7b5e8f9438..6eb99c356f9 100644 --- a/include/server.h +++ b/include/server.h @@ -114,6 +114,7 @@ struct new_process_request IN int inherit_all; /* inherit all handles from parent */ IN int create_flags; /* creation flags */ IN int start_flags; /* flags from startup info */ + IN int exe_file; /* file handle for main exe */ IN int hstdin; /* handle for stdin */ IN int hstdout; /* handle for stdout */ IN int hstderr; /* handle for stderr */ @@ -151,6 +152,7 @@ struct init_process_request IN void* ldt_copy; /* addr of LDT copy */ IN void* ldt_flags; /* addr of LDT flags */ OUT int start_flags; /* flags from startup info */ + OUT int exe_file; /* file handle for main exe */ OUT int hstdin; /* handle for stdin */ OUT int hstdout; /* handle for stdout */ OUT int hstderr; /* handle for stderr */ diff --git a/loader/dos/module.c b/loader/dos/module.c index 45e2cc99ae6..a1b6a7983bb 100644 --- a/loader/dos/module.c +++ b/loader/dos/module.c @@ -503,7 +503,7 @@ BOOL MZ_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmdline, LPCSTR env return FALSE; } inherit = TRUE; /* bad hack for inheriting the CreatePipe... */ - if (!PROCESS_Create( pModule, cmdline, env, + if (!PROCESS_Create( pModule, hFile, cmdline, env, psa, tsa, inherit, flags, startup, info )) return FALSE; } diff --git a/loader/ne/module.c b/loader/ne/module.c index 74ad1aafd21..38c5bf345bd 100644 --- a/loader/ne/module.c +++ b/loader/ne/module.c @@ -1072,7 +1072,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock ) } SYSLEVEL_ReleaseWin16Lock(); - pdb = PROCESS_Create( pModule, new_cmd_line, env, + pdb = PROCESS_Create( pModule, -1, new_cmd_line, env, NULL, NULL, TRUE, 0, &startup, &info ); SYSLEVEL_RestoreWin16Lock(); @@ -1136,7 +1136,7 @@ BOOL NE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR en SYSLEVEL_LeaveWin16Lock(); - if ( !PROCESS_Create( pModule, cmd_line, env, + if ( !PROCESS_Create( pModule, hFile, cmd_line, env, psa, tsa, inherit, flags, startup, info ) ) return FALSE; diff --git a/loader/pe_image.c b/loader/pe_image.c index f81e4d97eab..09e98da5e42 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -1003,7 +1003,7 @@ BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR en pModule->module32 = hModule32; /* Create new process */ - if ( !PROCESS_Create( pModule, cmd_line, env, + if ( !PROCESS_Create( pModule, hFile, cmd_line, env, psa, tsa, inherit, flags, startup, info ) ) return FALSE; diff --git a/loader/task.c b/loader/task.c index 69bdc8c4626..8c38da3e8a6 100644 --- a/loader/task.c +++ b/loader/task.c @@ -56,6 +56,7 @@ THHOOK *pThhook = &DefaultThhook; static UINT16 nTaskCount = 0; +static HTASK initial_task; /*********************************************************************** * TASK_InstallTHHook @@ -385,6 +386,8 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow) /* Enter task handle into thread and process */ pTask->teb->htask16 = pTask->teb->process->task = hTask; + if (!initial_task) initial_task = hTask; + TRACE("module='%s' cmdline='%s' task=%04x\n", name, cmd_line, hTask ); /* Add the task to the linked list */ @@ -481,7 +484,7 @@ void TASK_KillTask( HTASK16 hTask ) * The initial task should probably install hooks or something * to get informed about task termination :-/ */ - Callout.PostAppMessage16( PROCESS_Initial()->task, WM_NULL, 0, 0 ); + Callout.PostAppMessage16( initial_task, WM_NULL, 0, 0 ); /* Remove the task from the list to be sure we never switch back to it */ TASK_UnlinkTask( hTask ); diff --git a/scheduler/process.c b/scheduler/process.c index 7ea00626662..cc3f45c9c7e 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -64,19 +64,6 @@ void PROCESS_WalkProcess(void) return; } -/*********************************************************************** - * PROCESS_Initial - * - * FIXME: This works only while running all processes in the same - * address space (or, at least, the initial process is mapped - * into all address spaces as is KERNEL32 in Windows 95) - * - */ -PDB *PROCESS_Initial(void) -{ - return &initial_pdb; -} - /*********************************************************************** * PROCESS_IsCurrent * @@ -255,6 +242,7 @@ static BOOL PROCESS_CreateEnvDB(void) req->ldt_copy = ldt_copy; req->ldt_flags = ldt_flags_copy; if (server_call( REQ_INIT_PROCESS )) return FALSE; + pdb->exe_file = req->exe_file; startup->dwFlags = req->start_flags; startup->wShowWindow = req->cmd_show; env_db->hStdin = startup->hStdInput = req->hstdin; @@ -529,7 +517,7 @@ void PROCESS_Start(void) * * Create a new process database and associated info. */ -PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, +PDB *PROCESS_Create( NE_MODULE *pModule, HFILE hFile, LPCSTR cmd_line, LPCSTR env, LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, BOOL inherit, DWORD flags, STARTUPINFOA *startup, PROCESS_INFORMATION *info ) @@ -553,6 +541,7 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, req->inherit_all = inherit; req->create_flags = flags; req->start_flags = startup->dwFlags; + req->exe_file = hFile; req->event = load_done_evt; if (startup->dwFlags & STARTF_USESTDHANDLES) { diff --git a/server/process.c b/server/process.c index b12221efde0..0dd779df0ac 100644 --- a/server/process.c +++ b/server/process.c @@ -72,6 +72,7 @@ static int set_creation_info( struct process *process, struct new_process_reques req->inherit_all = 0; req->create_flags = CREATE_NEW_CONSOLE; req->start_flags = STARTF_USESTDHANDLES; + req->exe_file = -1; req->hstdin = -1; req->hstdout = -1; req->hstderr = -1; @@ -142,6 +143,7 @@ struct thread *create_process( int fd, struct process *parent, process->prev = NULL; process->thread_list = NULL; process->debugger = NULL; + process->exe_file = NULL; process->handles = NULL; process->exit_code = STILL_ACTIVE; process->running_threads = 0; @@ -171,6 +173,14 @@ struct thread *create_process( int fd, struct process *parent, /* alloc a handle for the process itself */ alloc_handle( process, process, PROCESS_ALL_ACCESS, 0 ); + /* retrieve the main exe file */ + if (process->info->exe_file != -1) + { + if (!(process->exe_file = get_file_obj( parent, process->info->exe_file, + GENERIC_READ ))) goto error; + process->info->exe_file = -1; + } + /* get the init done event */ if (process->info->event != -1) { @@ -215,6 +225,7 @@ static void process_destroy( struct object *obj ) else first_process = process->next; if (process->info) free( process->info ); if (process->init_event) release_object( process->init_event ); + if (process->exe_file) release_object( process->exe_file ); } /* dump a process on stdout for debugging purposes */ @@ -261,6 +272,8 @@ static void process_killed( struct process *process, int exit_code ) release_object( process->handles ); process->handles = NULL; free_console( process ); + if (process->exe_file) release_object( process->exe_file ); + process->exe_file = NULL; wake_up( &process->obj, 0 ); if (!--running_processes) { @@ -548,6 +561,7 @@ DECL_HANDLER(init_process) current->process->ldt_copy = req->ldt_copy; current->process->ldt_flags = req->ldt_flags; current->process->info = NULL; + req->exe_file = -1; req->start_flags = info->start_flags; req->hstdin = info->hstdin; req->hstdout = info->hstdout; @@ -555,6 +569,9 @@ DECL_HANDLER(init_process) req->cmd_show = info->cmd_show; req->env_ptr = info->env_ptr; strcpy( req->cmdline, info->cmdline ); + if (current->process->exe_file) + req->exe_file = alloc_handle( current->process, current->process->exe_file, + GENERIC_READ, 0 ); free( info ); } diff --git a/server/process.h b/server/process.h index 6e84a32657e..873aad7f7da 100644 --- a/server/process.h +++ b/server/process.h @@ -22,6 +22,7 @@ struct process struct process *prev; struct thread *thread_list; /* head of the thread list */ struct thread *debugger; /* thread debugging this process */ + struct file *exe_file; /* main exe file */ struct object *handles; /* handle entries */ int exit_code; /* process exit code */ int running_threads; /* number of threads running in this process */ diff --git a/server/trace.c b/server/trace.c index ab0b439dec0..c38f7dbaf85 100644 --- a/server/trace.c +++ b/server/trace.c @@ -203,6 +203,7 @@ static void dump_new_process_request( const struct new_process_request *req ) fprintf( stderr, " inherit_all=%d,", req->inherit_all ); fprintf( stderr, " create_flags=%d,", req->create_flags ); fprintf( stderr, " start_flags=%d,", req->start_flags ); + fprintf( stderr, " exe_file=%d,", req->exe_file ); fprintf( stderr, " hstdin=%d,", req->hstdin ); fprintf( stderr, " hstdout=%d,", req->hstdout ); fprintf( stderr, " hstderr=%d,", req->hstderr ); @@ -246,6 +247,7 @@ static void dump_init_process_request( const struct init_process_request *req ) static void dump_init_process_reply( const struct init_process_request *req ) { fprintf( stderr, " start_flags=%d,", req->start_flags ); + fprintf( stderr, " exe_file=%d,", req->exe_file ); fprintf( stderr, " hstdin=%d,", req->hstdin ); fprintf( stderr, " hstdout=%d,", req->hstdout ); fprintf( stderr, " hstderr=%d,", req->hstderr );