aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcomex2015-02-14 23:50:30 -0500
committercomex2015-02-14 23:50:30 -0500
commit7dd3043eed8d9bac9ce48765335fdbe52b907b42 (patch)
treef62413fb90461eb4d1f71d695adc730f4722edb1
parentTrampoline fixes. (diff)
downloadsubstitute-7dd3043eed8d9bac9ce48765335fdbe52b907b42.tar.gz
fix test cases
-rw-r--r--lib/x86/arch-transform-dis.inc.h2
-rw-r--r--lib/x86/jump-patch.h2
-rwxr-xr-xscript/test-transform-dis.sh6
-rw-r--r--test/transform-dis-cases-i386.S10
4 files changed, 14 insertions, 6 deletions
diff --git a/lib/x86/arch-transform-dis.inc.h b/lib/x86/arch-transform-dis.inc.h
index 6ec6c16..67390c9 100644
--- a/lib/x86/arch-transform-dis.inc.h
+++ b/lib/x86/arch-transform-dis.inc.h
@@ -76,7 +76,7 @@ static void transform_dis_branch(struct transform_dis_ctx *ctx, uint_tptr dpc,
code += ctx->base.op_size;
struct arch_dis_ctx arch;
- uintptr_t source = ctx->pc_trampoline + 2;
+ uintptr_t source = ctx->pc_trampoline + ctx->base.op_size + 2;
int size = jump_patch_size(source, dpc, arch, true);
/* If not taken, jmp past the big jump - this is a bit suboptimal but not
* that bad.
diff --git a/lib/x86/jump-patch.h b/lib/x86/jump-patch.h
index 8cd7d6f..ca7b16c 100644
--- a/lib/x86/jump-patch.h
+++ b/lib/x86/jump-patch.h
@@ -15,7 +15,7 @@ static inline int jump_patch_size(uint_tptr pc, uint_tptr dpc,
static inline void make_jump_patch(void **codep, uint_tptr pc, uint_tptr dpc,
UNUSED struct arch_dis_ctx arch) {
- uint_tptr diff = pc - (dpc + 5);
+ uint_tptr diff = dpc - (pc + 5);
void *code = *codep;
if (diff == (uint_tptr) (int32_t) diff) {
op8(&code, 0xe9);
diff --git a/script/test-transform-dis.sh b/script/test-transform-dis.sh
new file mode 100755
index 0000000..556746b
--- /dev/null
+++ b/script/test-transform-dis.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -xe
+make out/transform-dis-cases-$1.bin out/test-transform-dis-$1
+out/test-transform-dis-$1 auto < out/transform-dis-cases-$1.bin
+
+
diff --git a/test/transform-dis-cases-i386.S b/test/transform-dis-cases-i386.S
index 57707cc..3e468d4 100644
--- a/test/transform-dis-cases-i386.S
+++ b/test/transform-dis-cases-i386.S
@@ -10,8 +10,10 @@ GIVEN jmp 0f; 0: nop
EXPECT_ERR
GIVEN jne .+0x1000
-/* we expect to generate an unnecessarily long jump, so hardcode it */
-EXPECT 2: .byte 0x0f, 0x85; .long 2; jmp 1f; 0: jmp 2b+0x1000; 1:
+/* we expect to generate an unnecessarily long jump, so hardcode it the 0x10000
+ * is because we pretend our trampoline is 0x10000 bytes before the original
+ * function */
+EXPECT 2: .byte 0x0f, 0x85; .long 2; jmp 1f; 0: jmp .+0x10000+0x1000-8; 1:
-GIVEN loopne 0xdead0080
-EXPECT loopne 0f; jmp 1f; 0: jmp 0xdead1000; 1:
+GIVEN loopne .+0x80
+EXPECT loopne 0f; jmp 1f; 0: jmp .+0x10000+0x80-4; 1: