From f69be6c561fcf5e151e96ad9729f3ec501b8393a Mon Sep 17 00:00:00 2001 From: winesync Date: Fri, 11 Sep 2020 13:00:06 +0200 Subject: [PATCH] [WINESYNC] dbghelp: Determine the wine loader name from the target process's architecture. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard wine commit id a981edf0bc7c828e6b55fdc73b51a2f457043c4a by Zebediah Figura --- dll/win32/dbghelp/compat.c | 22 +++++++---- dll/win32/dbghelp/compat.h | 39 ++++++++++--------- dll/win32/dbghelp/dbghelp.c | 7 ++++ dll/win32/dbghelp/dbghelp_private.h | 60 +++++++++++++++-------------- dll/win32/dbghelp/elf_module.c | 7 +++- dll/win32/dbghelp/macho_module.c | 4 +- dll/win32/dbghelp/module.c | 59 ++++++++++++++-------------- sdk/tools/winesync/dbghelp.cfg | 2 +- 8 files changed, 112 insertions(+), 88 deletions(-) diff --git a/dll/win32/dbghelp/compat.c b/dll/win32/dbghelp/compat.c index 51a43453fa8..dfd9ec13d29 100644 --- a/dll/win32/dbghelp/compat.c +++ b/dll/win32/dbghelp/compat.c @@ -71,8 +71,8 @@ __RtlImageRvaToSection( PVOID __RtlImageRvaToVa -(const IMAGE_NT_HEADERS* NtHeader, - PVOID BaseAddress, +(const IMAGE_NT_HEADERS* NtHeader, + PVOID BaseAddress, ULONG Rva, PIMAGE_SECTION_HEADER *SectionHeader) { @@ -160,7 +160,7 @@ HANDLE __CreateFileW( { char buf[MAX_PATH]; HANDLE res; - + WideCharToMultiByte(CP_ACP, 0, lpFileName, -1, buf, MAX_PATH, NULL, NULL); res = CreateFileA(buf, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); return res; @@ -187,7 +187,7 @@ void* __MapViewOfFile(HANDLE file,DWORD d1,DWORD d2,DWORD d3,SIZE_T s) free(result); return NULL; } - + return result; } @@ -222,15 +222,15 @@ __WideCharToMultiByte(UINT page, DWORD flags, LPCWSTR src, INT srclen, } if (srclen < 0) srclen = strlenW(src) + 1; - + if(!dstlen) return srclen; - + for(i=0; ihandle = hProcess; + IsWow64Process(GetCurrentProcess(), &wow64); + + if (!IsWow64Process(hProcess, &child_wow64)) + return FALSE; + pcs->is_64bit = (sizeof(void *) == 8 || wow64) && !child_wow64; + if (UserSearchPath) { pcs->search_path = lstrcpyW(HeapAlloc(GetProcessHeap(), 0, diff --git a/dll/win32/dbghelp/dbghelp_private.h b/dll/win32/dbghelp/dbghelp_private.h index 0d1e8e4274d..a78bd156673 100644 --- a/dll/win32/dbghelp/dbghelp_private.h +++ b/dll/win32/dbghelp/dbghelp_private.h @@ -415,7 +415,7 @@ struct module struct wine_rb_tree sources_offsets_tree; }; -struct process +struct process { struct process* next; HANDLE handle; @@ -433,6 +433,8 @@ struct process unsigned buffer_size; void* buffer; + + BOOL is_64bit; }; struct line_info @@ -639,11 +641,13 @@ extern void module_reset_debug_info(struct module* module) DECLSPEC_HIDD extern BOOL module_remove(struct process* pcs, struct module* module) DECLSPEC_HIDDEN; extern void module_set_module(struct module* module, const WCHAR* name) DECLSPEC_HIDDEN; -extern const WCHAR *get_wine_loader_name(void) DECLSPEC_HIDDEN; +#ifndef __REACTOS__ +extern WCHAR * get_wine_loader_name(struct process *pcs) DECLSPEC_HIDDEN; +#endif /* msc.c */ extern BOOL pe_load_debug_directory(const struct process* pcs, - struct module* module, + struct module* module, const BYTE* mapping, const IMAGE_SECTION_HEADER* sectp, DWORD nsect, const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg) DECLSPEC_HIDDEN; @@ -657,7 +661,7 @@ extern BOOL pdb_virtual_unwind(struct cpu_stack_walk* csw, DWORD_PTR ip, /* path.c */ extern BOOL path_find_symbol_file(const struct process* pcs, const struct module* module, - PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2, + PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2, PSTR buffer, BOOL* is_unmatched) DECLSPEC_HIDDEN; /* pe_module.c */ @@ -720,14 +724,14 @@ extern struct symt_compiland* symt_new_compiland(struct module* module, unsigned long address, unsigned src_idx) DECLSPEC_HIDDEN; extern struct symt_public* - symt_new_public(struct module* module, - struct symt_compiland* parent, + symt_new_public(struct module* module, + struct symt_compiland* parent, const char* typename, BOOL is_function, unsigned long address, unsigned size) DECLSPEC_HIDDEN; extern struct symt_data* - symt_new_global_variable(struct module* module, + symt_new_global_variable(struct module* module, struct symt_compiland* parent, const char* name, unsigned is_static, struct location loc, unsigned long size, @@ -738,31 +742,31 @@ extern struct symt_function* const char* name, unsigned long addr, unsigned long size, struct symt* type) DECLSPEC_HIDDEN; -extern BOOL symt_normalize_function(struct module* module, +extern BOOL symt_normalize_function(struct module* module, const struct symt_function* func) DECLSPEC_HIDDEN; extern void symt_add_func_line(struct module* module, - struct symt_function* func, - unsigned source_idx, int line_num, + struct symt_function* func, + unsigned source_idx, int line_num, unsigned long offset) DECLSPEC_HIDDEN; extern struct symt_data* - symt_add_func_local(struct module* module, - struct symt_function* func, + symt_add_func_local(struct module* module, + struct symt_function* func, enum DataKind dt, const struct location* loc, struct symt_block* block, struct symt* type, const char* name) DECLSPEC_HIDDEN; extern struct symt_block* - symt_open_func_block(struct module* module, + symt_open_func_block(struct module* module, struct symt_function* func, - struct symt_block* block, + struct symt_block* block, unsigned pc, unsigned len) DECLSPEC_HIDDEN; extern struct symt_block* - symt_close_func_block(struct module* module, + symt_close_func_block(struct module* module, const struct symt_function* func, struct symt_block* block, unsigned pc) DECLSPEC_HIDDEN; extern struct symt_hierarchy_point* - symt_add_function_point(struct module* module, + symt_add_function_point(struct module* module, struct symt_function* func, - enum SymTagEnum point, + enum SymTagEnum point, const struct location* loc, const char* name) DECLSPEC_HIDDEN; extern BOOL symt_fill_func_line_info(const struct module* module, @@ -770,7 +774,7 @@ extern BOOL symt_fill_func_line_info(const struct module* module, DWORD64 addr, IMAGEHLP_LINE64* line) DECLSPEC_HIDDEN; extern BOOL symt_get_func_line_next(const struct module* module, PIMAGEHLP_LINE64 line) DECLSPEC_HIDDEN; extern struct symt_thunk* - symt_new_thunk(struct module* module, + symt_new_thunk(struct module* module, struct symt_compiland* parent, const char* name, THUNK_ORDINAL ord, unsigned long addr, unsigned long size) DECLSPEC_HIDDEN; @@ -791,38 +795,38 @@ extern void symt_init_basic(struct module* module) DECLSPEC_HIDDEN; extern BOOL symt_get_info(struct module* module, const struct symt* type, IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo) DECLSPEC_HIDDEN; extern struct symt_basic* - symt_new_basic(struct module* module, enum BasicType, + symt_new_basic(struct module* module, enum BasicType, const char* typename, unsigned size) DECLSPEC_HIDDEN; extern struct symt_udt* symt_new_udt(struct module* module, const char* typename, unsigned size, enum UdtKind kind) DECLSPEC_HIDDEN; extern BOOL symt_set_udt_size(struct module* module, struct symt_udt* type, unsigned size) DECLSPEC_HIDDEN; -extern BOOL symt_add_udt_element(struct module* module, - struct symt_udt* udt_type, +extern BOOL symt_add_udt_element(struct module* module, + struct symt_udt* udt_type, const char* name, - struct symt* elt_type, unsigned offset, + struct symt* elt_type, unsigned offset, unsigned size) DECLSPEC_HIDDEN; extern struct symt_enum* symt_new_enum(struct module* module, const char* typename, struct symt* basetype) DECLSPEC_HIDDEN; -extern BOOL symt_add_enum_element(struct module* module, - struct symt_enum* enum_type, +extern BOOL symt_add_enum_element(struct module* module, + struct symt_enum* enum_type, const char* name, int value) DECLSPEC_HIDDEN; extern struct symt_array* - symt_new_array(struct module* module, int min, int max, + symt_new_array(struct module* module, int min, int max, struct symt* base, struct symt* index) DECLSPEC_HIDDEN; extern struct symt_function_signature* - symt_new_function_signature(struct module* module, + symt_new_function_signature(struct module* module, struct symt* ret_type, enum CV_call_e call_conv) DECLSPEC_HIDDEN; extern BOOL symt_add_function_signature_parameter(struct module* module, struct symt_function_signature* sig, struct symt* param) DECLSPEC_HIDDEN; extern struct symt_pointer* - symt_new_pointer(struct module* module, + symt_new_pointer(struct module* module, struct symt* ref_type, unsigned long size) DECLSPEC_HIDDEN; extern struct symt_typedef* - symt_new_typedef(struct module* module, struct symt* ref, + symt_new_typedef(struct module* module, struct symt* ref, const char* name) DECLSPEC_HIDDEN; diff --git a/dll/win32/dbghelp/elf_module.c b/dll/win32/dbghelp/elf_module.c index e841b1b707a..4d877b44214 100644 --- a/dll/win32/dbghelp/elf_module.c +++ b/dll/win32/dbghelp/elf_module.c @@ -50,6 +50,7 @@ #include "wine/library.h" #include "wine/debug.h" +#include "wine/heap.h" #ifdef __ELF__ @@ -1568,13 +1569,17 @@ static BOOL elf_enum_modules_internal(const struct process* pcs, */ static BOOL elf_search_loader(struct process* pcs, struct elf_info* elf_info) { + WCHAR *loader = get_wine_loader_name(pcs); PROCESS_BASIC_INFORMATION pbi; ULONG_PTR base = 0; + BOOL ret; if (!NtQueryInformationProcess( pcs->handle, ProcessBasicInformation, &pbi, sizeof(pbi), NULL )) ReadProcessMemory( pcs->handle, &pbi.PebBaseAddress->Reserved[0], &base, sizeof(base), NULL ); - return elf_search_and_load_file(pcs, get_wine_loader_name(), base, 0, elf_info); + ret = elf_search_and_load_file(pcs, loader, base, 0, elf_info); + heap_free(loader); + return ret; } /****************************************************************** diff --git a/dll/win32/dbghelp/macho_module.c b/dll/win32/dbghelp/macho_module.c index 01fa300eff7..4018c9dbf2d 100644 --- a/dll/win32/dbghelp/macho_module.c +++ b/dll/win32/dbghelp/macho_module.c @@ -1703,6 +1703,7 @@ BOOL macho_synchronize_module_list(struct process* pcs) */ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info) { + WCHAR *loader = get_wine_loader_name(pcs); BOOL ret = FALSE; ULONG_PTR dyld_image_info_address; struct dyld_all_image_infos image_infos; @@ -1757,7 +1758,8 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in } if (!ret) - ret = macho_search_and_load_file(pcs, get_wine_loader_name(), 0, macho_info); + ret = macho_search_and_load_file(pcs, loader, 0, macho_info); + heap_free(loader); return ret; } diff --git a/dll/win32/dbghelp/module.c b/dll/win32/dbghelp/module.c index 2ddf3f50644..8f7150460be 100644 --- a/dll/win32/dbghelp/module.c +++ b/dll/win32/dbghelp/module.c @@ -149,44 +149,41 @@ void module_set_module(struct module* module, const WCHAR* name) module_fill_module(name, module->modulename, sizeof(module->modulename) / sizeof(module->modulename[0])); } -const WCHAR *get_wine_loader_name(void) +#ifndef __REACTOS__ +/* Returned string must be freed by caller */ +WCHAR *get_wine_loader_name(struct process *pcs) { - static const BOOL is_win64 = sizeof(void *) > sizeof(int); /* FIXME: should depend on target process */ static const WCHAR wineW[] = {'w','i','n','e',0}; static const WCHAR suffixW[] = {'6','4',0}; - static const WCHAR *loader; + WCHAR *buffer, *p; + const char *env; - if (!loader) + /* All binaries are loaded with WINELOADER (if run from tree) or by the + * main executable + */ + if ((env = getenv("WINELOADER"))) { - WCHAR *p, *buffer; - const char *ptr; - - /* All binaries are loaded with WINELOADER (if run from tree) or by the - * main executable - */ - if ((ptr = getenv("WINELOADER"))) - { - DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 ); - buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); - MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len ); - } - else - { - buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(wineW) + 2 * sizeof(WCHAR) ); - strcpyW( buffer, wineW ); - } - p = buffer + strlenW( buffer ) - strlenW( suffixW ); - if (p > buffer && !strcmpW( p, suffixW )) - { - if (!is_win64) *p = 0; - } - else if (is_win64) strcatW( buffer, suffixW ); - - TRACE( "returning %s\n", debugstr_w(buffer) ); - loader = buffer; + DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, env, -1, NULL, 0 ); + buffer = heap_alloc( len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_UNIXCP, 0, env, -1, buffer, len ); } - return loader; + else + { + buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) ); + strcpyW( buffer, wineW ); + } + + p = buffer + strlenW( buffer ) - strlenW( suffixW ); + if (p > buffer && !strcmpW( p, suffixW )) + *p = 0; + + if (pcs->is_64bit) + strcatW(buffer, suffixW); + + TRACE( "returning %s\n", debugstr_w(buffer) ); + return buffer; } +#endif static const char* get_module_type(enum module_type type, BOOL virtual) { diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg index 55c41591d34..db9fd318575 100644 --- a/sdk/tools/winesync/dbghelp.cfg +++ b/sdk/tools/winesync/dbghelp.cfg @@ -3,4 +3,4 @@ directories: files: include/dbghelp.h: sdk/include/psdk/dbghelp.h tags: - wine: 9b973eee9e06a3dca7a6c5739741446bf46e27f5 + wine: a981edf0bc7c828e6b55fdc73b51a2f457043c4a