summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2024-09-26 15:33:59 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2024-09-26 16:57:37 +0000
commitd53f0ae0e7a045c29a3e270504ef8b82bf0581b9 (patch)
treee24b7ac686ba36979f581696dfd4b459644a3a1d
parentea269f69d05fe333e4b36634b925c3c40fc8ce95 (diff)
Reland "Do not unmap twice a mapping."
This reverts commit ed67125787c5ec24285e694e56f6e4f1f7fef1be. Bug: 363118250 Bug: 319203762 Reason for revert: Adjust MapFileAtAddress with new expectations Change-Id: Ie3e3daf7d92468f154d661f6ada2605d4015861e
-rw-r--r--libartbase/base/mem_map.cc3
-rw-r--r--libartbase/base/mem_map.h26
-rw-r--r--runtime/jit/jit.cc9
3 files changed, 27 insertions, 11 deletions
diff --git a/libartbase/base/mem_map.cc b/libartbase/base/mem_map.cc
index 08d452b5ff..5c785618ba 100644
--- a/libartbase/base/mem_map.cc
+++ b/libartbase/base/mem_map.cc
@@ -531,10 +531,9 @@ MemMap MemMap::MapFileAtAddress(uint8_t* expected_ptr,
// Note that we do not allow MAP_FIXED unless reuse == true or we have an existing
// reservation, i.e we expect this mapping to be contained within an existing map.
- if (reuse) {
+ if (reuse && expected_ptr != nullptr) {
// reuse means it is okay that it overlaps an existing page mapping.
// Only use this if you actually made the page reservation yourself.
- CHECK(expected_ptr != nullptr);
DCHECK(reservation == nullptr);
DCHECK(error_msg != nullptr);
DCHECK(ContainedWithinExistingMap(expected_ptr, byte_count, error_msg))
diff --git a/libartbase/base/mem_map.h b/libartbase/base/mem_map.h
index a3af44fadb..4b4a56a23f 100644
--- a/libartbase/base/mem_map.h
+++ b/libartbase/base/mem_map.h
@@ -220,6 +220,28 @@ class MemMap {
error_msg);
}
+ static MemMap MapFile(size_t byte_count,
+ int prot,
+ int flags,
+ int fd,
+ off_t start,
+ bool low_4gb,
+ const char* filename,
+ bool reuse,
+ std::string* error_msg) {
+ return MapFileAtAddress(nullptr,
+ byte_count,
+ prot,
+ flags,
+ fd,
+ start,
+ /*low_4gb=*/ low_4gb,
+ filename,
+ reuse,
+ /*reservation=*/ nullptr,
+ error_msg);
+ }
+
// Map part of a file, taking care of non-page aligned offsets. The "start" offset is absolute,
// not relative. This version allows requesting a specific address for the base of the mapping.
//
@@ -425,8 +447,8 @@ class MemMap {
size_t base_size_ = 0u; // Length of mapping. May be changed by RemapAtEnd (ie Zygote).
int prot_ = 0; // Protection of the map.
- // When reuse_ is true, this is just a view of an existing mapping
- // and we do not take ownership and are not responsible for
+ // When reuse_ is true, this is a view of a mapping on which
+ // we do not take ownership and are not responsible for
// unmapping.
bool reuse_ = false;
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 46a1a4aa73..594f4a8e8a 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -568,6 +568,7 @@ void Jit::NotifyZygoteCompilationDone() {
/* start= */ 0,
/* low_4gb= */ false,
"boot-image-methods",
+ /* reuse= */ true, // The mapping will be reused by the mremaps below.
&error_str);
if (!child_mapping_methods.IsValid()) {
@@ -640,10 +641,6 @@ void Jit::NotifyZygoteCompilationDone() {
// Mark that compilation of boot classpath is done, and memory can now be
// shared. Other processes will pick up this information.
code_cache_->GetZygoteMap()->SetCompilationState(ZygoteCompilationState::kNotifiedOk);
-
- // The private mapping created for this process has been mremaped. We can
- // reset it.
- child_mapping_methods.Reset();
}
class JitCompileTask final : public Task {
@@ -975,6 +972,7 @@ void Jit::MapBootImageMethods() {
/* start= */ 0,
/* low_4gb= */ false,
"boot-image-methods",
+ /* reuse= */ true, // The mapping will be reused by the mremaps below.
&error_str);
// We don't need the fd anymore.
@@ -1071,9 +1069,6 @@ void Jit::MapBootImageMethods() {
offset += capacity;
}
- // The private mapping created for this process has been mremaped. We can
- // reset it.
- child_mapping_methods.Reset();
LOG(INFO) << "Successfully mapped boot image methods";
}