Alexandre Julliard : dbghelp: Add a helper function to determine the name of the wine loader.

Alexandre Julliard julliard at winehq.org
Fri Jan 28 12:30:12 CST 2011


Module: wine
Branch: master
Commit: 3bae7d03836bc57ccd602c40586e00609a6d9585
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3bae7d03836bc57ccd602c40586e00609a6d9585

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Jan 28 11:41:14 2011 +0100

dbghelp: Add a helper function to determine the name of the wine loader.

---

 dlls/dbghelp/dbghelp_private.h |    2 +-
 dlls/dbghelp/elf_module.c      |   18 +-----------------
 dlls/dbghelp/macho_module.c    |   20 +-------------------
 dlls/dbghelp/module.c          |   35 +++++++++++++++++++++++++++++++----
 4 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 388908a..b2b13c0 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -528,7 +528,6 @@ extern BOOL         macho_synchronize_module_list(struct process* pcs);
 /* module.c */
 extern const WCHAR      S_ElfW[];
 extern const WCHAR      S_WineLoaderW[];
-extern const WCHAR      S_WineW[];
 extern const WCHAR      S_SlashW[];
 
 extern struct module*
@@ -555,6 +554,7 @@ extern void         module_reset_debug_info(struct module* module);
 extern BOOL         module_remove(struct process* pcs,
                                   struct module* module);
 extern void         module_set_module(struct module* module, const WCHAR* name);
+extern const WCHAR *get_wine_loader_name(void);
 
 /* msc.c */
 extern BOOL         pe_load_debug_directory(const struct process* pcs,
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index a64fe9f..e2391bd 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -1458,23 +1458,7 @@ static BOOL elf_enum_modules_internal(const struct process* pcs,
  */
 static BOOL elf_search_loader(struct process* pcs, struct elf_info* elf_info)
 {
-    BOOL                ret;
-    const char*         ptr;
-
-    /* All binaries are loaded with WINELOADER (if run from tree) or by the
-     * main executable
-     */
-    if ((ptr = getenv("WINELOADER")))
-    {
-        WCHAR   tmp[MAX_PATH];
-        MultiByteToWideChar(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp) / sizeof(WCHAR));
-        ret = elf_search_and_load_file(pcs, tmp, 0, 0, elf_info);
-    }
-    else
-    {
-        ret = elf_search_and_load_file(pcs, S_WineW, 0, 0, elf_info);
-    }
-    return ret;
+    return elf_search_and_load_file(pcs, get_wine_loader_name(), 0, 0, elf_info);
 }
 
 /******************************************************************
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c
index ae67188..6b03fee 100644
--- a/dlls/dbghelp/macho_module.c
+++ b/dlls/dbghelp/macho_module.c
@@ -1274,25 +1274,7 @@ BOOL    macho_synchronize_module_list(struct process* pcs)
  */
 static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info)
 {
-    BOOL                ret;
-    const char*         ptr;
-
-    TRACE("(%p/%p, %p)\n", pcs, pcs->handle, macho_info);
-
-    /* All binaries are loaded with WINELOADER (if run from tree) or by the
-     * main executable
-     */
-    if ((ptr = getenv("WINELOADER")))
-    {
-        WCHAR   tmp[MAX_PATH];
-        MultiByteToWideChar(CP_UNIXCP, 0, ptr, -1, tmp, sizeof(tmp) / sizeof(WCHAR));
-        ret = macho_search_and_load_file(pcs, tmp, 0, macho_info);
-    }
-    else
-    {
-        ret = macho_search_and_load_file(pcs, S_WineW, 0, macho_info);
-    }
-    return ret;
+    return macho_search_and_load_file(pcs, get_wine_loader_name(), 0, macho_info);
 }
 
 /******************************************************************
diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index debfd5d..50cf114 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -38,7 +38,6 @@ static const WCHAR S_DotSoW[]       = {'.','s','o','\0'};
 static const WCHAR S_DotDylibW[]    = {'.','d','y','l','i','b','\0'};
 static const WCHAR S_DotPdbW[]      = {'.','p','d','b','\0'};
 static const WCHAR S_DotDbgW[]      = {'.','d','b','g','\0'};
-const WCHAR        S_WineW[]        = {'w','i','n','e',0};
 const WCHAR        S_SlashW[]       = {'/','\0'};
 
 static const WCHAR S_AcmW[] = {'.','a','c','m','\0'};
@@ -78,6 +77,7 @@ static const WCHAR* get_filename(const WCHAR* name, const WCHAR* endptr)
 
 static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
 {
+    const WCHAR *loader = get_wine_loader_name();
     const WCHAR *ptr, *endptr;
     size_t      len, l;
 
@@ -87,7 +87,7 @@ static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
     out[len] = '\0';
     if (len > 4 && (l = match_ext(out, len)))
         out[len - l] = '\0';
-    else if (len > 4 && !strcmpiW(out + len - 4, S_WineW))
+    else if (len > strlenW(loader) && !strcmpiW(out + len - strlenW(loader), loader))
         lstrcpynW(out, S_WineLoaderW, size);
     else
     {
@@ -106,6 +106,29 @@ void module_set_module(struct module* module, const WCHAR* name)
                         NULL, NULL);
 }
 
+const WCHAR *get_wine_loader_name(void)
+{
+    static const WCHAR wineW[] = {'w','i','n','e',0};
+    static const WCHAR *loader;
+    const char *ptr;
+
+    if (!loader)
+    {
+        /* All binaries are loaded with WINELOADER (if run from tree) or by the
+         * main executable
+         */
+        if ((ptr = getenv("WINELOADER")))
+        {
+            DWORD len = MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
+            WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+            MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
+            loader = buffer;
+        }
+        else loader = wineW;
+    }
+    return loader;
+}
+
 static const char*      get_module_type(enum module_type type, BOOL virtual)
 {
     switch (type)
@@ -417,7 +440,8 @@ static BOOL module_is_container_loaded(const struct process* pcs,
  */
 enum module_type module_get_type_by_name(const WCHAR* name)
 {
-    int len = strlenW(name);
+    int loader_len, len = strlenW(name);
+    const WCHAR *loader;
 
     /* Skip all version extensions (.[digits]) regex: "(\.\d+)*$" */
     do
@@ -452,7 +476,10 @@ enum module_type module_get_type_by_name(const WCHAR* name)
         return DMT_DBG;
 
     /* wine is also a native module (Mach-O on Mac OS X, ELF elsewhere) */
-    if (((len > 4 && name[len - 5] == '/') || len == 4) && !strcmpiW(name + len - 4, S_WineW))
+    loader = get_wine_loader_name();
+    loader_len = strlenW( loader );
+    if ((len == loader_len || (len > loader_len && name[len - loader_len - 1] == '/')) &&
+        !strcmpiW(name + len - loader_len, loader))
     {
 #ifdef __APPLE__
         return DMT_MACHO;




More information about the wine-cvs mailing list