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 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "vm/virtual_memory.h" | 8 #include "vm/virtual_memory.h" |
9 | 9 |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| 11 #include "vm/os.h" |
11 | 12 |
12 namespace dart { | 13 namespace dart { |
13 | 14 |
14 uword VirtualMemory::page_size_ = 0; | 15 uword VirtualMemory::page_size_ = 0; |
15 | 16 |
16 | 17 |
17 void VirtualMemory::InitOnce() { | 18 void VirtualMemory::InitOnce() { |
18 SYSTEM_INFO info; | 19 SYSTEM_INFO info; |
19 GetSystemInfo(&info); | 20 GetSystemInfo(&info); |
20 page_size_ = info.dwPageSize; | 21 page_size_ = info.dwPageSize; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ASSERT(Contains(addr)); | 57 ASSERT(Contains(addr)); |
57 ASSERT(Contains(addr + size) || (addr + size == end())); | 58 ASSERT(Contains(addr + size) || (addr + size == end())); |
58 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 59 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
59 if (VirtualAlloc(address(), size, MEM_COMMIT, prot) == NULL) { | 60 if (VirtualAlloc(address(), size, MEM_COMMIT, prot) == NULL) { |
60 return false; | 61 return false; |
61 } | 62 } |
62 return true; | 63 return true; |
63 } | 64 } |
64 | 65 |
65 | 66 |
66 bool VirtualMemory::Protect(Protection mode) { | 67 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { |
| 68 uword start_address = reinterpret_cast<uword>(address); |
| 69 uword end_address = start_address + size; |
| 70 uword page_address = Utils::RoundDown(start_address, PageSize()); |
67 DWORD prot = 0; | 71 DWORD prot = 0; |
68 switch (mode) { | 72 switch (mode) { |
69 case kNoAccess: | 73 case kNoAccess: |
70 prot = PAGE_NOACCESS; | 74 prot = PAGE_NOACCESS; |
71 break; | 75 break; |
72 case kReadOnly: | 76 case kReadOnly: |
73 prot = PAGE_READONLY; | 77 prot = PAGE_READONLY; |
74 break; | 78 break; |
75 case kReadWrite: | 79 case kReadWrite: |
76 prot = PAGE_READWRITE; | 80 prot = PAGE_READWRITE; |
77 break; | 81 break; |
78 case kReadExecute: | 82 case kReadExecute: |
79 prot = PAGE_EXECUTE_READ; | 83 prot = PAGE_EXECUTE_READ; |
80 break; | 84 break; |
81 case kReadWriteExecute: | |
82 prot = PAGE_EXECUTE_READWRITE; | |
83 break; | |
84 } | 85 } |
85 DWORD old_prot = 0; | 86 DWORD old_prot = 0; |
86 return VirtualProtect(address(), size(), prot, &old_prot); | 87 bool result = VirtualProtect(reinterpret_cast<void*>(page_address), |
| 88 end_address - page_address, |
| 89 prot, |
| 90 &old_prot); |
| 91 return result; |
87 } | 92 } |
88 | 93 |
89 } // namespace dart | 94 } // namespace dart |
90 | 95 |
91 #endif // defined(TARGET_OS_WINDOWS) | 96 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |