| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" // Needed here to get TARGET_ARCH_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| 11 #include "vm/ic_data.h" | 11 #include "vm/ic_data.h" |
| 12 #include "vm/instructions.h" | 12 #include "vm/instructions.h" |
| 13 #include "vm/object.h" | 13 #include "vm/object.h" |
| 14 #include "vm/raw_object.h" | 14 #include "vm/raw_object.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 // The pattern of a Dart call is: | 18 // The pattern of a Dart call is: |
| 19 // 1: mov ECX, immediate 1 | 19 // 1: mov ECX, immediate 1 |
| 20 // 2: mov EDX, immediate 2 | 20 // 2: mov EDX, immediate 2 |
| 21 // 3: call target_address | 21 // 3: call target_address |
| 22 // <- return_address | 22 // <- return_address |
| 23 class DartCallPattern : public ValueObject { | 23 class DartCallPattern : public ValueObject { |
| 24 public: | 24 public: |
| 25 explicit DartCallPattern(uword return_address) | 25 explicit DartCallPattern(uword return_address) |
| 26 : start_(return_address - (kNumInstructions * kInstructionSize)) { | 26 : start_(return_address - (kNumInstructions * kInstructionSize)) { |
| 27 ASSERT(*reinterpret_cast<uint8_t*>(start_) == 0xB9); | 27 ASSERT(IsValid(return_address)); |
| 28 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 1 * kInstructionSize) == 0xBA); | |
| 29 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 2 * kInstructionSize) == 0xE8); | |
| 30 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); | 28 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); |
| 31 } | 29 } |
| 32 | 30 |
| 31 static bool IsValid(uword return_address) { |
| 32 uint8_t* code_bytes = |
| 33 reinterpret_cast<uint8_t*>( |
| 34 return_address - (kNumInstructions * kInstructionSize)); |
| 35 return (code_bytes[0] == 0xB9) && |
| 36 (code_bytes[kInstructionSize] == 0xBA) && |
| 37 (code_bytes[2 * kInstructionSize] == 0xE8); |
| 38 } |
| 39 |
| 33 uword target() const { | 40 uword target() const { |
| 34 const uword offset = *reinterpret_cast<uword*>(call_address() + 1); | 41 const uword offset = *reinterpret_cast<uword*>(call_address() + 1); |
| 35 return return_address() + offset; | 42 return return_address() + offset; |
| 36 } | 43 } |
| 37 | 44 |
| 38 void set_target(uword target) const { | 45 void set_target(uword target) const { |
| 39 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); | 46 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); |
| 40 uword offset = target - return_address(); | 47 uword offset = target - return_address(); |
| 41 *target_addr = offset; | 48 *target_addr = offset; |
| 42 CPU::FlushICache(call_address(), kInstructionSize); | 49 CPU::FlushICache(call_address(), kInstructionSize); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) { | 217 for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) { |
| 211 const uword addr = code.GetPointerOffsetAt(i) + code.EntryPoint(); | 218 const uword addr = code.GetPointerOffsetAt(i) + code.EntryPoint(); |
| 212 if (addr < limit) { | 219 if (addr < limit) { |
| 213 return false; | 220 return false; |
| 214 } | 221 } |
| 215 } | 222 } |
| 216 return true; | 223 return true; |
| 217 } | 224 } |
| 218 | 225 |
| 219 | 226 |
| 227 bool CodePatcher::IsDartCall(uword return_address) { |
| 228 return DartCallPattern::IsValid(return_address); |
| 229 } |
| 230 |
| 231 |
| 220 void CodePatcher::GetInstanceCallAt(uword return_address, | 232 void CodePatcher::GetInstanceCallAt(uword return_address, |
| 221 String* function_name, | 233 String* function_name, |
| 222 int* num_arguments, | 234 int* num_arguments, |
| 223 int* num_named_arguments, | 235 int* num_named_arguments, |
| 224 uword* target) { | 236 uword* target) { |
| 225 ASSERT(function_name != NULL); | 237 ASSERT(function_name != NULL); |
| 226 ASSERT(num_arguments != NULL); | 238 ASSERT(num_arguments != NULL); |
| 227 ASSERT(num_named_arguments != NULL); | 239 ASSERT(num_named_arguments != NULL); |
| 228 ASSERT(target != NULL); | 240 ASSERT(target != NULL); |
| 229 InstanceCall call(return_address); | 241 InstanceCall call(return_address); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 248 } | 260 } |
| 249 | 261 |
| 250 | 262 |
| 251 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 263 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
| 252 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; | 264 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; |
| 253 } | 265 } |
| 254 | 266 |
| 255 } // namespace dart | 267 } // namespace dart |
| 256 | 268 |
| 257 #endif // defined TARGET_ARCH_IA32 | 269 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |