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" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ASSERT(Contains(addr)); | 56 ASSERT(Contains(addr)); |
57 ASSERT(Contains(addr + size) || (addr + size == end())); | 57 ASSERT(Contains(addr + size) || (addr + size == end())); |
58 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 58 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
59 if (VirtualAlloc(address(), size, MEM_COMMIT, prot) == NULL) { | 59 if (VirtualAlloc(address(), size, MEM_COMMIT, prot) == NULL) { |
60 return false; | 60 return false; |
61 } | 61 } |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 | 65 |
66 bool VirtualMemory::Protect(Protection mode) { | 66 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { |
| 67 uword start_address = reinterpret_cast<uword>(address); |
| 68 uword end_address = start_address + size; |
| 69 uword page_address = start_address & ~(PageSize() - 1); |
67 DWORD prot = 0; | 70 DWORD prot = 0; |
68 switch (mode) { | 71 switch (mode) { |
69 case kNoAccess: | 72 case kNoAccess: |
70 prot = PAGE_NOACCESS; | 73 prot = PAGE_NOACCESS; |
71 break; | 74 break; |
72 case kReadOnly: | 75 case kReadOnly: |
73 prot = PAGE_READONLY; | 76 prot = PAGE_READONLY; |
74 break; | 77 break; |
75 case kReadWrite: | 78 case kReadWrite: |
76 prot = PAGE_READWRITE; | 79 prot = PAGE_READWRITE; |
77 break; | 80 break; |
78 case kReadExecute: | 81 case kReadExecute: |
79 prot = PAGE_EXECUTE_READ; | 82 prot = PAGE_EXECUTE_READ; |
80 break; | 83 break; |
81 case kReadWriteExecute: | 84 case kReadWriteExecute: |
82 prot = PAGE_EXECUTE_READWRITE; | 85 prot = PAGE_EXECUTE_READWRITE; |
83 break; | 86 break; |
84 } | 87 } |
85 DWORD old_prot = 0; | 88 DWORD old_prot = 0; |
86 return VirtualProtect(address(), size(), prot, &old_prot); | 89 return VirtualProtect(reinterpret_cast<void*>(address), |
| 90 end_address - page_address, |
| 91 prot, |
| 92 &old_prot); |
87 } | 93 } |
88 | 94 |
89 } // namespace dart | 95 } // namespace dart |
90 | 96 |
91 #endif // defined(TARGET_OS_WINDOWS) | 97 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |