OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #ifndef VM_VIRTUAL_MEMORY_H_ | 5 #ifndef VM_VIRTUAL_MEMORY_H_ |
6 #define VM_VIRTUAL_MEMORY_H_ | 6 #define VM_VIRTUAL_MEMORY_H_ |
7 | 7 |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/memory_region.h" | 10 #include "vm/memory_region.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 class VirtualMemory { | 14 class VirtualMemory { |
15 public: | 15 public: |
| 16 enum Protection { |
| 17 kNoAccess, |
| 18 kReadOnly, |
| 19 kReadWrite, |
| 20 kReadExecute, |
| 21 kReadWriteExecute |
| 22 }; |
| 23 |
16 // The reserved memory is unmapped on destruction. | 24 // The reserved memory is unmapped on destruction. |
17 ~VirtualMemory(); | 25 ~VirtualMemory(); |
18 | 26 |
19 uword start() const { return region_.start(); } | 27 uword start() const { return region_.start(); } |
20 uword end() const { return region_.end(); } | 28 uword end() const { return region_.end(); } |
21 void* address() const { return region_.pointer(); } | 29 void* address() const { return region_.pointer(); } |
22 intptr_t size() const { return region_.size(); } | 30 intptr_t size() const { return region_.size(); } |
23 | 31 |
24 static void InitOnce(); | 32 static void InitOnce(); |
25 | 33 |
26 bool Contains(uword addr) const { | 34 bool Contains(uword addr) const { |
27 return region_.Contains(addr); | 35 return region_.Contains(addr); |
28 } | 36 } |
29 | 37 |
30 // Commits the virtual memory area. | 38 // Commits the virtual memory area. |
31 bool Commit(bool is_executable) { | 39 bool Commit(bool is_executable) { |
32 return Commit(start(), size(), is_executable); | 40 return Commit(start(), size(), is_executable); |
33 } | 41 } |
34 | 42 |
| 43 // Changes the protection of the virtual memory area. |
| 44 bool Protect(Protection mode); |
| 45 |
35 // Reserves a virtual memory segment with size. If a segment of the requested | 46 // Reserves a virtual memory segment with size. If a segment of the requested |
36 // size cannot be allocated NULL is returned. | 47 // size cannot be allocated NULL is returned. |
37 static VirtualMemory* Reserve(intptr_t size); | 48 static VirtualMemory* Reserve(intptr_t size); |
38 | 49 |
39 // Reserves a virtual memory segment with the start address being aligned to | 50 // Reserves a virtual memory segment with the start address being aligned to |
40 // the requested power of two. | 51 // the requested power of two. |
41 static VirtualMemory* ReserveAligned(intptr_t size, intptr_t alignment); | 52 static VirtualMemory* ReserveAligned(intptr_t size, intptr_t alignment); |
42 | 53 |
43 static intptr_t PageSize() { | 54 static intptr_t PageSize() { |
44 ASSERT(page_size_ != 0); | 55 ASSERT(page_size_ != 0); |
(...skipping 29 matching lines...) Expand all Loading... |
74 void* reserved_pointer_; | 85 void* reserved_pointer_; |
75 | 86 |
76 static uword page_size_; | 87 static uword page_size_; |
77 | 88 |
78 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); | 89 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); |
79 }; | 90 }; |
80 | 91 |
81 } // namespace dart | 92 } // namespace dart |
82 | 93 |
83 #endif // VM_VIRTUAL_MEMORY_H_ | 94 #endif // VM_VIRTUAL_MEMORY_H_ |
OLD | NEW |