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

Unified Diff: runtime/vm/virtual_memory_fuchsia.cc

Issue 2148533002: Fuchsia: Platform specific calls needed to Initialize and Cleanup VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/virtual_memory.h ('k') | tools/fuchsia_link.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « runtime/vm/virtual_memory.h ('k') | tools/fuchsia_link.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698