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

--- loader.c.0_9_2	2006-01-02 13:40:27.000000000 -0800
+++ loader.c	2006-01-03 14:11:16.000000000 -0800
@@ -937,9 +937,15 @@
             LDR_MODULE *mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
 
             if (mod->Flags & (LDR_LOAD_IN_PROGRESS | LDR_PROCESS_ATTACHED)) continue;
+if (mod->Flags & LDR_WINE_INTERNAL) // todo
+{
+	mod->Flags &= ~LDR_WINE_INTERNAL;
+	TRACE("Turned off LDR_WINE_INTERNAL (%ld)", mod->Flags);
+}
             TRACE( "found implicitly loaded %s, attaching to it\n",
                    debugstr_w(mod->BaseDllName.Buffer));
             process_attach( CONTAINING_RECORD(mod, WINE_MODREF, ldr), reserved );
+mod->LoadCount = -1; /* exclude from the unload mechanism */
             break;  /* restart the search from the start */
         }
         if (entry == mark) break;  /* nothing found */


Reply via email to