From a18719fd248081a2eb121e5cba656fd2a10cbd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20Jozi=C4=87?= Date: Wed, 4 Oct 2023 17:04:23 +0200 Subject: [PATCH] Fix FreeBSD ucontext_t issues --- lib/vm/src/trap/traphandlers.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index 51389d8a09a..00627b990cd 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -52,7 +52,25 @@ struct ucontext_t { uc_mcontext: libc::mcontext_t, } -#[cfg(all(unix, not(all(target_arch = "aarch64", target_os = "macos"))))] +// Current definition of `ucontext_t` in the `libc` crate is not present +// on aarch64-unknown-freebsd so it's defined here. +#[repr(C)] +#[cfg(all(target_arch = "aarch64", target_os = "freebsd"))] +#[allow(non_camel_case_types)] +struct ucontext_t { + uc_sigmask: libc::sigset_t, + uc_mcontext: libc::mcontext_t, + uc_link: *mut ucontext_t, + uc_stack: libc::stack_t, + uc_flags: libc::c_int, + spare: [libc::c_int; 4], +} + +#[cfg(all( + unix, + not(all(target_arch = "aarch64", target_os = "macos")), + not(all(target_arch = "aarch64", target_os = "freebsd")) +))] use libc::ucontext_t; /// Default stack size is 1MB. @@ -434,7 +452,8 @@ cfg_if::cfg_if! { (*context.uc_mcontext).__ss.__fp = x29; (*context.uc_mcontext).__ss.__lr = lr; } else if #[cfg(all(target_os = "freebsd", target_arch = "aarch64"))] { - context.uc_mcontext.mc_gpregs.gp_pc = pc as libc::register_t; + let TrapHandlerRegs { pc, sp, x0, x1, x29, lr } = regs; + context.uc_mcontext.mc_gpregs.gp_elr = pc as libc::register_t; context.uc_mcontext.mc_gpregs.gp_sp = sp as libc::register_t; context.uc_mcontext.mc_gpregs.gp_x[0] = x0 as libc::register_t; context.uc_mcontext.mc_gpregs.gp_x[1] = x1 as libc::register_t;