[PATCH 2/4] [DbgHelp]: rewrote module_is_elf_container_loaded so that it no longer uses

Eric Pouech eric.pouech at wanadoo.fr
Tue Mar 13 11:32:57 CDT 2007


the stored ModuleName (that the dbghelp's caller can override) but rather a
combination of base address and filename for the module

A+
---

 dlls/dbghelp/module.c |   42 +++++++++++++++++++++++++++---------------
 1 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index 448ff56..3bff6b7 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -67,7 +67,7 @@ static int match_ext(const WCHAR* ptr, s
 static const WCHAR* get_filename(const WCHAR* name, const WCHAR* endptr)
 {
     const WCHAR*        ptr;
-    
+
     if (!endptr) endptr = name + strlenW(name);
     for (ptr = endptr - 1; ptr >= name; ptr--)
     {
@@ -358,27 +358,39 @@ struct module* module_find_by_addr(const
     return module;
 }
 
+/******************************************************************
+ *		module_is_elf_container_loaded
+ *
+ * checks whether the ELF container, for a (supposed) PE builtin is
+ * already loaded
+ */
 static BOOL module_is_elf_container_loaded(struct process* pcs,
-                                           const WCHAR* ImageName,
-                                           const WCHAR* ModuleName)
+                                           const WCHAR* ImageName, DWORD base)
 {
-    WCHAR               buffer[MAX_PATH];
     size_t              len;
     struct module*      module;
+    LPCWSTR             filename, modname;
+
+    if (!base) return FALSE;
+    filename = get_filename(ImageName, NULL);
+    len = strlenW(filename);
 
-    if (!ModuleName)
-    {
-        module_fill_module(ImageName, buffer, sizeof(buffer));
-        ModuleName = buffer;
-    }
-    len = strlenW(ModuleName);
     for (module = pcs->lmodules; module; module = module->next)
     {
-        if (!strncmpiW(module->module.ModuleName, ModuleName, len) &&
-            module->type == DMT_ELF &&
-            !strcmpW(module->module.ModuleName + len, S_ElfW))
-            return TRUE;
+        if (module->type == DMT_ELF &&
+            base >= module->module.BaseOfImage &&
+            base < module->module.BaseOfImage + module->module.ImageSize)
+        {
+            modname = get_filename(module->module.LoadedImageName, NULL);
+            if (!strncmpiW(modname, filename, len) &&
+                !memcmp(modname + len, S_DotSoW, 3 * sizeof(WCHAR)))
+            {
+                return TRUE;
+            }
+        }
     }
+    /* likely a native PE module */
+    WARN("Couldn't find container for %s\n", debugstr_w(ImageName));
     return FALSE;
 }
 
@@ -499,7 +511,7 @@ DWORD64 WINAPI  SymLoadModuleExW(HANDLE 
     /* this is a Wine extension to the API just to redo the synchronisation */
     if (!wImageName && !hFile) return 0;
 
-    if (module_is_elf_container_loaded(pcs, wImageName, wModuleName))
+    if (module_is_elf_container_loaded(pcs, wImageName, BaseOfDll))
     {
         /* force the loading of DLL as builtin */
         if ((module = pe_load_module_from_pcs(pcs, wImageName, wModuleName,



More information about the wine-patches mailing list