From 67ebaf0d22fefa885d29c3c697fbe61956d18354 Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 14 Feb 2015 23:14:14 -0500 Subject: Trampoline fixes. The transformed code was incorrect because it assumed the pointer it was writing to was where the code would execute, but it was actually 'rewritten_temp'. Changed transform_dis_main to take a pc_trampoline pointer, which also helps the test harness. However, this means that it has to be called after the trampoline has been allocated, while before the trampoline allocation depended on the generated size; this change doesn't bother to use two passes or anything, but just allocates a new code buffer if the maximum possible size isn't available - not the end of the world, since trampoline_ptr will still only be increased by the actual size before the next hook in the series (if any). --- lib/arm64/arch-dis.h | 4 ++++ lib/arm64/jump-patch.h | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/arm64') diff --git a/lib/arm64/arch-dis.h b/lib/arm64/arch-dis.h index 2990f5a..f5b0518 100644 --- a/lib/arm64/arch-dis.h +++ b/lib/arm64/arch-dis.h @@ -26,6 +26,10 @@ static inline void arch_dis_ctx_init(struct arch_dis_ctx *ctx) { ctx->regs_possibly_written = 0; } +static inline int arch_code_alignment(UNUSED struct arch_dis_ctx ctx) { + return 4; +} + static inline int arm64_get_unwritten_temp_reg(struct arch_dis_ctx *ctx) { uint32_t avail = ~ctx->regs_possibly_written & ((1 << 19) - (1 << 9)); if (!avail) diff --git a/lib/arm64/jump-patch.h b/lib/arm64/jump-patch.h index 3d3d653..0a276ba 100644 --- a/lib/arm64/jump-patch.h +++ b/lib/arm64/jump-patch.h @@ -1,12 +1,13 @@ #pragma once #include "arm64/assemble.h" -#define MAX_JUMP_PATCH_SIZE 12 +#define MAX_JUMP_PATCH_SIZE 20 + static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc, UNUSED struct arch_dis_ctx arch, bool force) { intptr_t diff = (dpc & ~0xfff) - (pc & ~0xfff); if (!(diff >= -0x100000000 && diff < 0x100000000)) - return force ? 16 : -1; + return force ? (size_of_MOVi64(dpc) + 4) : -1; else if (!(dpc & 0xfff)) return 8; else -- cgit v1.2.3