aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorViktor Prutyanov <viktor.prutyanov@phystech.edu>2018-12-20 04:24:38 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2019-02-05 16:50:17 +0100
commit4ea1a21d8413b84d36d57a708c40a5a19b266584 (patch)
treea5996c2b6906a9dc2e28ab977334cd612a5afafc /contrib
parentbd4d0da7db2bbbfd8715f5040edda9f146628d98 (diff)
contrib/elf2dmp: use GLib in PDB processing
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 <viktor.prutyanov@phystech.edu> Message-Id: <20181220012441.13694-4-viktor.prutyanov@phystech.edu> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/elf2dmp/pdb.c29
-rw-r--r--contrib/elf2dmp/pdb.h2
2 files changed, 9 insertions, 22 deletions
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index bcb01b414f..52e352df79 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 a3a3cac2c1..1640d544eb 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;