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

Side by Side Diff: runtime/vm/virtual_memory.h

Issue 136563002: Landing: Write protect executable pages in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/pages.cc ('k') | runtime/vm/virtual_memory.cc » ('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) 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 // Read-write-execute is not available because it is never used.
16 enum Protection { 17 enum Protection {
17 kNoAccess, 18 kNoAccess,
18 kReadOnly, 19 kReadOnly,
19 kReadWrite, 20 kReadWrite,
20 kReadExecute, 21 kReadExecute,
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 uword start() const { return region_.start(); } 27 uword start() const { return region_.start(); }
28 uword end() const { return region_.end(); } 28 uword end() const { return region_.end(); }
29 void* address() const { return region_.pointer(); } 29 void* address() const { return region_.pointer(); }
30 intptr_t size() const { return region_.size(); } 30 intptr_t size() const { return region_.size(); }
31 31
32 static void InitOnce(); 32 static void InitOnce();
33 33
34 bool Contains(uword addr) const { 34 bool Contains(uword addr) const {
35 return region_.Contains(addr); 35 return region_.Contains(addr);
36 } 36 }
37 37
38 // Commits the virtual memory area. 38 // Commits the virtual memory area.
39 bool Commit(bool is_executable) { 39 bool Commit(bool is_executable) {
40 return Commit(start(), size(), is_executable); 40 return Commit(start(), size(), is_executable);
41 } 41 }
42 42
43 // Changes the protection of the virtual memory area. 43 // Changes the protection of the virtual memory area.
44 bool Protect(Protection mode); 44 static bool Protect(void* address, intptr_t size, Protection mode);
45 bool Protect(Protection mode) {
46 return Protect(address(), size(), mode);
47 }
45 48
46 // Reserves a virtual memory segment with size. If a segment of the requested 49 // Reserves a virtual memory segment with size. If a segment of the requested
47 // size cannot be allocated NULL is returned. 50 // size cannot be allocated NULL is returned.
48 static VirtualMemory* Reserve(intptr_t size); 51 static VirtualMemory* Reserve(intptr_t size);
49 52
50 // Reserves a virtual memory segment with the start address being aligned to 53 // Reserves a virtual memory segment with the start address being aligned to
51 // the requested power of two. 54 // the requested power of two.
52 static VirtualMemory* ReserveAligned(intptr_t size, intptr_t alignment); 55 static VirtualMemory* ReserveAligned(intptr_t size, intptr_t alignment);
53 56
54 static intptr_t PageSize() { 57 static intptr_t PageSize() {
55 ASSERT(page_size_ != 0); 58 ASSERT(page_size_ != 0);
56 ASSERT(Utils::IsPowerOfTwo(page_size_)); 59 ASSERT(Utils::IsPowerOfTwo(page_size_));
57 return page_size_; 60 return page_size_;
58 } 61 }
59 62
63 static bool InSamePage(uword address0, uword address1);
64
60 private: 65 private:
61 // Truncate this virtual memory segment. 66 // Truncate this virtual memory segment.
62 void Truncate(uword new_start, intptr_t size); 67 void Truncate(uword new_start, intptr_t size);
63 68
64 // Free a sub segment. On operating systems that support it this 69 // Free a sub segment. On operating systems that support it this
65 // can give back the virtual memory to the system. 70 // can give back the virtual memory to the system.
66 void FreeSubSegment(void* address, intptr_t size); 71 void FreeSubSegment(void* address, intptr_t size);
67 72
68 // This constructor is only used internally when reserving new virtual spaces. 73 // This constructor is only used internally when reserving new virtual spaces.
69 // It does not reserve any virtual address space on its own. 74 // It does not reserve any virtual address space on its own.
(...skipping 15 matching lines...) Expand all
85 void* reserved_pointer_; 90 void* reserved_pointer_;
86 91
87 static uword page_size_; 92 static uword page_size_;
88 93
89 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory); 94 DISALLOW_IMPLICIT_CONSTRUCTORS(VirtualMemory);
90 }; 95 };
91 96
92 } // namespace dart 97 } // namespace dart
93 98
94 #endif // VM_VIRTUAL_MEMORY_H_ 99 #endif // VM_VIRTUAL_MEMORY_H_
OLDNEW
« no previous file with comments | « runtime/vm/pages.cc ('k') | runtime/vm/virtual_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698