From 9ee3c029425a20ed16831c92c4cb3e192a909a61 Mon Sep 17 00:00:00 2001 From: bellard Date: Wed, 26 Apr 2006 22:05:26 +0000 Subject: added entry parameter to ELF loader git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1859 c046a42c-6fe2-441c-8c8c-71466251a162 --- elf_ops.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'elf_ops.h') diff --git a/elf_ops.h b/elf_ops.h index a7d027e1ab..4da755e1b3 100644 --- a/elf_ops.h +++ b/elf_ops.h @@ -138,13 +138,14 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab) return -1; } -int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, int must_swab) +int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, + int must_swab, uint64_t *pentry) { struct elfhdr ehdr; struct elf_phdr *phdr = NULL, *ph; int size, i, total_size; elf_word mem_size, addr; - uint8_t *data; + uint8_t *data = NULL; if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) goto fail; @@ -152,6 +153,9 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, int must_swab) glue(bswap_ehdr, SZ)(&ehdr); } + if (pentry) + *pentry = (uint64_t)ehdr.e_entry; + glue(load_symbols, SZ)(&ehdr, fd, must_swab); size = ehdr.e_phnum * sizeof(phdr[0]); @@ -176,7 +180,8 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, int must_swab) /* XXX: avoid allocating */ data = qemu_mallocz(mem_size); if (ph->p_filesz > 0) { - lseek(fd, ph->p_offset, SEEK_SET); + if (lseek(fd, ph->p_offset, SEEK_SET) < 0) + goto fail; if (read(fd, data, ph->p_filesz) != ph->p_filesz) goto fail; } @@ -187,10 +192,12 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, int must_swab) total_size += mem_size; qemu_free(data); + data = NULL; } } return total_size; fail: + qemu_free(data); qemu_free(phdr); return -1; } -- cgit v1.2.3