ntdll: Map explicitly loaded apiset dlls to their target library.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2022-02-22 12:31:40 +01:00
parent 31e151362b
commit 7b233f3032
2 changed files with 31 additions and 18 deletions

View File

@ -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 );

View File

@ -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 );
}