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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (VirtualAlloc(reinterpret_cast<void*>(addr), size, MEM_COMMIT, prot) == | 59 if (VirtualAlloc(reinterpret_cast<void*>(addr), size, MEM_COMMIT, prot) == |
60 NULL) { | 60 NULL) { |
61 return false; | 61 return false; |
62 } | 62 } |
63 return true; | 63 return true; |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { | 67 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { |
68 ASSERT(Thread::Current()->IsMutatorThread() || | 68 ASSERT(Thread::Current()->IsMutatorThread() || |
69 !Isolate::Current()->HasMutatorThread() || | |
70 Isolate::Current()->mutator_thread()->IsAtSafepoint()); | 69 Isolate::Current()->mutator_thread()->IsAtSafepoint()); |
71 uword start_address = reinterpret_cast<uword>(address); | 70 uword start_address = reinterpret_cast<uword>(address); |
72 uword end_address = start_address + size; | 71 uword end_address = start_address + size; |
73 uword page_address = Utils::RoundDown(start_address, PageSize()); | 72 uword page_address = Utils::RoundDown(start_address, PageSize()); |
74 DWORD prot = 0; | 73 DWORD prot = 0; |
75 switch (mode) { | 74 switch (mode) { |
76 case kNoAccess: | 75 case kNoAccess: |
77 prot = PAGE_NOACCESS; | 76 prot = PAGE_NOACCESS; |
78 break; | 77 break; |
79 case kReadOnly: | 78 case kReadOnly: |
(...skipping 13 matching lines...) Expand all Loading... |
93 bool result = VirtualProtect(reinterpret_cast<void*>(page_address), | 92 bool result = VirtualProtect(reinterpret_cast<void*>(page_address), |
94 end_address - page_address, | 93 end_address - page_address, |
95 prot, | 94 prot, |
96 &old_prot); | 95 &old_prot); |
97 return result; | 96 return result; |
98 } | 97 } |
99 | 98 |
100 } // namespace dart | 99 } // namespace dart |
101 | 100 |
102 #endif // defined(TARGET_OS_WINDOWS) | 101 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |