https://git.reactos.org/?p=reactos.git;a=commitdiff;h=27e660114b63badaafda70...
commit 27e660114b63badaafda70a737b86431253fc09c Author: winesync ros-dev@reactos.org AuthorDate: Fri Sep 11 19:00:45 2020 +0200 Commit: Jérôme Gardou jerome.gardou@reactos.org CommitDate: Wed Sep 16 10:35:56 2020 +0200
[WINESYNC] dbghelp: Introduce read_process_memory helper.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
wine commit id 26f5bfdd4d071a91a38b25c0064ed5ea48993249 by Jacek Caban jacek@codeweavers.com --- dll/win32/dbghelp/cpu_x86_64.c | 4 +--- dll/win32/dbghelp/dbghelp_private.h | 5 +++++ dll/win32/dbghelp/elf_module.c | 19 ++++++------------- dll/win32/dbghelp/macho_module.c | 16 +++++++--------- dll/win32/dbghelp/minidump.c | 8 ++------ sdk/tools/winesync/dbghelp.cfg | 2 +- 6 files changed, 22 insertions(+), 32 deletions(-)
diff --git a/dll/win32/dbghelp/cpu_x86_64.c b/dll/win32/dbghelp/cpu_x86_64.c index f0c12207357..e0606cdbefd 100644 --- a/dll/win32/dbghelp/cpu_x86_64.c +++ b/dll/win32/dbghelp/cpu_x86_64.c @@ -947,9 +947,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/dll/win32/dbghelp/dbghelp_private.h b/dll/win32/dbghelp/dbghelp_private.h index b43eec1a2ed..4d5aed1aeb1 100644 --- a/dll/win32/dbghelp/dbghelp_private.h +++ b/dll/win32/dbghelp/dbghelp_private.h @@ -448,6 +448,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/dll/win32/dbghelp/elf_module.c b/dll/win32/dbghelp/elf_module.c index 23cb8a54b70..96c7484cef5 100644 --- a/dll/win32/dbghelp/elf_module.c +++ b/dll/win32/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/dll/win32/dbghelp/macho_module.c b/dll/win32/dbghelp/macho_module.c index ff0072d5a9d..8b32a190d86 100644 --- a/dll/win32/dbghelp/macho_module.c +++ b/dll/win32/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/dll/win32/dbghelp/minidump.c b/dll/win32/dbghelp/minidump.c index f8b4015c23c..74bb429ab43 100644 --- a/dll/win32/dbghelp/minidump.c +++ b/dll/win32/dbghelp/minidump.c @@ -854,9 +854,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; @@ -912,9 +910,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; diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg index 62645fd8735..ddccc59b537 100644 --- a/sdk/tools/winesync/dbghelp.cfg +++ b/sdk/tools/winesync/dbghelp.cfg @@ -4,4 +4,4 @@ files: include/dbghelp.h: sdk/include/psdk/dbghelp.h include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h tags: - wine: 53b5c3b6c674f4bd6d02f20986598b5b6580a2d8 + wine: 26f5bfdd4d071a91a38b25c0064ed5ea48993249