This series: - fixes a couple of issues in mach-o modules support (getting information from system modules in wow setups, machine information...) - stops hiding information in some fields between dbghelp and winedbg (using an extensible solution, where more information can be shared in the future) - display elf/mach-o in winedbg (previously mach-o was reported as elf) - display PE native vs builtin module information in winedbg
-- v2: dbghelp: Remove unneeded parameter to pe_map_file. dbghelp: Simplified module_find_by_addr(). dbghelp: Set the machine type for mach-O modules. dbghelp: Use is_host_64bit for handling bitness of mach-o libs. dbghelp: Rename internal field (system -> host).
From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/dbghelp/dbghelp.c | 4 ++-- dlls/dbghelp/dbghelp_private.h | 2 +- dlls/dbghelp/elf_module.c | 6 +++--- dlls/dbghelp/module.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index 3ce3ef6f707..18e8ef7bca2 100644 --- a/dlls/dbghelp/dbghelp.c +++ b/dlls/dbghelp/dbghelp.c @@ -378,7 +378,7 @@ static BOOL check_live_target(struct process* pcs, BOOL wow64, BOOL child_wow64) peb_addr += 0x1000; if (!ReadProcessMemory(pcs->handle, peb_addr, &peb32, sizeof(peb32), NULL)) return FALSE; base = *(const DWORD*)((const char*)&peb32 + 0x460 /* CloudFileFlags */); - pcs->is_system_64bit = FALSE; + pcs->is_host_64bit = FALSE; if (read_process_memory(pcs, peb32.ProcessParameters + 0x48, &env32, sizeof(env32))) env = env32; } if (pcs->is_64bit || base == 0) @@ -388,7 +388,7 @@ static BOOL check_live_target(struct process* pcs, BOOL wow64, BOOL child_wow64) if (!pcs->is_64bit) peb_addr -= 0x1000; /* PEB32 => PEB64 */ if (!ReadProcessMemory(pcs->handle, peb_addr, &peb, sizeof(peb), NULL)) return FALSE; base = *(const DWORD64*)&peb.CloudFileFlags; - pcs->is_system_64bit = TRUE; + pcs->is_host_64bit = TRUE; if (pcs->is_64bit) ReadProcessMemory(pcs->handle, (char *)(ULONG_PTR)peb.ProcessParameters + FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, Environment), diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 1ce221a0f27..b90c5c57513 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -517,7 +517,7 @@ struct process void* buffer;
BOOL is_64bit; - BOOL is_system_64bit; + BOOL is_host_64bit; };
static inline BOOL read_process_memory(const struct process *process, UINT64 addr, void *buf, size_t size) diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index a2a60752a68..5ada8c70c9b 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -1345,7 +1345,7 @@ static BOOL elf_search_auxv(const struct process* pcs, unsigned type, ULONG_PTR* { char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME]; SYMBOL_INFO*si = (SYMBOL_INFO*)buffer; - const unsigned ptr_size = pcs->is_system_64bit ? 8 : 4; + const unsigned ptr_size = pcs->is_host_64bit ? 8 : 4; UINT64 envp; UINT64 addr; UINT64 str; @@ -1385,7 +1385,7 @@ static BOOL elf_search_auxv(const struct process* pcs, unsigned type, ULONG_PTR* if (str) break; }
- if (pcs->is_system_64bit) + if (pcs->is_host_64bit) { struct { @@ -1479,7 +1479,7 @@ static BOOL elf_enum_modules_internal(const struct process* pcs, char bufstr[256]; ULONG_PTR lm_addr;
- if (pcs->is_system_64bit) + if (pcs->is_host_64bit) { struct { diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index 22b58950b43..75567127f37 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -134,7 +134,7 @@ WCHAR *get_wine_loader_name(struct process *pcs) unsigned len;
name = process_getenv(pcs, L"WINELOADER"); - if (!name) name = pcs->is_system_64bit ? L"wine64" : L"wine"; + if (!name) name = pcs->is_host_64bit ? L"wine64" : L"wine"; len = lstrlenW(name);
/* WINELOADER isn't properly updated in Wow64 process calling inside Windows env block @@ -145,14 +145,14 @@ WCHAR *get_wine_loader_name(struct process *pcs) if (altname) { memcpy(altname, name, len * sizeof(WCHAR)); - if (pcs->is_system_64bit && len >= 2 && memcmp(name + len - 2, L"64", 2 * sizeof(WCHAR)) != 0) + if (pcs->is_host_64bit && len >= 2 && memcmp(name + len - 2, L"64", 2 * sizeof(WCHAR)) != 0) { lstrcpyW(altname + len, L"64"); /* in multi-arch wow configuration, wine64 doesn't exist */ if (GetFileAttributesW(altname) == INVALID_FILE_ATTRIBUTES) altname[len] = L'\0'; } - else if (!pcs->is_system_64bit && len >= 2 && !memcmp(name + len - 2, L"64", 2 * sizeof(WCHAR))) + else if (!pcs->is_host_64bit && len >= 2 && !memcmp(name + len - 2, L"64", 2 * sizeof(WCHAR))) altname[len - 2] = '\0'; else altname[len] = '\0';
From: Eric Pouech eric.pouech@gmail.com
Wine-Bugs: https://bugs.winehq.org/show_bug.cgi?id=55650
Signed-off-by: Eric Pouech eric.pouech@gmail.com --- dlls/dbghelp/macho_module.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c index f1b3107408c..d5f7df9001f 100644 --- a/dlls/dbghelp/macho_module.c +++ b/dlls/dbghelp/macho_module.c @@ -744,9 +744,9 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW, WCHAR* filename; struct section_info info; BOOL ret = FALSE; - UINT32 target_cpu = (pcs->is_64bit) ? MACHO_CPU_TYPE_X86_64 : MACHO_CPU_TYPE_X86; - UINT32 target_magic = (pcs->is_64bit) ? MACHO_MH_MAGIC_64 : MACHO_MH_MAGIC_32; - UINT32 target_cmd = (pcs->is_64bit) ? MACHO_LC_SEGMENT_64 : MACHO_LC_SEGMENT; + UINT32 target_cpu = (pcs->is_host_64bit) ? MACHO_CPU_TYPE_X86_64 : MACHO_CPU_TYPE_X86; + UINT32 target_magic = (pcs->is_host_64bit) ? MACHO_MH_MAGIC_64 : MACHO_MH_MAGIC_32; + UINT32 target_cmd = (pcs->is_host_64bit) ? MACHO_LC_SEGMENT_64 : MACHO_LC_SEGMENT; DWORD bytes_read;
struct @@ -762,8 +762,8 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW, ifm->modtype = DMT_MACHO; ifm->ops = &macho_file_map_ops; ifm->alternate = NULL; - ifm->addr_size = (pcs->is_64bit) ? 64 : 32; - fmap->header_size = (pcs->is_64bit) ? sizeof(struct macho_header) : FIELD_OFFSET(struct macho_header, reserved); + ifm->addr_size = (pcs->is_host_64bit) ? 64 : 32; + fmap->header_size = (pcs->is_host_64bit) ? sizeof(struct macho_header) : FIELD_OFFSET(struct macho_header, reserved);
if (!(filename = get_dos_file_name(filenameW))) return FALSE;
@@ -1339,8 +1339,8 @@ static BOOL image_uses_split_segs(struct process* process, ULONG_PTR load_addr)
if (load_addr) { - UINT32 target_cpu = (process->is_64bit) ? MACHO_CPU_TYPE_X86_64 : MACHO_CPU_TYPE_X86; - UINT32 target_magic = (process->is_64bit) ? MACHO_MH_MAGIC_64 : MACHO_MH_MAGIC_32; + UINT32 target_cpu = (process->is_host_64bit) ? MACHO_CPU_TYPE_X86_64 : MACHO_CPU_TYPE_X86; + UINT32 target_magic = (process->is_host_64bit) ? MACHO_MH_MAGIC_64 : MACHO_MH_MAGIC_32; struct macho_header header;
if (read_process_memory(process, load_addr, &header, FIELD_OFFSET(struct macho_header, reserved)) && @@ -1608,14 +1608,14 @@ static BOOL macho_enum_modules_internal(const struct process* pcs, TRACE("(%p/%p, %s, %p, %p)\n", pcs, pcs->handle, debugstr_w(main_name), cb, user);
- if (pcs->is_64bit) + if (pcs->is_host_64bit) len = sizeof(image_infos.infos64); else len = sizeof(image_infos.infos32); if (!pcs->dbg_hdr_addr || !read_process_memory(pcs, pcs->dbg_hdr_addr, &image_infos, len)) goto done; - if (!pcs->is_64bit) + if (!pcs->is_host_64bit) { struct dyld_all_image_infos32 temp = image_infos.infos32; image_infos.infos64.infoArrayCount = temp.infoArrayCount; @@ -1625,7 +1625,7 @@ static BOOL macho_enum_modules_internal(const struct process* pcs, goto done; TRACE("Process has %u image infos at %I64x\n", image_infos.infos64.infoArrayCount, image_infos.infos64.infoArray);
- if (pcs->is_64bit) + if (pcs->is_host_64bit) len = sizeof(info_array->info64); else len = sizeof(info_array->info32); @@ -1639,7 +1639,7 @@ static BOOL macho_enum_modules_internal(const struct process* pcs, for (i = 0; i < image_infos.infos64.infoArrayCount; i++) { struct dyld_image_info64 info; - if (pcs->is_64bit) + if (pcs->is_host_64bit) info = info_array[i].info64; else { @@ -1829,13 +1829,13 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in char path[1024]; BOOL got_path = FALSE;
- if (pcs->is_64bit) + if (pcs->is_host_64bit) len = sizeof(image_infos.infos64); else len = sizeof(image_infos.infos32); if (read_process_memory(pcs, pcs->dbg_hdr_addr, &image_infos, len)) { - if (pcs->is_64bit) + if (pcs->is_host_64bit) len = sizeof(image_info.info64); else { @@ -1847,7 +1847,7 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in if (image_infos.infos64.infoArray && image_infos.infos64.infoArrayCount && read_process_memory(pcs, image_infos.infos64.infoArray, &image_info, len)) { - if (!pcs->is_64bit) + if (!pcs->is_host_64bit) { struct dyld_image_info32 temp = image_info.info32; image_info.info64.imageLoadAddress = temp.imageLoadAddress;
From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/dbghelp/macho_module.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c index d5f7df9001f..b0569593fba 100644 --- a/dlls/dbghelp/macho_module.c +++ b/dlls/dbghelp/macho_module.c @@ -206,6 +206,18 @@ static char* format_uuid(const UINT8 uuid[16], char out[UUID_STRING_LEN]) return out; }
+static USHORT macho_cpu_to_machine(unsigned cpu) +{ + switch (cpu) + { + case MACHO_CPU_TYPE_X86: return IMAGE_FILE_MACHINE_I386; + case MACHO_CPU_TYPE_X86_64: return IMAGE_FILE_MACHINE_AMD64; + default: + FIXME("Untranslated Mach-O CPU %x\n", cpu); + return IMAGE_FILE_MACHINE_UNKNOWN; + } +} + /****************************************************************** * macho_calc_range * @@ -1354,6 +1366,26 @@ static BOOL image_uses_split_segs(struct process* process, ULONG_PTR load_addr) return split_segs; }
+/****************************************************************** + * image_get_machine + * + * For a module identified by its load address, return the machine field + * of the (loaded) Macho header. + */ +static USHORT image_get_machine(struct process *process, ULONG_PTR load_addr) +{ + if (load_addr) + { + struct macho_header header; + UINT32 target_magic = (process->is_host_64bit) ? MACHO_MH_MAGIC_64 : MACHO_MH_MAGIC_32; + + if (read_process_memory(process, load_addr, &header, FIELD_OFFSET(struct macho_header, reserved)) && + header.magic == target_magic) + return macho_cpu_to_machine(header.cputype); + } + return IMAGE_FILE_MACHINE_UNKNOWN; +} + /****************************************************************** * macho_load_debug_info * @@ -1479,7 +1511,7 @@ static BOOL macho_load_file(struct process* pcs, const WCHAR* filename, load_addr = fmap.u.macho.segs_start; macho_info->module = module_new(pcs, filename, DMT_MACHO, FALSE, load_addr, fmap.u.macho.segs_size, 0, calc_crc32(fmap.u.macho.handle), - IMAGE_FILE_MACHINE_UNKNOWN); + image_get_machine(pcs, load_addr)); if (!macho_info->module) { HeapFree(GetProcessHeap(), 0, modfmt);
From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/dbghelp/cpu_x86_64.c | 2 +- dlls/dbghelp/dbghelp_private.h | 4 +--- dlls/dbghelp/module.c | 38 +++++++++++++++------------------- dlls/dbghelp/source.c | 2 +- dlls/dbghelp/symbol.c | 6 +++--- 5 files changed, 23 insertions(+), 29 deletions(-)
diff --git a/dlls/dbghelp/cpu_x86_64.c b/dlls/dbghelp/cpu_x86_64.c index 957ce36cc5d..8c9228747b0 100644 --- a/dlls/dbghelp/cpu_x86_64.c +++ b/dlls/dbghelp/cpu_x86_64.c @@ -962,7 +962,7 @@ static BOOL x86_64_fetch_minidump_module(struct dump_context* dc, unsigned index ULONG size;
if (!(pcs = process_find_by_handle(dc->process->handle)) || - !(module = module_find_by_addr(pcs, dc->modules[index].base, DMT_UNKNOWN))) + !(module = module_find_by_addr(pcs, dc->modules[index].base))) return FALSE; rtf = (const RUNTIME_FUNCTION*)pe_map_directory(module, IMAGE_DIRECTORY_ENTRY_EXCEPTION, &size); if (rtf) diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index b90c5c57513..ae11771f1d9 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -398,7 +398,6 @@ struct symt_udt
enum module_type { - DMT_UNKNOWN, /* for lookup, not actually used for a module */ DMT_ELF, /* a real ELF shared module */ DMT_PE, /* a native or builtin PE module */ DMT_MACHO, /* a real Mach-O shared module */ @@ -732,8 +731,7 @@ extern const struct loader_ops empty_loader_ops DECLSPEC_HIDDEN; extern BOOL module_init_pair(struct module_pair* pair, HANDLE hProcess, DWORD64 addr) DECLSPEC_HIDDEN; extern struct module* - module_find_by_addr(const struct process* pcs, DWORD64 addr, - enum module_type type) DECLSPEC_HIDDEN; + module_find_by_addr(const struct process* pcs, DWORD64 addr) DECLSPEC_HIDDEN; extern struct module* module_find_by_nameW(const struct process* pcs, const WCHAR* name) DECLSPEC_HIDDEN; diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index 75567127f37..a7a83e47f31 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -262,7 +262,7 @@ struct module* module_new(struct process* pcs, const WCHAR* name, BOOL module_init_pair(struct module_pair* pair, HANDLE hProcess, DWORD64 addr) { if (!(pair->pcs = process_find_by_handle(hProcess))) return FALSE; - pair->requested = module_find_by_addr(pair->pcs, addr, DMT_UNKNOWN); + pair->requested = module_find_by_addr(pair->pcs, addr); return module_get_debug(pair); }
@@ -413,29 +413,25 @@ BOOL module_get_debug(struct module_pair* pair) /*********************************************************************** * module_find_by_addr * - * either the addr where module is loaded, or any address inside the + * either the addr where module is loaded, or any address inside the * module */ -struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr, - enum module_type type) +struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr) { - struct module* module; - - if (type == DMT_UNKNOWN) + struct module* module; + + for (module = pcs->lmodules; module; module = module->next) { - if ((module = module_find_by_addr(pcs, addr, DMT_PE)) || - (module = module_find_by_addr(pcs, addr, DMT_ELF)) || - (module = module_find_by_addr(pcs, addr, DMT_MACHO))) + if (module->type == DMT_PE && addr >= module->module.BaseOfImage && + addr < module->module.BaseOfImage + module->module.ImageSize) return module; } - else + for (module = pcs->lmodules; module; module = module->next) { - for (module = pcs->lmodules; module; module = module->next) - { - if (type == module->type && addr >= module->module.BaseOfImage && - addr < module->module.BaseOfImage + module->module.ImageSize) - return module; - } + if ((module->type == DMT_ELF || module->type == DMT_MACHO) && + addr >= module->module.BaseOfImage && + addr < module->module.BaseOfImage + module->module.ImageSize) + return module; } SetLastError(ERROR_MOD_NOT_FOUND); return module; @@ -1094,7 +1090,7 @@ BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
pcs = process_find_by_handle(hProcess); if (!pcs) return FALSE; - module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN); + module = module_find_by_addr(pcs, BaseOfDll); if (!module) return FALSE; module_remove(pcs, module); return TRUE; @@ -1498,7 +1494,7 @@ BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
if (!pcs) return FALSE; if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE; - module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN); + module = module_find_by_addr(pcs, dwAddr); if (!module) return FALSE;
miw64 = module->module; @@ -1537,7 +1533,7 @@ DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr) struct module* module;
if (!pcs) return 0; - module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN); + module = module_find_by_addr(pcs, dwAddr); if (!module) return 0; return module->module.BaseOfImage; } @@ -1595,7 +1591,7 @@ PVOID WINAPI SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) struct module* module;
if (!pcs) return NULL; - module = module_find_by_addr(pcs, AddrBase, DMT_UNKNOWN); + module = module_find_by_addr(pcs, AddrBase); if (!module || !module->cpu->find_runtime_function) return NULL;
return module->cpu->find_runtime_function(module, AddrBase); diff --git a/dlls/dbghelp/source.c b/dlls/dbghelp/source.c index 3e35c7e62d2..f2dc84d4769 100644 --- a/dlls/dbghelp/source.c +++ b/dlls/dbghelp/source.c @@ -152,7 +152,7 @@ BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask,
if (ModBase) { - pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN); + pair.requested = module_find_by_addr(pair.pcs, ModBase); if (!module_get_debug(&pair)) return FALSE; } else diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c index 7d7dc9b40a3..68ab81816cd 100644 --- a/dlls/dbghelp/symbol.c +++ b/dlls/dbghelp/symbol.c @@ -1148,7 +1148,7 @@ static BOOL symt_enum_locals(struct process* pcs, const WCHAR* mask, se->sym_info->MaxNameLen = sizeof(se->buffer) - sizeof(SYMBOL_INFO);
pair.pcs = pcs; - pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc, DMT_UNKNOWN); + pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc); if (!module_get_debug(&pair)) return FALSE;
if (symt_check_tag(pcs->localscope_symt, SymTagFunction) || @@ -1318,7 +1318,7 @@ static BOOL sym_enum(HANDLE hProcess, ULONG64 BaseOfDll, PCWSTR Mask, HeapFree(GetProcessHeap(), 0, mod); return TRUE; } - pair.requested = module_find_by_addr(pair.pcs, BaseOfDll, DMT_UNKNOWN); + pair.requested = module_find_by_addr(pair.pcs, BaseOfDll); if (!module_get_debug(&pair)) return FALSE;
@@ -1624,7 +1624,7 @@ BOOL WINAPI SymFromName(HANDLE hProcess, PCSTR Name, PSYMBOL_INFO Symbol)
/* search first in local context */ pair.pcs = pcs; - pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc, DMT_UNKNOWN); + pair.requested = module_find_by_addr(pair.pcs, pcs->localscope_pc); if (module_get_debug(&pair) && (symt_check_tag(pcs->localscope_symt, SymTagFunction) || symt_check_tag(pcs->localscope_symt, SymTagInlineSite)))
From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- dlls/dbghelp/image_private.h | 2 +- dlls/dbghelp/module.c | 4 +- dlls/dbghelp/pe_module.c | 124 ++++++++++++++++------------------- 3 files changed, 61 insertions(+), 69 deletions(-)
diff --git a/dlls/dbghelp/image_private.h b/dlls/dbghelp/image_private.h index 964e974e49d..5730c5c79d9 100644 --- a/dlls/dbghelp/image_private.h +++ b/dlls/dbghelp/image_private.h @@ -197,7 +197,7 @@ BOOL image_check_alternate(struct image_file_map* fmap, const struct module* mod struct image_file_map* image_load_debugaltlink(struct image_file_map* fmap, struct module* module) DECLSPEC_HIDDEN;
BOOL elf_map_handle(HANDLE handle, struct image_file_map* fmap) DECLSPEC_HIDDEN; -BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) DECLSPEC_HIDDEN; +BOOL pe_map_file(HANDLE file, struct image_file_map* fmap) DECLSPEC_HIDDEN;
struct image_file_map_ops { diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index a7a83e47f31..e6ee9534ff4 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -497,7 +497,7 @@ static BOOL image_check_debug_link_crc(const WCHAR* file, struct image_file_map*
SetFilePointer(handle, 0, 0, FILE_BEGIN); if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE) - ret = pe_map_file(handle, fmap, DMT_PE); + ret = pe_map_file(handle, fmap); else ret = elf_map_handle(handle, fmap); CloseHandle(handle); @@ -521,7 +521,7 @@ static BOOL image_check_debug_link_gnu_id(const WCHAR* file, struct image_file_m TRACE("Located debug information file at %s\n", debugstr_w(file));
if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE) - ret = pe_map_file(handle, fmap, DMT_PE); + ret = pe_map_file(handle, fmap); else ret = elf_map_handle(handle, fmap); CloseHandle(handle); diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c index fc3542b4db5..77f1aae9283 100644 --- a/dlls/dbghelp/pe_module.c +++ b/dlls/dbghelp/pe_module.c @@ -243,11 +243,14 @@ static BOOL pe_is_valid_pointer_table(const IMAGE_NT_HEADERS* nthdr, const void* * * Maps an PE file into memory (and checks it's a real PE file) */ -BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) +BOOL pe_map_file(HANDLE file, struct image_file_map* fmap) { - void* mapping; + void* mapping; + IMAGE_NT_HEADERS* nthdr; + IMAGE_SECTION_HEADER* section; + unsigned i;
- fmap->modtype = mt; + fmap->modtype = DMT_PE; fmap->ops = &pe_file_map_ops; fmap->alternate = NULL; fmap->u.pe.hMap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL); @@ -256,72 +259,61 @@ BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) fmap->u.pe.full_map = NULL; if (!(mapping = pe_map_full(fmap, NULL))) goto error;
- switch (mt) + if (!(nthdr = RtlImageNtHeader(mapping))) goto error; + memcpy(&fmap->u.pe.file_header, &nthdr->FileHeader, sizeof(fmap->u.pe.file_header)); + switch (nthdr->OptionalHeader.Magic) { - case DMT_PE: - { - IMAGE_NT_HEADERS* nthdr; - IMAGE_SECTION_HEADER* section; - unsigned i; - - if (!(nthdr = RtlImageNtHeader(mapping))) goto error; - memcpy(&fmap->u.pe.file_header, &nthdr->FileHeader, sizeof(fmap->u.pe.file_header)); - switch (nthdr->OptionalHeader.Magic) - { - case IMAGE_NT_OPTIONAL_HDR32_MAGIC: - fmap->addr_size = 32; - memcpy(&fmap->u.pe.opt.header32, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header32)); - break; - case IMAGE_NT_OPTIONAL_HDR64_MAGIC: - if (sizeof(void*) == 4) return FALSE; - fmap->addr_size = 64; - memcpy(&fmap->u.pe.opt.header64, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header64)); - break; - default: - return FALSE; - } + case IMAGE_NT_OPTIONAL_HDR32_MAGIC: + fmap->addr_size = 32; + memcpy(&fmap->u.pe.opt.header32, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header32)); + break; + case IMAGE_NT_OPTIONAL_HDR64_MAGIC: + if (sizeof(void*) == 4) return FALSE; + fmap->addr_size = 64; + memcpy(&fmap->u.pe.opt.header64, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header64)); + break; + default: + return FALSE; + }
- fmap->u.pe.builtin = !memcmp((const IMAGE_DOS_HEADER*)mapping + 1, builtin_signature, sizeof(builtin_signature)); - section = IMAGE_FIRST_SECTION( nthdr ); - fmap->u.pe.sect = HeapAlloc(GetProcessHeap(), 0, - nthdr->FileHeader.NumberOfSections * sizeof(fmap->u.pe.sect[0])); - if (!fmap->u.pe.sect) goto error; - for (i = 0; i < nthdr->FileHeader.NumberOfSections; i++) - { - memcpy(&fmap->u.pe.sect[i].shdr, section + i, sizeof(IMAGE_SECTION_HEADER)); - fmap->u.pe.sect[i].mapped = IMAGE_NO_MAP; - } - if (nthdr->FileHeader.PointerToSymbolTable && nthdr->FileHeader.NumberOfSymbols) - { - LARGE_INTEGER li; + fmap->u.pe.builtin = !memcmp((const IMAGE_DOS_HEADER*)mapping + 1, builtin_signature, sizeof(builtin_signature)); + section = IMAGE_FIRST_SECTION( nthdr ); + fmap->u.pe.sect = HeapAlloc(GetProcessHeap(), 0, + nthdr->FileHeader.NumberOfSections * sizeof(fmap->u.pe.sect[0])); + if (!fmap->u.pe.sect) goto error; + for (i = 0; i < nthdr->FileHeader.NumberOfSections; i++) + { + memcpy(&fmap->u.pe.sect[i].shdr, section + i, sizeof(IMAGE_SECTION_HEADER)); + fmap->u.pe.sect[i].mapped = IMAGE_NO_MAP; + } + if (nthdr->FileHeader.PointerToSymbolTable && nthdr->FileHeader.NumberOfSymbols) + { + LARGE_INTEGER li;
- if (GetFileSizeEx(file, &li) && pe_is_valid_pointer_table(nthdr, mapping, li.QuadPart)) - { - /* FIXME ugly: should rather map the relevant content instead of copying it */ - const char* src = (const char*)mapping + - nthdr->FileHeader.PointerToSymbolTable + - nthdr->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL); - char* dst; - DWORD sz = *(DWORD*)src; - - if ((dst = HeapAlloc(GetProcessHeap(), 0, sz))) - memcpy(dst, src, sz); - fmap->u.pe.strtable = dst; - } - else - { - WARN("Bad coff table... wipping out\n"); - /* we have bad information here, wipe it out */ - fmap->u.pe.file_header.PointerToSymbolTable = 0; - fmap->u.pe.file_header.NumberOfSymbols = 0; - fmap->u.pe.strtable = NULL; - } - } - else fmap->u.pe.strtable = NULL; + if (GetFileSizeEx(file, &li) && pe_is_valid_pointer_table(nthdr, mapping, li.QuadPart)) + { + /* FIXME ugly: should rather map the relevant content instead of copying it */ + const char* src = (const char*)mapping + + nthdr->FileHeader.PointerToSymbolTable + + nthdr->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL); + char* dst; + DWORD sz = *(DWORD*)src; + + if ((dst = HeapAlloc(GetProcessHeap(), 0, sz))) + memcpy(dst, src, sz); + fmap->u.pe.strtable = dst; + } + else + { + WARN("Bad coff table... wipping out\n"); + /* we have bad information here, wipe it out */ + fmap->u.pe.file_header.PointerToSymbolTable = 0; + fmap->u.pe.file_header.NumberOfSymbols = 0; + fmap->u.pe.strtable = NULL; } - break; - default: assert(0); goto error; } + else fmap->u.pe.strtable = NULL; + pe_unmap_full(fmap);
return TRUE; @@ -757,7 +749,7 @@ static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path) { struct builtin_search *search = param;
- if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE; + if (!pe_map_file(handle, &search->fmap)) return FALSE;
search->path = wcsdup(path); return TRUE; @@ -815,7 +807,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name, if ((modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info)))) { modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1); - if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE)) + if (pe_map_file(hFile, &modfmt->u.pe_info->fmap)) { struct builtin_search builtin = { NULL }; if (opened && modfmt->u.pe_info->fmap.u.pe.builtin &&
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=138523
Your paranoid android.
=== debian11b (64 bit WoW report) ===
quartz: dsoundrender: Timeout
V2 pushed, but creating a new API requires a bit of cleanup, so splitting in several parts.
First part:
* use corrrect module bitness for Macho modules * expose machine out of Macho modules * clean-up
pipeline failures are compilation errors in mmdevapi... so not related
@julliard what's the status of this MR?