| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/test_util_mac.h" | 5 #include "ipc/test_util_mac.h" |
| 6 | 6 |
| 7 #include <mach/mach_vm.h> |
| 7 #include <servers/bootstrap.h> | 8 #include <servers/bootstrap.h> |
| 8 | 9 |
| 9 #include "base/mac/mach_logging.h" | 10 #include "base/mac/mach_logging.h" |
| 10 #include "base/mac/scoped_mach_port.h" | 11 #include "base/mac/scoped_mach_port.h" |
| 11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Structs used to pass a Mach port over mach_msg(). | 17 // Structs used to pass a Mach port over mach_msg(). |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 MACH_PORT_RIGHT_SEND, &ref_count); | 108 MACH_PORT_RIGHT_SEND, &ref_count); |
| 108 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; | 109 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; |
| 109 return ref_count; | 110 return ref_count; |
| 110 } | 111 } |
| 111 | 112 |
| 112 void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right) { | 113 void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right) { |
| 113 kern_return_t kr = mach_port_mod_refs(mach_task_self(), name, right, 1); | 114 kern_return_t kr = mach_port_mod_refs(mach_task_self(), name, right, 1); |
| 114 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; | 115 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; |
| 115 } | 116 } |
| 116 | 117 |
| 118 bool GetMachProtections(void* address, size_t size, int* current, int* max) { |
| 119 vm_region_info_t region_info; |
| 120 mach_vm_address_t mem_address = reinterpret_cast<mach_vm_address_t>(address); |
| 121 mach_vm_size_t mem_size = size; |
| 122 vm_region_basic_info_64 basic_info; |
| 123 |
| 124 region_info = reinterpret_cast<vm_region_recurse_info_t>(&basic_info); |
| 125 vm_region_flavor_t flavor = VM_REGION_BASIC_INFO_64; |
| 126 memory_object_name_t memory_object; |
| 127 mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64; |
| 128 |
| 129 kern_return_t kr = |
| 130 mach_vm_region(mach_task_self(), &mem_address, &mem_size, flavor, |
| 131 region_info, &count, &memory_object); |
| 132 if (kr != KERN_SUCCESS) { |
| 133 MACH_LOG(ERROR, kr) << "Failed to get region info."; |
| 134 return false; |
| 135 } |
| 136 |
| 137 *current = basic_info.protection; |
| 138 *max = basic_info.max_protection; |
| 139 return true; |
| 140 } |
| 141 |
| 117 } // namespace IPC | 142 } // namespace IPC |
| OLD | NEW |