aboutsummaryrefslogtreecommitdiff
path: root/driver/sanitizer_hooks_with_pc.cpp
diff options
context:
space:
mode:
authorFabian Meumertzheim <fabian@meumertzhe.im>2021-10-16 09:08:56 +0200
committerFabian Meumertzheim <fabian@meumertzhe.im>2021-10-18 22:31:42 +0200
commit34784b75639dff03db2e5fbcd69a4569c2ade3d3 (patch)
treebb7b7905add117eb309e92eb93822fb2fb5e9c64 /driver/sanitizer_hooks_with_pc.cpp
parent5a3da229c53462d2d3990a52ab5d5056da4b0640 (diff)
downloadjazzer-api-34784b75639dff03db2e5fbcd69a4569c2ade3d3.tar.gz
Adapt inline asm for Windows
Diffstat (limited to 'driver/sanitizer_hooks_with_pc.cpp')
-rw-r--r--driver/sanitizer_hooks_with_pc.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/driver/sanitizer_hooks_with_pc.cpp b/driver/sanitizer_hooks_with_pc.cpp
index ceb9513b..af538163 100644
--- a/driver/sanitizer_hooks_with_pc.cpp
+++ b/driver/sanitizer_hooks_with_pc.cpp
@@ -36,6 +36,20 @@
#define REPEAT_4096(a) REPEAT_16(REPEAT_16(REPEAT_16(a)))
+// The first four registers to pass arguments in according to the
+// platform-specific x64 calling convention.
+#ifdef _WIN64
+#define REG_1 "rcx"
+#define REG_2 "rdx"
+#define REG_3 "r8"
+#define REG_4 "r9"
+#else
+#define REG_1 "rdi"
+#define REG_2 "rsi"
+#define REG_3 "rdx"
+#define REG_4 "rcx"
+#endif
+
// Call the function at address `func` with arguments `arg1` and `arg2` while
// ensuring that the return address is `fake_pc` up to a globally constant
// offset.
@@ -44,10 +58,10 @@ __attribute__((noinline)) void trampoline(uint64_t arg1, uint64_t arg2,
// arg1 and arg2 have to be forwarded according to the x64 calling convention.
// We also fix func and fake_pc to their registers so that we can safely use
// rax below.
- [[maybe_unused]] register uint64_t arg1_loc asm("rdi") = arg1;
- [[maybe_unused]] register uint64_t arg2_loc asm("rsi") = arg2;
- [[maybe_unused]] register void *func_loc asm("rdx") = func;
- [[maybe_unused]] register uint64_t fake_pc_loc asm("rcx") = fake_pc;
+ [[maybe_unused]] register uint64_t arg1_loc asm(REG_1) = arg1;
+ [[maybe_unused]] register uint64_t arg2_loc asm(REG_2) = arg2;
+ [[maybe_unused]] register void *func_loc asm(REG_3) = func;
+ [[maybe_unused]] register uint64_t fake_pc_loc asm(REG_4) = fake_pc;
asm volatile goto(
// Load RIP-relative address of the end of this function.
"lea %l[end_of_function](%%rip), %%rax \n\t"