aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2024-02-27 06:47:49 -1000
committerRichard Henderson <richard.henderson@linaro.org>2024-02-29 11:03:52 -1000
commit1928d50bec7ef7956499e408ac3a501f02c57c47 (patch)
treeaedb1991ceab3b1cb392d0644fb90fe9bf712ae8 /linux-user
parentb4c7ab816b48e0d2dd15753c0329bd4aa59f713f (diff)
downloadqemu-1928d50bec7ef7956499e408ac3a501f02c57c47.zip
qemu-1928d50bec7ef7956499e408ac3a501f02c57c47.tar.gz
qemu-1928d50bec7ef7956499e408ac3a501f02c57c47.tar.bz2
linux-user/elfload: Simplify vma_dump_size
Use the flags that we've already saved in order to test accessibility. Use g2h_untagged and compare guest memory directly instead of copy_from_user. Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/elfload.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 491e754..47b5ce3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4166,37 +4166,23 @@ static int vma_get_mapping_count(const struct mm_struct *mm)
*/
static abi_ulong vma_dump_size(const struct vm_area_struct *vma)
{
- /* if we cannot even read the first page, skip it */
- if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE))
- return (0);
+ /* The area must be readable. */
+ if (!(vma->vma_flags & PROT_READ)) {
+ return 0;
+ }
/*
* Usually we don't dump executable pages as they contain
* non-writable code that debugger can read directly from
- * target library etc. However, thread stacks are marked
- * also executable so we read in first page of given region
- * and check whether it contains elf header. If there is
- * no elf header, we dump it.
+ * target library etc. If there is no elf header, we dump it.
*/
- if (vma->vma_flags & PROT_EXEC) {
- char page[TARGET_PAGE_SIZE];
-
- if (copy_from_user(page, vma->vma_start, sizeof (page))) {
- return 0;
- }
- if ((page[EI_MAG0] == ELFMAG0) &&
- (page[EI_MAG1] == ELFMAG1) &&
- (page[EI_MAG2] == ELFMAG2) &&
- (page[EI_MAG3] == ELFMAG3)) {
- /*
- * Mappings are possibly from ELF binary. Don't dump
- * them.
- */
- return (0);
- }
+ if (!(vma->vma_flags & PROT_WRITE) &&
+ (vma->vma_flags & PROT_EXEC) &&
+ memcmp(g2h_untagged(vma->vma_start), ELFMAG, SELFMAG) == 0) {
+ return 0;
}
- return (vma->vma_end - vma->vma_start);
+ return vma->vma_end - vma->vma_start;
}
static int vma_walker(void *priv, target_ulong start, target_ulong end,