[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 37/49] contrib/elf2dmp: use GLib in ELF processing
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 37/49] contrib/elf2dmp: use GLib in ELF processing |
Date: |
Mon, 21 Jan 2019 19:06:08 +0100 |
From: Viktor Prutyanov <address@hidden>
Replace POSIX mmap with GLib g_mapped_file_new in ELF processing module
to make elf2dmp cross-platform.
Signed-off-by: Viktor Prutyanov <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
contrib/elf2dmp/qemu_elf.c | 27 ++++++++-------------------
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 e9c0d25..0db7816 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 da70aff..2a79638 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;
--
1.8.3.1
- [Qemu-devel] [PULL 32/49] i386: remove the new CPUID 'PCONFIG' from Icelake-Server CPU model, (continued)
- [Qemu-devel] [PULL 32/49] i386: remove the new CPUID 'PCONFIG' from Icelake-Server CPU model, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 36/49] contrib/elf2dmp: fix elf.h including, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 30/49] hw/i386/pc: use PVH option rom, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 39/49] contrib/elf2dmp: fix structures definitions, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 26/49] pvh: Boot uncompressed kernel using direct boot ABI, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 27/49] pvh: load initrd and expose it through fw_cfg, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 38/49] contrib/elf2dmp: use GLib in PDB processing, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 41/49] configure: enable elf2dmp build for Windows hosts, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 34/49] Revert "i386: Add CPUID bit for PCONFIG", Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 35/49] target-i386: hvf: remove MPX support, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 37/49] contrib/elf2dmp: use GLib in ELF processing,
Paolo Bonzini <=
- [Qemu-devel] [PULL 02/49] include: update Linux headers to 4.21-rc1/5.0-rc1, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 29/49] linuxboot_dma: move common functions in a new header, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 33/49] i386: remove the 'INTEL_PT' CPUID bit from named CPU models, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 42/49] monitor: do not use QTAILQ_FOREACH_SAFE across critical sections, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 43/49] crypto: finish removing TABs, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 44/49] ui: vnc: finish removing TABs, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 47/49] i386: import & use bootparam.h, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 48/49] i386: allow to load initrd below 4 GB for recent linux, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 46/49] hw/core/loader.c: Read as long as possible in load_image_size(), Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 45/49] unify len and addr type for memory/address APIs, Paolo Bonzini, 2019/01/21