Skip to content

Commit

Permalink
linux-user/elfload: Open core file after vma_init
Browse files Browse the repository at this point in the history
Swap the ordering of vma_init and open.  This will be necessary
for further changes, and adjusts the error cleanup path.  Narrow
the scope of corefile, as the variable can be freed immediately
after use in open().

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Feb 29, 2024
1 parent ccb6f3e commit 106f8da
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions linux-user/elfload.c
Original file line number Diff line number Diff line change
Expand Up @@ -4625,7 +4625,6 @@ static int elf_core_dump(int signr, const CPUArchState *env)
const CPUState *cpu = env_cpu((CPUArchState *)env);
const TaskState *ts = (const TaskState *)cpu->opaque;
struct vm_area_struct *vma = NULL;
g_autofree char *corefile = NULL;
struct elf_note_info info;
struct elfhdr elf;
struct elf_phdr phdr;
Expand All @@ -4644,19 +4643,22 @@ static int elf_core_dump(int signr, const CPUArchState *env)
return 0;
}

corefile = core_dump_filename(ts);

if ((fd = open(corefile, O_WRONLY | O_CREAT,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
return (-errno);

/*
* Walk through target process memory mappings and
* set up structure containing this information. After
* this point vma_xxx functions can be used.
*/
vma_init(&mm);

{
g_autofree char *corefile = core_dump_filename(ts);
fd = open(corefile, O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
}
if (fd < 0) {
goto out;
}

walk_memory_regions(&mm, vma_walker);
segs = vma_get_mapping_count(&mm);

Expand Down

0 comments on commit 106f8da

Please sign in to comment.