summaryrefslogtreecommitdiff
path: root/linux-user/elfload.c
diff options
context:
space:
mode:
authorYunQiang Su <syq@debian.org>2018-02-20 18:33:05 +0100
committerLaurent Vivier <laurent@vivier.eu>2018-02-25 17:28:49 +0100
commit768fe76e92477870ab14399dbc6bb8d801621c5c (patch)
treebefe6ca9718d06ae9b1e03256ea43f555a864c01 /linux-user/elfload.c
parent542ca4349878a2ea3818aea5c448a6db567da3ae (diff)
downloadqemu-768fe76e92477870ab14399dbc6bb8d801621c5c.tar.gz
linux-user: introduce functions to detect CPU type
Add a function to return ELF e_flags and use it to select the CPU model. Signed-off-by: YunQiang Su <syq@debian.org> [lv: split the patch and some cleanup in get_elf_eflags()] Signed-off-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20180220173307.25125-3-laurent@vivier.eu>
Diffstat (limited to 'linux-user/elfload.c')
-rw-r--r--linux-user/elfload.c35
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;