diff options
author | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2006-12-23 14:18:40 +0000 |
---|---|---|
committer | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2006-12-23 14:18:40 +0000 |
commit | 9042c0e20de166542b603621fd30dc8be95dfd4d (patch) | |
tree | 84ea028032cb2c70fff393af4d94854eea585f3f /loader.c | |
parent | 70ead4341212ecb3181d5c780284cef0fc7b51fc (diff) |
Check ELF binaries for machine type and endianness.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2274 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'loader.c')
-rw-r--r-- | loader.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -197,7 +197,7 @@ static void *load_at(int fd, int offset, int size) int load_elf(const char *filename, int64_t virt_to_phys_addend, uint64_t *pentry) { - int fd, data_order, must_swab, ret; + int fd, data_order, host_data_order, must_swab, ret; uint8_t e_ident[EI_NIDENT]; fd = open(filename, O_RDONLY | O_BINARY); @@ -218,7 +218,15 @@ int load_elf(const char *filename, int64_t virt_to_phys_addend, data_order = ELFDATA2LSB; #endif must_swab = data_order != e_ident[EI_DATA]; - + +#ifdef TARGET_WORDS_BIGENDIAN + host_data_order = ELFDATA2MSB; +#else + host_data_order = ELFDATA2LSB; +#endif + if (host_data_order != e_ident[EI_DATA]) + return -1; + lseek(fd, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { ret = load_elf64(fd, virt_to_phys_addend, must_swab, pentry); |