Index: ipc/test_util_mac.cc |
diff --git a/ipc/test_util_mac.cc b/ipc/test_util_mac.cc |
index 4639b13babe9f90ab8fd524c7d390c53b973797c..5e26e1f78f4f1f7e5c9686325717cf3d21e81f2a 100644 |
--- a/ipc/test_util_mac.cc |
+++ b/ipc/test_util_mac.cc |
@@ -4,6 +4,7 @@ |
#include "ipc/test_util_mac.h" |
+#include <mach/mach_vm.h> |
#include <servers/bootstrap.h> |
#include "base/mac/mach_logging.h" |
@@ -114,4 +115,28 @@ void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right) { |
MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; |
} |
+bool GetMachProtections(void* address, size_t size, int* current, int* max) { |
+ vm_region_info_t region_info; |
+ mach_vm_address_t mem_address = reinterpret_cast<mach_vm_address_t>(address); |
+ mach_vm_size_t mem_size = size; |
+ vm_region_basic_info_64 basic_info; |
+ |
+ region_info = reinterpret_cast<vm_region_recurse_info_t>(&basic_info); |
+ vm_region_flavor_t flavor = VM_REGION_BASIC_INFO_64; |
+ memory_object_name_t memory_object; |
+ mach_port_t ctype; |
+ |
+ kern_return_t kr = |
+ mach_vm_region(mach_task_self(), &mem_address, &mem_size, flavor, |
+ region_info, &memory_object, &ctype); |
+ if (kr != KERN_SUCCESS) { |
+ LOG(ERROR) << "Failed to get region info."; |
+ return false; |
+ } |
+ |
+ *current = basic_info.protection; |
+ *max = basic_info.max_protection; |
+ return true; |
+} |
+ |
} // namespace IPC |