diff options
Diffstat (limited to 'runtime/oat/elf_file.h')
| -rw-r--r-- | runtime/oat/elf_file.h | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/runtime/oat/elf_file.h b/runtime/oat/elf_file.h index 4206e1926a..fa49e86e55 100644 --- a/runtime/oat/elf_file.h +++ b/runtime/oat/elf_file.h @@ -17,17 +17,16 @@ #ifndef ART_RUNTIME_OAT_ELF_FILE_H_ #define ART_RUNTIME_OAT_ELF_FILE_H_ -#include <memory> #include <string> +#include <vector> #include "base/macros.h" +#include "base/mem_map.h" #include "base/os.h" #include "elf/elf_utils.h" namespace art HIDDEN { -class MemMap; - template <typename ElfTypes> class ElfFileImpl; @@ -44,46 +43,51 @@ class ElfFile { bool low_4gb, /*out*/ std::string* error_msg); - ~ElfFile(); + virtual ~ElfFile() = default; // Load segments into memory based on PT_LOAD program headers - bool Load(File* file, - bool executable, - bool low_4gb, - /*inout*/ MemMap* reservation, - /*out*/ std::string* error_msg); + virtual bool Load(File* file, + bool executable, + bool low_4gb, + /*inout*/ MemMap* reservation, + /*out*/ std::string* error_msg) = 0; - const uint8_t* FindDynamicSymbolAddress(const std::string& symbol_name) const; + virtual const uint8_t* FindDynamicSymbolAddress(const std::string& symbol_name) const = 0; - size_t Size() const; + const std::string& GetFilePath() const { return file_path_; } - // The start of the memory map address range for this ELF file. - uint8_t* Begin() const; + uint8_t* GetBaseAddress() const { return base_address_; } - // The end of the memory map address range for this ELF file. - uint8_t* End() const; + uint8_t* Begin() const { return map_.Begin(); } - const std::string& GetFilePath() const; + uint8_t* End() const { return map_.End(); } - bool GetLoadedSize(size_t* size, std::string* error_msg) const; + size_t Size() const { return map_.Size(); } - size_t GetElfSegmentAlignmentFromFile() const; + virtual bool GetLoadedSize(size_t* size, std::string* error_msg) const = 0; - const uint8_t* GetBaseAddress() const; + virtual size_t GetElfSegmentAlignmentFromFile() const = 0; - bool Is64Bit() const { return elf64_.get() != nullptr; } + virtual bool Is64Bit() const = 0; - ElfFileImpl32* GetImpl32() const { return elf32_.get(); } + protected: + ElfFile() = default; - ElfFileImpl64* GetImpl64() const { return elf64_.get(); } + const std::string file_path_; - private: - explicit ElfFile(ElfFileImpl32* elf32); - explicit ElfFile(ElfFileImpl64* elf64); + // ELF header mapping. If program_header_only_ is false, will + // actually point to the entire elf file. + MemMap map_; + std::vector<MemMap> segments_; - const std::unique_ptr<ElfFileImpl32> elf32_; - const std::unique_ptr<ElfFileImpl64> elf64_; + // Pointer to start of first PT_LOAD program segment after Load() + // when program_header_only_ is true. + uint8_t* base_address_ = nullptr; + // The program header should always available but use GetProgramHeadersStart() to be sure. + uint8_t* program_headers_start_ = nullptr; + + private: DISALLOW_COPY_AND_ASSIGN(ElfFile); }; |