diff options
author | Viktor Prutyanov | 2018-12-20 02:24:37 +0100 |
---|---|---|
committer | Paolo Bonzini | 2019-02-05 16:50:17 +0100 |
commit | bd4d0da7db2bbbfd8715f5040edda9f146628d98 (patch) | |
tree | fda5739343a1655738c5167e99ed9f74a2153d5c /contrib/elf2dmp | |
parent | contrib/elf2dmp: fix elf.h including (diff) | |
download | qemu-bd4d0da7db2bbbfd8715f5040edda9f146628d98.tar.gz qemu-bd4d0da7db2bbbfd8715f5040edda9f146628d98.tar.xz qemu-bd4d0da7db2bbbfd8715f5040edda9f146628d98.zip |
contrib/elf2dmp: use GLib in ELF processing
Replace POSIX mmap with GLib g_mapped_file_new in ELF processing module
to make elf2dmp cross-platform.
Signed-off-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
Message-Id: <20181220012441.13694-3-viktor.prutyanov@phystech.edu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'contrib/elf2dmp')
-rw-r--r-- | contrib/elf2dmp/qemu_elf.c | 27 | ||||
-rw-r--r-- | contrib/elf2dmp/qemu_elf.h | 2 |
2 files changed, 9 insertions, 20 deletions
diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index e9c0d2534a..0db7816586 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -120,25 +120,17 @@ static void exit_states(QEMU_Elf *qe) int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) { + GError *gerr = NULL; int err = 0; - struct stat st; - qe->fd = open(filename, O_RDONLY, 0); - if (qe->fd == -1) { - eprintf("Failed to open ELF dump file \'%s\'\n", filename); + qe->gmf = g_mapped_file_new(filename, TRUE, &gerr); + if (gerr) { + eprintf("Failed to map ELF dump file \'%s\'\n", filename); return 1; } - fstat(qe->fd, &st); - qe->size = st.st_size; - - qe->map = mmap(NULL, qe->size, PROT_READ | PROT_WRITE, - MAP_PRIVATE, qe->fd, 0); - if (qe->map == MAP_FAILED) { - eprintf("Failed to map ELF file\n"); - err = 1; - goto out_fd; - } + qe->map = g_mapped_file_get_contents(qe->gmf); + qe->size = g_mapped_file_get_length(qe->gmf); if (init_states(qe)) { eprintf("Failed to extract QEMU CPU states\n"); @@ -149,9 +141,7 @@ int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) return 0; out_unmap: - munmap(qe->map, qe->size); -out_fd: - close(qe->fd); + g_mapped_file_unref(qe->gmf); return err; } @@ -159,6 +149,5 @@ out_fd: void QEMU_Elf_exit(QEMU_Elf *qe) { exit_states(qe); - munmap(qe->map, qe->size); - close(qe->fd); + g_mapped_file_unref(qe->gmf); } diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h index da70affaa4..2a7963821a 100644 --- a/contrib/elf2dmp/qemu_elf.h +++ b/contrib/elf2dmp/qemu_elf.h @@ -33,7 +33,7 @@ typedef struct QEMUCPUState { int is_system(QEMUCPUState *s); typedef struct QEMU_Elf { - int fd; + GMappedFile *gmf; size_t size; void *map; QEMUCPUState **state; |