Index: ipc/test_util_mac.cc |
diff --git a/ipc/test_util_mac.cc b/ipc/test_util_mac.cc |
index 4639b13babe9f90ab8fd524c7d390c53b973797c..87270773f9ba6d3de4a41e0193155f22e8260074 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_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64; |
+ |
+ kern_return_t kr = |
+ mach_vm_region(mach_task_self(), &mem_address, &mem_size, flavor, |
+ region_info, &count, &memory_object); |
+ if (kr != KERN_SUCCESS) { |
+ MACH_LOG(ERROR, kr) << "Failed to get region info."; |
+ return false; |
+ } |
+ |
+ *current = basic_info.protection; |
+ *max = basic_info.max_protection; |
+ return true; |
+} |
+ |
} // namespace IPC |