| 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 { | 16 enum Protection { |
| 17 kNoAccess, | 17 kNoAccess, |
| 18 kReadOnly, | 18 kReadOnly, |
| 19 kReadWrite, | 19 kReadWrite, |
| 20 kReadExecute, | 20 kReadExecute, |
| 21 kReadWriteExecute | 21 kReadWriteExecute |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 // The reserved memory is unmapped on destruction. | 24 // The reserved memory is unmapped on destruction. |
| 25 ~VirtualMemory(); | 25 ~VirtualMemory(); |
| 26 | 26 |
| 27 int32_t handle() const { return handle_; } |
| 27 uword start() const { return region_.start(); } | 28 uword start() const { return region_.start(); } |
| 28 uword end() const { return region_.end(); } | 29 uword end() const { return region_.end(); } |
| 29 void* address() const { return region_.pointer(); } | 30 void* address() const { return region_.pointer(); } |
| 30 intptr_t size() const { return region_.size(); } | 31 intptr_t size() const { return region_.size(); } |
| 31 | 32 |
| 32 static void InitOnce(); | 33 static void InitOnce(); |
| 33 | 34 |
| 34 bool Contains(uword addr) const { | 35 bool Contains(uword addr) const { |
| 35 return region_.Contains(addr); | 36 return region_.Contains(addr); |
| 36 } | 37 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 private: | 77 private: |
| 77 static VirtualMemory* ReserveInternal(intptr_t size); | 78 static VirtualMemory* ReserveInternal(intptr_t size); |
| 78 | 79 |
| 79 // Free a sub segment. On operating systems that support it this | 80 // Free a sub segment. On operating systems that support it this |
| 80 // can give back the virtual memory to the system. Returns true on success. | 81 // can give back the virtual memory to the system. Returns true on success. |
| 81 static bool FreeSubSegment(void* address, intptr_t size); | 82 static bool FreeSubSegment(void* address, intptr_t size); |
| 82 | 83 |
| 83 // This constructor is only used internally when reserving new virtual spaces. | 84 // This constructor is only used internally when reserving new virtual spaces. |
| 84 // It does not reserve any virtual address space on its own. | 85 // It does not reserve any virtual address space on its own. |
| 85 explicit VirtualMemory(const MemoryRegion& region) : | 86 explicit VirtualMemory(const MemoryRegion& region, int32_t handle = 0) : |
| 86 region_(region.pointer(), region.size()), | 87 region_(region.pointer(), region.size()), |
| 87 reserved_size_(region.size()), | 88 reserved_size_(region.size()), |
| 89 handle_(handle), |
| 88 embedder_allocated_(false) { } | 90 embedder_allocated_(false) { } |
| 89 | 91 |
| 90 MemoryRegion region_; | 92 MemoryRegion region_; |
| 91 | 93 |
| 92 // The size of the underlying reservation not yet given back to the OS. | 94 // The size of the underlying reservation not yet given back to the OS. |
| 93 // Its start coincides with region_, but its size might not, due to Truncate. | 95 // Its start coincides with region_, but its size might not, due to Truncate. |
| 94 intptr_t reserved_size_; | 96 intptr_t reserved_size_; |
| 95 | 97 |
| 98 int32_t handle_; |
| 99 |
| 96 static uword page_size_; | 100 static uword page_size_; |
| 97 | 101 |
| 98 // True for a region provided by the embedder. | 102 // True for a region provided by the embedder. |
| 99 bool embedder_allocated_; | 103 bool embedder_allocated_; |
| 100 | 104 |
| 101 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); | 105 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); |
| 102 }; | 106 }; |
| 103 | 107 |
| 104 } // namespace dart | 108 } // namespace dart |
| 105 | 109 |
| 106 #endif // VM_VIRTUAL_MEMORY_H_ | 110 #endif // VM_VIRTUAL_MEMORY_H_ |
| OLD | NEW |