diff options
author | comex | 2015-01-24 21:59:37 -0500 |
---|---|---|
committer | comex | 2015-01-24 21:59:37 -0500 |
commit | 98afb15eaa8f8c31bf5763de0e3c83a845414b0a (patch) | |
tree | e603aae961ead4e596fc994ed06df884eaee7b9a /lib/arm64/jump-patch.h | |
parent | Add function to deal with mprotecting RW and back. A bit more complex than t... (diff) | |
download | substitute-98afb15eaa8f8c31bf5763de0e3c83a845414b0a.tar.gz |
...
Diffstat (limited to 'lib/arm64/jump-patch.h')
-rw-r--r-- | lib/arm64/jump-patch.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/arm64/jump-patch.h b/lib/arm64/jump-patch.h new file mode 100644 index 0000000..f0f149f --- /dev/null +++ b/lib/arm64/jump-patch.h @@ -0,0 +1,19 @@ +#pragma once +#include "arm64/assemble.h" +#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) { + intptr_t diff = (dpc & ~0xfff) - (pc & ~0xfff); + if (!(diff >= -0x100000000 && diff < 0x100000000)) + return -1; + else if (pc & 0xfff) + return 8; + else + return 12; +} + +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); +} |