[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 38/49] contrib/elf2dmp: use GLib in PDB processing
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 38/49] contrib/elf2dmp: use GLib in PDB processing |
Date: |
Mon, 21 Jan 2019 19:06:09 +0100 |
From: Viktor Prutyanov <address@hidden>
Replace POSIX mmap with GLib g_mapped_file_new in PDB processing stage
to make elf2dmp cross-platform. There are no direct POSIX in elf2dmp
after this patch.
Signed-off-by: Viktor Prutyanov <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
contrib/elf2dmp/pdb.c | 29 ++++++++---------------------
contrib/elf2dmp/pdb.h | 2 +-
2 files changed, 9 insertions(+), 22 deletions(-)
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index bcb01b4..52e352d 100644
--- a/contrib/elf2dmp/pdb.c
+++ b/contrib/elf2dmp/pdb.c
@@ -277,28 +277,18 @@ static void pdb_reader_exit(struct pdb_reader *r)
int pdb_init_from_file(const char *name, struct pdb_reader *reader)
{
+ GError *gerr = NULL;
int err = 0;
- int fd;
void *map;
- struct stat st;
- fd = open(name, O_RDONLY, 0);
- if (fd == -1) {
- eprintf("Failed to open PDB file \'%s\'\n", name);
+ reader->gmf = g_mapped_file_new(name, TRUE, &gerr);
+ if (gerr) {
+ eprintf("Failed to map PDB file \'%s\'\n", name);
return 1;
}
- reader->fd = fd;
-
- fstat(fd, &st);
- reader->file_size = st.st_size;
-
- map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (map == MAP_FAILED) {
- eprintf("Failed to map PDB file\n");
- err = 1;
- goto out_fd;
- }
+ reader->file_size = g_mapped_file_get_length(reader->gmf);
+ map = g_mapped_file_get_contents(reader->gmf);
if (pdb_reader_init(reader, map)) {
err = 1;
goto out_unmap;
@@ -307,16 +297,13 @@ int pdb_init_from_file(const char *name, struct
pdb_reader *reader)
return 0;
out_unmap:
- munmap(map, st.st_size);
-out_fd:
- close(fd);
+ g_mapped_file_unref(reader->gmf);
return err;
}
void pdb_exit(struct pdb_reader *reader)
{
- munmap(reader->ds.header, reader->file_size);
- close(reader->fd);
+ g_mapped_file_unref(reader->gmf);
pdb_reader_exit(reader);
}
diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h
index a3a3cac..1640d54 100644
--- a/contrib/elf2dmp/pdb.h
+++ b/contrib/elf2dmp/pdb.h
@@ -216,7 +216,7 @@ typedef struct pdb_seg {
#define IMAGE_FILE_MACHINE_AMD64 0x8664
struct pdb_reader {
- int fd;
+ GMappedFile *gmf;
size_t file_size;
struct {
PDB_DS_HEADER *header;
--
1.8.3.1
- [Qemu-devel] [PULL 25/49] pvh: Add x86/HVM direct boot ABI header file, (continued)
- [Qemu-devel] [PULL 25/49] pvh: Add x86/HVM direct boot ABI header file, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 28/49] linuxboot_dma: remove duplicate definitions of FW_CFG, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 23/49] elf: Add optional function ptr to load_elf() to parse ELF notes, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 31/49] optionrom/pvh: load initrd from fw_cfg, Paolo Bonzini, 2019/01/21
- [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 <=
- [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, 2019/01/21
- [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