mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 08:23:01 +00:00
[WINESYNC] dbghelp: Make dll builtin PE path search helper more generic.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 21af2e194792aaa263c144c8fb42fe678ad2ecd7 by Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
parent
981f24bd1a
commit
e01d28abd8
4 changed files with 110 additions and 72 deletions
|
@ -703,6 +703,7 @@ extern BOOL path_find_symbol_file(const struct process* pcs, const struc
|
||||||
PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2,
|
PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2,
|
||||||
WCHAR *buffer, BOOL* is_unmatched) DECLSPEC_HIDDEN;
|
WCHAR *buffer, BOOL* is_unmatched) DECLSPEC_HIDDEN;
|
||||||
extern WCHAR *get_dos_file_name(const WCHAR *filename) 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 const WCHAR* file_name(const WCHAR* str) DECLSPEC_HIDDEN;
|
extern const WCHAR* file_name(const WCHAR* str) DECLSPEC_HIDDEN;
|
||||||
extern const char* file_nameA(const char* str) DECLSPEC_HIDDEN;
|
extern const char* file_nameA(const char* str) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
|
|
|
@ -720,3 +720,91 @@ WCHAR *get_dos_file_name(const WCHAR *filename)
|
||||||
}
|
}
|
||||||
return dos_path;
|
return dos_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __REACTOS__
|
||||||
|
BOOL search_dll_path(const WCHAR *name, BOOL (*match)(void*, HANDLE, const WCHAR*), void *param)
|
||||||
|
{
|
||||||
|
size_t len, i;
|
||||||
|
HANDLE file;
|
||||||
|
WCHAR *buf;
|
||||||
|
BOOL ret;
|
||||||
|
|
||||||
|
static const WCHAR winebuilddirW[] = {'W','I','N','E','B','U','I','L','D','D','I','R',0};
|
||||||
|
static const WCHAR winedlldirW[] = {'W','I','N','E','D','L','L','D','I','R','%','u',0};
|
||||||
|
|
||||||
|
name = file_name(name);
|
||||||
|
|
||||||
|
if ((len = GetEnvironmentVariableW(winebuilddirW, NULL, 0)))
|
||||||
|
{
|
||||||
|
WCHAR *p, *end;
|
||||||
|
const WCHAR dllsW[] = { '\\','d','l','l','s','\\' };
|
||||||
|
const WCHAR programsW[] = { '\\','p','r','o','g','r','a','m','s','\\' };
|
||||||
|
const WCHAR dot_dllW[] = {'.','d','l','l',0};
|
||||||
|
const WCHAR dot_exeW[] = {'.','e','x','e',0};
|
||||||
|
const WCHAR dot_soW[] = {'.','s','o',0};
|
||||||
|
|
||||||
|
if (!(buf = heap_alloc((len + 8 + 3 * lstrlenW(name)) * sizeof(WCHAR)))) return FALSE;
|
||||||
|
end = buf + GetEnvironmentVariableW(winebuilddirW, buf, len);
|
||||||
|
|
||||||
|
memcpy(end, dllsW, sizeof(dllsW));
|
||||||
|
strcpyW(end + ARRAY_SIZE(dllsW), name);
|
||||||
|
if ((p = strrchrW(end, '.')) && !lstrcmpW(p, dot_soW)) *p = 0;
|
||||||
|
if ((p = strrchrW(end, '.')) && !lstrcmpW(p, dot_dllW)) *p = 0;
|
||||||
|
p = end + strlenW(end);
|
||||||
|
*p++ = '\\';
|
||||||
|
strcpyW(p, name);
|
||||||
|
file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (file != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
ret = match(param, file, buf);
|
||||||
|
CloseHandle(file);
|
||||||
|
if (ret) goto found;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(end, programsW, sizeof(programsW));
|
||||||
|
end += ARRAY_SIZE(programsW);
|
||||||
|
strcpyW(end, name);
|
||||||
|
if ((p = strrchrW(end, '.')) && !lstrcmpW(p, dot_soW)) *p = 0;
|
||||||
|
if ((p = strrchrW(end, '.')) && !lstrcmpW(p, dot_exeW)) *p = 0;
|
||||||
|
p = end + strlenW(end);
|
||||||
|
*p++ = '\\';
|
||||||
|
strcpyW(p, name);
|
||||||
|
file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (file != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
ret = match(param, file, buf);
|
||||||
|
CloseHandle(file);
|
||||||
|
if (ret) goto found;
|
||||||
|
}
|
||||||
|
|
||||||
|
heap_free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0;; i++)
|
||||||
|
{
|
||||||
|
WCHAR env_name[64];
|
||||||
|
sprintfW(env_name, winedlldirW, i);
|
||||||
|
if (!(len = GetEnvironmentVariableW(env_name, NULL, 0))) break;
|
||||||
|
if (!(buf = heap_alloc((len + lstrlenW(name) + 2) * sizeof(WCHAR)))) return FALSE;
|
||||||
|
|
||||||
|
len = GetEnvironmentVariableW(env_name, buf, len);
|
||||||
|
buf[len++] = '\\';
|
||||||
|
strcpyW(buf + len, name);
|
||||||
|
file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (file != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
ret = match(param, file, buf);
|
||||||
|
CloseHandle(file);
|
||||||
|
if (ret) goto found;
|
||||||
|
}
|
||||||
|
heap_free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
found:
|
||||||
|
TRACE("found %s\n", debugstr_w(buf));
|
||||||
|
heap_free(buf);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -775,68 +775,23 @@ BOOL pe_load_debug_info(const struct process* pcs, struct module* module)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __REACTOS__
|
#ifndef __REACTOS__
|
||||||
static WCHAR *find_builtin_pe(const WCHAR *path, HANDLE *file)
|
struct builtin_search
|
||||||
{
|
{
|
||||||
const WCHAR *base_name;
|
WCHAR *path;
|
||||||
size_t len, i;
|
struct image_file_map fmap;
|
||||||
WCHAR *buf;
|
};
|
||||||
|
|
||||||
static const WCHAR winebuilddirW[] = {'W','I','N','E','B','U','I','L','D','D','I','R',0};
|
static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path)
|
||||||
static const WCHAR winedlldirW[] = {'W','I','N','E','D','L','L','D','I','R','%','u',0};
|
{
|
||||||
|
struct builtin_search *search = param;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
if ((base_name = strrchrW(path, '\\'))) base_name++;
|
if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE;
|
||||||
else base_name = path;
|
|
||||||
|
|
||||||
if ((len = GetEnvironmentVariableW(winebuilddirW, NULL, 0)))
|
size = (lstrlenW(path) + 1) * sizeof(WCHAR);
|
||||||
{
|
if ((search->path = heap_alloc(size)))
|
||||||
WCHAR *p, *end;
|
memcpy(search->path, path, size);
|
||||||
const WCHAR dllsW[] = { '\\','d','l','l','s','\\' };
|
return TRUE;
|
||||||
const WCHAR programsW[] = { '\\','p','r','o','g','r','a','m','s','\\' };
|
|
||||||
const WCHAR dot_dllW[] = {'.','d','l','l',0};
|
|
||||||
const WCHAR dot_exeW[] = {'.','e','x','e',0};
|
|
||||||
|
|
||||||
if (!(buf = heap_alloc((len + 8 + 2 * lstrlenW(base_name)) * sizeof(WCHAR)))) return NULL;
|
|
||||||
end = buf + GetEnvironmentVariableW(winebuilddirW, buf, len);
|
|
||||||
|
|
||||||
memcpy(end, dllsW, sizeof(dllsW));
|
|
||||||
strcpyW(end + ARRAY_SIZE(dllsW), base_name);
|
|
||||||
if ((p = strchrW(end, '.')) && !lstrcmpW(p, dot_dllW)) *p = 0;
|
|
||||||
p = end + strlenW(end);
|
|
||||||
*p++ = '\\';
|
|
||||||
strcpyW(p, base_name);
|
|
||||||
*file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (*file != INVALID_HANDLE_VALUE) return buf;
|
|
||||||
|
|
||||||
memcpy(end, programsW, sizeof(programsW));
|
|
||||||
end += ARRAY_SIZE(programsW);
|
|
||||||
strcpyW(end, base_name);
|
|
||||||
if ((p = strchrW(end, '.')) && !lstrcmpW(p, dot_exeW)) *p = 0;
|
|
||||||
p = end + strlenW(end);
|
|
||||||
*p++ = '\\';
|
|
||||||
strcpyW(p, base_name);
|
|
||||||
*file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (*file != INVALID_HANDLE_VALUE) return buf;
|
|
||||||
|
|
||||||
heap_free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0;; i++)
|
|
||||||
{
|
|
||||||
WCHAR name[64];
|
|
||||||
sprintfW(name, winedlldirW, i);
|
|
||||||
if (!(len = GetEnvironmentVariableW(name, NULL, 0))) break;
|
|
||||||
if (!(buf = heap_alloc((len + lstrlenW(base_name) + 2) * sizeof(WCHAR)))) return NULL;
|
|
||||||
|
|
||||||
GetEnvironmentVariableW(name, buf, len);
|
|
||||||
buf[len++] = '\\';
|
|
||||||
strcpyW(buf + len, base_name);
|
|
||||||
*file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (*file != INVALID_HANDLE_VALUE) return buf;
|
|
||||||
|
|
||||||
heap_free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -870,18 +825,12 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
|
||||||
if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE))
|
if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE))
|
||||||
{
|
{
|
||||||
#ifndef __REACTOS__
|
#ifndef __REACTOS__
|
||||||
WCHAR *builtin_path = NULL;
|
struct builtin_search builtin = { NULL };
|
||||||
HANDLE builtin_module;
|
if (modfmt->u.pe_info->fmap.u.pe.builtin && search_dll_path(loaded_name, search_builtin_pe, &builtin))
|
||||||
if (modfmt->u.pe_info->fmap.u.pe.builtin && (builtin_path = find_builtin_pe(loaded_name, &builtin_module)))
|
|
||||||
{
|
{
|
||||||
struct image_file_map builtin_fmap;
|
TRACE("reloaded %s from %s\n", debugstr_w(loaded_name), debugstr_w(builtin.path));
|
||||||
if (pe_map_file(builtin_module, &builtin_fmap, DMT_PE))
|
image_unmap_file(&modfmt->u.pe_info->fmap);
|
||||||
{
|
modfmt->u.pe_info->fmap = builtin.fmap;
|
||||||
TRACE("reloaded %s from %s\n", debugstr_w(loaded_name), debugstr_w(builtin_path));
|
|
||||||
image_unmap_file(&modfmt->u.pe_info->fmap);
|
|
||||||
modfmt->u.pe_info->fmap = builtin_fmap;
|
|
||||||
}
|
|
||||||
CloseHandle(builtin_module);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!base) base = modfmt->u.pe_info->fmap.u.pe.ntheader.OptionalHeader.ImageBase;
|
if (!base) base = modfmt->u.pe_info->fmap.u.pe.ntheader.OptionalHeader.ImageBase;
|
||||||
|
@ -895,7 +844,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
|
||||||
#ifdef __REACTOS__
|
#ifdef __REACTOS__
|
||||||
module->real_path = NULL;
|
module->real_path = NULL;
|
||||||
#else
|
#else
|
||||||
module->real_path = builtin_path;
|
module->real_path = builtin.path;
|
||||||
#endif
|
#endif
|
||||||
modfmt->module = module;
|
modfmt->module = module;
|
||||||
modfmt->remove = pe_module_remove;
|
modfmt->remove = pe_module_remove;
|
||||||
|
@ -912,7 +861,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
|
||||||
{
|
{
|
||||||
ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
|
ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
|
||||||
#ifndef __REACTOS__
|
#ifndef __REACTOS__
|
||||||
heap_free(module->real_path);
|
heap_free(builtin.path);
|
||||||
#endif
|
#endif
|
||||||
image_unmap_file(&modfmt->u.pe_info->fmap);
|
image_unmap_file(&modfmt->u.pe_info->fmap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,4 @@ files:
|
||||||
include/dbghelp.h: sdk/include/psdk/dbghelp.h
|
include/dbghelp.h: sdk/include/psdk/dbghelp.h
|
||||||
include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
|
include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
|
||||||
tags:
|
tags:
|
||||||
wine: 77e880e6d22ef9be031f783fbb4b6a5e8c8826e8
|
wine: 21af2e194792aaa263c144c8fb42fe678ad2ecd7
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue