diff options
Diffstat (limited to 'fesvr')
-rw-r--r-- | fesvr/elf.h | 7 | ||||
-rw-r--r-- | fesvr/elfloader.cc | 3 |
2 files changed, 10 insertions, 0 deletions
diff --git a/fesvr/elf.h b/fesvr/elf.h index b4b0add..c791685 100644 --- a/fesvr/elf.h +++ b/fesvr/elf.h @@ -5,6 +5,10 @@ #include <stdint.h> +#define ET_EXEC 2 +#define EM_RISCV 243 +#define EV_CURRENT 1 + #define IS_ELF(hdr) \ ((hdr).e_ident[0] == 0x7f && (hdr).e_ident[1] == 'E' && \ (hdr).e_ident[2] == 'L' && (hdr).e_ident[3] == 'F') @@ -13,6 +17,9 @@ #define IS_ELF64(hdr) (IS_ELF(hdr) && (hdr).e_ident[4] == 2) #define IS_ELFLE(hdr) (IS_ELF(hdr) && (hdr).e_ident[5] == 1) #define IS_ELFBE(hdr) (IS_ELF(hdr) && (hdr).e_ident[5] == 2) +#define IS_ELF_EXEC(hdr) (IS_ELF(hdr) && (hdr).e_type == ET_EXEC) +#define IS_ELF_RISCV(hdr) (IS_ELF(hdr) && (hdr).e_machine == EM_RISCV) +#define IS_ELF_VCURRENT(hdr) (IS_ELF(hdr) && (hdr).e_version == EV_CURRENT) #define PT_LOAD 1 diff --git a/fesvr/elfloader.cc b/fesvr/elfloader.cc index 610e520..fe0fbf0 100644 --- a/fesvr/elfloader.cc +++ b/fesvr/elfloader.cc @@ -32,6 +32,9 @@ std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t* const Elf64_Ehdr* eh64 = (const Elf64_Ehdr*)buf; assert(IS_ELF32(*eh64) || IS_ELF64(*eh64)); assert(IS_ELFLE(*eh64)); + assert(IS_ELF_EXEC(*eh64)); + assert(IS_ELF_RISCV(*eh64)); + assert(IS_ELF_VCURRENT(*eh64)); std::vector<uint8_t> zeros; std::map<std::string, uint64_t> symbols; |