diff --git a/include/process.h b/include/process.h index 63f6b378b3..48a7c9ba07 100644 --- a/include/process.h +++ b/include/process.h @@ -95,7 +95,6 @@ typedef struct _PDB 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 */ diff --git a/include/server.h b/include/server.h index 2e5f7f1a43..234d8db611 100644 --- a/include/server.h +++ b/include/server.h @@ -113,6 +113,7 @@ struct new_process_request IN int hstderr; /* handle for stderr */ IN int cmd_show; /* main window show mode */ IN int alloc_fd; /* create the fd pair right now? */ + IN char filename[1]; /* file name of main exe */ }; @@ -160,6 +161,7 @@ struct init_process_request OUT int hstdout; /* handle for stdout */ OUT int hstderr; /* handle for stderr */ OUT int cmd_show; /* main window show mode */ + OUT char filename[1]; /* file name of main exe */ }; @@ -1253,7 +1255,7 @@ enum request REQ_NB_REQUESTS }; -#define SERVER_PROTOCOL_VERSION 10 +#define SERVER_PROTOCOL_VERSION 11 /* ### make_requests end ### */ /* Everything above this line is generated automatically by tools/make_requests */ diff --git a/scheduler/process.c b/scheduler/process.c index 5955a108f4..14e0864730 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -39,6 +39,7 @@ DECLARE_DEBUG_CHANNEL(win32); static ENVDB initial_envdb; static STARTUPINFOA initial_startup; +static HFILE main_exe_file = -1; static PDB *PROCESS_First; @@ -195,7 +196,6 @@ static BOOL PROCESS_CreateEnvDB(void) req->ldt_flags = ldt_flags_copy; req->ppid = getppid(); 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; @@ -292,7 +292,7 @@ BOOL PROCESS_Init( BOOL win32 ) req->ldt_flags = ldt_flags_copy; req->ppid = getppid(); if (server_call( REQ_INIT_PROCESS )) return FALSE; - pdb->exe_file = req->exe_file; + main_exe_file = req->exe_file; initial_startup.dwFlags = req->start_flags; initial_startup.wShowWindow = req->cmd_show; initial_envdb.hStdin = initial_startup.hStdInput = req->hstdin; @@ -337,7 +337,7 @@ BOOL PROCESS_Init( BOOL win32 ) * * Load system DLLs into the initial process (and initialize them) */ -static int load_system_dlls(void) +static inline int load_system_dlls(void) { char driver[MAX_PATH]; @@ -446,14 +446,13 @@ static void start_process(void) */ void PROCESS_Init32( HFILE hFile, LPCSTR filename, LPCSTR cmd_line ) { - WORD version; HMODULE main_module; PDB *pdb = PROCESS_Current(); pdb->env_db->cmd_line = HEAP_strdupA( GetProcessHeap(), 0, cmd_line ); /* load main module */ - if ((main_module = PE_LoadImage( hFile, filename, &version )) < 32) + if ((main_module = PE_LoadImage( hFile, filename )) < 32) ExitProcess( main_module ); #if 0 if (PE_HEADER(main_module)->FileHeader.Characteristics & IMAGE_FILE_DLL) @@ -727,6 +726,7 @@ BOOL PROCESS_CreateUnixProcess( LPCSTR filename, LPCSTR cmd_line, LPCSTR env, } req->cmd_show = startup->wShowWindow; req->alloc_fd = 0; + lstrcpynA( req->filename, unixfilename, server_remaining(req->filename) ); if (server_call( REQ_NEW_PROCESS )) return FALSE; /* fork and execute */ @@ -948,6 +948,7 @@ PDB *PROCESS_Create( NE_MODULE *pModule, HFILE hFile, LPCSTR cmd_line, LPCSTR en } req->cmd_show = startup->wShowWindow; req->alloc_fd = 1; + req->filename[0] = 0; if (server_call_fd( REQ_NEW_PROCESS, -1, &fd )) goto error; if (pModule->module32) /* Win32 process */ diff --git a/server/process.c b/server/process.c index 57825e8684..733b69393d 100644 --- a/server/process.c +++ b/server/process.c @@ -63,11 +63,12 @@ struct startup_info int inherit_all; /* inherit all handles from parent */ int create_flags; /* creation flags */ int start_flags; /* flags from startup info */ - int exe_file; /* file handle for main exe */ int hstdin; /* handle for stdin */ int hstdout; /* handle for stdout */ int hstderr; /* handle for stderr */ int cmd_show; /* main window show mode */ + struct file *exe_file; /* file handle for main exe */ + char *filename; /* file name for main exe */ struct process *process; /* created process */ struct thread *thread; /* created thread */ }; @@ -229,10 +230,9 @@ static void init_process( int ppid, struct init_process_request *req ) /* retrieve the main exe file */ req->exe_file = -1; - if (parent && info->exe_file != -1) + if (parent && info->exe_file) { - if (!(process->exe.file = get_file_obj( parent, info->exe_file, GENERIC_READ ))) - goto error; + process->exe.file = (struct file *)grab_object( info->exe_file ); if ((req->exe_file = alloc_handle( process, process->exe.file, GENERIC_READ, 0 )) == -1) goto error; } @@ -256,6 +256,7 @@ static void init_process( int ppid, struct init_process_request *req ) { req->start_flags = info->start_flags; req->cmd_show = info->cmd_show; + strcpy( req->filename, info->filename ); info->process = (struct process *)grab_object( process ); info->thread = (struct thread *)grab_object( current ); wake_up( &info->obj, 0 ); @@ -264,6 +265,7 @@ static void init_process( int ppid, struct init_process_request *req ) { req->start_flags = STARTF_USESTDHANDLES; req->cmd_show = 0; + req->filename[0] = 0; } error: } @@ -305,6 +307,8 @@ static void startup_info_destroy( struct object *obj ) { struct startup_info *info = (struct startup_info *)obj; assert( obj->ops == &startup_info_ops ); + if (info->filename) free( info->filename ); + if (info->exe_file) release_object( info->exe_file ); if (info->process) release_object( info->process ); if (info->thread) release_object( info->thread ); } @@ -314,8 +318,8 @@ static void startup_info_dump( struct object *obj, int verbose ) struct startup_info *info = (struct startup_info *)obj; assert( obj->ops == &startup_info_ops ); - fprintf( stderr, "Startup info flags=%x in=%d out=%d err=%d\n", - info->start_flags, info->hstdin, info->hstdout, info->hstderr ); + fprintf( stderr, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n", + info->start_flags, info->hstdin, info->hstdout, info->hstderr, info->filename ); } static int startup_info_signaled( struct object *obj, struct thread *thread ) @@ -699,6 +703,7 @@ struct module_snapshot *module_snap( struct process *process, int *count ) /* create a new process */ DECL_HANDLER(new_process) { + size_t len = get_req_strlen( req, req->filename ); struct startup_info *info; int sock[2]; @@ -713,14 +718,29 @@ DECL_HANDLER(new_process) info->inherit_all = req->inherit_all; info->create_flags = req->create_flags; info->start_flags = req->start_flags; - info->exe_file = req->exe_file; info->hstdin = req->hstdin; info->hstdout = req->hstdout; info->hstderr = req->hstderr; info->cmd_show = req->cmd_show; + info->exe_file = NULL; + info->filename = NULL; info->process = NULL; info->thread = NULL; + if ((req->exe_file != -1) && + !(info->exe_file = get_file_obj( current->process, req->exe_file, GENERIC_READ ))) + { + release_object( info ); + return; + } + + if (!(info->filename = memdup( req->filename, len+1 ))) + { + release_object( info ); + return; + } + info->filename[len] = 0; + if (req->alloc_fd) { if (socketpair( AF_UNIX, SOCK_STREAM, 0, sock ) == -1) @@ -753,6 +773,7 @@ DECL_HANDLER(wait_process) req->tid = 0; req->phandle = -1; req->thandle = -1; + req->event = -1; if (req->cancel) { release_object( current->info ); diff --git a/server/trace.c b/server/trace.c index 1fca5cd0f2..176c02eabe 100644 --- a/server/trace.c +++ b/server/trace.c @@ -223,7 +223,9 @@ static void dump_new_process_request( const struct new_process_request *req ) fprintf( stderr, " hstdout=%d,", req->hstdout ); fprintf( stderr, " hstderr=%d,", req->hstderr ); fprintf( stderr, " cmd_show=%d,", req->cmd_show ); - fprintf( stderr, " alloc_fd=%d", req->alloc_fd ); + fprintf( stderr, " alloc_fd=%d,", req->alloc_fd ); + fprintf( stderr, " filename=" ); + dump_string( req, req->filename ); } static void dump_wait_process_request( const struct wait_process_request *req ) @@ -274,7 +276,9 @@ static void dump_init_process_reply( const struct init_process_request *req ) fprintf( stderr, " hstdin=%d,", req->hstdin ); fprintf( stderr, " hstdout=%d,", req->hstdout ); fprintf( stderr, " hstderr=%d,", req->hstderr ); - fprintf( stderr, " cmd_show=%d", req->cmd_show ); + fprintf( stderr, " cmd_show=%d,", req->cmd_show ); + fprintf( stderr, " filename=" ); + dump_string( req, req->filename ); } static void dump_init_process_done_request( const struct init_process_done_request *req )