Index: src/x64/assembler-x64.cc |
=================================================================== |
--- src/x64/assembler-x64.cc (revision 2868) |
+++ src/x64/assembler-x64.cc (working copy) |
@@ -173,22 +173,32 @@ |
// Patch the code at the current PC with a call to the target address. |
// Additional guard int3 instructions can be added if required. |
void RelocInfo::PatchCodeWithCall(Address target, int guard_bytes) { |
- // Call instruction takes up 13 bytes and int3 takes up one byte. |
- static const int kCallInstructionSize = 13; |
- Address patch_site = pc_; |
- Memory::uint16_at(patch_site) = 0xBA49u; // movq r10, imm64 |
- // Write "0x00, call r10" starting at last byte of address. We overwrite |
- // the 0x00 later, and this lets us write a uint32. |
- Memory::uint32_at(patch_site + 9) = 0xD2FF4900u; // 0x00, call r10 |
- Memory::Address_at(patch_site + 2) = target; |
+ // Load register with immediate 64 and call through a register instructions |
+ // takes up 13 bytes and int3 takes up one byte. |
+ static const int kCallCodeSize = 13; |
+ int code_size = kCallCodeSize + guard_bytes; |
+ // Create a code patcher. |
+ CodePatcher patcher(pc_, code_size); |
+ |
+ // Add a label for checking the size of the code used for returning. |
+#ifdef DEBUG |
+ Label check_codesize; |
+ patcher.masm()->bind(&check_codesize); |
+#endif |
+ |
+ // Patch the code. |
+ patcher.masm()->movq(r10, target, RelocInfo::NONE); |
+ patcher.masm()->call(r10); |
+ |
+ // Check that the size of the code generated is as expected. |
+ ASSERT_EQ(kCallCodeSize, |
+ patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize)); |
+ |
// Add the requested number of int3 instructions after the call. |
for (int i = 0; i < guard_bytes; i++) { |
- *(patch_site + kCallInstructionSize + i) = 0xCC; // int3 |
+ patcher.masm()->int3(); |
} |
- |
- // Indicate that code has changed. |
- CPU::FlushICache(patch_site, kCallInstructionSize + guard_bytes); |
} |
@@ -197,6 +207,9 @@ |
for (int i = 0; i < instruction_count; i++) { |
*(pc_ + i) = *(instructions + i); |
} |
+ |
+ // Indicate that code has changed. |
+ CPU::FlushICache(pc_, instruction_count); |
} |
// ----------------------------------------------------------------------------- |