aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_kvm_amd64.h
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2025-09-30 11:02:37 +0200
committerAlexander Potapenko <glider@google.com>2025-10-17 06:51:20 +0000
commit6ca4530067ac25a78291b176b6d3dbe6ba592d15 (patch)
tree731490cefa5b43b5ccf48f83f77979a829da72c0 /executor/common_kvm_amd64.h
parent554d3ef1c24ae1bc3c8c439e8c8f3a9006434244 (diff)
executor: introduce DEFINE_GUEST_FN_TO_GPA_FN()
DEFINE_GUEST_FN_TO_GPA_FN() allows to define helper functions to calculate guest addresses in the host/guest code.
Diffstat (limited to 'executor/common_kvm_amd64.h')
-rw-r--r--executor/common_kvm_amd64.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/executor/common_kvm_amd64.h b/executor/common_kvm_amd64.h
index 718d63243..39804b4b8 100644
--- a/executor/common_kvm_amd64.h
+++ b/executor/common_kvm_amd64.h
@@ -883,6 +883,16 @@ static volatile long syz_kvm_setup_cpu(volatile long a0, volatile long a1, volat
#endif
#if SYZ_EXECUTOR || __NR_syz_kvm_add_vcpu
+
+// Post-processing code in pkg/csource/csource.go is very picky and won't let us directly pass
+// fail() to DEFINE_GUEST_FN_TO_GPA_FN.
+static inline void error_in_executor_fn_guest_addr()
+{
+ fail("SYZOS: executor_fn_guest_addr: invalid guest address");
+}
+
+DEFINE_GUEST_FN_TO_GPA_FN(executor_fn_guest_addr, X86_SYZOS_ADDR_EXECUTOR_CODE, error_in_executor_fn_guest_addr());
+
static void reset_cpu_regs(int cpufd, int cpu_id, size_t text_size)
{
struct kvm_regs regs;
@@ -890,7 +900,7 @@ static void reset_cpu_regs(int cpufd, int cpu_id, size_t text_size)
regs.rflags |= 2; // bit 1 is always set
// PC points to the relative offset of guest_main() within the guest code.
- regs.rip = X86_SYZOS_ADDR_EXECUTOR_CODE + ((uint64)guest_main - (uint64)&__start_guest);
+ regs.rip = executor_fn_guest_addr((uintptr_t)guest_main);
regs.rsp = X86_SYZOS_ADDR_STACK0;
// Pass parameters to guest_main().
regs.rdi = text_size;