From 152b0ec12697db4a822fd5bd11326b1d923b9271 Mon Sep 17 00:00:00 2001 From: Arsenii Lyashenko Date: Sun, 6 Oct 2024 05:19:41 +0300 Subject: [PATCH] Try to fix halted tests --- Cargo.lock | 12 +----------- lazy-pages/Cargo.toml | 1 + lazy-pages/src/lib.rs | 5 +++++ sandbox/sandbox/Cargo.toml | 2 -- sandbox/sandbox/src/embedded_executor.rs | 18 ++++++++++++------ sandbox/sandbox/src/host_executor.rs | 2 ++ 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0dbb7e1720..e2bec45e0e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3186,16 +3186,6 @@ dependencies = [ "subtle 2.6.1", ] -[[package]] -name = "ctor" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" -dependencies = [ - "quote", - "syn 2.0.71", -] - [[package]] name = "ctr" version = "0.7.0" @@ -6643,6 +6633,7 @@ dependencies = [ "errno", "gear-core", "gear-lazy-pages-common", + "gear-sandbox", "gear-sandbox-host", "libc", "log", @@ -6866,7 +6857,6 @@ name = "gear-sandbox" version = "1.6.1" dependencies = [ "assert_matches", - "ctor", "gear-sandbox-env", "gear-sandbox-interface", "gear-wasmer-cache", diff --git a/lazy-pages/Cargo.toml b/lazy-pages/Cargo.toml index d0bb3f5f295..5f084554324 100644 --- a/lazy-pages/Cargo.toml +++ b/lazy-pages/Cargo.toml @@ -19,6 +19,7 @@ derive_more.workspace = true numerated.workspace = true gear-sandbox-host.workspace = true +gear-sandbox.workspace = true gear-core.workspace = true gear-lazy-pages-common.workspace = true diff --git a/lazy-pages/src/lib.rs b/lazy-pages/src/lib.rs index c0bd86c1e6d..273b97a5c6e 100644 --- a/lazy-pages/src/lib.rs +++ b/lazy-pages/src/lib.rs @@ -442,6 +442,11 @@ pub fn init_with_handler( }) }); + // TODO: remove after usage of `wasmi::Store::set_trap_handler` for lazy-pages + // we capture executor signal handlers first to call them later + // if our handlers are not effective + gear_sandbox::default_executor::init_traps(); + unsafe { init_for_process::()? } unsafe { sys::init_for_thread().map_err(InitForThread)? } diff --git a/sandbox/sandbox/Cargo.toml b/sandbox/sandbox/Cargo.toml index c847e59e4e0..936382d4542 100644 --- a/sandbox/sandbox/Cargo.toml +++ b/sandbox/sandbox/Cargo.toml @@ -22,7 +22,6 @@ wasmer-types = { workspace = true, optional = true } wasmer-vm = { workspace = true, optional = true } wasmer-compiler = { workspace = true, optional = true } gear-wasmer-cache = { workspace = true, optional = true } -ctor = { version = "0.2.8", optional = true } sp-core.workspace = true sp-std.workspace = true sp-wasm-interface-common.workspace = true @@ -48,6 +47,5 @@ std = [ "wasmer-vm", "wasmer-compiler", "gear-wasmer-cache", - "ctor", ] strict = [] diff --git a/sandbox/sandbox/src/embedded_executor.rs b/sandbox/sandbox/src/embedded_executor.rs index 043a7e86bf0..b36dbdc5c50 100644 --- a/sandbox/sandbox/src/embedded_executor.rs +++ b/sandbox/sandbox/src/embedded_executor.rs @@ -18,6 +18,8 @@ //! An embedded WASM executor utilizing `wasmi`. +pub use wasmer_vm::init_traps; + use crate::{ AsContextExt, Error, GlobalsSetError, HostError, HostFuncType, ReturnValue, SandboxStore, Value, TARGET, @@ -38,12 +40,6 @@ use wasmer::{ }; use wasmer_types::{ExternType, Target}; -// TODO: remove after usage of `wasmi::Store::set_trap_handler` for lazy-pages -#[ctor::ctor] -fn init_wasmer() { - wasmer_vm::init_traps(); -} - fn fs_cache() -> PathBuf { const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); assert!(MANIFEST_DIR.ends_with("sandbox/sandbox")); @@ -202,6 +198,11 @@ impl Store { fn engine(&self) -> &Engine { self.inner.engine() } + + fn trap_handler() -> bool { + log::trace!("`wasmer::Store::set_trap_handler` call"); + false + } } impl SandboxStore for Store { @@ -212,6 +213,11 @@ impl SandboxStore for Store { .with_wasm_stack_size(16 * 1024 * 1024); engine.set_tunables(tunables); let mut store = wasmer::Store::new(engine); + #[cfg(unix)] + let trap_handler = |_, _, _| Self::trap_handler(); + #[cfg(windows)] + let trap_handler = |_| Self::trap_handler(); + store.set_trap_handler(Some(Box::new(trap_handler))); let state = FunctionEnv::new(&mut store, InnerState::new(state)); diff --git a/sandbox/sandbox/src/host_executor.rs b/sandbox/sandbox/src/host_executor.rs index a05be46ca7a..cda895eb342 100644 --- a/sandbox/sandbox/src/host_executor.rs +++ b/sandbox/sandbox/src/host_executor.rs @@ -28,6 +28,8 @@ use sp_core::RuntimeDebug; use sp_std::{marker, mem, prelude::*, rc::Rc, slice, vec}; use sp_wasm_interface_common::HostPointer; +pub fn init_traps() {} + mod ffi { use super::HostFuncType; use sp_std::mem;