Alexandre Julliard : ntdll: Map explicitly loaded apiset dlls to their target library.
Alexandre Julliard
julliard at winehq.org
Tue Feb 22 16:06:51 CST 2022
Module: wine
Branch: master
Commit: 7b233f3032e4850b0f387faef4aae5ed6d5175de
URL: https://source.winehq.org/git/wine.git/?a=commit;h=7b233f3032e4850b0f387faef4aae5ed6d5175de
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Feb 22 12:31:40 2022 +0100
ntdll: Map explicitly loaded apiset dlls to their target library.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/kernel32/tests/module.c | 6 ++----
dlls/ntdll/loader.c | 43 +++++++++++++++++++++++++++++--------------
2 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
index dcf3b8b3765..bd151708220 100644
--- a/dlls/kernel32/tests/module.c
+++ b/dlls/kernel32/tests/module.c
@@ -708,7 +708,6 @@ static void test_LoadLibraryEx_search_flags(void)
ok( !!mod, "Got NULL module, error %u.\n", GetLastError() );
ok( !!GetModuleHandleA( apiset_dll ), "Got NULL handle.\n" );
shcore = GetModuleHandleA( "shcore.dll" );
- todo_wine
ok( mod == shcore, "wrong module %p/%p\n", mod, shcore );
ret = FreeLibrary( mod );
ok( ret, "FreeLibrary failed, error %u.\n", GetLastError() );
@@ -722,7 +721,6 @@ static void test_LoadLibraryEx_search_flags(void)
ok( !!mod, "Got NULL module, error %u.\n", GetLastError() );
ok( !!GetModuleHandleA( apiset_dll ), "Got NULL handle.\n" );
shcore = GetModuleHandleA( "shcore.dll" );
- todo_wine
ok( mod == shcore, "wrong module %p/%p\n", mod, shcore );
ret = FreeLibrary( mod );
ok( ret, "FreeLibrary failed, error %u.\n", GetLastError() );
@@ -733,7 +731,6 @@ static void test_LoadLibraryEx_search_flags(void)
strcpy( buffer, apiset_dll );
buffer[strlen(buffer) - 5] = '9';
mod = LoadLibraryExA( buffer, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR );
- todo_wine
ok( !!mod || broken(!mod) /* win8 */, "Got NULL module, error %u.\n", GetLastError() );
if (mod)
{
@@ -776,9 +773,10 @@ static void test_LoadLibraryEx_search_flags(void)
ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
SetLastError( 0xdeadbeef );
mod = LoadLibraryExA( "ext-ms-win-ras-rasapi32-l1-1-0.dll", NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR );
+ todo_wine /* rasapi32 doesn't have interesting dependencies on wine */
ok( !mod, "rasapi32 loaded\n" );
- ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
if (mod) FreeLibrary( mod );
+ else ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
mod = LoadLibraryA( "ext-ms-win-ras-rasapi32-l1-1-0.dll" );
ok( !!mod || broken(!mod) /* win7 */, "rasapi32 not found %u\n", GetLastError() );
if (mod) FreeLibrary( mod );
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 387f8b6b2d6..49911d6c707 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -2830,6 +2830,30 @@ done:
}
+
+/******************************************************************************
+ * find_apiset_dll
+ */
+static NTSTATUS find_apiset_dll( const WCHAR *name, WCHAR **fullname )
+{
+ const API_SET_NAMESPACE *map = NtCurrentTeb()->Peb->ApiSetMap;
+ const API_SET_NAMESPACE_ENTRY *entry;
+ UNICODE_STRING str;
+ ULONG len;
+
+ if (get_apiset_entry( map, name, wcslen(name), &entry )) return STATUS_APISET_NOT_PRESENT;
+ if (get_apiset_target( map, entry, NULL, &str )) return STATUS_DLL_NOT_FOUND;
+
+ len = wcslen( system_dir ) + str.Length / sizeof(WCHAR);
+ if (!(*fullname = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) )))
+ return STATUS_NO_MEMORY;
+ wcscpy( *fullname, system_dir );
+ memcpy( *fullname + wcslen( system_dir ), str.Buffer, str.Length );
+ (*fullname)[len] = 0;
+ return STATUS_SUCCESS;
+}
+
+
/***********************************************************************
* get_env_var
*/
@@ -2991,17 +3015,6 @@ done:
return status;
}
-/***********************************************************************
- * is_apiset_dll_name
- *
- */
-static BOOL is_apiset_dll_name( const WCHAR *name )
-{
- static const WCHAR name_prefix[] = L"api-ms-win-";
-
- return !wcsnicmp( name, name_prefix, ARRAY_SIZE(name_prefix) - 1 );
-}
-
/***********************************************************************
* find_dll_file
*
@@ -3024,7 +3037,11 @@ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname, UNI
if (!contains_path( libname ))
{
- status = find_actctx_dll( libname, &fullname );
+ status = find_apiset_dll( libname, &fullname );
+ if (status == STATUS_DLL_NOT_FOUND) goto done;
+
+ if (status) status = find_actctx_dll( libname, &fullname );
+
if (status == STATUS_SUCCESS)
{
TRACE ("found %s for %s\n", debugstr_w(fullname), debugstr_w(libname) );
@@ -3044,8 +3061,6 @@ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname, UNI
if (RtlDetermineDosPathNameType_U( libname ) == RELATIVE_PATH)
{
status = search_dll_file( load_path, libname, nt_name, pwm, mapping, image_info, id );
- if (status == STATUS_DLL_NOT_FOUND && load_path && is_apiset_dll_name( libname ))
- status = search_dll_file( NULL, libname, nt_name, pwm, mapping, image_info, id );
if (status == STATUS_DLL_NOT_FOUND)
status = find_builtin_without_file( libname, nt_name, pwm, mapping, image_info, id );
}
More information about the wine-cvs
mailing list