diff options
| author | 2017-10-19 13:59:55 +0100 | |
|---|---|---|
| committer | 2017-10-20 14:22:52 +0100 | |
| commit | 095c6c96236476b605b3ac672f6d2b8c151e9479 (patch) | |
| tree | fe04b7fe93e65efadd3f019dd1ecba4c2c40df18 | |
| parent | b277aa1385f7f4593c9978d8106669142d158f4f (diff) | |
Pass the verify flag to DexFileLoader utilities.
Refactoring-only change.
Also remove unused DexFilerLoader::OpenMemory.
bug: 30972906
bug: 63920015
Test: build.
Change-Id: I7cd4b5787565ab1a3457ce2be6bb14657229c550
| -rw-r--r-- | dex2oat/dex2oat_image_test.cc | 1 | ||||
| -rw-r--r-- | dex2oat/dex2oat_test.cc | 6 | ||||
| -rw-r--r-- | dex2oat/linker/oat_writer.cc | 3 | ||||
| -rw-r--r-- | dexdump/dexdump.cc | 3 | ||||
| -rw-r--r-- | dexlayout/dexlayout.cc | 3 | ||||
| -rw-r--r-- | dexlayout/dexlayout_test.cc | 3 | ||||
| -rw-r--r-- | dexlist/dexlist.cc | 3 | ||||
| -rw-r--r-- | openjdkjvmti/ti_search.cc | 3 | ||||
| -rw-r--r-- | profman/profman.cc | 2 | ||||
| -rw-r--r-- | runtime/class_loader_context.cc | 1 | ||||
| -rw-r--r-- | runtime/common_runtime_test.cc | 10 | ||||
| -rw-r--r-- | runtime/dex2oat_environment_test.h | 2 | ||||
| -rw-r--r-- | runtime/dex_file_loader.cc | 26 | ||||
| -rw-r--r-- | runtime/dex_file_loader.h | 15 | ||||
| -rw-r--r-- | runtime/dex_file_test.cc | 12 | ||||
| -rw-r--r-- | runtime/dex_file_verifier_test.cc | 3 | ||||
| -rw-r--r-- | runtime/oat_file_manager.cc | 8 | ||||
| -rw-r--r-- | runtime/runtime.cc | 3 |
18 files changed, 69 insertions, 38 deletions
diff --git a/dex2oat/dex2oat_image_test.cc b/dex2oat/dex2oat_image_test.cc index ae7ebe2da1..0a5068112f 100644 --- a/dex2oat/dex2oat_image_test.cc +++ b/dex2oat/dex2oat_image_test.cc @@ -65,6 +65,7 @@ class Dex2oatImageTest : public CommonRuntimeTest { std::string error_msg; CHECK(DexFileLoader::Open(dex.c_str(), dex, + /*verify*/ true, /*verify_checksum*/ false, &error_msg, &dex_files)) diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 1b731fc7f6..dc1d54fa71 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -678,7 +678,8 @@ class Dex2oatLayoutTest : public Dex2oatTest { const char* location = dex_location.c_str(); std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - ASSERT_TRUE(DexFileLoader::Open(location, location, true, &error_msg, &dex_files)); + ASSERT_TRUE(DexFileLoader::Open( + location, location, /* verify */ true, /* verify_checksum */ true, &error_msg, &dex_files)); EXPECT_EQ(dex_files.size(), 1U); std::unique_ptr<const DexFile>& dex_file = dex_files[0]; GenerateProfile(profile_location, @@ -812,7 +813,8 @@ class Dex2oatLayoutTest : public Dex2oatTest { const char* location = dex_location.c_str(); std::vector<std::unique_ptr<const DexFile>> dex_files; - ASSERT_TRUE(DexFileLoader::Open(location, location, true, &error_msg, &dex_files)); + ASSERT_TRUE(DexFileLoader::Open( + location, location, /* verify */ true, /* verify_checksum */ true, &error_msg, &dex_files)); EXPECT_EQ(dex_files.size(), 1U); std::unique_ptr<const DexFile>& old_dex_file = dex_files[0]; diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index 17ceca3662..702358ecf0 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -3259,7 +3259,8 @@ bool OatWriter::LayoutAndWriteDexFile(OutputStream* out, OatDexFile* oat_dex_fil PLOG(ERROR) << "Failed to dup dex file descriptor (" << raw_file->Fd() << ") at " << location; return false; } - dex_file = DexFileLoader::OpenDex(dup_fd, location, /* verify_checksum */ true, &error_msg); + dex_file = DexFileLoader::OpenDex( + dup_fd, location, /* verify */ true, /* verify_checksum */ true, &error_msg); } else { // The source data is a vdex file. CHECK(oat_dex_file->source_.IsRawData()) diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc index 3648a3edd0..4bfd91fdd9 100644 --- a/dexdump/dexdump.cc +++ b/dexdump/dexdump.cc @@ -1883,7 +1883,8 @@ int processFile(const char* fileName) { const bool kVerifyChecksum = !gOptions.ignoreBadChecksum; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - if (!DexFileLoader::Open(fileName, fileName, kVerifyChecksum, &error_msg, &dex_files)) { + if (!DexFileLoader::Open( + fileName, fileName, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) { // Display returned error message to user. Note that this error behavior // differs from the error messages shown by the original Dalvik dexdump. fputs(error_msg.c_str(), stderr); diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc index 40449ae8bd..7dfe62957f 100644 --- a/dexlayout/dexlayout.cc +++ b/dexlayout/dexlayout.cc @@ -2062,7 +2062,8 @@ int DexLayout::ProcessFile(const char* file_name) { const bool verify_checksum = !options_.ignore_bad_checksum_; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - if (!DexFileLoader::Open(file_name, file_name, verify_checksum, &error_msg, &dex_files)) { + if (!DexFileLoader::Open( + file_name, file_name, /* verify */ true, verify_checksum, &error_msg, &dex_files)) { // Display returned error message to user. Note that this error behavior // differs from the error messages shown by the original Dalvik dexdump. fputs(error_msg.c_str(), stderr); diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc index f8fa893069..f34e7ecd4b 100644 --- a/dexlayout/dexlayout_test.cc +++ b/dexlayout/dexlayout_test.cc @@ -325,7 +325,8 @@ class DexLayoutTest : public CommonRuntimeTest { std::string error_msg; bool result = DexFileLoader::Open(input_dex.c_str(), input_dex, - false, + /*verify*/ true, + /*verify_checksum*/ false, &error_msg, &dex_files); diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc index e5870522a3..c8bc132da0 100644 --- a/dexlist/dexlist.cc +++ b/dexlist/dexlist.cc @@ -179,7 +179,8 @@ static int processFile(const char* fileName) { static constexpr bool kVerifyChecksum = true; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - if (!DexFileLoader::Open(fileName, fileName, kVerifyChecksum, &error_msg, &dex_files)) { + if (!DexFileLoader::Open( + fileName, fileName, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) { fputs(error_msg.c_str(), stderr); fputc('\n', stderr); return -1; diff --git a/openjdkjvmti/ti_search.cc b/openjdkjvmti/ti_search.cc index bafc8552b1..5c67b895fc 100644 --- a/openjdkjvmti/ti_search.cc +++ b/openjdkjvmti/ti_search.cc @@ -227,7 +227,8 @@ jvmtiError SearchUtil::AddToBootstrapClassLoaderSearch(jvmtiEnv* env ATTRIBUTE_U std::string error_msg; std::vector<std::unique_ptr<const art::DexFile>> dex_files; - if (!art::DexFileLoader::Open(segment, segment, true, &error_msg, &dex_files)) { + if (!art::DexFileLoader::Open( + segment, segment, /* verify */ true, /* verify_checksum */ true, &error_msg, &dex_files)) { LOG(WARNING) << "Could not open " << segment << " for boot classpath extension: " << error_msg; return ERR(ILLEGAL_ARGUMENT); } diff --git a/profman/profman.cc b/profman/profman.cc index 8ccf7b4c1d..4c4bb87e49 100644 --- a/profman/profman.cc +++ b/profman/profman.cc @@ -331,6 +331,7 @@ class ProfMan FINAL { if (use_apk_fd_list) { if (DexFileLoader::OpenZip(apks_fd_[i], dex_locations_[i], + /* verify */ true, kVerifyChecksum, &error_msg, &dex_files_for_location)) { @@ -341,6 +342,7 @@ class ProfMan FINAL { } else { if (DexFileLoader::Open(apk_files_[i].c_str(), dex_locations_[i], + /* verify */ true, kVerifyChecksum, &error_msg, &dex_files_for_location)) { diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc index 167533d68a..5510743362 100644 --- a/runtime/class_loader_context.cc +++ b/runtime/class_loader_context.cc @@ -230,6 +230,7 @@ bool ClassLoaderContext::OpenDexFiles(InstructionSet isa, const std::string& cla // contents. So pass true to verify_checksum. if (!DexFileLoader::Open(location.c_str(), location.c_str(), + /*verify*/ true, /*verify_checksum*/ true, &error_msg, &info.opened_dex_files)) { diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index 0c2e49010e..d35402fd47 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -373,7 +373,8 @@ std::unique_ptr<const DexFile> CommonRuntimeTestImpl::LoadExpectSingleDexFile( std::string error_msg; MemMap::Init(); static constexpr bool kVerifyChecksum = true; - if (!DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files)) { + if (!DexFileLoader::Open( + location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) { LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n"; UNREACHABLE(); } else { @@ -572,8 +573,11 @@ std::vector<std::unique_ptr<const DexFile>> CommonRuntimeTestImpl::OpenTestDexFi static constexpr bool kVerifyChecksum = true; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - bool success = DexFileLoader::Open( - filename.c_str(), filename.c_str(), kVerifyChecksum, &error_msg, &dex_files); + bool success = DexFileLoader::Open(filename.c_str(), + filename.c_str(), + /* verify */ true, + kVerifyChecksum, + &error_msg, &dex_files); CHECK(success) << "Failed to open '" << filename << "': " << error_msg; for (auto& dex_file : dex_files) { CHECK_EQ(PROT_READ, dex_file->GetPermissions()); diff --git a/runtime/dex2oat_environment_test.h b/runtime/dex2oat_environment_test.h index a9bb95480e..57cef3de47 100644 --- a/runtime/dex2oat_environment_test.h +++ b/runtime/dex2oat_environment_test.h @@ -84,6 +84,7 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { std::vector<std::unique_ptr<const DexFile>> multi1; ASSERT_TRUE(DexFileLoader::Open(GetMultiDexSrc1().c_str(), GetMultiDexSrc1().c_str(), + /* verify */ true, kVerifyChecksum, &error_msg, &multi1)) << error_msg; @@ -92,6 +93,7 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { std::vector<std::unique_ptr<const DexFile>> multi2; ASSERT_TRUE(DexFileLoader::Open(GetMultiDexSrc2().c_str(), GetMultiDexSrc2().c_str(), + /* verify */ true, kVerifyChecksum, &error_msg, &multi2)) << error_msg; diff --git a/runtime/dex_file_loader.cc b/runtime/dex_file_loader.cc index e300e0e58f..d581eb7bbc 100644 --- a/runtime/dex_file_loader.cc +++ b/runtime/dex_file_loader.cc @@ -186,6 +186,7 @@ std::unique_ptr<const DexFile> DexFileLoader::Open(const std::string& location, bool DexFileLoader::Open(const char* filename, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files) { @@ -198,12 +199,12 @@ bool DexFileLoader::Open(const char* filename, return false; } if (IsZipMagic(magic)) { - return OpenZip(fd.Release(), location, verify_checksum, error_msg, dex_files); + return OpenZip(fd.Release(), location, verify, verify_checksum, error_msg, dex_files); } if (IsMagicValid(magic)) { std::unique_ptr<const DexFile> dex_file(OpenFile(fd.Release(), location, - /* verify */ true, + verify, verify_checksum, error_msg)); if (dex_file.get() != nullptr) { @@ -219,14 +220,16 @@ bool DexFileLoader::Open(const char* filename, std::unique_ptr<const DexFile> DexFileLoader::OpenDex(int fd, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg) { ScopedTrace trace("Open dex file " + std::string(location)); - return OpenFile(fd, location, true /* verify */, verify_checksum, error_msg); + return OpenFile(fd, location, verify, verify_checksum, error_msg); } bool DexFileLoader::OpenZip(int fd, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files) { @@ -237,7 +240,8 @@ bool DexFileLoader::OpenZip(int fd, DCHECK(!error_msg->empty()); return false; } - return OpenAllDexFilesFromZip(*zip_archive, location, verify_checksum, error_msg, dex_files); + return OpenAllDexFilesFromZip( + *zip_archive, location, verify, verify_checksum, error_msg, dex_files); } std::unique_ptr<const DexFile> DexFileLoader::OpenFile(int fd, @@ -304,6 +308,7 @@ std::unique_ptr<const DexFile> DexFileLoader::OpenOneDexFileFromZip( const ZipArchive& zip_archive, const char* entry_name, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, ZipOpenErrorCode* error_code) { @@ -357,7 +362,7 @@ std::unique_ptr<const DexFile> DexFileLoader::OpenOneDexFileFromZip( location, zip_entry->GetCrc32(), kNoOatDexFile, - /* verify */ true, + verify, verify_checksum, error_msg, &verify_result); @@ -391,16 +396,18 @@ std::unique_ptr<const DexFile> DexFileLoader::OpenOneDexFileFromZip( static constexpr size_t kWarnOnManyDexFilesThreshold = 100; bool DexFileLoader::OpenAllDexFilesFromZip(const ZipArchive& zip_archive, - const std::string& location, - bool verify_checksum, - std::string* error_msg, - std::vector<std::unique_ptr<const DexFile>>* dex_files) { + const std::string& location, + bool verify, + bool verify_checksum, + std::string* error_msg, + std::vector<std::unique_ptr<const DexFile>>* dex_files) { ScopedTrace trace("Dex file open from Zip " + std::string(location)); DCHECK(dex_files != nullptr) << "DexFile::OpenFromZip: out-param is nullptr"; ZipOpenErrorCode error_code; std::unique_ptr<const DexFile> dex_file(OpenOneDexFileFromZip(zip_archive, kClassesDex, location, + verify, verify_checksum, error_msg, &error_code)); @@ -421,6 +428,7 @@ bool DexFileLoader::OpenAllDexFilesFromZip(const ZipArchive& zip_archive, std::unique_ptr<const DexFile> next_dex_file(OpenOneDexFileFromZip(zip_archive, name.c_str(), fake_location, + verify, verify_checksum, error_msg, &error_code)); diff --git a/runtime/dex_file_loader.h b/runtime/dex_file_loader.h index cb17eccfc9..a1167dc3fd 100644 --- a/runtime/dex_file_loader.h +++ b/runtime/dex_file_loader.h @@ -79,6 +79,7 @@ class DexFileLoader { // Opens all .dex files found in the file, guessing the container format based on file extension. static bool Open(const char* filename, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files); @@ -86,12 +87,14 @@ class DexFileLoader { // Open a single dex file from an fd. This function closes the fd. static std::unique_ptr<const DexFile> OpenDex(int fd, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg); // Opens dex files from within a .jar, .zip, or .apk file static bool OpenZip(int fd, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files); @@ -158,6 +161,7 @@ class DexFileLoader { // Open all classesXXX.dex files from a zip archive. static bool OpenAllDexFilesFromZip(const ZipArchive& zip_archive, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files); @@ -167,6 +171,7 @@ class DexFileLoader { static std::unique_ptr<const DexFile> OpenOneDexFileFromZip(const ZipArchive& zip_archive, const char* entry_name, const std::string& location, + bool verify, bool verify_checksum, std::string* error_msg, ZipOpenErrorCode* error_code); @@ -186,16 +191,6 @@ class DexFileLoader { bool verify_checksum, std::string* error_msg, VerifyResult* verify_result = nullptr); - - - // Opens a .dex file at the given address, optionally backed by a MemMap - static std::unique_ptr<const DexFile> OpenMemory(const uint8_t* dex_file, - size_t size, - const std::string& location, - uint32_t location_checksum, - std::unique_ptr<MemMap> mem_map, - const OatDexFile* oat_dex_file, - std::string* error_msg); }; } // namespace art diff --git a/runtime/dex_file_test.cc b/runtime/dex_file_test.cc index b3011379c6..90bc4b8f94 100644 --- a/runtime/dex_file_test.cc +++ b/runtime/dex_file_test.cc @@ -236,7 +236,8 @@ static bool OpenDexFilesBase64(const char* base64, ScopedObjectAccess soa(Thread::Current()); static constexpr bool kVerifyChecksum = true; std::vector<std::unique_ptr<const DexFile>> tmp; - bool success = DexFileLoader::Open(location, location, kVerifyChecksum, error_msg, &tmp); + bool success = DexFileLoader::Open( + location, location, /* verify */ true, kVerifyChecksum, error_msg, &tmp); if (success) { for (std::unique_ptr<const DexFile>& dex_file : tmp) { EXPECT_EQ(PROT_READ, dex_file->GetPermissions()); @@ -366,7 +367,8 @@ TEST_F(DexFileTest, Version40Rejected) { static constexpr bool kVerifyChecksum = true; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - ASSERT_FALSE(DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files)); + ASSERT_FALSE(DexFileLoader::Open( + location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)); } TEST_F(DexFileTest, Version41Rejected) { @@ -378,7 +380,8 @@ TEST_F(DexFileTest, Version41Rejected) { static constexpr bool kVerifyChecksum = true; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - ASSERT_FALSE(DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files)); + ASSERT_FALSE(DexFileLoader::Open( + location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)); } TEST_F(DexFileTest, ZeroLengthDexRejected) { @@ -390,7 +393,8 @@ TEST_F(DexFileTest, ZeroLengthDexRejected) { static constexpr bool kVerifyChecksum = true; std::string error_msg; std::vector<std::unique_ptr<const DexFile>> dex_files; - ASSERT_FALSE(DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files)); + ASSERT_FALSE(DexFileLoader::Open( + location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)); } TEST_F(DexFileTest, GetLocationChecksum) { diff --git a/runtime/dex_file_verifier_test.cc b/runtime/dex_file_verifier_test.cc index 9f3505d3be..7bda89dd8d 100644 --- a/runtime/dex_file_verifier_test.cc +++ b/runtime/dex_file_verifier_test.cc @@ -114,7 +114,8 @@ static std::unique_ptr<const DexFile> OpenDexFileBase64(const char* base64, // read dex file ScopedObjectAccess soa(Thread::Current()); std::vector<std::unique_ptr<const DexFile>> tmp; - bool success = DexFileLoader::Open(location, location, true, error_msg, &tmp); + bool success = DexFileLoader::Open( + location, location, /* verify */ true, /* verify_checksum */ true, error_msg, &tmp); CHECK(success) << *error_msg; EXPECT_EQ(1U, tmp.size()); std::unique_ptr<const DexFile> dex_file = std::move(tmp[0]); diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index 1e7cf723dc..a3cbe959ae 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -597,8 +597,12 @@ std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat( if (oat_file_assistant.HasOriginalDexFiles()) { if (Runtime::Current()->IsDexFileFallbackEnabled()) { static constexpr bool kVerifyChecksum = true; - if (!DexFileLoader::Open( - dex_location, dex_location, kVerifyChecksum, /*out*/ &error_msg, &dex_files)) { + if (!DexFileLoader::Open(dex_location, + dex_location, + /*verify*/ true, + kVerifyChecksum, + /*out*/ &error_msg, + &dex_files)) { LOG(WARNING) << error_msg; error_msgs->push_back("Failed to open dex files from " + std::string(dex_location) + " because: " + error_msg); diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 7f2f7895db..a9db48716f 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -1026,7 +1026,8 @@ static size_t OpenDexFiles(const std::vector<std::string>& dex_filenames, LOG(WARNING) << "Skipping non-existent dex file '" << dex_filename << "'"; continue; } - if (!DexFileLoader::Open(dex_filename, dex_location, kVerifyChecksum, &error_msg, dex_files)) { + if (!DexFileLoader::Open( + dex_filename, dex_location, /* verify */ true, kVerifyChecksum, &error_msg, dex_files)) { LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "': " << error_msg; ++failure_count; } |