ntdll: Properly track refcount with forwarded exports.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52094
This commit is contained in:
Jinoh Kang 2024-04-19 00:42:57 +09:00
parent 7686456a4e
commit 5ffce73492
2 changed files with 12 additions and 7 deletions

View file

@ -2775,7 +2775,6 @@ static void subtest_export_forwarder_dep_chain( size_t num_chained_export_module
/* FreeLibrary() should *not* unload the DLL immediately */ /* FreeLibrary() should *not* unload the DLL immediately */
module = GetModuleHandleA( temp_paths[i] ); module = GetModuleHandleA( temp_paths[i] );
todo_wine_if(i < ultimate_depender_index && i + 1 != importer_index)
ok( module == modules[i], "modules[%Iu] expected %p, got %p (unloaded?) err=%lu\n", ok( module == modules[i], "modules[%Iu] expected %p, got %p (unloaded?) err=%lu\n",
i, modules[i], module, GetLastError() ); i, modules[i], module, GetLastError() );
} }
@ -2787,7 +2786,6 @@ static void subtest_export_forwarder_dep_chain( size_t num_chained_export_module
{ {
HMODULE module = GetModuleHandleA( temp_paths[i] ); HMODULE module = GetModuleHandleA( temp_paths[i] );
todo_wine_if(i < ultimate_depender_index && i + 1 != importer_index)
ok( module == modules[i], "modules[%Iu] expected %p, got %p (unloaded?) err=%lu\n", ok( module == modules[i], "modules[%Iu] expected %p, got %p (unloaded?) err=%lu\n",
i, modules[i], module, GetLastError() ); i, modules[i], module, GetLastError() );
} }

View file

@ -1033,11 +1033,7 @@ static FARPROC find_forwarded_export( HMODULE module, const char *forward, LPCWS
if (load_dll( load_path, mod_name, 0, &wm, imp->system ) == STATUS_SUCCESS && if (load_dll( load_path, mod_name, 0, &wm, imp->system ) == STATUS_SUCCESS &&
!(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS)) !(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS))
{ {
if (!imports_fixup_done) if (imports_fixup_done && process_attach( wm->ldr.DdagNode, NULL ) != STATUS_SUCCESS)
{
add_module_dependency( current_importer->modref->ldr.DdagNode, wm->ldr.DdagNode );
}
else if (process_attach( wm->ldr.DdagNode, NULL ) != STATUS_SUCCESS)
{ {
LdrUnloadDll( wm->ldr.DllBase ); LdrUnloadDll( wm->ldr.DllBase );
wm = NULL; wm = NULL;
@ -1051,6 +1047,11 @@ static FARPROC find_forwarded_export( HMODULE module, const char *forward, LPCWS
return NULL; return NULL;
} }
} }
else
{
if (wm->ldr.LoadCount != -1) wm->ldr.LoadCount++;
}
if ((exports = RtlImageDirectoryEntryToData( wm->ldr.DllBase, TRUE, if ((exports = RtlImageDirectoryEntryToData( wm->ldr.DllBase, TRUE,
IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size ))) IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
{ {
@ -1070,6 +1071,12 @@ static FARPROC find_forwarded_export( HMODULE module, const char *forward, LPCWS
forward, debugstr_w(get_modref(module)->ldr.FullDllName.Buffer), forward, debugstr_w(get_modref(module)->ldr.FullDllName.Buffer),
debugstr_w(get_modref(module)->ldr.BaseDllName.Buffer) ); debugstr_w(get_modref(module)->ldr.BaseDllName.Buffer) );
} }
else if (wm->ldr.DdagNode != node_ntdll && wm->ldr.DdagNode != node_kernel32)
{
add_module_dependency( current_importer->modref->ldr.DdagNode, wm->ldr.DdagNode );
wm = NULL;
}
if (wm) LdrUnloadDll( wm->ldr.DllBase );
return proc; return proc;
} }