X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=elf_ops.h;h=173d12f05a7212888c354615c04dd614ab966e9e;hb=d7e4b87e53923542c1a7220e08bcae2252f5a22e;hp=1cd4f2b3d529d7a000f73e46c2633e673347cc71;hpb=9042c0e20de166542b603621fd30dc8be95dfd4d;p=qemu diff --git a/elf_ops.h b/elf_ops.h index 1cd4f2b..173d12f 100644 --- a/elf_ops.h +++ b/elf_ops.h @@ -49,7 +49,7 @@ static void glue(bswap_sym, SZ)(struct elf_sym *sym) bswap16s(&sym->st_shndx); } -static struct elf_shdr *glue(find_section, SZ)(struct elf_shdr *shdr_table, +static struct elf_shdr *glue(find_section, SZ)(struct elf_shdr *shdr_table, int n, int type) { int i; @@ -71,17 +71,17 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab) int nsyms, i; char *str = NULL; - shdr_table = load_at(fd, ehdr->e_shoff, + shdr_table = load_at(fd, ehdr->e_shoff, sizeof(struct elf_shdr) * ehdr->e_shnum); if (!shdr_table) return -1; - + if (must_swab) { for (i = 0; i < ehdr->e_shnum; i++) { glue(bswap_shdr, SZ)(shdr_table + i); } } - + symtab = glue(find_section, SZ)(shdr_table, ehdr->e_shnum, SHT_SYMTAB); if (!symtab) goto fail; @@ -139,12 +139,14 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab) } int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, - int must_swab, uint64_t *pentry) + int must_swab, uint64_t *pentry, + uint64_t *lowaddr, uint64_t *highaddr) { struct elfhdr ehdr; struct elf_phdr *phdr = NULL, *ph; int size, i, total_size; - elf_word mem_size, addr; + elf_word mem_size; + uint64_t addr, low = 0, high = 0; uint8_t *data = NULL; if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) @@ -167,14 +169,14 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, if (!phdr) goto fail; if (read(fd, phdr, size) != size) - goto fail1; + goto fail; if (must_swab) { for(i = 0; i < ehdr.e_phnum; i++) { ph = &phdr[i]; glue(bswap_phdr, SZ)(ph); } } - + total_size = 0; for(i = 0; i < ehdr.e_phnum; i++) { ph = &phdr[i]; @@ -184,27 +186,32 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, data = qemu_mallocz(mem_size); if (ph->p_filesz > 0) { if (lseek(fd, ph->p_offset, SEEK_SET) < 0) - goto fail2; + goto fail; if (read(fd, data, ph->p_filesz) != ph->p_filesz) - goto fail2; + goto fail; } addr = ph->p_vaddr + virt_to_phys_addend; cpu_physical_memory_write_rom(addr, data, mem_size); total_size += mem_size; + if (!low || addr < low) + low = addr; + if (!high || (addr + mem_size) > high) + high = addr + mem_size; qemu_free(data); data = NULL; } } qemu_free(phdr); + if (lowaddr) + *lowaddr = (uint64_t)low; + if (highaddr) + *highaddr = (uint64_t)high; return total_size; -fail2: + fail: qemu_free(data); -fail1: qemu_free(phdr); -fail: return -1; } -