Revert "Revert "Full-stack integrity: check vdex contents.""
bug: 30972906
Initial revert due to 'check' file of the test needing updating for target tests.
This reverts commit a19b7649faf8780737be7ce3ec48a12d81c6d69f.
Change-Id: I455780bd88cd89ff80c9084d399e2beeb819b95f
diff --git a/runtime/dex/art_dex_file_loader.cc b/runtime/dex/art_dex_file_loader.cc
index 14386a3..c456764 100644
--- a/runtime/dex/art_dex_file_loader.cc
+++ b/runtime/dex/art_dex_file_loader.cc
@@ -85,7 +85,8 @@
bool ArtDexFileLoader::GetMultiDexChecksums(const char* filename,
std::vector<uint32_t>* checksums,
std::string* error_msg,
- int zip_fd) const {
+ int zip_fd,
+ bool* zip_file_only_contains_uncompressed_dex) const {
CHECK(checksums != nullptr);
uint32_t magic;
@@ -119,7 +120,17 @@
return false;
}
+ if (zip_file_only_contains_uncompressed_dex != nullptr) {
+ // Start by assuming everything is uncompressed.
+ *zip_file_only_contains_uncompressed_dex = true;
+ }
+
do {
+ if (zip_file_only_contains_uncompressed_dex != nullptr) {
+ if (!(zip_entry->IsUncompressed() && zip_entry->IsAlignedToDexHeader())) {
+ *zip_file_only_contains_uncompressed_dex = false;
+ }
+ }
checksums->push_back(zip_entry->GetCrc32());
zip_entry_name = GetMultiDexClassesDexName(i++);
zip_entry.reset(zip_archive->Find(zip_entry_name.c_str(), error_msg));
diff --git a/runtime/dex/art_dex_file_loader.h b/runtime/dex/art_dex_file_loader.h
index 3585381..7c7a59b 100644
--- a/runtime/dex/art_dex_file_loader.h
+++ b/runtime/dex/art_dex_file_loader.h
@@ -50,7 +50,8 @@
bool GetMultiDexChecksums(const char* filename,
std::vector<uint32_t>* checksums,
std::string* error_msg,
- int zip_fd = -1) const OVERRIDE;
+ int zip_fd = -1,
+ 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,
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 0170073..6bf05b7 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -515,6 +515,18 @@
VLOG(oat) << "Image checksum test skipped for compiler filter " << current_compiler_filter;
}
+ // zip_file_only_contains_uncompressed_dex_ is only set during fetching the dex checksums.
+ DCHECK(required_dex_checksums_attempted_);
+ if (only_load_system_executable_ &&
+ !LocationIsOnSystem(file.GetLocation().c_str()) &&
+ file.ContainsDexCode() &&
+ zip_file_only_contains_uncompressed_dex_) {
+ LOG(ERROR) << "Not loading "
+ << dex_location_
+ << ": oat file has dex code, but APK has uncompressed dex code";
+ return kOatDexOutOfDate;
+ }
+
if (CompilerFilter::IsAotCompilationEnabled(current_compiler_filter)) {
if (!file.IsPic()) {
const ImageInfo* image_info = GetImageInfo();
@@ -879,7 +891,8 @@
if (dex_file_loader.GetMultiDexChecksums(dex_location_.c_str(),
&cached_required_dex_checksums_,
&error_msg,
- zip_fd_)) {
+ zip_fd_,
+ &zip_file_only_contains_uncompressed_dex_)) {
required_dex_checksums_found_ = true;
has_original_dex_files_ = true;
} else {
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index a184807..6da49a9 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -508,6 +508,9 @@
// Whether only oat files on /system are loaded executable.
const bool only_load_system_executable_ = false;
+ // Whether the potential zip file only contains uncompressed dex.
+ // Will be set during GetRequiredDexChecksums.
+ bool zip_file_only_contains_uncompressed_dex_ = true;
// Cached value of the required dex checksums.
// This should be accessed only by the GetRequiredDexChecksums() method.
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index c7f73d1..c61ecc8 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -334,6 +334,8 @@
.IntoKey(M::HiddenApiChecks)
.Define("-Xuse-stderr-logger")
.IntoKey(M::UseStderrLogger)
+ .Define("-Xonly-use-system-oat-files")
+ .IntoKey(M::OnlyUseSystemOatFiles)
.Ignore({
"-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
"-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_",
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 2074f1e..4442fc6 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1593,6 +1593,11 @@
VLOG(startup) << "Runtime::Init exiting";
+ // Set OnlyUseSystemOatFiles only after boot classpath has been set up.
+ if (runtime_options.Exists(Opt::OnlyUseSystemOatFiles)) {
+ oat_file_manager_->SetOnlyUseSystemOatFiles();
+ }
+
return true;
}
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index dba648e..4121ad6 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -152,4 +152,6 @@
RUNTIME_OPTIONS_KEY (unsigned int, GlobalRefAllocStackTraceLimit, 0) // 0 = off
RUNTIME_OPTIONS_KEY (Unit, UseStderrLogger)
+RUNTIME_OPTIONS_KEY (Unit, OnlyUseSystemOatFiles)
+
#undef RUNTIME_OPTIONS_KEY