From ac2e4f1e3d544c754473a5ed11d399b49fa189c0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 25 Oct 2001 19:52:12 +0000 Subject: [PATCH] Don't keep main exe and dlls handles open when the file is on removable media. --- loader/pe_image.c | 6 ++++++ scheduler/process.c | 12 +++++++++++- server/process.c | 12 ++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/loader/pe_image.c b/loader/pe_image.c index 8211c5117f1..cafea327ac5 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -667,6 +667,12 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags, if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL) { + if (hFile) + { + UINT drive_type = GetDriveTypeA( wm->short_filename ); + /* don't keep the file handle open on removable media */ + if (drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_CDROM) hFile = 0; + } SERVER_START_REQ( load_dll ) { req->handle = hFile; diff --git a/scheduler/process.c b/scheduler/process.c index 5ff6e78beac..355f4801ff5 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -319,6 +319,7 @@ static void start_process(void) int debugged, console_app; LPTHREAD_START_ROUTINE entry; WINE_MODREF *wm; + HFILE main_file = main_exe_file; /* use original argv[0] as name for the main module */ if (!main_exe_name[0]) @@ -327,6 +328,13 @@ static void start_process(void) lstrcpynA( main_exe_name, full_argv0, sizeof(main_exe_name) ); } + if (main_file) + { + UINT drive_type = GetDriveTypeA( main_exe_name ); + /* don't keep the file handle open on removable media */ + if (drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_CDROM) main_file = 0; + } + /* Retrieve entry point address */ entry = (LPTHREAD_START_ROUTINE)((char*)current_process.module + PE_HEADER(current_process.module)->OptionalHeader.AddressOfEntryPoint); @@ -340,7 +348,7 @@ static void start_process(void) req->entry = entry; /* API requires a double indirection */ req->name = &main_exe_name_ptr; - req->exe_file = main_exe_file; + req->exe_file = main_file; req->gui = !console_app; SERVER_CALL(); debugged = req->debugged; @@ -357,6 +365,8 @@ static void start_process(void) goto error; wm->refCount++; + if (main_exe_file) CloseHandle( main_exe_file ); /* we no longer need it */ + RtlAcquirePebLock(); PE_InitTls(); MODULE_DllProcessAttach( NULL, (LPVOID)1 ); diff --git a/server/process.c b/server/process.c index 39f40e6f301..d331e08bed8 100644 --- a/server/process.c +++ b/server/process.c @@ -788,8 +788,9 @@ DECL_HANDLER(init_process) /* signal the end of the process initialization */ DECL_HANDLER(init_process_done) { - struct file *file; + struct file *file = NULL; struct process *process = current->process; + if (!process->init_event) { fatal_protocol_error( current, "init_process_done: no event\n" ); @@ -798,11 +799,10 @@ DECL_HANDLER(init_process_done) process->exe.base = req->module; process->exe.name = req->name; - if (req->exe_file && (file = get_file_obj( current->process, req->exe_file, GENERIC_READ ))) - { - if (process->exe.file) release_object( process->exe.file ); - process->exe.file = file; - } + if (req->exe_file) file = get_file_obj( current->process, req->exe_file, GENERIC_READ ); + if (process->exe.file) release_object( process->exe.file ); + process->exe.file = file; + generate_startup_debug_events( current->process, req->entry ); set_event( process->init_event ); release_object( process->init_event );