| OLD | NEW |
| 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(TARGET_OS_FUCHSIA) | 6 #if defined(TARGET_OS_FUCHSIA) |
| 7 | 7 |
| 8 #include "vm/virtual_memory.h" | 8 #include "vm/virtual_memory.h" |
| 9 | 9 |
| 10 #include <magenta/syscalls.h> | 10 #include <magenta/syscalls.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { | 27 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { |
| 28 mx_handle_t vmo = MX_HANDLE_INVALID; | 28 mx_handle_t vmo = MX_HANDLE_INVALID; |
| 29 mx_status_t status = mx_vmo_create(size, 0u, &vmo); | 29 mx_status_t status = mx_vmo_create(size, 0u, &vmo); |
| 30 if (status != NO_ERROR) { | 30 if (status != NO_ERROR) { |
| 31 return NULL; | 31 return NULL; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // TODO(zra): map with PERM_NONE, when that works, and relax with | 34 // TODO(zra): map with PERM_NONE, when that works, and relax with |
| 35 // Commit and Protect when they are implemented. | 35 // Commit and Protect when they are implemented. |
| 36 // Issue MG-161. | 36 // Issue MG-161. |
| 37 const int prot = MX_VM_FLAG_PERM_READ | | 37 const int prot = |
| 38 MX_VM_FLAG_PERM_WRITE | | 38 MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_WRITE | MX_VM_FLAG_PERM_EXECUTE; |
| 39 MX_VM_FLAG_PERM_EXECUTE; | |
| 40 uintptr_t addr; | 39 uintptr_t addr; |
| 41 status = mx_process_map_vm( | 40 status = mx_process_map_vm(mx_process_self(), vmo, 0, size, &addr, prot); |
| 42 mx_process_self(), vmo, 0, size, &addr, prot); | |
| 43 if (status != NO_ERROR) { | 41 if (status != NO_ERROR) { |
| 44 mx_handle_close(vmo); | 42 mx_handle_close(vmo); |
| 45 FATAL("VirtualMemory::ReserveInternal FAILED"); | 43 FATAL("VirtualMemory::ReserveInternal FAILED"); |
| 46 return NULL; | 44 return NULL; |
| 47 } | 45 } |
| 48 | 46 |
| 49 MemoryRegion region(reinterpret_cast<void*>(addr), size); | 47 MemoryRegion region(reinterpret_cast<void*>(addr), size); |
| 50 return new VirtualMemory(region, vmo); | 48 return new VirtualMemory(region, vmo); |
| 51 } | 49 } |
| 52 | 50 |
| 53 | 51 |
| 54 VirtualMemory::~VirtualMemory() { | 52 VirtualMemory::~VirtualMemory() { |
| 55 if (!embedder_allocated()) { | 53 if (!embedder_allocated()) { |
| 56 // TODO(zra): Use reserved_size_. | 54 // TODO(zra): Use reserved_size_. |
| 57 // Issue MG-162. | 55 // Issue MG-162. |
| 58 uintptr_t addr = reinterpret_cast<uintptr_t>(address()); | 56 uintptr_t addr = reinterpret_cast<uintptr_t>(address()); |
| 59 mx_status_t status = mx_process_unmap_vm( | 57 mx_status_t status = |
| 60 mx_process_self(), addr, 0 /*reserved_size_*/); | 58 mx_process_unmap_vm(mx_process_self(), addr, 0 /*reserved_size_*/); |
| 61 if (status != NO_ERROR) { | 59 if (status != NO_ERROR) { |
| 62 FATAL("VirtualMemory::~VirtualMemory: unamp FAILED"); | 60 FATAL("VirtualMemory::~VirtualMemory: unamp FAILED"); |
| 63 } | 61 } |
| 64 | 62 |
| 65 status = mx_handle_close(handle()); | 63 status = mx_handle_close(handle()); |
| 66 if (status != NO_ERROR) { | 64 if (status != NO_ERROR) { |
| 67 FATAL("VirtualMemory::~VirtualMemory: handle_close FAILED"); | 65 FATAL("VirtualMemory::~VirtualMemory: handle_close FAILED"); |
| 68 } | 66 } |
| 69 } | 67 } |
| 70 } | 68 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 85 | 83 |
| 86 | 84 |
| 87 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { | 85 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { |
| 88 // TODO(zra): Implement when Fuchsia has an mprotect-like call. | 86 // TODO(zra): Implement when Fuchsia has an mprotect-like call. |
| 89 return true; | 87 return true; |
| 90 } | 88 } |
| 91 | 89 |
| 92 } // namespace dart | 90 } // namespace dart |
| 93 | 91 |
| 94 #endif // defined(TARGET_OS_FUCHSIA) | 92 #endif // defined(TARGET_OS_FUCHSIA) |
| OLD | NEW |