mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-09 00:07:57 -06:00
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>
This commit is contained in:
parent
e53f3466e3
commit
bd4d0da7db
2 changed files with 9 additions and 20 deletions
|
@ -120,25 +120,17 @@ static void exit_states(QEMU_Elf *qe)
|
||||||
|
|
||||||
int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
|
int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
|
||||||
{
|
{
|
||||||
|
GError *gerr = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
qe->fd = open(filename, O_RDONLY, 0);
|
qe->gmf = g_mapped_file_new(filename, TRUE, &gerr);
|
||||||
if (qe->fd == -1) {
|
if (gerr) {
|
||||||
eprintf("Failed to open ELF dump file \'%s\'\n", filename);
|
eprintf("Failed to map ELF dump file \'%s\'\n", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fstat(qe->fd, &st);
|
qe->map = g_mapped_file_get_contents(qe->gmf);
|
||||||
qe->size = st.st_size;
|
qe->size = g_mapped_file_get_length(qe->gmf);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (init_states(qe)) {
|
if (init_states(qe)) {
|
||||||
eprintf("Failed to extract QEMU CPU states\n");
|
eprintf("Failed to extract QEMU CPU states\n");
|
||||||
|
@ -149,9 +141,7 @@ int QEMU_Elf_init(QEMU_Elf *qe, const char *filename)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_unmap:
|
out_unmap:
|
||||||
munmap(qe->map, qe->size);
|
g_mapped_file_unref(qe->gmf);
|
||||||
out_fd:
|
|
||||||
close(qe->fd);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -159,6 +149,5 @@ out_fd:
|
||||||
void QEMU_Elf_exit(QEMU_Elf *qe)
|
void QEMU_Elf_exit(QEMU_Elf *qe)
|
||||||
{
|
{
|
||||||
exit_states(qe);
|
exit_states(qe);
|
||||||
munmap(qe->map, qe->size);
|
g_mapped_file_unref(qe->gmf);
|
||||||
close(qe->fd);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ typedef struct QEMUCPUState {
|
||||||
int is_system(QEMUCPUState *s);
|
int is_system(QEMUCPUState *s);
|
||||||
|
|
||||||
typedef struct QEMU_Elf {
|
typedef struct QEMU_Elf {
|
||||||
int fd;
|
GMappedFile *gmf;
|
||||||
size_t size;
|
size_t size;
|
||||||
void *map;
|
void *map;
|
||||||
QEMUCPUState **state;
|
QEMUCPUState **state;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue