aboutsummaryrefslogtreecommitdiff
path: root/loader.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-23 14:18:40 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-23 14:18:40 +0000
commit9042c0e20de166542b603621fd30dc8be95dfd4d (patch)
tree84ea028032cb2c70fff393af4d94854eea585f3f /loader.c
parent70ead4341212ecb3181d5c780284cef0fc7b51fc (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.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/loader.c b/loader.c
index 3fa681dbb0..7823add917 100644
--- a/loader.c
+++ b/loader.c
@@ -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);