diff --git a/dlls/dbghelp/cpu_x86_64.c b/dlls/dbghelp/cpu_x86_64.c index 13de1fd0e43..c2789d0d71b 100644 --- a/dlls/dbghelp/cpu_x86_64.c +++ b/dlls/dbghelp/cpu_x86_64.c @@ -949,9 +949,7 @@ static BOOL x86_64_fetch_minidump_module(struct dump_context* dc, unsigned index /* we need to read into the other process */ /* rtf = (RUNTIME_FUNCTION*)(module->module.BaseOfImage + (rtf->UnwindData & ~1)); */ } - if (ReadProcessMemory(dc->process->handle, - (void*)(dc->modules[index].base + rtf->UnwindData), - &ui, sizeof(ui), NULL)) + if (read_process_memory(dc->process, dc->modules[index].base + rtf->UnwindData, &ui, sizeof(ui))) minidump_add_memory_block(dc, dc->modules[index].base + rtf->UnwindData, FIELD_OFFSET(UNWIND_INFO, UnwindCode) + ui.CountOfCodes * sizeof(UNWIND_CODE), 0); rtf++; diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 73b9cf9c8c1..cdd074709d7 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -421,6 +421,11 @@ struct process BOOL is_64bit; }; +static inline BOOL read_process_memory(const struct process *process, UINT64 addr, void *buf, size_t size) +{ + return ReadProcessMemory(process->handle, (void*)(UINT_PTR)addr, buf, size, NULL); +} + struct line_info { ULONG_PTR is_first : 1, diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index 23cb8a54b70..96c7484cef5 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -1486,9 +1486,7 @@ static BOOL elf_enum_modules_internal(const struct process* pcs, UINT64 l_next, l_prev; } lm; - if (!pcs->dbg_hdr_addr || - !ReadProcessMemory(pcs->handle, (void*)pcs->dbg_hdr_addr, - &dbg_hdr, sizeof(dbg_hdr), NULL)) + if (!pcs->dbg_hdr_addr || !read_process_memory(pcs, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr))) return FALSE; /* Now walk the linked list. In all known ELF implementations, @@ -1498,12 +1496,11 @@ static BOOL elf_enum_modules_internal(const struct process* pcs, */ for (lm_addr = dbg_hdr.r_map; lm_addr; lm_addr = lm.l_next) { - if (!ReadProcessMemory(pcs->handle, (void*)lm_addr, &lm, sizeof(lm), NULL)) + if (!read_process_memory(pcs, lm_addr, &lm, sizeof(lm))) return FALSE; if (lm.l_prev && /* skip first entry, normally debuggee itself */ - lm.l_name && - ReadProcessMemory(pcs->handle, (void*)(ULONG_PTR)lm.l_name, bufstr, sizeof(bufstr), NULL)) + lm.l_name && read_process_memory(pcs, lm.l_name, bufstr, sizeof(bufstr))) { bufstr[sizeof(bufstr) - 1] = '\0'; MultiByteToWideChar(CP_UNIXCP, 0, bufstr, -1, bufstrW, ARRAY_SIZE(bufstrW)); @@ -1531,9 +1528,7 @@ static BOOL elf_enum_modules_internal(const struct process* pcs, UINT32 l_next, l_prev; } lm; - if (!pcs->dbg_hdr_addr || - !ReadProcessMemory(pcs->handle, (void*)pcs->dbg_hdr_addr, - &dbg_hdr, sizeof(dbg_hdr), NULL)) + if (!pcs->dbg_hdr_addr || !read_process_memory(pcs, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr))) return FALSE; /* Now walk the linked list. In all known ELF implementations, @@ -1543,13 +1538,11 @@ static BOOL elf_enum_modules_internal(const struct process* pcs, */ for (lm_addr = dbg_hdr.r_map; lm_addr; lm_addr = lm.l_next) { - if (!ReadProcessMemory(pcs->handle, (void*)lm_addr, &lm, sizeof(lm), NULL)) + if (!read_process_memory(pcs, lm_addr, &lm, sizeof(lm))) return FALSE; if (lm.l_prev && /* skip first entry, normally debuggee itself */ - lm.l_name && - ReadProcessMemory(pcs->handle, (void *)(DWORD_PTR)lm.l_name, - bufstr, sizeof(bufstr), NULL)) + lm.l_name && read_process_memory(pcs, lm.l_name, bufstr, sizeof(bufstr))) { bufstr[sizeof(bufstr) - 1] = '\0'; MultiByteToWideChar(CP_UNIXCP, 0, bufstr, -1, bufstrW, ARRAY_SIZE(bufstrW)); diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c index ff0072d5a9d..8b32a190d86 100644 --- a/dlls/dbghelp/macho_module.c +++ b/dlls/dbghelp/macho_module.c @@ -1349,7 +1349,7 @@ static BOOL image_uses_split_segs(struct process* process, ULONG_PTR load_addr) UINT32 target_magic = (process->is_64bit) ? MACHO_MH_MAGIC_64 : MACHO_MH_MAGIC_32; struct macho_header header; - if (ReadProcessMemory(process->handle, (void*)load_addr, &header, FIELD_OFFSET(struct macho_header, reserved), NULL) && + if (read_process_memory(process, load_addr, &header, FIELD_OFFSET(struct macho_header, reserved)) && header.magic == target_magic && header.cputype == target_cpu && header.flags & MACHO_DYLD_IN_SHARED_CACHE) { @@ -1629,8 +1629,7 @@ static BOOL macho_enum_modules_internal(const struct process* pcs, else len = sizeof(image_infos.infos32); if (!pcs->dbg_hdr_addr || - !ReadProcessMemory(pcs->handle, (void*)pcs->dbg_hdr_addr, - &image_infos, len, NULL)) + !read_process_memory(pcs, pcs->dbg_hdr_addr, &image_infos, len)) goto done; if (!pcs->is_64bit) { @@ -1649,8 +1648,7 @@ static BOOL macho_enum_modules_internal(const struct process* pcs, len *= image_infos.infos64.infoArrayCount; info_array = HeapAlloc(GetProcessHeap(), 0, len); if (!info_array || - !ReadProcessMemory(pcs->handle, (void*)image_infos.infos64.infoArray, - info_array, len, NULL)) + !read_process_memory(pcs, image_infos.infos64.infoArray, info_array, len)) goto done; TRACE("... read image infos\n"); @@ -1666,7 +1664,7 @@ static BOOL macho_enum_modules_internal(const struct process* pcs, info.imageFilePath = info32->imageFilePath; } if (info.imageFilePath && - ReadProcessMemory(pcs->handle, (void*)info.imageFilePath, bufstr, sizeof(bufstr), NULL)) + read_process_memory(pcs, info.imageFilePath, bufstr, sizeof(bufstr))) { bufstr[sizeof(bufstr) - 1] = '\0'; TRACE("[%d] image file %s\n", i, debugstr_a(bufstr)); @@ -1850,7 +1848,7 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in len = sizeof(image_infos.infos64); else len = sizeof(image_infos.infos32); - if (ReadProcessMemory(pcs->handle, (void*)pcs->dbg_hdr_addr, &image_infos, len, NULL)) + if (read_process_memory(pcs, pcs->dbg_hdr_addr, &image_infos, len)) { if (pcs->is_64bit) len = sizeof(image_info.info64); @@ -1862,7 +1860,7 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in len = sizeof(image_info.info32); } if (image_infos.infos64.infoArray && image_infos.infos64.infoArrayCount && - ReadProcessMemory(pcs->handle, (void*)image_infos.infos64.infoArray, &image_info, len, NULL)) + read_process_memory(pcs, image_infos.infos64.infoArray, &image_info, len)) { if (!pcs->is_64bit) { @@ -1872,7 +1870,7 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in } for (len = sizeof(path); image_info.info64.imageFilePath && len > 0; len /= 2) { - if (ReadProcessMemory(pcs->handle, (void*)image_info.info64.imageFilePath, path, len, NULL)) + if (read_process_memory(pcs, image_info.info64.imageFilePath, path, len)) { path[len - 1] = 0; got_path = TRUE; diff --git a/dlls/dbghelp/minidump.c b/dlls/dbghelp/minidump.c index f934aab83c8..cdee1a8b2e4 100644 --- a/dlls/dbghelp/minidump.c +++ b/dlls/dbghelp/minidump.c @@ -832,9 +832,7 @@ static unsigned dump_memory_info(struct dump_context* dc) for (pos = 0; pos < dc->mem[i].size; pos += sizeof(tmp)) { len = min(dc->mem[i].size - pos, sizeof(tmp)); - if (ReadProcessMemory(dc->process->handle, - (void*)(DWORD_PTR)(dc->mem[i].base + pos), - tmp, len, NULL)) + if (read_process_memory(dc->process, dc->mem[i].base + pos, tmp, len)) WriteFile(dc->hFile, tmp, len, &written, NULL); } dc->rva += mdMem.Memory.DataSize; @@ -890,9 +888,7 @@ static unsigned dump_memory64_info(struct dump_context* dc) for (pos = 0; pos < dc->mem64[i].size; pos += sizeof(tmp)) { len = min(dc->mem64[i].size - pos, sizeof(tmp)); - if (ReadProcessMemory(dc->process->handle, - (void*)(ULONG_PTR)(dc->mem64[i].base + pos), - tmp, len, NULL)) + if (read_process_memory(dc->process, dc->mem64[i].base + pos, tmp, len)) WriteFile(dc->hFile, tmp, len, &written, NULL); } filepos.QuadPart += mdMem64.DataSize;