| 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/virtual_memory.h" | 5 #include "vm/virtual_memory.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) { | 52 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) { |
| 53 ASSERT(Contains(addr)); | 53 ASSERT(Contains(addr)); |
| 54 ASSERT(Contains(addr + size) || (addr + size == end())); | 54 ASSERT(Contains(addr + size) || (addr + size == end())); |
| 55 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 55 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| 56 if (VirtualAlloc(address(), size, MEM_COMMIT, prot) == NULL) { | 56 if (VirtualAlloc(address(), size, MEM_COMMIT, prot) == NULL) { |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 return true; | 59 return true; |
| 60 } | 60 } |
| 61 | 61 |
| 62 |
| 63 bool VirtualMemory::Protect(Protection mode) { |
| 64 int prot = 0; |
| 65 switch (mode) { |
| 66 case kNoAccess: |
| 67 prot = PAGE_NOACCESS; |
| 68 break; |
| 69 case kReadOnly: |
| 70 prot = PAGE_READONLY; |
| 71 break; |
| 72 case kReadWrite: |
| 73 prot = PAGE_READWRITE; |
| 74 break; |
| 75 case kReadExecute: |
| 76 prot = PAGE_EXECUTE_READ; |
| 77 break; |
| 78 case kReadWriteExecute: |
| 79 prot = PAGE_EXECUTE_READWRITE; |
| 80 break; |
| 81 } |
| 82 int old_prot = 0; |
| 83 return VirtualProtect(address(), size(), prot, &old_prot); |
| 84 } |
| 85 |
| 62 } // namespace dart | 86 } // namespace dart |
| OLD | NEW |