diff options
author | 2023-01-25 18:57:39 +0000 | |
---|---|---|
committer | 2023-02-02 19:52:22 +0000 | |
commit | 2bcd3a0a864dd2f721c52a6be0c43ef8ff5d4609 (patch) | |
tree | a96bc7814edddfc2db23a1fe4eaa8b443369c4c1 | |
parent | 53aca9a46b02bed3cc7037e0a9bf5df4488ee89f (diff) |
Dex: Use DexFileContainer instead of begin/size.
Cleanup. The DexFileContainer already specifies memory range
of the dex file, so there is no need to pass it separately.
Remove unused GetPermissions from DexFileContainer.
Bug: 266950186
Test: ./art/test.py -b --host --64
Change-Id: I94e4547edaa807d9b9c082e7c2c4c2493abe3a64
-rw-r--r-- | dexlayout/dexlayout.cc | 20 | ||||
-rw-r--r-- | dexlayout/dexlayout.h | 15 | ||||
-rw-r--r-- | dexlayout/dexlayout_test.cc | 32 | ||||
-rw-r--r-- | libartbase/base/common_art_test.cc | 1 | ||||
-rw-r--r-- | libdexfile/dex/art_dex_file_loader.cc | 108 | ||||
-rw-r--r-- | libdexfile/dex/art_dex_file_loader.h | 40 | ||||
-rw-r--r-- | libdexfile/dex/compact_dex_file.cc | 4 | ||||
-rw-r--r-- | libdexfile/dex/compact_dex_file.h | 4 | ||||
-rw-r--r-- | libdexfile/dex/dex_file.cc | 5 | ||||
-rw-r--r-- | libdexfile/dex/dex_file.h | 35 | ||||
-rw-r--r-- | libdexfile/dex/dex_file_loader.cc | 112 | ||||
-rw-r--r-- | libdexfile/dex/dex_file_loader.h | 38 | ||||
-rw-r--r-- | libdexfile/dex/standard_dex_file.h | 1 | ||||
-rw-r--r-- | runtime/vdex_file.cc | 19 |
14 files changed, 187 insertions, 247 deletions
diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc index 648c52dd1e..a35c6522b7 100644 --- a/dexlayout/dexlayout.cc +++ b/dexlayout/dexlayout.cc @@ -2014,18 +2014,16 @@ bool DexLayout::ProcessDexFile(const char* file_name, DexContainer::Section* const data_section = (*dex_container)->GetDataSection(); DCHECK_EQ(file_size, main_section->Size()) << main_section->Size() << " " << data_section->Size(); + auto container = std::make_unique<DexLoaderContainer>( + main_section->Begin(), main_section->End(), data_section->Begin(), data_section->End()); std::unique_ptr<const DexFile> output_dex_file( - dex_file_loader.OpenWithDataSection( - main_section->Begin(), - main_section->Size(), - data_section->Begin(), - data_section->Size(), - location, - /* location_checksum= */ 0, - /*oat_dex_file=*/ nullptr, - verify, - /*verify_checksum=*/ false, - error_msg)); + dex_file_loader.Open(std::move(container), + location, + /* location_checksum= */ 0, + /*oat_dex_file=*/nullptr, + verify, + /*verify_checksum=*/false, + error_msg)); CHECK(output_dex_file != nullptr) << "Failed to re-open output file:" << *error_msg; // Do IR-level comparison between input and output. This check ignores potential differences diff --git a/dexlayout/dexlayout.h b/dexlayout/dexlayout.h index bdc7863cd1..767cad03a0 100644 --- a/dexlayout/dexlayout.h +++ b/dexlayout/dexlayout.h @@ -199,6 +199,21 @@ class DexLayout { DISALLOW_COPY_AND_ASSIGN(DexLayout); }; +class DexLoaderContainer : public MemoryDexFileContainer { + public: + DexLoaderContainer(const uint8_t* begin, + const uint8_t* end, + const uint8_t* data_begin, + const uint8_t* data_end) + : MemoryDexFileContainer(begin, end), data_begin_(data_begin), data_end_(data_end) {} + const uint8_t* DataBegin() const override { return data_begin_; } + const uint8_t* DataEnd() const override { return data_end_; } + + private: + const uint8_t* data_begin_; + const uint8_t* data_end_; +}; + } // namespace art #endif // ART_DEXLAYOUT_DEXLAYOUT_H_ diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc index 3c37e6dffb..8d034b89ed 100644 --- a/dexlayout/dexlayout_test.cc +++ b/dexlayout/dexlayout_test.cc @@ -14,13 +14,16 @@ * limitations under the License. */ -#include <sstream> -#include <string> -#include <vector> +#include "dexlayout.h" #include <sys/types.h> #include <unistd.h> +#include <memory> +#include <sstream> +#include <string> +#include <vector> + #include "base/common_art_test.h" #include "base/unix_file/fd_file.h" #include "base/utils.h" @@ -30,7 +33,6 @@ #include "dex/code_item_accessors-inl.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_loader.h" -#include "dexlayout.h" #include "exec_utils.h" #include "profile/profile_compilation_info.h" @@ -802,18 +804,18 @@ TEST_F(DexLayoutTest, ClassFilter) { &out, &error_msg); ASSERT_TRUE(result) << "Failed to run dexlayout " << error_msg; + auto container = std::make_unique<DexLoaderContainer>(out->GetMainSection()->Begin(), + out->GetMainSection()->End(), + out->GetDataSection()->Begin(), + out->GetDataSection()->End()); std::unique_ptr<const DexFile> output_dex_file( - dex_file_loader.OpenWithDataSection( - out->GetMainSection()->Begin(), - out->GetMainSection()->Size(), - out->GetDataSection()->Begin(), - out->GetDataSection()->Size(), - dex_file->GetLocation().c_str(), - /* location_checksum= */ 0, - /*oat_dex_file=*/ nullptr, - /* verify= */ true, - /*verify_checksum=*/ false, - &error_msg)); + dex_file_loader.Open(std::move(container), + dex_file->GetLocation().c_str(), + /* location_checksum= */ 0, + /*oat_dex_file=*/nullptr, + /* verify= */ true, + /*verify_checksum=*/false, + &error_msg)); ASSERT_TRUE(output_dex_file != nullptr); ASSERT_EQ(output_dex_file->NumClassDefs(), options.class_filter_.size()); diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc index 1aba5475d0..c839216854 100644 --- a/libartbase/base/common_art_test.cc +++ b/libartbase/base/common_art_test.cc @@ -526,7 +526,6 @@ std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenDexFiles(cons &dex_files); CHECK(success) << "Failed to open '" << filename << "': " << error_msg; for (auto& dex_file : dex_files) { - CHECK_EQ(PROT_READ, dex_file->GetPermissions()); CHECK(dex_file->IsReadOnly()); } return dex_files; diff --git a/libdexfile/dex/art_dex_file_loader.cc b/libdexfile/dex/art_dex_file_loader.cc index 1057bbcc65..654668e13b 100644 --- a/libdexfile/dex/art_dex_file_loader.cc +++ b/libdexfile/dex/art_dex_file_loader.cc @@ -18,6 +18,8 @@ #include <sys/stat.h> +#include <memory> + #include "android-base/stringprintf.h" #include "base/file_magic.h" #include "base/file_utils.h" @@ -42,7 +44,7 @@ class MemMapContainer : public DexFileContainer { explicit MemMapContainer(MemMap&& mem_map) : mem_map_(std::move(mem_map)) { } ~MemMapContainer() override { } - int GetPermissions() override { + int GetPermissions() const { if (!mem_map_.IsValid()) { return 0; } else { @@ -50,9 +52,7 @@ class MemMapContainer : public DexFileContainer { } } - bool IsReadOnly() override { - return GetPermissions() == PROT_READ; - } + bool IsReadOnly() const override { return GetPermissions() == PROT_READ; } bool EnableWrite() override { CHECK(IsReadOnly()); @@ -72,6 +72,10 @@ class MemMapContainer : public DexFileContainer { } } + const uint8_t* Begin() const override { return mem_map_.Begin(); } + + const uint8_t* End() const override { return mem_map_.End(); } + private: MemMap mem_map_; DISALLOW_COPY_AND_ASSIGN(MemMapContainer); @@ -162,29 +166,42 @@ bool ArtDexFileLoader::GetMultiDexChecksums(const char* filename, return false; } -std::unique_ptr<const DexFile> ArtDexFileLoader::Open( - const uint8_t* base, - size_t size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg, - std::unique_ptr<DexFileContainer> container) const { +std::unique_ptr<const DexFile> ArtDexFileLoader::Open(const uint8_t* base, + size_t size, + const std::string& location, + uint32_t location_checksum, + const OatDexFile* oat_dex_file, + bool verify, + bool verify_checksum, + std::string* error_msg) const { ScopedTrace trace(std::string("Open dex file from RAM ") + location); - return OpenCommon(base, - size, - /*data_base=*/ nullptr, - /*data_size=*/ 0u, - location, + auto container = std::make_unique<MemoryDexFileContainer>(base, base + size); + return OpenCommon(location, + location_checksum, + oat_dex_file, + verify, + verify_checksum, + error_msg, + std::move(container), + /*verify_result=*/nullptr); +} + +std::unique_ptr<const DexFile> ArtDexFileLoader::Open(std::unique_ptr<DexFileContainer> container, + const std::string& location, + uint32_t location_checksum, + const OatDexFile* oat_dex_file, + bool verify, + bool verify_checksum, + std::string* error_msg) const { + ScopedTrace trace(std::string("Open dex file from ") + location); + return OpenCommon(location, location_checksum, oat_dex_file, verify, verify_checksum, error_msg, std::move(container), - /*verify_result=*/ nullptr); + /*verify_result=*/nullptr); } std::unique_ptr<const DexFile> ArtDexFileLoader::Open(const std::string& location, @@ -204,19 +221,14 @@ std::unique_ptr<const DexFile> ArtDexFileLoader::Open(const std::string& locatio return nullptr; } - uint8_t* begin = map.Begin(); - std::unique_ptr<DexFile> dex_file = OpenCommon(begin, - size, - /*data_base=*/ nullptr, - /*data_size=*/ 0u, - location, + std::unique_ptr<DexFile> dex_file = OpenCommon(location, location_checksum, kNoOatDexFile, verify, verify_checksum, error_msg, std::make_unique<MemMapContainer>(std::move(map)), - /*verify_result=*/ nullptr); + /*verify_result=*/nullptr); // Opening CompactDex is only supported from vdex files. if (dex_file != nullptr && dex_file->IsCompactDexFile()) { *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files", @@ -404,18 +416,14 @@ std::unique_ptr<const DexFile> ArtDexFileLoader::OpenFile(int fd, const DexFile::Header* dex_header = reinterpret_cast<const DexFile::Header*>(begin); - std::unique_ptr<DexFile> dex_file = OpenCommon(begin, - size, - /*data_base=*/ nullptr, - /*data_size=*/ 0u, - location, + std::unique_ptr<DexFile> dex_file = OpenCommon(location, dex_header->checksum_, kNoOatDexFile, verify, verify_checksum, error_msg, std::make_unique<MemMapContainer>(std::move(map)), - /*verify_result=*/ nullptr); + /*verify_result=*/nullptr); // Opening CompactDex is only supported from vdex files. if (dex_file != nullptr && dex_file->IsCompactDexFile()) { @@ -483,13 +491,7 @@ std::unique_ptr<const DexFile> ArtDexFileLoader::OpenOneDexFileFromZip( return nullptr; } VerifyResult verify_result; - uint8_t* begin = map.Begin(); - size_t size = map.Size(); - std::unique_ptr<DexFile> dex_file = OpenCommon(begin, - size, - /*data_base=*/ nullptr, - /*data_size=*/ 0u, - location, + std::unique_ptr<DexFile> dex_file = OpenCommon(location, zip_entry->GetCrc32(), kNoOatDexFile, verify, @@ -593,30 +595,4 @@ bool ArtDexFileLoader::OpenAllDexFilesFromZip( } } -std::unique_ptr<DexFile> ArtDexFileLoader::OpenCommon(const uint8_t* base, - size_t size, - const uint8_t* data_base, - size_t data_size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg, - std::unique_ptr<DexFileContainer> container, - VerifyResult* verify_result) { - return DexFileLoader::OpenCommon(base, - size, - data_base, - data_size, - location, - location_checksum, - oat_dex_file, - verify, - verify_checksum, - error_msg, - std::move(container), - verify_result); -} - } // namespace art diff --git a/libdexfile/dex/art_dex_file_loader.h b/libdexfile/dex/art_dex_file_loader.h index 49c81f40bd..acf7e28853 100644 --- a/libdexfile/dex/art_dex_file_loader.h +++ b/libdexfile/dex/art_dex_file_loader.h @@ -59,16 +59,23 @@ class ArtDexFileLoader : public DexFileLoader { bool* only_contains_uncompressed_dex = nullptr) const override; // Opens .dex file, backed by existing memory - std::unique_ptr<const DexFile> Open( - const uint8_t* base, - size_t size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg, - std::unique_ptr<DexFileContainer> container = nullptr) const override; + std::unique_ptr<const DexFile> Open(const uint8_t* base, + size_t size, + const std::string& location, + uint32_t location_checksum, + const OatDexFile* oat_dex_file, + bool verify, + bool verify_checksum, + std::string* error_msg) const override; + + // Opens .dex file, backed by existing memory + std::unique_ptr<const DexFile> Open(std::unique_ptr<DexFileContainer> container, + const std::string& location, + uint32_t location_checksum, + const OatDexFile* oat_dex_file, + bool verify, + bool verify_checksum, + std::string* error_msg) const; // Opens .dex file that has been memory-mapped by the caller. std::unique_ptr<const DexFile> Open(const std::string& location, @@ -168,19 +175,6 @@ class ArtDexFileLoader : public DexFileLoader { bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files) const; - - static std::unique_ptr<DexFile> OpenCommon(const uint8_t* base, - size_t size, - const uint8_t* data_base, - size_t data_size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg, - std::unique_ptr<DexFileContainer> container, - VerifyResult* verify_result); }; } // namespace art diff --git a/libdexfile/dex/compact_dex_file.cc b/libdexfile/dex/compact_dex_file.cc index 205b829393..a14d4ecbd2 100644 --- a/libdexfile/dex/compact_dex_file.cc +++ b/libdexfile/dex/compact_dex_file.cc @@ -16,6 +16,8 @@ #include "compact_dex_file.h" +#include <memory> + #include "base/leb128.h" #include "code_item_accessors-inl.h" #include "dex_file-inl.h" @@ -97,7 +99,7 @@ CompactDexFile::CompactDexFile(const uint8_t* base, location_checksum, oat_dex_file, std::move(container), - /*is_compact_dex=*/ true), + /*is_compact_dex=*/true), debug_info_offsets_(DataBegin() + GetHeader().debug_info_offsets_pos_, GetHeader().debug_info_base_, GetHeader().debug_info_offsets_table_offset_) {} diff --git a/libdexfile/dex/compact_dex_file.h b/libdexfile/dex/compact_dex_file.h index 9c3b7a463b..6aa0030d13 100644 --- a/libdexfile/dex/compact_dex_file.h +++ b/libdexfile/dex/compact_dex_file.h @@ -17,9 +17,11 @@ #ifndef ART_LIBDEXFILE_DEX_COMPACT_DEX_FILE_H_ #define ART_LIBDEXFILE_DEX_COMPACT_DEX_FILE_H_ +#include <memory> + #include "base/casts.h" -#include "dex_file.h" #include "dex/compact_offset_table.h" +#include "dex_file.h" namespace art { diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc index c9088ed2b8..6ebb5b823c 100644 --- a/libdexfile/dex/dex_file.cc +++ b/libdexfile/dex/dex_file.cc @@ -74,11 +74,6 @@ uint32_t DexFile::ChecksumMemoryRange(const uint8_t* begin, size_t size) { return adler32(adler32(0L, Z_NULL, 0), begin, size); } -int DexFile::GetPermissions() const { - CHECK(container_.get() != nullptr); - return container_->GetPermissions(); -} - bool DexFile::IsReadOnly() const { CHECK(container_.get() != nullptr); return container_->IsReadOnly(); diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h index 37a601d3a1..757af7134d 100644 --- a/libdexfile/dex/dex_file.h +++ b/libdexfile/dex/dex_file.h @@ -17,16 +17,17 @@ #ifndef ART_LIBDEXFILE_DEX_DEX_FILE_H_ #define ART_LIBDEXFILE_DEX_DEX_FILE_H_ +#include <android-base/logging.h> + #include <memory> #include <optional> #include <string> #include <string_view> #include <vector> -#include <android-base/logging.h> - #include "base/globals.h" #include "base/macros.h" +#include "base/mman.h" // For the PROT_* and MAP_* constants. #include "base/value_object.h" #include "dex_file_structs.h" #include "dex_file_types.h" @@ -56,16 +57,38 @@ enum class Domain : char; class DexFileContainer { public: DexFileContainer() { } - virtual ~DexFileContainer() { } - virtual int GetPermissions() = 0; - virtual bool IsReadOnly() = 0; + virtual ~DexFileContainer() {} + virtual bool IsReadOnly() const = 0; virtual bool EnableWrite() = 0; virtual bool DisableWrite() = 0; + virtual const uint8_t* Begin() const = 0; + virtual const uint8_t* End() const = 0; + size_t Size() const { return End() - Begin(); } + + // TODO: Remove. This is only used by dexlayout to override the data section of the dex header, + // and redirect it to intermediate memory buffer at completely unrelated memory location. + virtual const uint8_t* DataBegin() const { return nullptr; } + virtual const uint8_t* DataEnd() const { return nullptr; } private: DISALLOW_COPY_AND_ASSIGN(DexFileContainer); }; +class MemoryDexFileContainer : public DexFileContainer { + public: + MemoryDexFileContainer(const uint8_t* begin, const uint8_t* end) : begin_(begin), end_(end) {} + bool IsReadOnly() const override { return true; } + bool EnableWrite() override { return false; } + bool DisableWrite() override { return false; } + const uint8_t* Begin() const override { return begin_; } + const uint8_t* End() const override { return end_; } + + private: + const uint8_t* const begin_; + const uint8_t* const end_; + DISALLOW_COPY_AND_ASSIGN(MemoryDexFileContainer); +}; + // Dex file is the API that exposes native dex files (ordinary dex files) and CompactDex. // Originally, the dex file format used by ART was mostly the same as APKs. The only change was // quickened opcodes and layout optimizations. @@ -709,8 +732,6 @@ class DexFile { } } - int GetPermissions() const; - bool IsReadOnly() const; bool EnableWrite() const; diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc index 861f911b67..541d10b68c 100644 --- a/libdexfile/dex/dex_file_loader.cc +++ b/libdexfile/dex/dex_file_loader.cc @@ -16,8 +16,9 @@ #include "dex_file_loader.h" -#include "android-base/stringprintf.h" +#include <memory> +#include "android-base/stringprintf.h" #include "base/stl_util.h" #include "compact_dex_file.h" #include "dex_file.h" @@ -34,13 +35,7 @@ class VectorContainer : public DexFileContainer { explicit VectorContainer(std::vector<uint8_t>&& vector) : vector_(std::move(vector)) { } ~VectorContainer() override { } - int GetPermissions() override { - return 0; - } - - bool IsReadOnly() override { - return true; - } + bool IsReadOnly() const override { return true; } bool EnableWrite() override { return false; @@ -50,6 +45,10 @@ class VectorContainer : public DexFileContainer { return false; } + const uint8_t* Begin() const override { return vector_.data(); } + + const uint8_t* End() const override { return vector_.data() + vector_.size(); } + private: std::vector<uint8_t> vector_; DISALLOW_COPY_AND_ASSIGN(VectorContainer); @@ -227,69 +226,33 @@ std::unique_ptr<const DexFile> DexFileLoader::Open( bool verify, bool verify_checksum, std::string* error_msg) { - auto memory_data = memory.data(); - auto memory_size = memory.size(); - return OpenCommon(memory_data, - memory_size, - /*data_base=*/ nullptr, - /*data_size=*/ 0, - location, + return OpenCommon(location, location_checksum, oat_dex_file, verify, verify_checksum, error_msg, std::make_unique<VectorContainer>(std::move(memory)), - /*verify_result=*/ nullptr); + /*verify_result=*/nullptr); } -std::unique_ptr<const DexFile> DexFileLoader::Open( - const uint8_t* base, - size_t size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg, - std::unique_ptr<DexFileContainer> container) const { - return OpenCommon(base, - size, - /*data_base=*/ nullptr, - /*data_size=*/ 0, - location, +std::unique_ptr<const DexFile> DexFileLoader::Open(const uint8_t* base, + size_t size, + const std::string& location, + uint32_t location_checksum, + const OatDexFile* oat_dex_file, + bool verify, + bool verify_checksum, + std::string* error_msg) const { + auto container = std::make_unique<MemoryDexFileContainer>(base, base + size); + return OpenCommon(location, location_checksum, oat_dex_file, verify, verify_checksum, error_msg, std::move(container), - /*verify_result=*/ nullptr); -} - -std::unique_ptr<const DexFile> DexFileLoader::OpenWithDataSection( - const uint8_t* base, - size_t size, - const uint8_t* data_base, - size_t data_size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg) const { - return OpenCommon(base, - size, - data_base, - data_size, - location, - location_checksum, - oat_dex_file, - verify, - verify_checksum, - error_msg, - /*container=*/ nullptr, - /*verify_result=*/ nullptr); + /*verify_result=*/nullptr); } bool DexFileLoader::OpenAll( @@ -338,11 +301,7 @@ bool DexFileLoader::OpenAll( return false; } -std::unique_ptr<DexFile> DexFileLoader::OpenCommon(const uint8_t* base, - size_t size, - const uint8_t* data_base, - size_t data_size, - const std::string& location, +std::unique_ptr<DexFile> DexFileLoader::OpenCommon(const std::string& location, uint32_t location_checksum, const OatDexFile* oat_dex_file, bool verify, @@ -350,6 +309,11 @@ std::unique_ptr<DexFile> DexFileLoader::OpenCommon(const uint8_t* base, std::string* error_msg, std::unique_ptr<DexFileContainer> container, VerifyResult* verify_result) { + CHECK(container != nullptr); + const uint8_t* base = container->Begin(); + size_t size = container->Size(); + const uint8_t* data_base = container->DataBegin(); + size_t data_size = container->DataEnd() - container->DataBegin(); if (verify_result != nullptr) { *verify_result = VerifyResult::kVerifyNotAttempted; } @@ -440,21 +404,15 @@ std::unique_ptr<const DexFile> DexFileLoader::OpenOneDexFileFromZip( return nullptr; } VerifyResult verify_result; - auto map_data = map.data(); - auto map_size = map.size(); - std::unique_ptr<const DexFile> dex_file = OpenCommon( - map_data, - map_size, - /*data_base=*/ nullptr, - /*data_size=*/ 0u, - location, - zip_entry->GetCrc32(), - /*oat_dex_file=*/ nullptr, - verify, - verify_checksum, - error_msg, - std::make_unique<VectorContainer>(std::move(map)), - &verify_result); + std::unique_ptr<const DexFile> dex_file = + OpenCommon(location, + zip_entry->GetCrc32(), + /*oat_dex_file=*/nullptr, + verify, + verify_checksum, + error_msg, + std::make_unique<VectorContainer>(std::move(map)), + &verify_result); if (verify_result != VerifyResult::kVerifySucceeded) { if (verify_result == VerifyResult::kVerifyNotAttempted) { *error_code = DexFileLoaderErrorCode::kDexFileError; diff --git a/libdexfile/dex/dex_file_loader.h b/libdexfile/dex/dex_file_loader.h index d6268bc23e..ef45aa8472 100644 --- a/libdexfile/dex/dex_file_loader.h +++ b/libdexfile/dex/dex_file_loader.h @@ -136,30 +136,14 @@ class DexFileLoader { std::string* error_msg); // Opens .dex file, backed by existing memory. - virtual std::unique_ptr<const DexFile> Open( - const uint8_t* base, - size_t size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg, - std::unique_ptr<DexFileContainer> container = nullptr) const; - - // Open a dex file with a separate data section. - virtual std::unique_ptr<const DexFile> OpenWithDataSection( - const uint8_t* base, - size_t size, - const uint8_t* data_base, - size_t data_size, - const std::string& location, - uint32_t location_checksum, - const OatDexFile* oat_dex_file, - bool verify, - bool verify_checksum, - std::string* error_msg) const; - + virtual std::unique_ptr<const DexFile> Open(const uint8_t* base, + size_t size, + const std::string& location, + uint32_t location_checksum, + const OatDexFile* oat_dex_file, + bool verify, + bool verify_checksum, + std::string* error_msg) const; // Opens all .dex files found in the memory map, guessing the container format based on file // extension. @@ -179,11 +163,7 @@ class DexFileLoader { kVerifyFailed }; - static std::unique_ptr<DexFile> OpenCommon(const uint8_t* base, - size_t size, - const uint8_t* data_base, - size_t data_size, - const std::string& location, + static std::unique_ptr<DexFile> OpenCommon(const std::string& location, uint32_t location_checksum, const OatDexFile* oat_dex_file, bool verify, diff --git a/libdexfile/dex/standard_dex_file.h b/libdexfile/dex/standard_dex_file.h index 25cf62a417..cbd9be967d 100644 --- a/libdexfile/dex/standard_dex_file.h +++ b/libdexfile/dex/standard_dex_file.h @@ -18,6 +18,7 @@ #define ART_LIBDEXFILE_DEX_STANDARD_DEX_FILE_H_ #include <iosfwd> +#include <memory> #include "dex_file.h" diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc index f07233c9c9..6ad8a0f91b 100644 --- a/runtime/vdex_file.cc +++ b/runtime/vdex_file.cc @@ -224,17 +224,14 @@ bool VdexFile::OpenAllDexFiles(std::vector<std::unique_ptr<const DexFile>>* dex_ // TODO: Supply the location information for a vdex file. static constexpr char kVdexLocation[] = ""; std::string location = DexFileLoader::GetMultiDexLocation(i, kVdexLocation); - std::unique_ptr<const DexFile> dex(dex_file_loader.OpenWithDataSection( - dex_file_start, - size, - /*data_base=*/ nullptr, - /*data_size=*/ 0u, - location, - GetLocationChecksum(i), - /*oat_dex_file=*/ nullptr, - /*verify=*/ false, - /*verify_checksum=*/ false, - error_msg)); + std::unique_ptr<const DexFile> dex(dex_file_loader.Open(dex_file_start, + size, + location, + GetLocationChecksum(i), + /*oat_dex_file=*/nullptr, + /*verify=*/false, + /*verify_checksum=*/false, + error_msg)); if (dex == nullptr) { return false; } |