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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/virtual_memory.h ('k') | tools/fuchsia_link.py » ('j') | 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(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 <unistd.h> // NOLINT 11 #include <unistd.h> // NOLINT
11 12
12 #include "platform/assert.h" 13 #include "platform/assert.h"
14 #include "vm/memory_region.h"
13 #include "vm/os.h" 15 #include "vm/os.h"
14 16
15 namespace dart { 17 namespace dart {
16 18
17 uword VirtualMemory::page_size_ = 0; 19 uword VirtualMemory::page_size_ = 0;
18 20
19 21
20 void VirtualMemory::InitOnce() { 22 void VirtualMemory::InitOnce() {
21 page_size_ = getpagesize(); 23 page_size_ = getpagesize();
22 } 24 }
23 25
24 26
25 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { 27 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) {
26 UNIMPLEMENTED(); 28 mx_handle_t vmo = _magenta_vm_object_create(size);
27 return NULL; 29 if (vmo <= 0) {
30 return NULL;
31 }
32
33 // TODO(zra): map with PERM_NONE, when that works, and relax with
34 // Commit and Protect when they are implemented.
35 // Issue MG-161.
36 const int prot = MX_VM_FLAG_PERM_READ |
37 MX_VM_FLAG_PERM_WRITE |
38 MX_VM_FLAG_PERM_EXECUTE;
39 uintptr_t addr;
40 mx_status_t status = _magenta_process_vm_map(0, vmo, 0, size, &addr, prot);
41 if (status != NO_ERROR) {
42 _magenta_handle_close(vmo);
43 FATAL("VirtualMemory::ReserveInternal FAILED");
44 return NULL;
45 }
46
47 MemoryRegion region(reinterpret_cast<void*>(addr), size);
48 return new VirtualMemory(region, vmo);
28 } 49 }
29 50
30 51
31 VirtualMemory::~VirtualMemory() { 52 VirtualMemory::~VirtualMemory() {
32 UNIMPLEMENTED(); 53 if (!embedder_allocated()) {
54 // TODO(zra): Use reserved_size_.
55 // Issue MG-162.
56 mx_status_t status = _magenta_process_vm_unmap(
57 0, reinterpret_cast<uintptr_t>(address()), 0 /*reserved_size_*/);
58 if (status != NO_ERROR) {
59 FATAL("VirtualMemory::~VirtualMemory: unamp FAILED");
60 }
61
62 status = _magenta_handle_close(handle());
63 if (status != NO_ERROR) {
64 FATAL("VirtualMemory::~VirtualMemory: handle_close FAILED");
65 }
66 }
33 } 67 }
34 68
35 69
36 bool VirtualMemory::FreeSubSegment(void* address, intptr_t size) { 70 bool VirtualMemory::FreeSubSegment(void* address, intptr_t size) {
37 UNIMPLEMENTED(); 71 UNIMPLEMENTED();
38 return false; 72 return false;
39 } 73 }
40 74
41 75
42 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) { 76 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) {
43 UNIMPLEMENTED(); 77 // TODO(zra): Implement when the protections for a mapping can be changed.
44 return false; 78 // Issue MG-133.
79 return true;
45 } 80 }
46 81
47 82
48 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { 83 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
49 UNIMPLEMENTED(); 84 // TODO(zra): Implement when Fuchsia has an mprotect-like call.
50 return false; 85 return true;
51 } 86 }
52 87
53 } // namespace dart 88 } // namespace dart
54 89
55 #endif // defined(TARGET_OS_FUCHSIA) 90 #endif // defined(TARGET_OS_FUCHSIA)
OLDNEW
« 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