diff options
author | Andreas Gampe <agampe@google.com> | 2014-04-04 22:08:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-04-04 22:08:03 +0000 |
commit | 312d70f1f01ff0e8ef7dfd0ccb4a1c360c74d0c4 (patch) | |
tree | c2bb0f9e9fb6df18d134a814484cf5939079d4d5 /runtime | |
parent | ebe5250f6162515c999f7966a918b1f86bb67396 (diff) | |
parent | 91268c1afd6c0d4fad55b7c86d907233d4660205 (diff) | |
download | art-312d70f1f01ff0e8ef7dfd0ccb4a1c360c74d0c4.zip art-312d70f1f01ff0e8ef7dfd0ccb4a1c360c74d0c4.tar.gz art-312d70f1f01ff0e8ef7dfd0ccb4a1c360c74d0c4.tar.bz2 |
Merge "Check the machine type of an ELF file when loading."
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/elf_file.cc | 35 | ||||
-rw-r--r-- | runtime/instruction_set.h | 14 |
2 files changed, 49 insertions, 0 deletions
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc index 0c8a4f0..01ca60f 100644 --- a/runtime/elf_file.cc +++ b/runtime/elf_file.cc @@ -22,6 +22,7 @@ #include "base/logging.h" #include "base/stl_util.h" #include "utils.h" +#include "instruction_set.h" namespace art { @@ -773,6 +774,40 @@ size_t ElfFile::GetLoadedSize() const { bool ElfFile::Load(bool executable, std::string* error_msg) { CHECK(program_header_only_) << file_->GetPath(); + + if (executable) { + InstructionSet elf_ISA = kNone; + switch (GetHeader().e_machine) { + case EM_ARM: { + elf_ISA = kArm; + break; + } + case EM_AARCH64: { + elf_ISA = kArm64; + break; + } + case EM_386: { + elf_ISA = kX86; + break; + } + case EM_X86_64: { + elf_ISA = kX86_64; + break; + } + case EM_MIPS: { + elf_ISA = kMips; + break; + } + } + + if (elf_ISA != kRuntimeISA) { + std::ostringstream oss; + oss << "Expected ISA " << kRuntimeISA << " but found " << elf_ISA; + *error_msg = oss.str(); + return false; + } + } + for (Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) { Elf32_Phdr& program_header = GetProgramHeader(i); diff --git a/runtime/instruction_set.h b/runtime/instruction_set.h index c5a4ec8..f4eecfc 100644 --- a/runtime/instruction_set.h +++ b/runtime/instruction_set.h @@ -35,6 +35,20 @@ enum InstructionSet { }; std::ostream& operator<<(std::ostream& os, const InstructionSet& rhs); +#if defined(__arm__) +static constexpr InstructionSet kRuntimeISA = kArm; +#elif defined(__aarch64__) +static constexpr InstructionSet kRuntimeISA = kArm64; +#elif defined(__mips__) +static constexpr InstructionSet kRuntimeISA = kMips; +#elif defined(__i386__) +static constexpr InstructionSet kRuntimeISA = kX86; +#elif defined(__x86_64__) +static constexpr InstructionSet kRuntimeISA = kX86_64; +#else +static constexpr InstructionSet kRuntimeISA = kNone; +#endif + enum InstructionFeatures { kHwDiv = 1 // Supports hardware divide. }; |