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