1 /* 2 * Copyright (c) 2018 Virtuozzo International GmbH 3 * 4 * This work is licensed under the terms of the GNU GPL, version 2 or later. 5 * 6 */ 7 8 #ifndef QEMU_ELF_H 9 #define QEMU_ELF_H 10 11 #include <stdint.h> 12 #include <elf.h> 13 14 typedef struct QEMUCPUSegment { 15 uint32_t selector; 16 uint32_t limit; 17 uint32_t flags; 18 uint32_t pad; 19 uint64_t base; 20 } QEMUCPUSegment; 21 22 typedef struct QEMUCPUState { 23 uint32_t version; 24 uint32_t size; 25 uint64_t rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp; 26 uint64_t r8, r9, r10, r11, r12, r13, r14, r15; 27 uint64_t rip, rflags; 28 QEMUCPUSegment cs, ds, es, fs, gs, ss; 29 QEMUCPUSegment ldt, tr, gdt, idt; 30 uint64_t cr[5]; 31 uint64_t kernel_gs_base; 32 } QEMUCPUState; 33 34 int is_system(QEMUCPUState *s); 35 36 typedef struct QEMU_Elf { 37 int fd; 38 size_t size; 39 void *map; 40 QEMUCPUState **state; 41 size_t state_nr; 42 int has_kernel_gs_base; 43 } QEMU_Elf; 44 45 int QEMU_Elf_init(QEMU_Elf *qe, const char *filename); 46 void QEMU_Elf_exit(QEMU_Elf *qe); 47 48 Elf64_Phdr *elf64_getphdr(void *map); 49 Elf64_Half elf_getphdrnum(void *map); 50 51 #endif /* QEMU_ELF_H */ 52