aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiko Asakura2021-03-21 17:07:50 -0400
committerReiko Asakura2021-03-21 17:07:50 -0400
commit6f788636b163ab354fb553e5a9cb3df8a433f3f0 (patch)
treec3e61b444cc153af7e576eeff0aa99ca7ec0df2d
parentAlign Thumb jump patch to halfword boundary (diff)
downloadsubstitute-6f788636b163ab354fb553e5a9cb3df8a433f3f0.tar.gz
Remove dead code for Vita: pc_callback
-rw-r--r--lib/arm/jump-patch.h1
-rw-r--r--lib/execmem.h4
-rw-r--r--lib/hook-functions.c41
-rw-r--r--lib/transform-dis.c8
-rw-r--r--lib/transform-dis.h1
-rw-r--r--lib/vita/execmem.c6
6 files changed, 6 insertions, 55 deletions
diff --git a/lib/arm/jump-patch.h b/lib/arm/jump-patch.h
index 5dd7d18..26153fa 100644
--- a/lib/arm/jump-patch.h
+++ b/lib/arm/jump-patch.h
@@ -2,7 +2,6 @@
#include "dis.h"
#include "arm/assemble.h"
#define MAX_JUMP_PATCH_SIZE 10
-#define MAX_EXTENDED_PATCH_SIZE (MAX_JUMP_PATCH_SIZE+14)
static inline int jump_patch_size(uint_tptr pc,
UNUSED uint_tptr dpc,
diff --git a/lib/execmem.h b/lib/execmem.h
index 9e2f8ca..fe8362f 100644
--- a/lib/execmem.h
+++ b/lib/execmem.h
@@ -18,6 +18,4 @@ struct execmem_foreign_write {
};
typedef uintptr_t (*execmem_pc_patch_callback)(void *ctx, uintptr_t pc);
int execmem_foreign_write_with_pc_patch(struct execmem_foreign_write *writes,
- size_t nwrites,
- execmem_pc_patch_callback callback,
- void *callback_ctx);
+ size_t nwrites);
diff --git a/lib/hook-functions.c b/lib/hook-functions.c
index c38b92a..4e11c67 100644
--- a/lib/hook-functions.c
+++ b/lib/hook-functions.c
@@ -11,7 +11,6 @@
#endif
struct hook_internal {
- int offset_by_pcdiff[MAX_EXTENDED_PATCH_SIZE + 1];
uint8_t jump_patch[MAX_JUMP_PATCH_SIZE];
size_t jump_patch_size;
void *code;
@@ -22,33 +21,6 @@ struct hook_internal {
struct arch_dis_ctx arch_dis_ctx;
};
-struct pc_callback_info {
- struct hook_internal *his;
- size_t nhooks;
- bool encountered_bad_pc;
-};
-
-static uintptr_t pc_callback(void *ctx, uintptr_t pc) {
- struct pc_callback_info *restrict info = ctx;
- uintptr_t real_pc = pc;
-#ifdef __arm__
- 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 - (uintptr_t) hi->code;
- if (diff < hi->jump_patch_size) {
- int offset = hi->offset_by_pcdiff[diff];
- if (offset == -1) {
- info->encountered_bad_pc = true;
- return pc;
- }
- return (uintptr_t) hi->outro_trampoline + offset;
- }
- }
- return pc;
-}
-
/* Figure out the size of the patch we need to jump from pc_patch_start
* to hook->replacement.
* On ARM, we can jump anywhere in 8 bytes. On ARM64, we can only do it in two
@@ -247,7 +219,7 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
trampoline_prev = trampoline_ptr;
if ((ret = transform_dis_main(code, &trampoline_ptr, pc_patch_start,
&pc_patch_end, trampoline_addr,
- &arch, hi->offset_by_pcdiff,
+ &arch,
(thread_safe ? TRANSFORM_DIS_BAN_CALLS : 0) |
(relaxed ? 0 : TRANSFORM_DIS_REL_JUMPS))))
goto end;
@@ -303,16 +275,11 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks,
}
}
- struct pc_callback_info info = {his, nhooks, false};
- if ((ret = execmem_foreign_write_with_pc_patch(
- fws, nhooks, thread_safe ? pc_callback : NULL, &info))) {
+ ret = execmem_foreign_write_with_pc_patch(fws, nhooks);
+ if (ret) {
/* Too late to free the trampolines. Chances are this is fatal anyway. */
goto end_dont_free;
}
- if (info.encountered_bad_pc) {
- ret = SUBSTITUTE_ERR_UNEXPECTED_PC_ON_OTHER_THREAD;
- goto end_dont_free;
- }
goto end_dont_free;
end:
@@ -343,7 +310,7 @@ int substitute_free_hooks(struct substitute_function_hook_record *records,
cur = (struct substitute_function_hook_record *)((char *)&cur->saved_buffer + cur->buffer_size);
}
/* TODO: Fix the case when thread is inside a patch/trampoline. */
- ret = execmem_foreign_write_with_pc_patch(fws, nhooks, NULL, NULL);
+ ret = execmem_foreign_write_with_pc_patch(fws, nhooks);
free(records);
return ret;
}
diff --git a/lib/transform-dis.c b/lib/transform-dis.c
index 20e2dfe..c6e6bbb 100644
--- a/lib/transform-dis.c
+++ b/lib/transform-dis.c
@@ -94,7 +94,6 @@ int transform_dis_main(const void *restrict code_ptr,
uint_tptr *pc_patch_end_p,
uint_tptr pc_trampoline,
struct arch_dis_ctx *arch_ctx_p,
- int *offset_by_pcdiff,
int options) {
struct transform_dis_ctx ctx;
memset(&ctx, 0, sizeof(ctx));
@@ -109,7 +108,6 @@ int transform_dis_main(const void *restrict code_ptr,
ctx.rewritten_ptr_ptr = rewritten_ptr_ptr;
void *rewritten_start = *rewritten_ptr_ptr;
int written_pcdiff = 0;
- offset_by_pcdiff[written_pcdiff++] = 0;
while (ctx.base.pc < ctx.pc_patch_end && !ctx.force_keep_transforming) {
ctx.base.modify = false;
ctx.err = 0;
@@ -145,12 +143,6 @@ int transform_dis_main(const void *restrict code_ptr,
ctx.base.pc += ctx.base.op_size;
transform_dis_post_dis(&ctx);
-
- int pcdiff = ctx.base.pc - ctx.pc_patch_start;
- while (written_pcdiff < pcdiff)
- offset_by_pcdiff[written_pcdiff++] = -1;
- offset_by_pcdiff[written_pcdiff++] =
- (int) (*rewritten_ptr_ptr - rewritten_start);
}
*pc_patch_end_p = ctx.base.pc;
*arch_ctx_p = ctx.arch;
diff --git a/lib/transform-dis.h b/lib/transform-dis.h
index 18e0b17..6fe436c 100644
--- a/lib/transform-dis.h
+++ b/lib/transform-dis.h
@@ -12,5 +12,4 @@ int transform_dis_main(const void *restrict code_ptr,
uint_tptr *pc_patch_end_p,
uint_tptr pc_trampoline,
struct arch_dis_ctx *arch_ctx_p,
- int *offset_by_pcdiff,
int options);
diff --git a/lib/vita/execmem.c b/lib/vita/execmem.c
index 2af1430..3e313d8 100644
--- a/lib/vita/execmem.c
+++ b/lib/vita/execmem.c
@@ -112,15 +112,11 @@ void execmem_free(void *ptr, void *opt) {
*
* @param writes List of writes
* @param[in] nwrites Number of writes
- * @param[in] callback Unused
- * @param callback_ctx Unused
*
* @return `SUBSTITUTE_OK` or `SUBSTITUTE_ERR_VM` on failure
*/
int execmem_foreign_write_with_pc_patch(struct execmem_foreign_write *writes,
- size_t nwrites,
- UNUSED execmem_pc_patch_callback callback,
- UNUSED void *callback_ctx) {
+ size_t nwrites) {
LOG("Patching exec memory: %d", nwrites);
for (int i = 0; i < nwrites; i++) {
struct slab_chain *slab = (struct slab_chain *)writes[i].opt;