summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r--runtime/class_linker.cc25
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()));
}
}
}