diff options
| author | 2017-05-18 17:45:07 -0700 | |
|---|---|---|
| committer | 2017-05-19 08:08:51 -0700 | |
| commit | 5f2a2fcdba7c3ee502f1fa5df1ba69be6c83da33 (patch) | |
| tree | eb96bbf4524cffb5eb49f01c3426640eba44f7e3 | |
| parent | a654e0378a8d0bb149362399917e4da2959e6991 (diff) | |
ART: Reserve sentinel early
Reserve the sentinel early. Its address is out of the way of the
image.
Test: m test-art-host
Change-Id: Id04a76baaab60db86e863746d5ad6966c60cd334
| -rw-r--r-- | runtime/runtime.cc | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 3697f2176c..c46bd8d2b9 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -1017,6 +1017,30 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) { MemMap::Init(); + // Try to reserve a dedicated fault page. This is allocated for clobbered registers and sentinels. + // If we cannot reserve it, log a warning. + // Note: We allocate this first to have a good chance of grabbing the page. The address (0xebad..) + // is out-of-the-way enough that it should not collide with boot image mapping. + // Note: Don't request an error message. That will lead to a maps dump in the case of failure, + // leading to logspam. + { + constexpr uintptr_t kSentinelAddr = + RoundDown(static_cast<uintptr_t>(Context::kBadGprBase), kPageSize); + protected_fault_page_.reset(MemMap::MapAnonymous("Sentinel fault page", + reinterpret_cast<uint8_t*>(kSentinelAddr), + kPageSize, + PROT_NONE, + /* low_4g */ true, + /* reuse */ false, + /* error_msg */ nullptr)); + if (protected_fault_page_ == nullptr) { + LOG(WARNING) << "Could not reserve sentinel fault page"; + } else if (reinterpret_cast<uintptr_t>(protected_fault_page_->Begin()) != kSentinelAddr) { + LOG(WARNING) << "Could not reserve sentinel fault page at the right address."; + protected_fault_page_.reset(); + } + } + using Opt = RuntimeArgumentMap; VLOG(startup) << "Runtime::Init -verbose:startup enabled"; @@ -1401,27 +1425,6 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) { callbacks_->NextRuntimePhase(RuntimePhaseCallback::RuntimePhase::kInitialAgents); } - // Try to reserve a dedicated fault page. This is allocated for clobbered registers and sentinels. - // If we cannot reserve it, log a warning. - // Note: This is allocated last so that the heap and other things have priority, if necessary. - { - constexpr uintptr_t kSentinelAddr = - RoundDown(static_cast<uintptr_t>(Context::kBadGprBase), kPageSize); - protected_fault_page_.reset(MemMap::MapAnonymous("Sentinel fault page", - reinterpret_cast<uint8_t*>(kSentinelAddr), - kPageSize, - PROT_NONE, - true, - false, - &error_msg)); - if (protected_fault_page_ == nullptr) { - LOG(WARNING) << "Could not reserve sentinel fault page: " << error_msg; - } else if (reinterpret_cast<uintptr_t>(protected_fault_page_->Begin()) != kSentinelAddr) { - LOG(WARNING) << "Could not reserve sentinel fault page at the right address."; - protected_fault_page_.reset(); - } - } - VLOG(startup) << "Runtime::Init exiting"; return true; |