diff options
author | 2023-01-30 14:29:11 +0000 | |
---|---|---|
committer | 2023-02-01 09:52:45 +0000 | |
commit | 0f6af5e3b51a7f5905d09a98ec8d531541666015 (patch) | |
tree | 7ed720cc521bb7f6e3b092cf6900a34d050c3aba /runtime/class_linker.cc | |
parent | d04ed700190056ecd367ee41e6b7f3b87dc7f901 (diff) |
Reland "Write classes in runtime-generated app image."
This reverts commit 24b3d648ff6c2c200003f55ac63fc910d7bfd40f.
Bug: 260557058
Reason for revert:
- Encode class loader context in image, and check it at load time.
- Set nterp entrypoint to methods that can.
Test: test.py
Test: atest com.android.bluetooth.opp.BluetoothOppObexServerSessionTest#onPut_withUnsupportedMimeTypeInHeader_returnsHttpBadRequest
Change-Id: Ibf4a8604c4a226d1acc021103668e211446bb53c
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index d5efb685c8..c772a9c29a 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1400,6 +1400,7 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) { std::vector<std::unique_ptr<const DexFile>> dex_files; if (!AddImageSpace(spaces[i], ScopedNullHandle<mirror::ClassLoader>(), + /* class_loader_context= */ nullptr, /*out*/&dex_files, error_msg)) { return false; @@ -1971,6 +1972,7 @@ static void VerifyAppImage(const ImageHeader& header, bool ClassLinker::AddImageSpace( gc::space::ImageSpace* space, Handle<mirror::ClassLoader> class_loader, + ClassLoaderContext* context, std::vector<std::unique_ptr<const DexFile>>* out_dex_files, std::string* error_msg) { DCHECK(out_dex_files != nullptr); @@ -2053,21 +2055,32 @@ bool ClassLinker::AddImageSpace( if (special_root == nullptr) { *error_msg = "Unexpected null special root in app image"; return false; - } else if (special_root->IsIntArray()) { - size_t count = special_root->AsIntArray()->GetLength(); + } else if (special_root->IsObjectArray()) { + ObjPtr<mirror::IntArray> checksums = + special_root->AsObjectArray<mirror::Object>()->Get(1)->AsIntArray(); + size_t count = checksums->GetLength(); if (oat_file->GetVdexFile()->GetNumberOfDexFiles() != count) { *error_msg = "Checksums count does not match"; return false; } static_assert(sizeof(VdexFile::VdexChecksum) == sizeof(int32_t)); const VdexFile::VdexChecksum* art_checksums = - reinterpret_cast<VdexFile::VdexChecksum*>(special_root->AsIntArray()->GetData()); + reinterpret_cast<VdexFile::VdexChecksum*>(checksums->GetData()); const VdexFile::VdexChecksum* vdex_checksums = oat_file->GetVdexFile()->GetDexChecksumsArray(); if (memcmp(art_checksums, vdex_checksums, sizeof(VdexFile::VdexChecksum) * count) != 0) { *error_msg = "Image and vdex checksums did not match"; return false; } + ObjPtr<mirror::String> encoded_context = + special_root->AsObjectArray<mirror::Object>()->Get(0)->AsString(); + std::string encoded_context_str = encoded_context->ToModifiedUtf8(); + if (context->VerifyClassLoaderContextMatch(encoded_context_str.c_str()) == + ClassLoaderContext::VerificationResult::kMismatch) { + *error_msg = + StringPrintf("Class loader contexts don't match: %s", encoded_context_str.c_str()); + return false; + } } else if (IsBootClassLoader(special_root.Get())) { *error_msg = "Unexpected BootClassLoader in app image"; return false; @@ -2180,9 +2193,11 @@ bool ClassLinker::AddImageSpace( ObjPtr<mirror::Class> klass(root.Read()); // Do not update class loader for boot image classes where the app image // class loader is only the initiating loader but not the defining loader. - // Avoid read barrier since we are comparing against null. - if (klass->GetClassLoader<kDefaultVerifyFlags, kWithoutReadBarrier>() != nullptr) { + if (space->HasAddress(klass.Ptr())) { klass->SetClassLoader(loader); + } else { + DCHECK(klass->IsBootStrapClassLoaded()); + DCHECK(Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(klass.Ptr())); } } } |