From e45add21acd1bfcbe0cd65a5534b607e27256602 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Fri, 21 Apr 2023 12:32:13 +0000 Subject: [PATCH] Add FreeBSD x86 support (#3782) Co-authored-by: ptitSeb --- lib/vm/src/trap/traphandlers.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index a5c75cf83a0..10e8a352841 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -264,7 +264,10 @@ cfg_if::cfg_if! { ))] { pc = context.uc_mcontext.gregs[libc::REG_EIP as usize] as usize; sp = context.uc_mcontext.gregs[libc::REG_ESP as usize] as usize; - } else if #[cfg(all(target_os = "freebsd", any(target_arch = "x86", target_arch = "x86_64")))] { + } else if #[cfg(all(target_os = "freebsd", target_arch = "x86"))] { + pc = context.uc_mcontext.mc_eip as usize; + sp = context.uc_mcontext.mc_esp as usize; + } else if #[cfg(all(target_os = "freebsd", target_arch = "x86_64"))] { pc = context.uc_mcontext.mc_rip as usize; sp = context.uc_mcontext.mc_rsp as usize; } else if #[cfg(all(target_vendor = "apple", target_arch = "x86_64"))] { @@ -330,6 +333,13 @@ cfg_if::cfg_if! { (*context.uc_mcontext).__ss.__rbp = rbp; (*context.uc_mcontext).__ss.__rdi = rdi; (*context.uc_mcontext).__ss.__rsi = rsi; + } else if #[cfg(all(target_os = "freebsd", target_arch = "x86"))] { + let TrapHandlerRegs { eip, esp, ebp, ecx, edx } = regs; + context.uc_mcontext.mc_eip = eip as libc::register_t; + context.uc_mcontext.mc_esp = esp as libc::register_t; + context.uc_mcontext.mc_ebp = ebp as libc::register_t; + context.uc_mcontext.mc_ecx = ecx as libc::register_t; + context.uc_mcontext.mc_edx = edx as libc::register_t; } else if #[cfg(all(target_os = "freebsd", target_arch = "x86_64"))] { let TrapHandlerRegs { rip, rsp, rbp, rdi, rsi } = regs; context.uc_mcontext.mc_rip = rip as libc::register_t;