| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 WritableInstructionsScope::~WritableInstructionsScope() { | 28 WritableInstructionsScope::~WritableInstructionsScope() { |
| 29 if (FLAG_write_protect_code) { | 29 if (FLAG_write_protect_code) { |
| 30 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address_), | 30 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address_), |
| 31 size_, | 31 size_, |
| 32 VirtualMemory::kReadExecute); | 32 VirtualMemory::kReadExecute); |
| 33 ASSERT(status); | 33 ASSERT(status); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 | |
| 38 // The patch code buffer contains the jmp code which will be inserted at | |
| 39 // entry point. | |
| 40 void CodePatcher::PatchEntry(const Code& code, const Code& new_code) { | |
| 41 ASSERT(code.instructions() == code.active_instructions()); | |
| 42 code.set_active_instructions(new_code.instructions()); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 // The entry point is a jmp instruction, the patch code buffer contains | |
| 47 // original code, the entry point contains the jump instruction. | |
| 48 void CodePatcher::RestoreEntry(const Code& code) { | |
| 49 if (!IsEntryPatched(code)) return; | |
| 50 ASSERT(code.instructions() != code.active_instructions()); | |
| 51 code.set_active_instructions(code.instructions()); | |
| 52 } | |
| 53 | |
| 54 | |
| 55 bool CodePatcher::IsEntryPatched(const Code& code) { | |
| 56 return code.instructions() != code.active_instructions(); | |
| 57 } | |
| 58 | |
| 59 } // namespace dart | 37 } // namespace dart |
| OLD | NEW |