https://git.reactos.org/?p=reactos.git;a=commitdiff;h=73bb9b5ffdadeda94e09d53c92bf756b8be5ff3b

commit 73bb9b5ffdadeda94e09d53c92bf756b8be5ff3b
Author:     winesync <[email protected]>
AuthorDate: Fri Sep 11 17:10:41 2020 +0200
Commit:     Jérôme Gardou <[email protected]>
CommitDate: Wed Sep 16 10:35:47 2020 +0200

    [WINESYNC] dbghelp: Introduce search_unix_path helper and use it in 
elf_search_and_load_file.
    
    Signed-off-by: Jacek Caban <[email protected]>
    Signed-off-by: Alexandre Julliard <[email protected]>
    
    wine commit id ca49552f646bf30b492da4668745f9f65b9de18d by Jacek Caban 
<[email protected]>
---
 dll/win32/dbghelp/dbghelp_private.h |  1 +
 dll/win32/dbghelp/elf_module.c      | 49 +++----------------------------------
 dll/win32/dbghelp/path.c            | 43 ++++++++++++++++++++++++++++++++
 sdk/tools/winesync/dbghelp.cfg      |  2 +-
 4 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/dll/win32/dbghelp/dbghelp_private.h 
b/dll/win32/dbghelp/dbghelp_private.h
index ac528c5dbe5..d98ccedf64a 100644
--- a/dll/win32/dbghelp/dbghelp_private.h
+++ b/dll/win32/dbghelp/dbghelp_private.h
@@ -704,6 +704,7 @@ extern BOOL         path_find_symbol_file(const struct 
process* pcs, const struc
                                           WCHAR *buffer, BOOL* is_unmatched) 
DECLSPEC_HIDDEN;
 extern WCHAR *get_dos_file_name(const WCHAR *filename) DECLSPEC_HIDDEN;
 extern BOOL search_dll_path(const WCHAR *name, BOOL (*match)(void*, HANDLE, 
const WCHAR*), void *param) DECLSPEC_HIDDEN;
+extern BOOL search_unix_path(const WCHAR *name, const char *path, BOOL 
(*match)(void*, HANDLE, const WCHAR*), void *param) DECLSPEC_HIDDEN;
 extern const WCHAR* file_name(const WCHAR* str) DECLSPEC_HIDDEN;
 extern const char* file_nameA(const char* str) DECLSPEC_HIDDEN;
 
diff --git a/dll/win32/dbghelp/elf_module.c b/dll/win32/dbghelp/elf_module.c
index 0433bf77e05..0b60524fc44 100644
--- a/dll/win32/dbghelp/elf_module.c
+++ b/dll/win32/dbghelp/elf_module.c
@@ -1274,47 +1274,6 @@ static BOOL elf_load_file_cb(void *param, HANDLE handle, 
const WCHAR *filename)
     return elf_load_file(load_file->process, filename, load_file->load_offset, 
load_file->dyn_addr, load_file->elf_info);
 }
 
-/******************************************************************
- *             elf_load_file_from_path
- * tries to load an ELF file from a set of paths (separated by ':')
- */
-static BOOL elf_load_file_from_path(HANDLE hProcess,
-                                    const WCHAR* filename,
-                                    unsigned long load_offset,
-                                    unsigned long dyn_addr,
-                                    const char* path,
-                                    struct elf_info* elf_info)
-{
-    BOOL                ret = FALSE;
-    WCHAR               *s, *t, *fn;
-    WCHAR*             pathW = NULL;
-    unsigned            len;
-
-    if (!path) return FALSE;
-
-    len = MultiByteToWideChar(CP_UNIXCP, 0, path, -1, NULL, 0);
-    pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-    if (!pathW) return FALSE;
-    MultiByteToWideChar(CP_UNIXCP, 0, path, -1, pathW, len);
-
-    for (s = pathW; s && *s; s = (t) ? (t+1) : NULL)
-    {
-       t = strchrW(s, ':');
-       if (t) *t = '\0';
-       fn = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1 + 
lstrlenW(s) + 1) * sizeof(WCHAR));
-       if (!fn) break;
-       strcpyW(fn, s);
-       strcatW(fn, S_SlashW);
-       strcatW(fn, filename);
-       ret = elf_load_file(hProcess, fn, load_offset, dyn_addr, elf_info);
-       HeapFree(GetProcessHeap(), 0, fn);
-       if (ret) break;
-    }
-
-    HeapFree(GetProcessHeap(), 0, pathW);
-    return ret;
-}
-
 #ifdef AT_SYSINFO_EHDR
 /******************************************************************
  *             elf_search_auxv
@@ -1418,11 +1377,9 @@ static BOOL elf_search_and_load_file(struct process* 
pcs, const WCHAR* filename,
         load_elf.dyn_addr    = dyn_addr;
         load_elf.elf_info    = elf_info;
 
-        ret = elf_load_file_from_path(pcs, filename, load_offset, dyn_addr,
-                                      getenv("PATH"), elf_info) ||
-            elf_load_file_from_path(pcs, filename, load_offset, dyn_addr,
-                                    getenv("LD_LIBRARY_PATH"), elf_info);
-        if (!ret) ret = search_dll_path(filename, elf_load_file_cb, &load_elf);
+        ret = search_unix_path(filename, getenv("PATH"), elf_load_file_cb, 
&load_elf)
+            || search_unix_path(filename, getenv("LD_LIBRARY_PATH"), 
elf_load_file_cb, &load_elf)
+            || search_dll_path(filename, elf_load_file_cb, &load_elf);
     }
 
     return ret;
diff --git a/dll/win32/dbghelp/path.c b/dll/win32/dbghelp/path.c
index e10318d35c6..a5b8b4fdd8d 100644
--- a/dll/win32/dbghelp/path.c
+++ b/dll/win32/dbghelp/path.c
@@ -807,4 +807,47 @@ found:
     heap_free(buf);
     return TRUE;
 }
+
+BOOL search_unix_path(const WCHAR *name, const char *path, BOOL 
(*match)(void*, HANDLE, const WCHAR*), void *param)
+{
+    const char *iter, *next;
+    size_t size, len;
+    WCHAR *dos_path;
+    char *buf;
+    BOOL ret = FALSE;
+
+    if (!path) return FALSE;
+    name = file_name(name);
+
+    size = WideCharToMultiByte(CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL) + 
strlen(path) + 1;
+    if (!(buf = heap_alloc(size))) return FALSE;
+
+    for (iter = path;; iter = next + 1)
+    {
+        if (!(next = strchr(iter, ':'))) next = iter + strlen(iter);
+        if (*iter == '/')
+        {
+            len = next - iter;
+            memcpy(buf, iter, len);
+            if (buf[len - 1] != '/') buf[len++] = '/';
+            WideCharToMultiByte(CP_UNIXCP, 0, name, -1, buf + len, size - len, 
NULL, NULL);
+            if ((dos_path = wine_get_dos_file_name(buf)))
+            {
+                HANDLE file = CreateFileW(dos_path, GENERIC_READ, 
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+                if (file != INVALID_HANDLE_VALUE)
+                {
+                    ret = match(param, file, dos_path);
+                    CloseHandle(file);
+                    if (ret) TRACE("found %s\n", debugstr_w(dos_path));
+                }
+                heap_free(dos_path);
+                if (ret) break;
+            }
+        }
+        if (*next != ':') break;
+    }
+
+    heap_free(buf);
+    return ret;
+}
 #endif
diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg
index 719150f9ac5..df209bd3ca0 100644
--- a/sdk/tools/winesync/dbghelp.cfg
+++ b/sdk/tools/winesync/dbghelp.cfg
@@ -4,4 +4,4 @@ files:
   include/dbghelp.h: sdk/include/psdk/dbghelp.h
   include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
 tags:
-  wine: ee5d29b7aa85c109bf9ad5ac59fbe484f53da0ea
+  wine: ca49552f646bf30b492da4668745f9f65b9de18d

Reply via email to