diff options
author | 2022-11-24 16:28:14 +0000 | |
---|---|---|
committer | 2022-12-06 11:31:10 +0000 | |
commit | 1ebfebc865ef6661b16e38011ea8fbb6d8608e61 (patch) | |
tree | ba2c46d3cf48ad6117a863b3abec59a42f9f6edc /runtime/class_linker.cc | |
parent | 45fc5bd35206e2f5a7884c107c24b83084283e75 (diff) |
Generate app image at runtime.
Generate an image only containing image_roots for now.
Test: 845-data-image, 846-multidex-data-image, test.py
Change-Id: Ic4186785065f7ae65600e33dab608cb91bdc633d
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index dc2ccb40f5..ca3d399a0d 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1432,7 +1432,7 @@ void ClassLinker::AddExtraBootDexFiles( } } -bool ClassLinker::IsBootClassLoader(ObjPtr<mirror::ClassLoader> class_loader) { +bool ClassLinker::IsBootClassLoader(ObjPtr<mirror::Object> class_loader) { return class_loader == nullptr || WellKnownClasses::java_lang_BootClassLoader == class_loader->GetClass(); } @@ -1999,9 +1999,8 @@ bool ClassLinker::AddImageSpace( hs.NewHandle(dex_caches_object->AsObjectArray<mirror::DexCache>())); Handle<mirror::ObjectArray<mirror::Class>> class_roots(hs.NewHandle( header.GetImageRoot(ImageHeader::kClassRoots)->AsObjectArray<mirror::Class>())); - MutableHandle<mirror::ClassLoader> image_class_loader(hs.NewHandle( - app_image ? header.GetImageRoot(ImageHeader::kAppImageClassLoader)->AsClassLoader() - : nullptr)); + MutableHandle<mirror::Object> special_root(hs.NewHandle( + app_image ? header.GetImageRoot(ImageHeader::kSpecialRoots) : nullptr)); DCHECK(class_roots != nullptr); if (class_roots->GetLength() != static_cast<int32_t>(ClassRoot::kMax)) { *error_msg = StringPrintf("Expected %d class roots but got %d", @@ -2048,9 +2047,30 @@ bool ClassLinker::AddImageSpace( if (app_image) { ScopedAssertNoThreadSuspension sants("Checking app image"); - if (IsBootClassLoader(image_class_loader.Get())) { + 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(); + if (oat_file->GetVdexFile()->GetNumberOfDexFiles() != count) { + *error_msg = "Cheksums 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()); + 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 cheksums did not match"; + return false; + } + } else if (IsBootClassLoader(special_root.Get())) { *error_msg = "Unexpected BootClassLoader in app image"; return false; + } else if (!special_root->IsClassLoader()) { + *error_msg = "Unexpected special root in app image"; + return false; } } |