| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "vm/virtual_memory.h" | 8 #include "vm/virtual_memory.h" |
| 9 | 9 |
| 10 #include <sys/mman.h> // NOLINT | 10 #include <sys/mman.h> // NOLINT |
| 11 #include <unistd.h> // NOLINT | 11 #include <unistd.h> // NOLINT |
| 12 | 12 |
| 13 #include "platform/assert.h" | 13 #include "platform/assert.h" |
| 14 #include "platform/utils.h" | 14 #include "platform/utils.h" |
| 15 | 15 |
| 16 #include "vm/isolate.h" |
| 17 |
| 16 namespace dart { | 18 namespace dart { |
| 17 | 19 |
| 18 // standard MAP_FAILED causes "error: use of old-style cast" as it | 20 // standard MAP_FAILED causes "error: use of old-style cast" as it |
| 19 // defines MAP_FAILED as ((void *) -1) | 21 // defines MAP_FAILED as ((void *) -1) |
| 20 #undef MAP_FAILED | 22 #undef MAP_FAILED |
| 21 #define MAP_FAILED reinterpret_cast<void*>(-1) | 23 #define MAP_FAILED reinterpret_cast<void*>(-1) |
| 22 | 24 |
| 23 uword VirtualMemory::page_size_ = 0; | 25 uword VirtualMemory::page_size_ = 0; |
| 24 | 26 |
| 25 | 27 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 MAP_PRIVATE | MAP_ANON | MAP_FIXED, | 75 MAP_PRIVATE | MAP_ANON | MAP_FIXED, |
| 74 -1, 0); | 76 -1, 0); |
| 75 if (address == MAP_FAILED) { | 77 if (address == MAP_FAILED) { |
| 76 return false; | 78 return false; |
| 77 } | 79 } |
| 78 return true; | 80 return true; |
| 79 } | 81 } |
| 80 | 82 |
| 81 | 83 |
| 82 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { | 84 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { |
| 85 ASSERT(Thread::Current()->IsMutatorThread() || |
| 86 Isolate::Current()->mutator_thread()->IsAtSafepoint()); |
| 83 uword start_address = reinterpret_cast<uword>(address); | 87 uword start_address = reinterpret_cast<uword>(address); |
| 84 uword end_address = start_address + size; | 88 uword end_address = start_address + size; |
| 85 uword page_address = Utils::RoundDown(start_address, PageSize()); | 89 uword page_address = Utils::RoundDown(start_address, PageSize()); |
| 86 int prot = 0; | 90 int prot = 0; |
| 87 switch (mode) { | 91 switch (mode) { |
| 88 case kNoAccess: | 92 case kNoAccess: |
| 89 prot = PROT_NONE; | 93 prot = PROT_NONE; |
| 90 break; | 94 break; |
| 91 case kReadOnly: | 95 case kReadOnly: |
| 92 prot = PROT_READ; | 96 prot = PROT_READ; |
| 93 break; | 97 break; |
| 94 case kReadWrite: | 98 case kReadWrite: |
| 95 prot = PROT_READ | PROT_WRITE; | 99 prot = PROT_READ | PROT_WRITE; |
| 96 break; | 100 break; |
| 97 case kReadExecute: | 101 case kReadExecute: |
| 98 prot = PROT_READ | PROT_EXEC; | 102 prot = PROT_READ | PROT_EXEC; |
| 99 break; | 103 break; |
| 100 case kReadWriteExecute: | 104 case kReadWriteExecute: |
| 101 prot = PROT_READ | PROT_WRITE | PROT_EXEC; | 105 prot = PROT_READ | PROT_WRITE | PROT_EXEC; |
| 102 break; | 106 break; |
| 103 } | 107 } |
| 104 return (mprotect(reinterpret_cast<void*>(page_address), | 108 return (mprotect(reinterpret_cast<void*>(page_address), |
| 105 end_address - page_address, | 109 end_address - page_address, |
| 106 prot) == 0); | 110 prot) == 0); |
| 107 } | 111 } |
| 108 | 112 |
| 109 } // namespace dart | 113 } // namespace dart |
| 110 | 114 |
| 111 #endif // defined(TARGET_OS_ANDROID) | 115 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |