diff options
author | 2025-03-12 16:45:38 +0000 | |
---|---|---|
committer | 2025-03-20 16:33:35 -0700 | |
commit | 5045a8060a75ccccea94eac7363744ed63580ff9 (patch) | |
tree | eeb8a7d5d62bbdd9d5968153a9c414bff2b1d7fd /runtime/gc/space/image_space.cc | |
parent | b2d23dd55d0f1d16beb43a247d62bf09a8060665 (diff) |
Allow APEX versions in the OAT header to be overriden.
APEX versions are stringified mtime's of the APEXes installed on device,
for detecting samegrade placebos (go/samegrade-placebos). In the case of
Cloud Compilation, we cannot put the APEX versions in the OAT header
because the OAT file is generated on the server. Instead, we put the
APEX versions in a separate file (SDC file) when the SDM file is being
installed on device. Therefore, we need a way to override the APEX
versions in the OAT header.
This is a no-op change.
Bug: 377474232
Test: m test-art-host-gtest-art_runtime_tests
Change-Id: I69658b61942979ff7f56e4908ce3204bd0a2116e
Diffstat (limited to 'runtime/gc/space/image_space.cc')
-rw-r--r-- | runtime/gc/space/image_space.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index 97512bc79c..f557f3c8a9 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -26,6 +26,7 @@ #include <optional> #include <random> #include <string> +#include <string_view> #include <vector> #include "android-base/logging.h" @@ -3415,31 +3416,39 @@ void ImageSpace::Dump(std::ostream& os) const { << ",name=\"" << GetName() << "\"]"; } -bool ImageSpace::ValidateApexVersions(const OatHeader& oat_header, - const std::string& apex_versions, - const std::string& file_location, +bool ImageSpace::ValidateApexVersions(const OatFile& oat_file, + std::string_view runtime_apex_versions, std::string* error_msg) { // For a boot image, the key value store only exists in the first OAT file. Skip other OAT files. - if (oat_header.GetKeyValueStoreSize() == 0) { + if (oat_file.GetOatHeader().GetKeyValueStoreSize() == 0) { return true; } - const char* oat_apex_versions = oat_header.GetStoreValueByKey(OatHeader::kApexVersionsKey); - if (oat_apex_versions == nullptr) { + std::optional<std::string_view> oat_apex_versions = oat_file.GetApexVersions(); + if (!oat_apex_versions.has_value()) { *error_msg = StringPrintf("ValidateApexVersions failed to get APEX versions from oat file '%s'", - file_location.c_str()); + oat_file.GetLocation().c_str()); return false; } + + return ValidateApexVersions( + *oat_apex_versions, runtime_apex_versions, oat_file.GetLocation(), error_msg); +} + +bool ImageSpace::ValidateApexVersions(std::string_view oat_apex_versions, + std::string_view runtime_apex_versions, + const std::string& file_location, + std::string* error_msg) { // For a boot image, it can be generated from a subset of the bootclasspath. // For an app image, some dex files get compiled with a subset of the bootclasspath. // For such cases, the OAT APEX versions will be a prefix of the runtime APEX versions. - if (!apex_versions.starts_with(oat_apex_versions)) { - *error_msg = StringPrintf( - "ValidateApexVersions found APEX versions mismatch between oat file '%s' and the runtime " - "(Oat file: '%s', Runtime: '%s')", - file_location.c_str(), + if (!runtime_apex_versions.starts_with(oat_apex_versions)) { + *error_msg = ART_FORMAT( + "ValidateApexVersions found APEX versions mismatch between oat file '{}' and the runtime " + "(Oat file: '{}', Runtime: '{}')", + file_location, oat_apex_versions, - apex_versions.c_str()); + runtime_apex_versions); return false; } return true; @@ -3455,10 +3464,7 @@ bool ImageSpace::ValidateOatFile(const OatFile& oat_file, ArrayRef<const std::string> dex_filenames, ArrayRef<File> dex_files, const std::string& apex_versions) { - if (!ValidateApexVersions(oat_file.GetOatHeader(), - apex_versions, - oat_file.GetLocation(), - error_msg)) { + if (!ValidateApexVersions(oat_file, apex_versions, error_msg)) { return false; } |