Index: runtime/vm/virtual_memory_fuchsia.cc |
diff --git a/runtime/vm/virtual_memory_fuchsia.cc b/runtime/vm/virtual_memory_fuchsia.cc |
index da32045f4c799618b4e75fe8f858cf12f28d1025..e694dca0e0e9710f064b2b499b0010bcea8b22a7 100644 |
--- a/runtime/vm/virtual_memory_fuchsia.cc |
+++ b/runtime/vm/virtual_memory_fuchsia.cc |
@@ -7,9 +7,11 @@ |
#include "vm/virtual_memory.h" |
+#include <magenta/syscalls.h> |
#include <unistd.h> // NOLINT |
#include "platform/assert.h" |
+#include "vm/memory_region.h" |
#include "vm/os.h" |
namespace dart { |
@@ -23,13 +25,45 @@ void VirtualMemory::InitOnce() { |
VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { |
- UNIMPLEMENTED(); |
- return NULL; |
+ mx_handle_t vmo = _magenta_vm_object_create(size); |
+ if (vmo <= 0) { |
+ return NULL; |
+ } |
+ |
+ // TODO(zra): map with PERM_NONE, when that works, and relax with |
+ // Commit and Protect when they are implemented. |
+ // Issue MG-161. |
+ const int prot = MX_VM_FLAG_PERM_READ | |
+ MX_VM_FLAG_PERM_WRITE | |
+ MX_VM_FLAG_PERM_EXECUTE; |
+ uintptr_t addr; |
+ mx_status_t status = _magenta_process_vm_map(0, vmo, 0, size, &addr, prot); |
+ if (status != NO_ERROR) { |
+ _magenta_handle_close(vmo); |
+ FATAL("VirtualMemory::ReserveInternal FAILED"); |
+ return NULL; |
+ } |
+ |
+ MemoryRegion region(reinterpret_cast<void*>(addr), size); |
+ return new VirtualMemory(region, vmo); |
} |
VirtualMemory::~VirtualMemory() { |
- UNIMPLEMENTED(); |
+ if (!embedder_allocated()) { |
+ // TODO(zra): Use reserved_size_. |
+ // Issue MG-162. |
+ mx_status_t status = _magenta_process_vm_unmap( |
+ 0, reinterpret_cast<uintptr_t>(address()), 0 /*reserved_size_*/); |
+ if (status != NO_ERROR) { |
+ FATAL("VirtualMemory::~VirtualMemory: unamp FAILED"); |
+ } |
+ |
+ status = _magenta_handle_close(handle()); |
+ if (status != NO_ERROR) { |
+ FATAL("VirtualMemory::~VirtualMemory: handle_close FAILED"); |
+ } |
+ } |
} |
@@ -40,14 +74,15 @@ bool VirtualMemory::FreeSubSegment(void* address, intptr_t size) { |
bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) { |
- UNIMPLEMENTED(); |
- return false; |
+ // TODO(zra): Implement when the protections for a mapping can be changed. |
+ // Issue MG-133. |
+ return true; |
} |
bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { |
- UNIMPLEMENTED(); |
- return false; |
+ // TODO(zra): Implement when Fuchsia has an mprotect-like call. |
+ return true; |
} |
} // namespace dart |