diff options
author | 2017-10-03 16:22:05 -0700 | |
---|---|---|
committer | 2017-10-03 21:24:28 -0700 | |
commit | 3425d028568f4e467e456f1fa0b75846b078bba6 (patch) | |
tree | a013b62ad56ba91d6c65f57dab019456628b2de4 | |
parent | 844a4edc7f72e33a3b328c3d53ef710909d2273d (diff) |
Rename CHECK_MEMORY_CALL to CheckedCall
Renamed CHECK_MEMORY_CALL to CheckedCall and moved it to utils. Will
use this new call for most madvise/mprotect in ART.
Test: test-art-host
Bug: 66910552
Change-Id: I32908012b310673a9c6488796f8009bb4432579b
-rw-r--r-- | runtime/gc/space/dlmalloc_space.cc | 2 | ||||
-rw-r--r-- | runtime/gc/space/malloc_space.cc | 8 | ||||
-rw-r--r-- | runtime/gc/space/malloc_space.h | 10 | ||||
-rw-r--r-- | runtime/gc/space/rosalloc_space.cc | 2 | ||||
-rw-r--r-- | runtime/utils.h | 9 |
5 files changed, 15 insertions, 16 deletions
diff --git a/runtime/gc/space/dlmalloc_space.cc b/runtime/gc/space/dlmalloc_space.cc index 7ec54f59fe..576a35c52d 100644 --- a/runtime/gc/space/dlmalloc_space.cc +++ b/runtime/gc/space/dlmalloc_space.cc @@ -60,7 +60,7 @@ DlMallocSpace* DlMallocSpace::CreateFromMemMap(MemMap* mem_map, const std::strin // Protect memory beyond the starting size. morecore will add r/w permissions when necessory uint8_t* end = mem_map->Begin() + starting_size; if (capacity - starting_size > 0) { - CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name); + CheckedCall(mprotect, name.c_str(), end, capacity - starting_size, PROT_NONE); } // Everything is set so record in immutable structure and leave diff --git a/runtime/gc/space/malloc_space.cc b/runtime/gc/space/malloc_space.cc index c99412785e..dcb783782f 100644 --- a/runtime/gc/space/malloc_space.cc +++ b/runtime/gc/space/malloc_space.cc @@ -141,7 +141,7 @@ void* MallocSpace::MoreCore(intptr_t increment) { // Should never be asked to increase the allocation beyond the capacity of the space. Enforced // by mspace_set_footprint_limit. CHECK_LE(new_end, Begin() + Capacity()); - CHECK_MEMORY_CALL(mprotect, (original_end, increment, PROT_READ | PROT_WRITE), GetName()); + CheckedCall(mprotect, GetName(), original_end, increment, PROT_READ | PROT_WRITE); } else { // Should never be asked for negative footprint (ie before begin). Zero footprint is ok. CHECK_GE(original_end + increment, Begin()); @@ -152,8 +152,8 @@ void* MallocSpace::MoreCore(intptr_t increment) { // removing ignoring the memory protection change here and in Space::CreateAllocSpace. It's // likely just a useful debug feature. size_t size = -increment; - CHECK_MEMORY_CALL(madvise, (new_end, size, MADV_DONTNEED), GetName()); - CHECK_MEMORY_CALL(mprotect, (new_end, size, PROT_NONE), GetName()); + CheckedCall(madvise, GetName(), new_end, size, MADV_DONTNEED); + CheckedCall(mprotect, GetName(), new_end, size, PROT_NONE); } // Update end_. SetEnd(new_end); @@ -201,7 +201,7 @@ ZygoteSpace* MallocSpace::CreateZygoteSpace(const char* alloc_space_name, bool l // Protect memory beyond the initial size. uint8_t* end = mem_map->Begin() + starting_size_; if (capacity > initial_size_) { - CHECK_MEMORY_CALL(mprotect, (end, capacity - initial_size_, PROT_NONE), alloc_space_name); + CheckedCall(mprotect, alloc_space_name, end, capacity - initial_size_, PROT_NONE); } *out_malloc_space = CreateInstance(mem_map.release(), alloc_space_name, allocator, End(), end, limit_, growth_limit, CanMoveObjects()); diff --git a/runtime/gc/space/malloc_space.h b/runtime/gc/space/malloc_space.h index f85ea4635b..a41ef43125 100644 --- a/runtime/gc/space/malloc_space.h +++ b/runtime/gc/space/malloc_space.h @@ -33,16 +33,6 @@ namespace space { class ZygoteSpace; -// TODO: Remove define macro -#define CHECK_MEMORY_CALL(call, args, what) \ - do { \ - int rc = call args; \ - if (UNLIKELY(rc != 0)) { \ - errno = rc; \ - PLOG(FATAL) << # call << " failed for " << (what); \ - } \ - } while (false) - // A common parent of DlMallocSpace and RosAllocSpace. class MallocSpace : public ContinuousMemMapAllocSpace { public: diff --git a/runtime/gc/space/rosalloc_space.cc b/runtime/gc/space/rosalloc_space.cc index eca0e43a97..5d1f191e4d 100644 --- a/runtime/gc/space/rosalloc_space.cc +++ b/runtime/gc/space/rosalloc_space.cc @@ -71,7 +71,7 @@ RosAllocSpace* RosAllocSpace::CreateFromMemMap(MemMap* mem_map, const std::strin // Protect memory beyond the starting size. MoreCore will add r/w permissions when necessory uint8_t* end = mem_map->Begin() + starting_size; if (capacity - starting_size > 0) { - CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name); + CheckedCall(mprotect, name.c_str(), end, capacity - starting_size, PROT_NONE); } // Everything is set so record in immutable structure and leave diff --git a/runtime/utils.h b/runtime/utils.h index 4cb06c1afa..fbf812a6b3 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -338,6 +338,15 @@ inline static int32_t Signum(T opnd) { // Madvise the largest page aligned region within begin and end. int MadviseLargestPageAlignedRegion(const uint8_t* begin, const uint8_t* end, int advice); +template <typename Func, typename... Args> +static inline void CheckedCall(const Func& function, const char* what, Args... args) { + int rc = function(args...); + if (UNLIKELY(rc != 0)) { + errno = rc; + PLOG(FATAL) << "Checked call failed for " << what; + } +} + } // namespace art #endif // ART_RUNTIME_UTILS_H_ |