aboutsummaryrefslogtreecommitdiff
path: root/lib/x86/jump-patch.h
diff options
context:
space:
mode:
authorcomex2015-02-08 23:45:24 -0500
committercomex2015-02-08 23:45:24 -0500
commiteb93cee2a22cde812ccd6b9bd418d36185c058f5 (patch)
tree43a22ccf021a1513dba3a9c99f7b81822fe950fa /lib/x86/jump-patch.h
parentformatting (diff)
downloadsubstitute-eb93cee2a22cde812ccd6b9bd418d36185c058f5.tar.gz
Refactor disassembly so x86 works, and add x86 transform-dis.
This patch is a monolithic mess, because I was too lazy to do the refactor first (that would require some stash fun, since I wasn't actually sure before doing x86 transform-dis what would be needed). Anyway, the resulting code should be cleaner - less duplication. This breaks ARM/ARM64.
Diffstat (limited to '')
-rw-r--r--lib/x86/jump-patch.h21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/x86/jump-patch.h b/lib/x86/jump-patch.h
index efd4825..4c0172d 100644
--- a/lib/x86/jump-patch.h
+++ b/lib/x86/jump-patch.h
@@ -1,5 +1,6 @@
#pragma once
#define MAX_JUMP_PATCH_SIZE 5
+#include "dis.h"
static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc,
UNUSED struct arch_dis_ctx arch,
@@ -12,21 +13,19 @@ static inline int jump_patch_size(uintptr_t pc, uintptr_t dpc,
return force ? (2+4+8) : -1;
}
-static inline void make_jump_patch(void **codep, UNUSED uintptr_t pc,
- uintptr_t dpc,
+static inline void make_jump_patch(void **codep, uintptr_t pc, uintptr_t dpc,
UNUSED struct arch_dis_ctx arch) {
uintptr_t diff = pc - (dpc + 5);
- uint8_t *code = *codep;
+ void *code = *codep;
if (diff == (uintptr_t) (int32_t) diff) {
- *(uint8_t *) code = 0xe9;
- *(uint32_t *) (code + 1) = diff;
- *codep = code + 5;
+ op8(&code, 0xe9);
+ op32(&code, diff);
} else {
/* jmpq *(%rip) */
- *code++ = 0xff;
- *code++ = 0x25;
- *(uint32_t *) code = 0; code += 4;
- *(uint64_t *) code = dpc; code += 8;
- *codep = code;
+ op8(&code, 0xff);
+ op8(&code, 0x25);
+ op32(&code, 0);
+ op64(&code, dpc);
}
+ *codep = code;
}