From 663166c5a38158ea29ee30d6c7ac3473ab8d0c32 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Fri, 8 May 2020 18:55:02 -0400 Subject: [PATCH] Add FreeBSD x86-64 support to runtime trap handler --- crates/runtime/src/helpers.c | 9 +++++++++ crates/runtime/src/traphandlers.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/runtime/src/helpers.c b/crates/runtime/src/helpers.c index 6436922243da..6f9fc9520804 100644 --- a/crates/runtime/src/helpers.c +++ b/crates/runtime/src/helpers.c @@ -27,6 +27,15 @@ void* GetPcFromUContext(ucontext_t *cx) { } #endif +#if defined(__FreeBSD__) && defined(__x86_64__) +#include + +void* GetPcFromUContext(ucontext_t *cx) { + return (void*) cx->uc_mcontext.mc_rip; +} +#endif + + #if defined(__linux__) && defined(__aarch64__) #include diff --git a/crates/runtime/src/traphandlers.rs b/crates/runtime/src/traphandlers.rs index 9ec38ba87247..76075e501141 100644 --- a/crates/runtime/src/traphandlers.rs +++ b/crates/runtime/src/traphandlers.rs @@ -164,7 +164,7 @@ cfg_if::cfg_if! { fn GetPcFromUContext(cx: *mut libc::c_void) -> *const u8; } GetPcFromUContext(cx) - } else if #[cfg(target_os = "macos")] { + } else if #[cfg(any(target_os = "macos", target_os = "freebsd"))] { // FIXME(rust-lang/libc#1702) - once that lands and is // released we should inline the definition here extern "C" {