From d91f0c3933e90cb2946655ed1f34cc4698b0ae91 Mon Sep 17 00:00:00 2001 From: subtly Date: Wed, 7 Oct 2020 06:30:14 -0500 Subject: [PATCH] get pc for freebsd (#2270) * get pc for freebsd * whitespace :| * fix; i386 to x86 * remove x86 since uc_mcontext isn't yet in libc * freebsd build of rust uses libcc/unwind --- crates/jit/src/unwind/systemv.rs | 4 ++-- crates/runtime/src/traphandlers.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/jit/src/unwind/systemv.rs b/crates/jit/src/unwind/systemv.rs index b5890fbbfa..b449f5d176 100644 --- a/crates/jit/src/unwind/systemv.rs +++ b/crates/jit/src/unwind/systemv.rs @@ -90,7 +90,7 @@ impl UnwindRegistry { let mut eh_frame = EhFrame(EndianVec::new(RunTimeEndian::default())); table.write_eh_frame(&mut eh_frame).unwrap(); - if cfg!(all(target_os = "linux", target_env = "gnu")) { + if cfg!(any(all(target_os = "linux", target_env = "gnu"), target_os = "freebsd")) { // libgcc expects a terminating "empty" length, so write a 0 length at the end of the table. eh_frame.0.write_u32(0).unwrap(); } @@ -101,7 +101,7 @@ impl UnwindRegistry { } unsafe fn register_frames(&mut self) { - if cfg!(all(target_os = "linux", target_env = "gnu")) { + if cfg!(any(all(target_os = "linux", target_env = "gnu"), target_os = "freebsd")) { // On gnu (libgcc), `__register_frame` will walk the FDEs until an entry of length 0 let ptr = self.frame_table.as_ptr(); __register_frame(ptr); diff --git a/crates/runtime/src/traphandlers.rs b/crates/runtime/src/traphandlers.rs index 198d03a640..f7ee445a1d 100644 --- a/crates/runtime/src/traphandlers.rs +++ b/crates/runtime/src/traphandlers.rs @@ -73,7 +73,7 @@ cfg_if::cfg_if! { // On ARM, handle Unaligned Accesses. // On Darwin, guard page accesses are raised as SIGBUS. - if cfg!(target_arch = "arm") || cfg!(target_os = "macos") { + if cfg!(target_arch = "arm") || cfg!(target_os = "macos") || cfg!(target_os = "freebsd") { register(&mut PREV_SIGBUS, libc::SIGBUS); } } @@ -167,6 +167,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "macos")] { let cx = &*(cx as *const libc::ucontext_t); (*cx.uc_mcontext).__ss.__rip as *const u8 + } else if #[cfg(all(target_os = "freebsd", target_arch = "x86_64"))] { + let cx = &*(cx as *const libc::ucontext_t); + cx.uc_mcontext.mc_rip as *const u8 } else { compile_error!("unsupported platform"); }