aboutsummaryrefslogtreecommitdiff
path: root/lib/x86/jump-patch.h
diff options
context:
space:
mode:
authorcomex2015-02-14 23:14:14 -0500
committercomex2015-02-14 23:41:06 -0500
commit67ebaf0d22fefa885d29c3c697fbe61956d18354 (patch)
treef9d3f5395054e8eca4292b344b03b4c97f3fa3ad /lib/x86/jump-patch.h
parenttest harness (diff)
downloadsubstitute-67ebaf0d22fefa885d29c3c697fbe61956d18354.tar.gz
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).
Diffstat (limited to '')
-rw-r--r--lib/x86/jump-patch.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/x86/jump-patch.h b/lib/x86/jump-patch.h
index 4c0172d..8cd7d6f 100644
--- a/lib/x86/jump-patch.h
+++ b/lib/x86/jump-patch.h
@@ -1,23 +1,23 @@
#pragma once
-#define MAX_JUMP_PATCH_SIZE 5
+#define MAX_JUMP_PATCH_SIZE 14
#include "dis.h"
-static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc,
+static inline int jump_patch_size(uint_tptr pc, uint_tptr dpc,
UNUSED struct arch_dis_ctx arch,
bool force) {
- uintptr_t diff = pc - (dpc + 5);
+ uint_tptr diff = pc - (dpc + 5);
/* fits in 32? */
- if (diff == (uintptr_t) (int32_t) diff)
+ if (diff == (uint_tptr) (int32_t) diff)
return 5;
else
return force ? (2+4+8) : -1;
}
-static inline void make_jump_patch(void **codep, uintptr_t pc, uintptr_t dpc,
+static inline void make_jump_patch(void **codep, uint_tptr pc, uint_tptr dpc,
UNUSED struct arch_dis_ctx arch) {
- uintptr_t diff = pc - (dpc + 5);
+ uint_tptr diff = pc - (dpc + 5);
void *code = *codep;
- if (diff == (uintptr_t) (int32_t) diff) {
+ if (diff == (uint_tptr) (int32_t) diff) {
op8(&code, 0xe9);
op32(&code, diff);
} else {