| 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/code_patcher.h" | 5 #include "vm/code_patcher.h" |
| 6 #include "vm/cpu.h" | 6 #include "vm/cpu.h" |
| 7 #include "vm/instructions.h" | 7 #include "vm/instructions.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/virtual_memory.h" | 9 #include "vm/virtual_memory.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DEFINE_FLAG(bool, write_protect_code, true, "Write protect jitted code"); | 13 DEFINE_FLAG(bool, write_protect_code, true, "Write protect jitted code"); |
| 14 | 14 |
| 15 | 15 |
| 16 WritableInstructionsScope::WritableInstructionsScope(uword address, | 16 WritableInstructionsScope::WritableInstructionsScope(uword address, |
| 17 intptr_t size) | 17 intptr_t size) |
| 18 : address_(address), size_(size) { | 18 : address_(address), size_(size) { |
| 19 if (FLAG_write_protect_code) { | 19 if (FLAG_write_protect_code) { |
| 20 bool status = | 20 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), |
| 21 VirtualMemory::Protect(reinterpret_cast<void*>(address), | 21 size, |
| 22 size, | 22 VirtualMemory::kReadWrite); |
| 23 VirtualMemory::kReadWrite); | |
| 24 ASSERT(status); | 23 ASSERT(status); |
| 25 } | 24 } |
| 26 } | 25 } |
| 27 | 26 |
| 28 | 27 |
| 29 WritableInstructionsScope::~WritableInstructionsScope() { | 28 WritableInstructionsScope::~WritableInstructionsScope() { |
| 30 if (FLAG_write_protect_code) { | 29 if (FLAG_write_protect_code) { |
| 31 bool status = | 30 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address_), |
| 32 VirtualMemory::Protect(reinterpret_cast<void*>(address_), | 31 size_, |
| 33 size_, | 32 VirtualMemory::kReadExecute); |
| 34 VirtualMemory::kReadExecute); | |
| 35 ASSERT(status); | 33 ASSERT(status); |
| 36 } | 34 } |
| 37 } | 35 } |
| 38 | 36 |
| 39 | 37 |
| 40 static void SwapCode(intptr_t num_bytes, char* code, char* buffer) { | 38 static void SwapCode(intptr_t num_bytes, char* code, char* buffer) { |
| 41 uword code_address = reinterpret_cast<uword>(code); | 39 uword code_address = reinterpret_cast<uword>(code); |
| 42 for (intptr_t i = 0; i < num_bytes; i++) { | 40 for (intptr_t i = 0; i < num_bytes; i++) { |
| 43 char tmp = *code; | 41 char tmp = *code; |
| 44 *code = *buffer; | 42 *code = *buffer; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 const uword obj_start = code.GetPointerOffsetAt(i) + code.EntryPoint(); | 129 const uword obj_start = code.GetPointerOffsetAt(i) + code.EntryPoint(); |
| 132 const uword obj_end = obj_start + kWordSize; | 130 const uword obj_end = obj_start + kWordSize; |
| 133 if ((obj_start < limit) && (obj_end > patch_addr)) { | 131 if ((obj_start < limit) && (obj_end > patch_addr)) { |
| 134 return false; | 132 return false; |
| 135 } | 133 } |
| 136 } | 134 } |
| 137 return true; | 135 return true; |
| 138 } | 136 } |
| 139 | 137 |
| 140 } // namespace dart | 138 } // namespace dart |
| OLD | NEW |