Jacek Caban : dbghelp: Introduce search_unix_path helper and use it in elf_search_and_load_file.
Alexandre Julliard
julliard at winehq.org
Mon Mar 23 15:47:11 CDT 2020
Module: wine
Branch: master
Commit: ca49552f646bf30b492da4668745f9f65b9de18d
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ca49552f646bf30b492da4668745f9f65b9de18d
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Mar 23 16:16:27 2020 +0100
dbghelp: Introduce search_unix_path helper and use it in elf_search_and_load_file.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dbghelp/dbghelp_private.h | 1 +
dlls/dbghelp/elf_module.c | 49 +++---------------------------------------
dlls/dbghelp/path.c | 43 ++++++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 46 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index e846d21054..9415881c57 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -671,6 +671,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/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index 0433bf77e0..0b60524fc4 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/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/dlls/dbghelp/path.c b/dlls/dbghelp/path.c
index 99f6d00395..15e5d344e7 100644
--- a/dlls/dbghelp/path.c
+++ b/dlls/dbghelp/path.c
@@ -806,3 +806,46 @@ 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;
+}
More information about the wine-cvs
mailing list