From 6ca4530067ac25a78291b176b6d3dbe6ba592d15 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Tue, 30 Sep 2025 11:02:37 +0200 Subject: 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. --- executor/common_kvm_arm64.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'executor/common_kvm_arm64.h') diff --git a/executor/common_kvm_arm64.h b/executor/common_kvm_arm64.h index 4428a3484..badfcf417 100644 --- a/executor/common_kvm_arm64.h +++ b/executor/common_kvm_arm64.h @@ -144,11 +144,20 @@ static void vcpu_set_reg(int vcpu_fd, uint64 id, uint64 val) ioctl(vcpu_fd, KVM_SET_ONE_REG, ®); } +// 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, ARM64_ADDR_EXECUTOR_CODE, error_in_executor_fn_guest_addr()); + // Set up CPU registers. static void reset_cpu_regs(int cpufd, int cpu_id, size_t text_size) { // PC points to the relative offset of guest_main() within the guest code. - vcpu_set_reg(cpufd, KVM_ARM64_REGS_PC, ARM64_ADDR_EXECUTOR_CODE + ((uint64)guest_main - (uint64)&__start_guest)); + vcpu_set_reg(cpufd, KVM_ARM64_REGS_PC, executor_fn_guest_addr((uintptr_t)guest_main)); vcpu_set_reg(cpufd, KVM_ARM64_REGS_SP_EL1, ARM64_ADDR_EL1_STACK_BOTTOM + KVM_PAGE_SIZE - 128); // Store the CPU ID in TPIDR_EL1. vcpu_set_reg(cpufd, KVM_ARM64_REGS_TPIDR_EL1, cpu_id); -- cgit mrf-deployment