From: Alex Light Date: Fri, 29 Aug 2014 17:28:25 +0000 (-0700) Subject: Fix segfault if running without image. X-Git-Tag: android-x86-6.0-r1~145^2~2^2~252 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=496cd337c19ca8386fec24633160f82c01993bbd;p=android-x86%2Fart.git Fix segfault if running without image. Bug: 17325091 (cherry picked from commit 7adb7ac3913364de8cc57b8934024dd12e1d3bea) Change-Id: I343099543ce0abf02219da84d61d9ce2dfc47980 --- diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 9ea6c4983..51ee448ff 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -947,31 +947,35 @@ const OatFile* ClassLinker::FindOatFileInOatLocationForDexFile(const char* dex_l return nullptr; } Runtime* runtime = Runtime::Current(); - const ImageHeader& image_header = runtime->GetHeap()->GetImageSpace()->GetImageHeader(); - uint32_t expected_image_oat_checksum = image_header.GetOatChecksum(); - uint32_t actual_image_oat_checksum = oat_file->GetOatHeader().GetImageFileLocationOatChecksum(); - if (expected_image_oat_checksum != actual_image_oat_checksum) { - *error_msg = StringPrintf("Failed to find oat file at '%s' with expected image oat checksum of " - "0x%x, found 0x%x", oat_location, expected_image_oat_checksum, - actual_image_oat_checksum); - return nullptr; - } + const gc::space::ImageSpace* image_space = runtime->GetHeap()->GetImageSpace(); + if (image_space != nullptr) { + const ImageHeader& image_header = image_space->GetImageHeader(); + uint32_t expected_image_oat_checksum = image_header.GetOatChecksum(); + uint32_t actual_image_oat_checksum = oat_file->GetOatHeader().GetImageFileLocationOatChecksum(); + if (expected_image_oat_checksum != actual_image_oat_checksum) { + *error_msg = StringPrintf("Failed to find oat file at '%s' with expected image oat checksum of " + "0x%x, found 0x%x", oat_location, expected_image_oat_checksum, + actual_image_oat_checksum); + return nullptr; + } - uintptr_t expected_image_oat_offset = reinterpret_cast(image_header.GetOatDataBegin()); - uint32_t actual_image_oat_offset = oat_file->GetOatHeader().GetImageFileLocationOatDataBegin(); - if (expected_image_oat_offset != actual_image_oat_offset) { - *error_msg = StringPrintf("Failed to find oat file at '%s' with expected image oat offset %" - PRIuPTR ", found %ud", oat_location, expected_image_oat_offset, - actual_image_oat_offset); - return nullptr; - } - int32_t expected_patch_delta = image_header.GetPatchDelta(); - int32_t actual_patch_delta = oat_file->GetOatHeader().GetImagePatchDelta(); - if (expected_patch_delta != actual_patch_delta) { - *error_msg = StringPrintf("Failed to find oat file at '%s' with expected patch delta %d, " - " found %d", oat_location, expected_patch_delta, actual_patch_delta); - return nullptr; + uintptr_t expected_image_oat_offset = reinterpret_cast(image_header.GetOatDataBegin()); + uint32_t actual_image_oat_offset = oat_file->GetOatHeader().GetImageFileLocationOatDataBegin(); + if (expected_image_oat_offset != actual_image_oat_offset) { + *error_msg = StringPrintf("Failed to find oat file at '%s' with expected image oat offset %" + PRIuPTR ", found %ud", oat_location, expected_image_oat_offset, + actual_image_oat_offset); + return nullptr; + } + int32_t expected_patch_delta = image_header.GetPatchDelta(); + int32_t actual_patch_delta = oat_file->GetOatHeader().GetImagePatchDelta(); + if (expected_patch_delta != actual_patch_delta) { + *error_msg = StringPrintf("Failed to find oat file at '%s' with expected patch delta %d, " + " found %d", oat_location, expected_patch_delta, actual_patch_delta); + return nullptr; + } } + const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_location, &dex_location_checksum); if (oat_dex_file == nullptr) {