aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcomex2015-01-24 22:23:27 -0500
committercomex2015-01-24 22:23:27 -0500
commitbd22f1a62adc6a5fc0645484039ba099a3a72e04 (patch)
tree200acf4e5ebed0862072d45ae4cc1631d6d8ed33
parent... (diff)
downloadsubstitute-bd22f1a62adc6a5fc0645484039ba099a3a72e04.tar.gz
it compiles...
-rw-r--r--lib/arm/assemble.h66
-rw-r--r--lib/arm/jump-patch.h11
-rw-r--r--lib/arm/misc.h3
-rw-r--r--lib/arm/transform-dis-arm-multi.inc.h41
-rw-r--r--lib/arm64/assemble.h4
-rw-r--r--lib/arm64/jump-patch.h13
-rw-r--r--lib/arm64/transform-dis-arm64.inc.h1
-rw-r--r--lib/darwin/execmem.c19
-rw-r--r--lib/hook-functions.c81
-rw-r--r--test/test-jump-dis.c2
-rw-r--r--test/test-transform-dis.c2
11 files changed, 140 insertions, 103 deletions
diff --git a/lib/arm/assemble.h b/lib/arm/assemble.h
index 90f91c9..6f1e8e7 100644
--- a/lib/arm/assemble.h
+++ b/lib/arm/assemble.h
@@ -1,52 +1,57 @@
#pragma once
#include "dis.h"
-static inline void PUSHone(void **codep, int Rt) {
- if (codep->arch.pc_low_bit)
- op32(codep, 0x0d04f84d | Rt << 28);
+struct assemble_ctx {
+ void **codep;
+ bool thumb;
+};
+
+static inline void PUSHone(struct assemble_ctx ctx, int Rt) {
+ if (ctx.thumb)
+ op32(ctx.codep, 0x0d04f84d | Rt << 28);
else
- op32(codep, 0xe52d0004 | Rt << 12);
+ op32(ctx.codep, 0xe52d0004 | Rt << 12);
}
-static inline void POPone(void **codep, int Rt) {
- if (codep->arch.pc_low_bit)
- op32(codep, 0x0b04f85d | Rt << 28);
+static inline void POPone(struct assemble_ctx ctx, int Rt) {
+ if (ctx.thumb)
+ op32(ctx.codep, 0x0b04f85d | Rt << 28);
else
- op32(codep, 0xe49d0004 | Rt << 12);
+ op32(ctx.codep, 0xe49d0004 | Rt << 12);
}
-static inline void POPmulti(void **codep, uint16_t mask) {
- if (codep->arch.pc_low_bit)
- op32(codep, 0x0000e8bd | mask << 16);
+static inline void POPmulti(struct assemble_ctx ctx, uint16_t mask) {
+ if (ctx.thumb)
+ op32(ctx.codep, 0x0000e8bd | mask << 16);
else
- op32(codep, 0xe8bd0000 | mask);
+ op32(ctx.codep, 0xe8bd0000 | mask);
}
-static inline void MOVW_MOVT(void **codep, int Rd, uint32_t val) {
+static inline void MOVW_MOVT(struct assemble_ctx ctx, int Rd, uint32_t val) {
uint16_t hi = val >> 16, lo = (uint16_t) val;
- if (codep->arch.pc_low_bit) {
- op32(codep, 0x0000f240 | Rd << 24 | lo >> 12 | (lo >> 11 & 1) << 10 |
- (lo >> 8 & 7) << 28 | (lo & 0xff) << 16);
- op32(codep, 0x0000f2c0 | Rd << 24 | hi >> 12 | (hi >> 11 & 1) << 10 |
- (hi >> 8 & 7) << 28 | (hi & 0xff) << 16);
+ if (ctx.thumb) {
+ op32(ctx.codep, 0x0000f240 | Rd << 24 | lo >> 12 | (lo >> 11 & 1) << 10 |
+ (lo >> 8 & 7) << 28 | (lo & 0xff) << 16);
+ op32(ctx.codep, 0x0000f2c0 | Rd << 24 | hi >> 12 | (hi >> 11 & 1) << 10 |
+ (hi >> 8 & 7) << 28 | (hi & 0xff) << 16);
} else {
- op32(codep, 0xe3000000 | Rd << 12 | (lo >> 12) << 16 | (lo & 0xfff));
- op32(codep, 0xe3400000 | Rd << 12 | (hi >> 12) << 16 | (hi & 0xfff));
+ op32(ctx.codep, 0xe3000000 | Rd << 12 | (lo >> 12) << 16 | (lo & 0xfff));
+ op32(ctx.codep, 0xe3400000 | Rd << 12 | (hi >> 12) << 16 | (hi & 0xfff));
}
}
-static inline void STRri(void **codep, int Rt, int Rn, uint32_t off) {
- if (codep->arch.pc_low_bit)
- op32(codep, 0x0000f8c0 | Rn | Rt << 28 | off << 16);
+static inline void STRri(struct assemble_ctx ctx, int Rt, int Rn, uint32_t off) {
+ if (ctx.thumb)
+ op32(ctx.codep, 0x0000f8c0 | Rn | Rt << 28 | off << 16);
else
- op32(codep, 0xe4800000 | Rn << 16 | Rt << 12 | off);
+ op32(ctx.codep, 0xe4800000 | Rn << 16 | Rt << 12 | off);
}
-static inline void LDRxi(void **codep, int Rt, int Rn, uint32_t off,
+static inline void LDRxi(struct assemble_ctx ctx, int Rt, int Rn, uint32_t off,
enum pcrel_load_mode load_mode) {
- if (codep->arch.pc_low_bit) {
+ if (ctx.thumb) {
int subop, sign;
switch (load_mode) {
case PLM_U8: subop = 0; sign = 0; break;
@@ -56,7 +61,8 @@ static inline void LDRxi(void **codep, int Rt, int Rn, uint32_t off,
case PLM_U32: subop = 2; sign = 0; break;
default: __builtin_abort();
}
- op32(codep, 0x0000f890 | Rn | Rt << 28 | subop << 5 | sign << 8 | off << 16);
+ op32(ctx.codep, 0x0000f890 | Rn | Rt << 28 | subop << 5 | sign << 8 |
+ off << 16);
} else {
int is_byte, subop, not_ldrd;
switch (load_mode) {
@@ -67,11 +73,11 @@ static inline void LDRxi(void **codep, int Rt, int Rn, uint32_t off,
case PLM_U32: is_byte = 0; goto type1;
case PLM_U128: subop = 13; not_ldrd = 0; goto type2;
type1:
- op32(codep, 0xe5900000 | Rn << 16 | Rt << 12 | off);
+ op32(ctx.codep, 0xe5900000 | Rn << 16 | Rt << 12 | off);
break;
type2:
- op32(codep, 0xe1c00000 | Rn << 16 | Rt << 12 | subop << 4 |
- (off & 0xf) | (off & 0xf0) << 4 | not_ldrd << 20);
+ op32(ctx.codep, 0xe1c00000 | Rn << 16 | Rt << 12 | subop << 4 |
+ (off & 0xf) | (off & 0xf0) << 4 | not_ldrd << 20);
break;
default:
__builtin_abort();
diff --git a/lib/arm/jump-patch.h b/lib/arm/jump-patch.h
index b19e90f..238d56e 100644
--- a/lib/arm/jump-patch.h
+++ b/lib/arm/jump-patch.h
@@ -3,16 +3,19 @@
#define MAX_JUMP_PATCH_SIZE 8
#define MAX_REWRITTEN_SIZE (12 * 4) /* actually should be less */
-static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc,
- struct arch_dis_ctx arch) {
+static inline int jump_patch_size(UNUSED uintptr_t pc,
+ UNUSED uintptr_t dpc,
+ UNUSED struct arch_dis_ctx arch,
+ UNUSED bool force) {
return 8;
}
-static inline void make_jump_patch(void **codep, uintptr_t pc, uintptr_t dpc,
+static inline void make_jump_patch(void **codep, UNUSED uintptr_t pc,
+ uintptr_t dpc,
struct arch_dis_ctx arch) {
if (arch.pc_low_bit)
op32(codep, 0xf000f8df);
else
op32(codep, 0xe51ff004);
- op32(codep, (uint32_t) pc);
+ op32(codep, (uint32_t) dpc);
}
diff --git a/lib/arm/misc.h b/lib/arm/misc.h
index 3dc9633..7ce1c05 100644
--- a/lib/arm/misc.h
+++ b/lib/arm/misc.h
@@ -12,6 +12,3 @@ enum { IS_LDRD_STRD = 1 << 16 };
#define JUMP_PATCH_SIZE 8
#define MAX_REWRITTEN_SIZE (12 * 4) /* actually should be less */
-static inline bool can_reach_with_jump_patch(uintptr_t pc, uintptr_t dpc) {
- return true;
-}
diff --git a/lib/arm/transform-dis-arm-multi.inc.h b/lib/arm/transform-dis-arm-multi.inc.h
index 001e613..2e6a62d 100644
--- a/lib/arm/transform-dis-arm-multi.inc.h
+++ b/lib/arm/transform-dis-arm-multi.inc.h
@@ -16,6 +16,7 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
newval[3] = o3;
void **codep = ctx->rewritten_ptr_ptr;
+ struct assemble_ctx actx = {ctx->rewritten_ptr_ptr, ctx->arch.pc_low_bit};
/* A few cases:
* 1. Move to PC that does not read PC. Probably fine.
@@ -54,33 +55,33 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
if (in_regs & 1 << 15)
return; /* case 1 */
/* case 2 */
- PUSHone(codep, scratch);
- PUSHone(codep, scratch);
- MOVW_MOVT(codep, scratch, pc);
+ PUSHone(actx, scratch);
+ PUSHone(actx, scratch);
+ MOVW_MOVT(actx, scratch, pc);
for (int i = 0; i < 4; i++)
if (newval[i] == 15)
newval[i] = scratch;
ctx->write_newop_here = *codep; *codep += ctx->op_size;
- STRri(codep, scratch, 13, 4);
- POPmulti(codep, 1 << scratch | 1 << 15);
+ STRri(actx, scratch, 13, 4);
+ POPmulti(actx, 1 << scratch | 1 << 15);
transform_dis_ret(ctx);
} else {
if (out_reg != -1 && !(in_regs & 1 << out_reg)) {
/* case 3 - ignore scratch */
- MOVW_MOVT(codep, out_reg, pc);
+ MOVW_MOVT(actx, out_reg, pc);
for (int i = 0; i < 4; i++)
if (newval[i] == 15)
newval[i] = out_reg;
ctx->write_newop_here = *codep; *codep += ctx->op_size;
} else {
/* case 4 */
- PUSHone(codep, scratch);
- MOVW_MOVT(codep, scratch, pc);
+ PUSHone(actx, scratch);
+ MOVW_MOVT(actx, scratch, pc);
for (int i = 0; i < 4; i++)
if (newval[i] == 15)
newval[i] = scratch;
- ctx->write_newop_here = *rpp; *rpp += ctx->op_size;
- POPone(codep, scratch);
+ ctx->write_newop_here = *codep; *codep += ctx->op_size;
+ POPone(actx, scratch);
}
}
ctx->modify = true;
@@ -97,20 +98,20 @@ static NOINLINE UNUSED void transform_dis_pcrel(struct transform_dis_ctx *ctx,
(void *) dpc, reg, load_mode);
#endif
ctx->write_newop_here = NULL;
- void **codep = ctx->rewritten_ptr_ptr;
+ struct assemble_ctx actx = {ctx->rewritten_ptr_ptr, ctx->arch.pc_low_bit};
if (reg == 15) {
int scratch = 0;
- PUSHone(codep, scratch);
- PUSHone(codep, scratch);
- MOVW_MOVT(codep, scratch, dpc);
+ PUSHone(actx, scratch);
+ PUSHone(actx, scratch);
+ MOVW_MOVT(actx, scratch, dpc);
if (load_mode != PLM_ADR)
- LDRxi(codep, scratch, scratch, 0, load_mode);
- STRri(codep, scratch, 13, 4);
- POPmulti(codep, 1 << scratch | 1 << 15);
- transform_dis_ret(codep);
+ LDRxi(actx, scratch, scratch, 0, load_mode);
+ STRri(actx, scratch, 13, 4);
+ POPmulti(actx, 1 << scratch | 1 << 15);
+ transform_dis_ret(ctx);
} else {
- MOVW_MOVT(codep, reg, dpc);
+ MOVW_MOVT(actx, reg, dpc);
if (load_mode != PLM_ADR)
- LDRxi(codep, reg, reg, 0, load_mode);
+ LDRxi(actx, reg, reg, 0, load_mode);
}
}
diff --git a/lib/arm64/assemble.h b/lib/arm64/assemble.h
index 00797e9..c20c219 100644
--- a/lib/arm64/assemble.h
+++ b/lib/arm64/assemble.h
@@ -47,7 +47,9 @@ static inline void ADRP_ADD(void **codep, int reg, uint64_t pc, uint64_t dpc) {
/* ADD reg, reg, #lo */
op32(codep, 0x91000000 | reg | reg << 5 | lo << 10);
}
- /* BR reg */
+}
+
+static inline void BR(void **codep, int reg) {
op32(codep, 0xd61f0000 | reg << 5);
}
diff --git a/lib/arm64/jump-patch.h b/lib/arm64/jump-patch.h
index f0f149f..c42c730 100644
--- a/lib/arm64/jump-patch.h
+++ b/lib/arm64/jump-patch.h
@@ -3,10 +3,11 @@
#define MAX_JUMP_PATCH_SIZE 12
#define MAX_REWRITTEN_SIZE (7 * 2 * 4) /* also conservative */
static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc,
- struct arch_dis_ctx arch) {
+ struct arch_dis_ctx arch,
+ bool force) {
intptr_t diff = (dpc & ~0xfff) - (pc & ~0xfff);
if (!(diff >= -0x100000000 && diff < 0x100000000))
- return -1;
+ return force ? 16 : -1;
else if (pc & 0xfff)
return 8;
else
@@ -15,5 +16,11 @@ static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc,
static inline void make_jump_patch(void **codep, uintptr_t pc, uintptr_t dpc,
struct arch_dis_ctx arch) {
- ADRP_ADD(codep, 12 /* XXX */, pc, dpc);
+ int reg = 12; /* XXX */
+ intptr_t diff = (dpc & ~0xfff) - (pc & ~0xfff);
+ if (!(diff >= -0x100000000 && diff < 0x100000000))
+ MOVi64(codep, reg, dpc);
+ else
+ ADRP_ADD(codep, reg, pc, dpc);
+ BR(codep, reg);
}
diff --git a/lib/arm64/transform-dis-arm64.inc.h b/lib/arm64/transform-dis-arm64.inc.h
index 3710b73..682613a 100644
--- a/lib/arm64/transform-dis-arm64.inc.h
+++ b/lib/arm64/transform-dis-arm64.inc.h
@@ -1,3 +1,4 @@
+#include "arm64/assemble.h"
static NOINLINE UNUSED void transform_dis_pcrel(struct transform_dis_ctx *ctx,
uintptr_t dpc, unsigned reg, enum pcrel_load_mode load_mode) {
diff --git a/lib/darwin/execmem.c b/lib/darwin/execmem.c
index c707db5..22c1c2e 100644
--- a/lib/darwin/execmem.c
+++ b/lib/darwin/execmem.c
@@ -55,3 +55,22 @@ int execmem_write(void *dest, const void *src, size_t len) {
}
return SUBSTITUTE_OK;
}
+
+int execmem_alloc_unsealed(uintptr_t hint, void **page_p, size_t *size_p) {
+ *size_p = PAGE_SIZE;
+ *page_p = mmap((void *) hint, *size_p, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED, -1, 0);
+ if (*page_p == MAP_FAILED)
+ return SUBSTITUTE_ERR_VM;
+ return SUBSTITUTE_OK;
+}
+
+int execmem_seal(void *page) {
+ if (mprotect(page, PAGE_SIZE, PROT_READ | PROT_EXEC))
+ return SUBSTITUTE_ERR_VM;
+ return SUBSTITUTE_OK;
+}
+
+void execmem_free(void *page) {
+ munmap(page, PAGE_SIZE);
+}
diff --git a/lib/hook-functions.c b/lib/hook-functions.c
index daf4093..5a502c8 100644
--- a/lib/hook-functions.c
+++ b/lib/hook-functions.c
@@ -11,7 +11,7 @@ struct hook_internal {
int offset_by_pcdiff[JUMP_PATCH_SIZE + 1];
uint8_t jump_patch[MAX_JUMP_PATCH_SIZE];
size_t jump_patch_size;
- uintptr_t pc_patch_start;
+ void *code;
void *outro_trampoline;
/* page allocated with execmem_alloc_unsealed - only if we had to allocate
* one when processing this hook */
@@ -21,18 +21,17 @@ struct hook_internal {
struct pc_callback_info {
struct hook_internal *his;
size_t nhooks;
-}
+};
static uintptr_t pc_callback(void *ctx, uintptr_t pc) {
struct pc_callback_info *restrict info = ctx;
uintptr_t real_pc = pc;
#ifdef __arm__
- bool thumb = pc & 1;
real_pc = pc & ~1;
#endif
for (size_t i = 0; i < info->nhooks; i++) {
struct hook_internal *hi = &info->his[i];
- uintptr_t diff = real_pc - hi->pc_patch_start;
+ uintptr_t diff = real_pc - (uintptr_t) hi->code;
if (diff < hi->jump_patch_size)
return (uintptr_t) hi->outro_trampoline + hi->offset_by_pcdiff[diff];
}
@@ -54,31 +53,27 @@ static uintptr_t pc_callback(void *ctx, uintptr_t pc) {
* If even that is out of range, then return an error code.
*/
-static int check_intro_trampline(void **trampoline_ptr_p
- size_t *trampoline_size_left_p,
- uintptr_t pc,
- uintptr_t dpc,
- int *patch_size_p,
- bool *need_intro_trampoline_p,
- void **trampoline_page_p,
- struct arch_dis_ctx arch) {
+static int check_intro_trampoline(void **trampoline_ptr_p,
+ size_t *trampoline_size_left_p,
+ uintptr_t pc,
+ uintptr_t dpc,
+ int *patch_size_p,
+ bool *need_intro_trampoline_p,
+ void **trampoline_page_p,
+ struct arch_dis_ctx arch) {
void *trampoline_ptr = *trampoline_ptr_p;
size_t trampoline_size_left = *trampoline_size_left_p;
/* Try direct */
*need_intro_trampoline_p = false;
- *patch_size_p = jump_patch_size(pc_patch_start,
- (uintptr_t) hook->replacement,
- arch);
+ *patch_size_p = jump_patch_size(pc, dpc, arch, /*force*/ false);
if (*patch_size_p != -1)
return SUBSTITUTE_OK;
/* Try existing trampoline */
- *patch_size_p = jump_patch_size(pc_patch_start,
- (uintptr_t) *trampoline_ptr,
- arch);
+ *patch_size_p = jump_patch_size(pc, (uintptr_t) trampoline_ptr, arch, false);
- if (*patch_size_p != -1 && *patch_size_p <= *trampoline_size_left_p)
+ if (*patch_size_p != -1 && (size_t) *patch_size_p <= *trampoline_size_left_p)
return SUBSTITUTE_OK;
/* Allocate new trampoline - try after dpc. If this fails, we can try
@@ -87,9 +82,7 @@ static int check_intro_trampline(void **trampoline_ptr_p
if (ret)
goto skip_after;
- *patch_size_p = jump_patch_size(pc_patch_start,
- (uintptr_t) *trampoline_ptr,
- arch);
+ *patch_size_p = jump_patch_size(pc, (uintptr_t) trampoline_ptr, arch, false);
if (*patch_size_p != -1) {
*trampoline_ptr_p = trampoline_ptr;
*trampoline_size_left_p = trampoline_size_left;
@@ -99,16 +92,14 @@ static int check_intro_trampline(void **trampoline_ptr_p
execmem_free(trampoline_ptr);
-skip_after:
+skip_after:;
/* Allocate new trampoline - try before dpc (xxx only meaningful on arm64) */
uintptr_t start_address = dpc - 0xffff0000;
ret = execmem_alloc_unsealed(start_address, &trampoline_ptr, &trampoline_size_left);
if (ret)
return ret;
- *patch_size_p = jump_patch_size(pc_patch_start,
- (uintptr_t) *trampoline_ptr,
- arch);
+ *patch_size_p = jump_patch_size(pc, (uintptr_t) trampoline_ptr, arch, false);
if (*patch_size_p != -1) {
*trampoline_ptr_p = trampoline_ptr;
*trampoline_size_left_p = trampoline_size_left;
@@ -126,7 +117,7 @@ EXPORT
int substitute_hook_functions(const struct substitute_function_hook *hooks,
size_t nhooks,
int options) {
- struct hook_internal *his = malloc(nhooks * sizeof(*hi));
+ struct hook_internal *his = malloc(nhooks * sizeof(*his));
if (!his)
return SUBSTITUTE_ERR_OOM;
@@ -160,6 +151,7 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
code--;
}
#endif
+ hi->code = code;
uintptr_t pc_patch_start = (uintptr_t) code;
int patch_size;
bool need_intro_trampoline;
@@ -180,7 +172,6 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
void *jp = hi->jump_patch;
make_jump_patch(&jp, pc_patch_start, initial_target, arch);
hi->jump_patch_size = (uint8_t *) jp - hi->jump_patch;
- hi->pc_patch_start = pc_patch_start;
uintptr_t pc_patch_end = pc_patch_start + patch_size;
/* Generate the rewritten start of the function for the outro
@@ -188,19 +179,27 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
uint8_t rewritten_temp[MAX_REWRITTEN_SIZE];
void *rp = rewritten_temp;
if ((ret = transform_dis_main(code, &rp, pc_patch_start, pc_patch_end,
- arch, hi->offset_by_pcdiff))
+ arch, hi->offset_by_pcdiff)))
goto end;
/* Check some of the rest of the function for jumps back into the
* patched region. */
- if ((ret = jump_dis(code, pc_patch_start, pc_patch_end, arch)))
+ if ((ret = jump_dis_main(code, pc_patch_start, pc_patch_end, arch)))
goto end;
- size_t rewritten_size = (uint8_t *) rp - hi->rewritten_temp;
- if (trampoline_size_left < rewritten_size) {
+ size_t rewritten_size = (uint8_t *) rp - rewritten_temp;
+ size_t jumpback_size =
+ jump_patch_size((uintptr_t) trampoline_ptr + rewritten_size,
+ pc_patch_end, arch, /* force */ true);
+ size_t outro_size = rewritten_size + jumpback_size;
+ if (outro_size > trampoline_size_left) {
/* Not enough space left in our existing block... */
- if (ret = execmem_alloc_unsealed(0, &trampoline_ptr,
- &trampoline_size_left))
+ if ((ret = execmem_alloc_unsealed(0, &trampoline_ptr,
+ &trampoline_size_left)))
goto end;
+ jumpback_size =
+ jump_patch_size((uintptr_t) trampoline_ptr + rewritten_size,
+ pc_patch_end, arch, /* force */ true);
+ outro_size = rewritten_size + jumpback_size;
}
hi->outro_trampoline = trampoline_ptr;
@@ -209,7 +208,10 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
hi->outro_trampoline++;
#endif
memcpy(trampoline_ptr, rewritten_temp, rewritten_size);
- trampoline_size_left -= rewritten_size;
+ trampoline_ptr += rewritten_size;
+ make_jump_patch(&trampoline_ptr, (uintptr_t) trampoline_ptr, pc_patch_end,
+ arch);
+ trampoline_size_left -= outro_size;
}
/* Now commit. */
@@ -217,20 +219,19 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
const struct substitute_function_hook *hook = &hooks[i];
struct hook_internal *hi = &his[i];
emw_finished_i = (ssize_t) i;
- if ((ret = execmem_write(hi->pc_patch_start, hi->jump_patch,
- hi->jump_patch_size))) {
+ if ((ret = execmem_write(hi->code, hi->jump_patch, hi->jump_patch_size))) {
/* User is probably screwed, since this probably means a failure to
* re-protect exec, thanks to code signing, so now the function is
* permanently inaccessible. */
goto end;
}
if (hook->old_ptr)
- *(void **) hook_old_ptr = hi->outro_trampoline;
+ *(void **) hook->old_ptr = hi->outro_trampoline;
}
/* *sigh of relief* now we can rewrite the PCs. */
if (stopped) {
- struct pc_callback_info info = {hi, nhooks};
+ struct pc_callback_info info = {his, nhooks};
if ((ret = apply_pc_patch_callback(stop_token, pc_callback, &info)))
goto end;
}
@@ -241,7 +242,7 @@ end:
if (page) {
/* if we failed, get rid of the trampolines. if we succeeded, make
* them executable */
- if (ret && i >= emw_finished) {
+ if (ret && (ssize_t) i >= emw_finished_i) {
execmem_free(page);
} else {
/* we already patched them all, too late to go back.. */
diff --git a/test/test-jump-dis.c b/test/test-jump-dis.c
index ef6add8..fde1b51 100644
--- a/test/test-jump-dis.c
+++ b/test/test-jump-dis.c
@@ -9,7 +9,7 @@ int main(UNUSED int argc, char **argv) {
int patch_size = atoi(argv[1]);
struct arch_dis_ctx arch;
memset(&arch, 0, sizeof(arch));
-#ifdef __arm__
+#ifdef TARGET_arm
int thumb = atoi(argv[2]);
arch.pc_low_bit = thumb;
#endif
diff --git a/test/test-transform-dis.c b/test/test-transform-dis.c
index a0a60d5..f90ae51 100644
--- a/test/test-transform-dis.c
+++ b/test/test-transform-dis.c
@@ -8,7 +8,7 @@ int main(UNUSED int argc, char **argv) {
int patch_size = atoi(argv[1]);
struct arch_dis_ctx arch;
memset(&arch, 0, sizeof(arch));
-#ifdef __arm__
+#ifdef TARGET_arm
int thumb = atoi(argv[2]);
arch.pc_low_bit = thumb;
#endif