Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable timeout functionality when building for musl libc #71

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions crates/wasmedge-sys/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -59,19 +63,19 @@ 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())
.unwrap_or(0)
+ 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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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,
Expand Down