Module: wine Branch: master Commit: ab8f0c3e214e2605b83c6fcf8e508c31f3bcf7d9 URL: https://source.winehq.org/git/wine.git/?a=commit;h=ab8f0c3e214e2605b83c6fcf8...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Mar 22 16:28:35 2021 +0100
ntdll: Load builtin dlls through NtMapViewOfSection().
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/kernel32/tests/virtual.c | 1 - dlls/ntdll/loader.c | 58 +++++++++++-------------------------------- 2 files changed, 14 insertions(+), 45 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c index 854d3e04e19..e6d9e8621a9 100644 --- a/dlls/kernel32/tests/virtual.c +++ b/dlls/kernel32/tests/virtual.c @@ -1331,7 +1331,6 @@ static void test_NtAreMappedFilesTheSame(void) ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 ); ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() ); status = pNtAreMappedFilesTheSame( ptr, GetModuleHandleA("kernel32.dll") ); - todo_wine ok( status == STATUS_SUCCESS, "NtAreMappedFilesTheSame returned %x\n", status );
file2 = CreateFileA( path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index c7e7c86e88f..eddceb60623 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2316,8 +2316,19 @@ static NTSTATUS load_native_dll( LPCWSTR load_path, const UNICODE_STRING *nt_nam ViewShare, 0, PAGE_EXECUTE_READ );
if (status == STATUS_IMAGE_NOT_AT_BASE) status = STATUS_SUCCESS; + if (status) return status; + + if ((*pwm = find_existing_module( module ))) /* already loaded */ + { + if ((*pwm)->ldr.LoadCount != -1) (*pwm)->ldr.LoadCount++; + TRACE( "found %s for %s at %p, count=%d\n", + debugstr_us(&(*pwm)->ldr.FullDllName), debugstr_us(nt_name), + (*pwm)->ldr.DllBase, (*pwm)->ldr.LoadCount); + if (module != (*pwm)->ldr.DllBase) NtUnmapViewOfSection( NtCurrentProcess(), module ); + return STATUS_SUCCESS; + } #ifdef _WIN64 - if (!status && !convert_to_pe64( module, image_info )) status = STATUS_INVALID_IMAGE_FORMAT; + if (!convert_to_pe64( module, image_info )) status = STATUS_INVALID_IMAGE_FORMAT; #endif if (!status) status = build_module( load_path, nt_name, &module, image_info, id, flags, pwm ); if (status && module) NtUnmapViewOfSection( NtCurrentProcess(), module ); @@ -2683,49 +2694,8 @@ static NTSTATUS load_dll( const WCHAR *load_path, const WCHAR *libname, const WC break;
case STATUS_SUCCESS: /* valid PE file */ - if (image_info.u.s.WineBuiltin) - { - switch (loadorder) - { - case LO_NATIVE_BUILTIN: - case LO_BUILTIN: - case LO_BUILTIN_NATIVE: - case LO_DEFAULT: - nts = load_builtin_dll( load_path, &nt_name, flags, pwm, FALSE ); - if (nts == STATUS_DLL_NOT_FOUND) - nts = load_native_dll( load_path, &nt_name, mapping, &image_info, &id, flags, pwm ); - break; - default: - nts = STATUS_DLL_NOT_FOUND; - break; - } - break; - } - if (!(image_info.u.s.WineFakeDll)) - { - switch (loadorder) - { - case LO_NATIVE: - case LO_NATIVE_BUILTIN: - nts = load_native_dll( load_path, &nt_name, mapping, &image_info, &id, flags, pwm ); - break; - case LO_BUILTIN: - nts = load_builtin_dll( load_path, &nt_name, flags, pwm, FALSE ); - break; - case LO_BUILTIN_NATIVE: - case LO_DEFAULT: - nts = load_builtin_dll( load_path, &nt_name, flags, pwm, loadorder == LO_DEFAULT ); - if (nts == STATUS_DLL_NOT_FOUND || nts == STATUS_IMAGE_ALREADY_LOADED) - nts = load_native_dll( load_path, &nt_name, mapping, &image_info, &id, flags, pwm ); - break; - default: - nts = STATUS_DLL_NOT_FOUND; - break; - } - break; - } - TRACE( "%s is a fake Wine dll\n", debugstr_us(&nt_name) ); - /* fall through */ + nts = load_native_dll( load_path, &nt_name, mapping, &image_info, &id, flags, pwm ); + break;
case STATUS_DLL_NOT_FOUND: /* no file found, try builtin */ switch (loadorder)