From 7cad99bba1372d10233eb2277057aa18f787c060 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Tue, 22 Jan 2013 14:33:36 +0100 Subject: [PATCH] Bug 831754 part 2 - Add patchable call instruction, x86/x64 part. r=dvander a=nonlibxul --- js/src/ion/shared/Assembler-x86-shared.h | 6 ++++++ js/src/ion/x64/Assembler-x64.h | 9 +++++++++ js/src/ion/x86/Assembler-x86.h | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/js/src/ion/shared/Assembler-x86-shared.h b/js/src/ion/shared/Assembler-x86-shared.h index a2cec5e3bd8..3d48e0a55ca 100644 --- a/js/src/ion/shared/Assembler-x86-shared.h +++ b/js/src/ion/shared/Assembler-x86-shared.h @@ -1246,6 +1246,12 @@ class AssemblerX86Shared JS_ASSERT(*ptr == 0xE9); *ptr = 0x3D; } + static void ToggleCall(CodeLocationLabel inst, bool enabled) { + uint8_t *ptr = (uint8_t *)inst.raw(); + JS_ASSERT(*ptr == 0x3D || // CMP + *ptr == 0xE8); // CALL + *ptr = enabled ? 0xE8 : 0x3D; + } }; } // namespace ion diff --git a/js/src/ion/x64/Assembler-x64.h b/js/src/ion/x64/Assembler-x64.h index 27940bdccc1..e0ba264d6e2 100644 --- a/js/src/ion/x64/Assembler-x64.h +++ b/js/src/ion/x64/Assembler-x64.h @@ -558,6 +558,15 @@ class Assembler : public AssemblerX86Shared addPendingJump(src, target->raw(), Relocation::IONCODE); } + // Emit a CALL or CMP (nop) instruction. ToggleCall can be used to patch + // this instruction. + CodeOffsetLabel toggledCall(IonCode *target, bool enabled) { + CodeOffsetLabel offset(size()); + JmpSrc src = enabled ? masm.call() : masm.cmp_eax(); + addPendingJump(src, target->raw(), Relocation::IONCODE); + return offset; + } + // Do not mask shared implementations. using AssemblerX86Shared::call; diff --git a/js/src/ion/x86/Assembler-x86.h b/js/src/ion/x86/Assembler-x86.h index 2113c6e3efa..0456c5e6e73 100644 --- a/js/src/ion/x86/Assembler-x86.h +++ b/js/src/ion/x86/Assembler-x86.h @@ -369,6 +369,15 @@ class Assembler : public AssemblerX86Shared addPendingJump(src, target.asPointer(), Relocation::HARDCODED); } + // Emit a CALL or CMP (nop) instruction. ToggleCall can be used to patch + // this instruction. + CodeOffsetLabel toggledCall(IonCode *target, bool enabled) { + CodeOffsetLabel offset(size()); + JmpSrc src = enabled ? masm.call() : masm.cmp_eax(); + addPendingJump(src, target->raw(), Relocation::IONCODE); + return offset; + } + // Re-routes pending jumps to an external target, flushing the label in the // process. void retarget(Label *label, void *target, Relocation::Kind reloc) {