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> | |
8 #include <servers/bootstrap.h> | 7 #include <servers/bootstrap.h> |
9 | 8 |
10 #include "base/mac/mach_logging.h" | 9 #include "base/mac/mach_logging.h" |
11 #include "base/mac/scoped_mach_port.h" | 10 #include "base/mac/scoped_mach_port.h" |
12 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 // Structs used to pass a Mach port over mach_msg(). | 16 // Structs used to pass a Mach port over mach_msg(). |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 MACH_PORT_RIGHT_SEND, &ref_count); | 107 MACH_PORT_RIGHT_SEND, &ref_count); |
109 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; | 108 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; |
110 return ref_count; | 109 return ref_count; |
111 } | 110 } |
112 | 111 |
113 void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right) { | 112 void IncrementMachRefCount(mach_port_name_t name, mach_port_right_t right) { |
114 kern_return_t kr = mach_port_mod_refs(mach_task_self(), name, right, 1); | 113 kern_return_t kr = mach_port_mod_refs(mach_task_self(), name, right, 1); |
115 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; | 114 MACH_CHECK(kr == KERN_SUCCESS, kr) << "GetRefCount"; |
116 } | 115 } |
117 | 116 |
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_port_t ctype; | |
128 | |
129 kern_return_t kr = | |
130 mach_vm_region(mach_task_self(), &mem_address, &mem_size, flavor, | |
131 region_info, &memory_object, &ctype); | |
132 if (kr != KERN_SUCCESS) { | |
133 LOG(ERROR) << "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 | |
142 } // namespace IPC | 117 } // namespace IPC |
OLD | NEW |