Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: runtime/vm/virtual_memory_fuchsia.cc

Issue 2935483002: Update Fuchsia-specific code to use the new MX_ error names (Closed)
Patch Set: not windows tho Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/thread_interrupter_fuchsia.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(HOST_OS_FUCHSIA) 6 #if defined(HOST_OS_FUCHSIA)
7 7
8 #include "vm/virtual_memory.h" 8 #include "vm/virtual_memory.h"
9 9
10 #include <magenta/process.h> 10 #include <magenta/process.h>
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 154
155 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { 155 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) {
156 mx_handle_t vmar = MX_HANDLE_INVALID; 156 mx_handle_t vmar = MX_HANDLE_INVALID;
157 uword addr = 0; 157 uword addr = 0;
158 const uint32_t flags = MX_VM_FLAG_COMPACT | MX_VM_FLAG_CAN_MAP_SPECIFIC | 158 const uint32_t flags = MX_VM_FLAG_COMPACT | MX_VM_FLAG_CAN_MAP_SPECIFIC |
159 MX_VM_FLAG_CAN_MAP_READ | MX_VM_FLAG_CAN_MAP_WRITE | 159 MX_VM_FLAG_CAN_MAP_READ | MX_VM_FLAG_CAN_MAP_WRITE |
160 MX_VM_FLAG_CAN_MAP_EXECUTE; 160 MX_VM_FLAG_CAN_MAP_EXECUTE;
161 mx_status_t status = 161 mx_status_t status =
162 mx_vmar_allocate(mx_vmar_root_self(), 0, size, flags, &vmar, &addr); 162 mx_vmar_allocate(mx_vmar_root_self(), 0, size, flags, &vmar, &addr);
163 if (status != NO_ERROR) { 163 if (status != MX_OK) {
164 LOG_ERR("mx_vmar_allocate(size = %ld) failed: %s\n", size, 164 LOG_ERR("mx_vmar_allocate(size = %ld) failed: %s\n", size,
165 mx_status_get_string(status)); 165 mx_status_get_string(status));
166 return NULL; 166 return NULL;
167 } 167 }
168 VmarList::AddVmar(vmar, addr, size); 168 VmarList::AddVmar(vmar, addr, size);
169 MemoryRegion region(reinterpret_cast<void*>(addr), size); 169 MemoryRegion region(reinterpret_cast<void*>(addr), size);
170 return new VirtualMemory(region, vmar); 170 return new VirtualMemory(region, vmar);
171 } 171 }
172 172
173 173
174 VirtualMemory::~VirtualMemory() { 174 VirtualMemory::~VirtualMemory() {
175 if (vm_owns_region()) { 175 if (vm_owns_region()) {
176 mx_handle_t vmar = static_cast<mx_handle_t>(handle()); 176 mx_handle_t vmar = static_cast<mx_handle_t>(handle());
177 mx_status_t status = mx_vmar_destroy(vmar); 177 mx_status_t status = mx_vmar_destroy(vmar);
178 if (status != NO_ERROR) { 178 if (status != MX_OK) {
179 LOG_ERR("mx_vmar_destroy failed: %s\n", mx_status_get_string(status)); 179 LOG_ERR("mx_vmar_destroy failed: %s\n", mx_status_get_string(status));
180 } 180 }
181 status = mx_handle_close(vmar); 181 status = mx_handle_close(vmar);
182 if (status != NO_ERROR) { 182 if (status != MX_OK) {
183 LOG_ERR("mx_handle_close failed: %s\n", mx_status_get_string(status)); 183 LOG_ERR("mx_handle_close failed: %s\n", mx_status_get_string(status));
184 } 184 }
185 VmarList::RemoveVmar(start()); 185 VmarList::RemoveVmar(start());
186 } 186 }
187 } 187 }
188 188
189 189
190 bool VirtualMemory::FreeSubSegment(int32_t handle, 190 bool VirtualMemory::FreeSubSegment(int32_t handle,
191 void* address, 191 void* address,
192 intptr_t size) { 192 intptr_t size) {
193 mx_handle_t vmar = static_cast<mx_handle_t>(handle); 193 mx_handle_t vmar = static_cast<mx_handle_t>(handle);
194 mx_status_t status = 194 mx_status_t status =
195 mx_vmar_unmap(vmar, reinterpret_cast<uintptr_t>(address), size); 195 mx_vmar_unmap(vmar, reinterpret_cast<uintptr_t>(address), size);
196 if (status != NO_ERROR) { 196 if (status != MX_OK) {
197 LOG_ERR("mx_vmar_unmap failed: %s\n", mx_status_get_string(status)); 197 LOG_ERR("mx_vmar_unmap failed: %s\n", mx_status_get_string(status));
198 return false; 198 return false;
199 } 199 }
200 return true; 200 return true;
201 } 201 }
202 202
203 203
204 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) { 204 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) {
205 ASSERT(Contains(addr)); 205 ASSERT(Contains(addr));
206 ASSERT(Contains(addr + size) || (addr + size == end())); 206 ASSERT(Contains(addr + size) || (addr + size == end()));
207 mx_handle_t vmo = MX_HANDLE_INVALID; 207 mx_handle_t vmo = MX_HANDLE_INVALID;
208 mx_status_t status = mx_vmo_create(size, 0u, &vmo); 208 mx_status_t status = mx_vmo_create(size, 0u, &vmo);
209 if (status != NO_ERROR) { 209 if (status != MX_OK) {
210 LOG_ERR("mx_vmo_create(%ld) failed: %s\n", size, 210 LOG_ERR("mx_vmo_create(%ld) failed: %s\n", size,
211 mx_status_get_string(status)); 211 mx_status_get_string(status));
212 return false; 212 return false;
213 } 213 }
214 214
215 mx_handle_t vmar = static_cast<mx_handle_t>(handle()); 215 mx_handle_t vmar = static_cast<mx_handle_t>(handle());
216 const size_t offset = addr - start(); 216 const size_t offset = addr - start();
217 const uint32_t flags = MX_VM_FLAG_SPECIFIC | MX_VM_FLAG_PERM_READ | 217 const uint32_t flags = MX_VM_FLAG_SPECIFIC | MX_VM_FLAG_PERM_READ |
218 MX_VM_FLAG_PERM_WRITE | 218 MX_VM_FLAG_PERM_WRITE |
219 (executable ? MX_VM_FLAG_PERM_EXECUTE : 0); 219 (executable ? MX_VM_FLAG_PERM_EXECUTE : 0);
220 uintptr_t mapped_addr; 220 uintptr_t mapped_addr;
221 status = mx_vmar_map(vmar, offset, vmo, 0, size, flags, &mapped_addr); 221 status = mx_vmar_map(vmar, offset, vmo, 0, size, flags, &mapped_addr);
222 if (status != NO_ERROR) { 222 if (status != MX_OK) {
223 mx_handle_close(vmo); 223 mx_handle_close(vmo);
224 LOG_ERR("mx_vmar_map(%ld, %ld, %u) failed: %s\n", offset, size, flags, 224 LOG_ERR("mx_vmar_map(%ld, %ld, %u) failed: %s\n", offset, size, flags,
225 mx_status_get_string(status)); 225 mx_status_get_string(status));
226 return false; 226 return false;
227 } 227 }
228 if (addr != mapped_addr) { 228 if (addr != mapped_addr) {
229 mx_handle_close(vmo); 229 mx_handle_close(vmo);
230 LOG_ERR("mx_vmar_map: addr != mapped_addr: %lx != %lx\n", addr, 230 LOG_ERR("mx_vmar_map: addr != mapped_addr: %lx != %lx\n", addr,
231 mapped_addr); 231 mapped_addr);
232 return false; 232 return false;
(...skipping 28 matching lines...) Expand all
261 case kReadExecute: 261 case kReadExecute:
262 prot = MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_EXECUTE; 262 prot = MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_EXECUTE;
263 break; 263 break;
264 case kReadWriteExecute: 264 case kReadWriteExecute:
265 prot = MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_WRITE | 265 prot = MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_WRITE |
266 MX_VM_FLAG_PERM_EXECUTE; 266 MX_VM_FLAG_PERM_EXECUTE;
267 break; 267 break;
268 } 268 }
269 mx_status_t status = 269 mx_status_t status =
270 mx_vmar_protect(vmar, page_address, end_address - page_address, prot); 270 mx_vmar_protect(vmar, page_address, end_address - page_address, prot);
271 if (status != NO_ERROR) { 271 if (status != MX_OK) {
272 LOG_ERR("mx_vmar_protect(%lx, %lx, %x) success: %s\n", page_address, 272 LOG_ERR("mx_vmar_protect(%lx, %lx, %x) success: %s\n", page_address,
273 end_address - page_address, prot, mx_status_get_string(status)); 273 end_address - page_address, prot, mx_status_get_string(status));
274 return false; 274 return false;
275 } 275 }
276 LOG_INFO("mx_vmar_protect(%lx, %lx, %x) success\n", page_address, 276 LOG_INFO("mx_vmar_protect(%lx, %lx, %x) success\n", page_address,
277 end_address - page_address, prot); 277 end_address - page_address, prot);
278 return true; 278 return true;
279 } 279 }
280 280
281 } // namespace dart 281 } // namespace dart
282 282
283 #endif // defined(HOST_OS_FUCHSIA) 283 #endif // defined(HOST_OS_FUCHSIA)
OLDNEW
« no previous file with comments | « runtime/vm/thread_interrupter_fuchsia.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698