From ea83733df6062bffce32e5d5c1344aded2413e9c Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Fri, 22 Sep 2023 11:52:53 +0100 Subject: [PATCH] Disable timeout in musl libc (#71) Signed-off-by: Jorge Prendes --- crates/wasmedge-sys/src/executor.rs | 37 +++++++++++++++++------------ src/executor.rs | 11 +++++---- src/externals/function.rs | 11 +++++---- src/vm.rs | 9 ++++--- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/crates/wasmedge-sys/src/executor.rs b/crates/wasmedge-sys/src/executor.rs index 9fd9dbbe8..6ca78f5ba 100644 --- a/crates/wasmedge-sys/src/executor.rs +++ b/crates/wasmedge-sys/src/executor.rs @@ -2,27 +2,31 @@ use super::ffi; #[cfg(all(feature = "async", target_os = "linux"))] -use crate::r#async::fiber::{AsyncState, FiberFuture, TimeoutFiberFuture}; +use crate::r#async::fiber::{AsyncState, FiberFuture}; + +#[cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))] +use crate::r#async::fiber::TimeoutFiberFuture; + use crate::{ instance::module::InnerInstance, types::WasmEdgeString, utils::check, Config, Engine, FuncRef, Function, ImportModule, Instance, Module, Statistics, Store, WasiInstance, WasmEdgeResult, WasmValue, }; use parking_lot::Mutex; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] use std::os::raw::c_void; use std::sync::Arc; use wasmedge_types::error::WasmEdgeError; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] pub(crate) struct JmpState { pub(crate) sigjmp_buf: *mut setjmp::sigjmp_buf, } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] scoped_tls::scoped_thread_local!(pub(crate) static JMP_BUF: JmpState); -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] unsafe extern "C" fn sync_timeout(sig: i32, info: *mut libc::siginfo_t) { if let Some(info) = info.as_mut() { let si_value = info.si_value(); @@ -39,7 +43,7 @@ unsafe extern "C" fn sync_timeout(sig: i32, info: *mut libc::siginfo_t) { } } } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] unsafe extern "C" fn pre_host_func(_: *mut c_void) { use libc::SIG_BLOCK; @@ -48,7 +52,7 @@ unsafe extern "C" fn pre_host_func(_: *mut c_void) { libc::sigaddset(&mut set, timeout_signo()); libc::pthread_sigmask(SIG_BLOCK, &set, std::ptr::null_mut()); } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] unsafe extern "C" fn post_host_func(_: *mut c_void) { use libc::SIG_UNBLOCK; @@ -59,7 +63,7 @@ unsafe extern "C" fn post_host_func(_: *mut c_void) { } #[inline] -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] pub(crate) fn timeout_signo() -> i32 { option_env!("SIG_OFFSET") .and_then(|s| s.parse().ok()) @@ -67,11 +71,11 @@ pub(crate) fn timeout_signo() -> i32 { + libc::SIGRTMIN() } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] static INIT_SIGNAL_LISTEN: std::sync::Once = std::sync::Once::new(); #[inline(always)] -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] pub(crate) unsafe fn init_signal_listen() { INIT_SIGNAL_LISTEN.call_once(|| { let mut new_act: libc::sigaction = std::mem::zeroed(); @@ -120,7 +124,7 @@ impl Executor { match ctx.is_null() { true => Err(Box::new(WasmEdgeError::ExecutorCreate)), false => { - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "musl")))] unsafe { ffi::WasmEdge_ExecutorExperimentalRegisterPreHostFunction( ctx, @@ -364,8 +368,8 @@ impl Executor { /// # Errors /// /// If fail to run the host function, then an error is returned. - #[cfg(target_os = "linux")] - #[cfg_attr(docsrs, doc(cfg(target_os = "linux")))] + #[cfg(all(target_os = "linux", not(target_env = "musl")))] + #[cfg_attr(docsrs, doc(cfg(all(target_os = "linux", not(target_env = "musl")))))] pub fn call_func_with_timeout( &self, func: &Function, @@ -467,8 +471,11 @@ impl Executor { /// # Errors /// /// If fail to run the host function, then an error is returned. - #[cfg(all(feature = "async", target_os = "linux"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "async", target_os = "linux"))))] + #[cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))) + )] #[cfg(feature = "async")] pub async fn call_func_async_with_timeout( &self, diff --git a/src/executor.rs b/src/executor.rs index 4378bc5ae..8a5a258e7 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -71,8 +71,8 @@ impl Executor { /// # Errors /// /// If fail to run the host function, then an error is returned. - #[cfg(target_os = "linux")] - #[cfg_attr(docsrs, doc(cfg(target_os = "linux")))] + #[cfg(all(target_os = "linux", not(target_env = "musl")))] + #[cfg_attr(docsrs, doc(cfg(all(target_os = "linux", not(target_env = "musl")))))] pub fn run_func_with_timeout( &self, func: &Func, @@ -124,8 +124,11 @@ impl Executor { /// # Errors /// /// If fail to run the host function, then an error is returned. - #[cfg(all(feature = "async", target_os = "linux"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "async", target_os = "linux"))))] + #[cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))) + )] pub async fn run_func_async_with_timeout( &self, async_state: &AsyncState, diff --git a/src/externals/function.rs b/src/externals/function.rs index 774c66302..e1b792db1 100644 --- a/src/externals/function.rs +++ b/src/externals/function.rs @@ -256,8 +256,8 @@ impl Func { /// # Error /// /// If fail to run the host function, then an error is returned. - #[cfg(target_os = "linux")] - #[cfg_attr(docsrs, doc(cfg(target_os = "linux")))] + #[cfg(all(target_os = "linux", not(target_env = "musl")))] + #[cfg_attr(docsrs, doc(cfg(all(target_os = "linux", not(target_env = "musl")))))] pub fn run_with_timeout( &self, executor: &Executor, @@ -302,8 +302,11 @@ impl Func { /// # Error /// /// If fail to run the host function, then an error is returned. - #[cfg(all(feature = "async", target_os = "linux"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "async", target_os = "linux"))))] + #[cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))) + )] pub async fn run_async_with_timeout( &self, async_state: &AsyncState, diff --git a/src/vm.rs b/src/vm.rs index ca4c483cc..71173f666 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -501,7 +501,7 @@ impl Vm { /// # Error /// /// If fail to run the wasm function, then an error is returned. - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "musl")))] pub fn run_func_with_timeout( &self, mod_name: Option<&str>, @@ -594,8 +594,11 @@ impl Vm { /// # Error /// /// If fail to run the wasm function, then an error is returned. - #[cfg(all(feature = "async", target_os = "linux"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "async", target_os = "linux"))))] + #[cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "async", target_os = "linux", not(target_env = "musl")))) + )] pub async fn run_func_async_with_timeout( &self, async_state: &AsyncState,