I am looking for some expert advice in how to handle unloading "implicitly loaded DLLs". I have found two issues.
(1) The first is a crash that happens in dlls/ntdll/loader.c MODULE_FlushModrefs. wine_unload_dll() is called for such a DLL, but SectionHandle is NULL so the call crashes.
My solution was to turn off the LDR_WINE_INTERNAL flag in attach_implicitly_loaded_dlls() but I am not real clear what that flag is or whether that approach is good. An alternative is to add a check for a null SectionHeader before calling wine_unload_dll().
(2) Second is that these DLLs are DLL_PROCESS_DETACHED in process_detach() every time _any_ DLL is unloaded. This happens because the LoadCount is 0. I set it to -1 in attach_implicitly_loaded_dlls() which does the trick. But again I don't know what the heck I am messing with. Is that OK?
Attached is a diff of the two changes. I'm not looking for points for style. But just a check on the approach for now. Thanks ... mo
Michael Ost most@museresearch.com writes:
(2) Second is that these DLLs are DLL_PROCESS_DETACHED in process_detach() every time _any_ DLL is unloaded. This happens because the LoadCount is 0. I set it to -1 in attach_implicitly_loaded_dlls() which does the trick. But again I don't know what the heck I am messing with. Is that OK?
Yes, that seems reasonable, we can't unload these dlls anyway. And it should fix your other problem too.