Check ELF binaries for machine type and endianness.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2274 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
ths
2006-12-23 14:18:40 +00:00
parent 70ead43412
commit 9042c0e20d
10 changed files with 44 additions and 15 deletions
+10 -2
View File
@@ -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);