diff options
author | Ian Rogers <irogers@google.com> | 2014-10-16 20:31:53 -0700 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2014-10-16 21:30:37 -0700 |
commit | d4c4d953035d4418126d36517e402f411d6a87f3 (patch) | |
tree | 735aacf812bbac7c1ae7c0788c1ca6f58cfa82ee /runtime/elf_file.h | |
parent | 6f3dbbadf4ce66982eb3d400e0a74cb73eb034f3 (diff) | |
download | art-d4c4d953035d4418126d36517e402f411d6a87f3.zip art-d4c4d953035d4418126d36517e402f411d6a87f3.tar.gz art-d4c4d953035d4418126d36517e402f411d6a87f3.tar.bz2 |
Some code clean-up.
Change-Id: I4b745fd5298cd61c793e3b57514b48347bd66c0e
Diffstat (limited to 'runtime/elf_file.h')
-rw-r--r-- | runtime/elf_file.h | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/runtime/elf_file.h b/runtime/elf_file.h index a7f3056..10d6360 100644 --- a/runtime/elf_file.h +++ b/runtime/elf_file.h @@ -17,12 +17,25 @@ #ifndef ART_RUNTIME_ELF_FILE_H_ #define ART_RUNTIME_ELF_FILE_H_ +#include <memory> #include <string> -#include "base/unix_file/fd_file.h" -#include "elf_file_impl.h" +#include "base/macros.h" +// Explicitly include our own elf.h to avoid Linux and other dependencies. +#include "./elf.h" +#include "os.h" namespace art { +template <typename Elf_Ehdr, typename Elf_Phdr, typename Elf_Shdr, typename Elf_Word, + typename Elf_Sword, typename Elf_Addr, typename Elf_Sym, typename Elf_Rel, + typename Elf_Rela, typename Elf_Dyn, typename Elf_Off> +class ElfFileImpl; + +// Explicitly instantiated in elf_file.cc +typedef ElfFileImpl<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Word, Elf32_Sword, + Elf32_Addr, Elf32_Sym, Elf32_Rel, Elf32_Rela, Elf32_Dyn, Elf32_Off> ElfFileImpl32; +typedef ElfFileImpl<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Word, Elf64_Sword, + Elf64_Addr, Elf64_Sym, Elf64_Rel, Elf64_Rela, Elf64_Dyn, Elf64_Off> ElfFileImpl64; // Used for compile time and runtime for ElfFile access. Because of // the need for use at runtime, cannot directly use LLVM classes such as @@ -35,8 +48,6 @@ class ElfFile { static ElfFile* Open(File* file, int mmap_prot, int mmap_flags, std::string* error_msg); ~ElfFile(); - const bool is_elf64_; - // Load segments into memory based on PT_LOAD program headers bool Load(bool executable, std::string* error_msg); @@ -68,17 +79,26 @@ class ElfFile { bool Fixup(uintptr_t base_address); - ElfFileImpl32* GetImpl32() const; - ElfFileImpl64* GetImpl64() const; + bool Is64Bit() const { + return elf64_.get() != nullptr; + } + + ElfFileImpl32* GetImpl32() const { + return elf32_.get(); + } + + ElfFileImpl64* GetImpl64() const { + return elf64_.get(); + } private: explicit ElfFile(ElfFileImpl32* elf32); explicit ElfFile(ElfFileImpl64* elf64); - union ElfFileContainer { - ElfFileImpl32* elf32_; - ElfFileImpl64* elf64_; - } elf_; + const std::unique_ptr<ElfFileImpl32> elf32_; + const std::unique_ptr<ElfFileImpl64> elf64_; + + DISALLOW_COPY_AND_ASSIGN(ElfFile); }; } // namespace art |