Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8302790: Set FileMapRegion::mapped_base() to null if mapping fails #16866

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/hotspot/share/cds/filemap.cpp
Original file line number Diff line number Diff line change
@@ -1463,7 +1463,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.
@@ -1472,8 +1472,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;
@@ -1758,13 +1758,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;
}

@@ -1801,6 +1801,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
@@ -1815,15 +1816,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.
@@ -1841,8 +1843,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");
@@ -1851,6 +1852,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()),
@@ -2126,13 +2128,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();
2 changes: 1 addition & 1 deletion src/hotspot/share/cds/filemap.hpp
Original file line number Diff line number Diff line change
@@ -170,7 +170,7 @@ class FileMapRegion: private CDSFileMapRegion {
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);
};