8302790: Set FileMapRegion::mapped_base() to null if mapping fails
Reviewed-by: iklam, ccheung
This commit is contained in:
parent
519ecd352a
commit
fe4c0a2f04
@ -1465,7 +1465,7 @@ BitMapView FileMapRegion::ptrmap_view() {
|
||||
return bitmap_view(false);
|
||||
}
|
||||
|
||||
bool FileMapRegion::check_region_crc() const {
|
||||
bool FileMapRegion::check_region_crc(char* base) const {
|
||||
// This function should be called after the region has been properly
|
||||
// loaded into memory via FileMapInfo::map_region() or FileMapInfo::read_region().
|
||||
// I.e., this->mapped_base() must be valid.
|
||||
@ -1474,8 +1474,8 @@ bool FileMapRegion::check_region_crc() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(mapped_base() != nullptr, "must be initialized");
|
||||
int crc = ClassLoader::crc32(0, mapped_base(), (jint)sz);
|
||||
assert(base != nullptr, "must be initialized");
|
||||
int crc = ClassLoader::crc32(0, base, (jint)sz);
|
||||
if (crc != this->crc()) {
|
||||
log_warning(cds)("Checksum verification failed.");
|
||||
return false;
|
||||
@ -1760,13 +1760,13 @@ bool FileMapInfo::read_region(int i, char* base, size_t size, bool do_commit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
r->set_mapped_from_file(false);
|
||||
r->set_mapped_base(base);
|
||||
|
||||
if (VerifySharedSpaces && !r->check_region_crc()) {
|
||||
if (VerifySharedSpaces && !r->check_region_crc(base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
r->set_mapped_from_file(false);
|
||||
r->set_mapped_base(base);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1803,6 +1803,7 @@ MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_ba
|
||||
return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
|
||||
} else {
|
||||
assert(r->mapped_base() != nullptr, "must be initialized");
|
||||
return MAP_ARCHIVE_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
// Note that this may either be a "fresh" mapping into unreserved address
|
||||
@ -1817,15 +1818,16 @@ MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_ba
|
||||
_memory_mapping_failed = true;
|
||||
return MAP_ARCHIVE_MMAP_FAILURE;
|
||||
}
|
||||
|
||||
if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
|
||||
return MAP_ARCHIVE_OTHER_FAILURE;
|
||||
}
|
||||
|
||||
r->set_mapped_from_file(true);
|
||||
r->set_mapped_base(requested_addr);
|
||||
}
|
||||
|
||||
if (VerifySharedSpaces && !r->check_region_crc()) {
|
||||
return MAP_ARCHIVE_OTHER_FAILURE;
|
||||
return MAP_ARCHIVE_SUCCESS;
|
||||
}
|
||||
|
||||
return MAP_ARCHIVE_SUCCESS;
|
||||
}
|
||||
|
||||
// The return value is the location of the archive relocation bitmap.
|
||||
@ -1843,8 +1845,7 @@ char* FileMapInfo::map_bitmap_region() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
r->set_mapped_base(bitmap_base);
|
||||
if (VerifySharedSpaces && !r->check_region_crc()) {
|
||||
if (VerifySharedSpaces && !r->check_region_crc(bitmap_base)) {
|
||||
log_error(cds)("relocation bitmap CRC error");
|
||||
if (!os::unmap_memory(bitmap_base, r->used_aligned())) {
|
||||
fatal("os::unmap_memory of relocation bitmap failed");
|
||||
@ -1853,6 +1854,7 @@ char* FileMapInfo::map_bitmap_region() {
|
||||
}
|
||||
|
||||
r->set_mapped_from_file(true);
|
||||
r->set_mapped_base(bitmap_base);
|
||||
log_info(cds)("Mapped %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
|
||||
is_static() ? "static " : "dynamic",
|
||||
MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
|
||||
@ -2128,13 +2130,14 @@ bool FileMapInfo::map_heap_region_impl() {
|
||||
return false;
|
||||
}
|
||||
|
||||
r->set_mapped_base(base);
|
||||
if (VerifySharedSpaces && !r->check_region_crc()) {
|
||||
if (VerifySharedSpaces && !r->check_region_crc(base)) {
|
||||
dealloc_heap_region();
|
||||
log_info(cds)("UseSharedSpaces: mapped heap region is corrupt");
|
||||
return false;
|
||||
}
|
||||
|
||||
r->set_mapped_base(base);
|
||||
|
||||
// If the requested range is different from the range allocated by GC, then
|
||||
// the pointers need to be patched.
|
||||
address mapped_start = (address) _mapped_heap_memregion.start();
|
||||
|
@ -170,7 +170,7 @@ public:
|
||||
BitMapView ptrmap_view();
|
||||
bool has_ptrmap() { return _ptrmap_size_in_bits != 0; }
|
||||
|
||||
bool check_region_crc() const;
|
||||
bool check_region_crc(char* base) const;
|
||||
void print(outputStream* st, int region_index);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user