Skip to content

Commit

Permalink
linux-user/elfload: Write process memory to core file in larger chunks
Browse files Browse the repository at this point in the history
We do not need to copy pages from guest memory before writing
them out.  Because vmas are contiguous in host memory, we can
write them in one go.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Feb 29, 2024
1 parent 243c470 commit b4c7ab8
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions linux-user/elfload.c
Original file line number Diff line number Diff line change
Expand Up @@ -4551,32 +4551,13 @@ static int elf_core_dump(int signr, const CPUArchState *env)
}

/*
* Finally we can dump process memory into corefile as well.
* Finally write process memory into the corefile as well.
*/
for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) {
abi_ulong addr;
abi_ulong end;
size_t size = vma_dump_size(vma);

end = vma->vma_start + vma_dump_size(vma);

for (addr = vma->vma_start; addr < end;
addr += TARGET_PAGE_SIZE) {
char page[TARGET_PAGE_SIZE];
int error;

/*
* Read in page from target process memory and
* write it to coredump file.
*/
error = copy_from_user(page, addr, sizeof (page));
if (error != 0) {
(void) fprintf(stderr, "unable to dump " TARGET_ABI_FMT_lx "\n",
addr);
errno = -error;
goto out;
}
if (dump_write(fd, page, TARGET_PAGE_SIZE) < 0)
goto out;
if (size && dump_write(fd, g2h_untagged(vma->vma_start), size) < 0) {
goto out;
}
}
errno = 0;
Expand Down

0 comments on commit b4c7ab8

Please sign in to comment.