diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2018-02-27 10:14:31 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2018-02-27 10:14:32 +0000 |
| commit | 438cd7082c70b9e93a26ff4e2e83ac3f6a0027c2 (patch) | |
| tree | bf2bbf59bb6d98715f1a04e8b52d053a270cf8cd /linux-user/elfload.c | |
| parent | 0a773d55ac76c5aa89ed9187a3bc5af8c5c2a6d0 (diff) | |
| parent | 45506bddba6fe73f61cf15fb682ffff73ce156c0 (diff) | |
| download | focaccia-qemu-438cd7082c70b9e93a26ff4e2e83ac3f6a0027c2.tar.gz focaccia-qemu-438cd7082c70b9e93a26ff4e2e83ac3f6a0027c2.zip | |
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-2.12-pull-request' into staging
# gpg: Signature made Sun 25 Feb 2018 17:54:21 GMT # gpg: using RSA key F30C38BD3F2FBE3C # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" # gpg: aka "Laurent Vivier <laurent@vivier.eu>" # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier2/tags/linux-user-for-2.12-pull-request: linux-user: MIPS set cpu to r6 CPU if binary is R6 linux-user, m68k: select CPU according to ELF header values linux-user: introduce functions to detect CPU type linux-user: Move CPU type name selection to a function Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'linux-user/elfload.c')
| -rw-r--r-- | linux-user/elfload.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8bb9a2c3e8..0208022445 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2396,6 +2396,41 @@ give_up: g_free(syms); } +uint32_t get_elf_eflags(int fd) +{ + struct elfhdr ehdr; + off_t offset; + int ret; + + /* Read ELF header */ + offset = lseek(fd, 0, SEEK_SET); + if (offset == (off_t) -1) { + return 0; + } + ret = read(fd, &ehdr, sizeof(ehdr)); + if (ret < sizeof(ehdr)) { + return 0; + } + offset = lseek(fd, offset, SEEK_SET); + if (offset == (off_t) -1) { + return 0; + } + + /* Check ELF signature */ + if (!elf_check_ident(&ehdr)) { + return 0; + } + + /* check header */ + bswap_ehdr(&ehdr); + if (!elf_check_ehdr(&ehdr)) { + return 0; + } + + /* return architecture id */ + return ehdr.e_flags; +} + int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) { struct image_info interp_info; |