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
diff --git a/runtime/gc/space/dlmalloc_space.cc b/runtime/gc/space/dlmalloc_space.cc
index 7ec54f5..576a35c 100644
--- a/runtime/gc/space/dlmalloc_space.cc
+++ b/runtime/gc/space/dlmalloc_space.cc
@@ -60,7 +60,7 @@
   // 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 c994127..dcb7837 100644
--- a/runtime/gc/space/malloc_space.cc
+++ b/runtime/gc/space/malloc_space.cc
@@ -141,7 +141,7 @@
       // 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 @@
       // 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 @@
   // 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 f85ea46..a41ef43 100644
--- a/runtime/gc/space/malloc_space.h
+++ b/runtime/gc/space/malloc_space.h
@@ -33,16 +33,6 @@
 
 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 eca0e43..5d1f191 100644
--- a/runtime/gc/space/rosalloc_space.cc
+++ b/runtime/gc/space/rosalloc_space.cc
@@ -71,7 +71,7 @@
   // 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 4cb06c1..fbf812a 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -338,6 +338,15 @@
 // 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_