Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/ntdll/loader.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 5a429b3f7a8..065bd62cac0 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2388,7 +2388,8 @@ static NTSTATUS get_dll_load_path_search_flags( LPCWSTR module, DWORD flags, WCH * Open a file for a new dll. Helper for find_dll_file. */ static NTSTATUS open_dll_file( UNICODE_STRING *nt_name, WINE_MODREF **pwm, void **module, - SECTION_IMAGE_INFORMATION *image_info, struct file_id *id ) + SECTION_IMAGE_INFORMATION *image_info, struct file_id *id, + BOOL loaded_only ) { FILE_BASIC_INFORMATION info; OBJECT_ATTRIBUTES attr; @@ -2441,6 +2442,14 @@ static NTSTATUS open_dll_file( UNICODE_STRING *nt_name, WINE_MODREF **pwm, void } }
+ if (loaded_only) + { + NtClose( handle ); + NtUnmapViewOfSection( NtCurrentProcess(), *module ); + *module = NULL; + return STATUS_DLL_NOT_FOUND; + } + size.QuadPart = 0; status = NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE, @@ -2665,7 +2674,7 @@ done: */ static NTSTATUS search_dll_file( LPCWSTR paths, LPCWSTR search, UNICODE_STRING *nt_name, WINE_MODREF **pwm, void **module, SECTION_IMAGE_INFORMATION *image_info, - struct file_id *id ) + struct file_id *id, BOOL loaded_only ) { WCHAR *name; BOOL found_image = FALSE; @@ -2692,7 +2701,7 @@ static NTSTATUS search_dll_file( LPCWSTR paths, LPCWSTR search, UNICODE_STRING * nt_name->Buffer = NULL; if ((status = RtlDosPathNameToNtPathName_U_WithStatus( name, nt_name, NULL, NULL ))) goto done;
- status = open_dll_file( nt_name, pwm, module, image_info, id ); + status = open_dll_file( nt_name, pwm, module, image_info, id, loaded_only ); if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) found_image = TRUE; else if (status != STATUS_DLL_NOT_FOUND) goto done; RtlFreeUnicodeString( nt_name ); @@ -2721,7 +2730,8 @@ done: */ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname, const WCHAR *default_ext, UNICODE_STRING *nt_name, WINE_MODREF **pwm, void **module, - SECTION_IMAGE_INFORMATION *image_info, struct file_id *id ) + SECTION_IMAGE_INFORMATION *image_info, struct file_id *id, + BOOL loaded_only ) { WCHAR *ext, *dllname; NTSTATUS status; @@ -2772,9 +2782,9 @@ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname, con }
if (RtlDetermineDosPathNameType_U( libname ) == RELATIVE_PATH) - status = search_dll_file( load_path, libname, nt_name, pwm, module, image_info, id ); + status = search_dll_file( load_path, libname, nt_name, pwm, module, image_info, id, loaded_only ); else if (!(status = RtlDosPathNameToNtPathName_U_WithStatus( libname, nt_name, NULL, NULL ))) - status = open_dll_file( nt_name, pwm, module, image_info, id ); + status = open_dll_file( nt_name, pwm, module, image_info, id, loaded_only );
if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) status = STATUS_INVALID_IMAGE_FORMAT;
@@ -2804,7 +2814,7 @@ static NTSTATUS load_dll( const WCHAR *load_path, const WCHAR *libname, const WC
TRACE( "looking for %s in %s\n", debugstr_w(libname), debugstr_w(load_path) );
- nts = find_dll_file( load_path, libname, default_ext, &nt_name, pwm, &module, &image_info, &id ); + nts = find_dll_file( load_path, libname, default_ext, &nt_name, pwm, &module, &image_info, &id, FALSE );
if (*pwm) /* found already loaded module */ { @@ -2885,7 +2895,7 @@ static NTSTATUS load_dll( const WCHAR *load_path, const WCHAR *libname, const WC LdrUnloadDll( (*pwm)->ldr.DllBase ); nts = STATUS_DLL_NOT_FOUND; /* map the dll again if it was unmapped */ - if (!module && open_dll_file( &nt_name, pwm, &module, &image_info, &id )) break; + if (!module && open_dll_file( &nt_name, pwm, &module, &image_info, &id, FALSE )) break; } if (nts == STATUS_DLL_NOT_FOUND) nts = load_native_dll( load_path, &nt_name, &module, &image_info, &id, flags, pwm ); @@ -3006,18 +3016,12 @@ NTSTATUS WINAPI LdrGetDllHandle( LPCWSTR load_path, ULONG flags, const UNICODE_S
if (!load_path) load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
- status = find_dll_file( load_path, name->Buffer, dllW, &nt_name, &wm, &module, &image_info, &id ); - - if (wm) + if (!(status = find_dll_file( load_path, name->Buffer, dllW, + &nt_name, &wm, &module, &image_info, &id, TRUE ))) { *base = wm->ldr.DllBase; unlock_modref( wm ); } - else - { - if (status == STATUS_SUCCESS) NtUnmapViewOfSection( NtCurrentProcess(), module ); - status = STATUS_DLL_NOT_FOUND; - } RtlFreeUnicodeString( &nt_name );
RtlLeaveCriticalSection( &loader_section );