Skip to content

Commit

Permalink
Try to fix halted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f committed Oct 6, 2024
1 parent e1c746a commit 152b0ec
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
12 changes: 1 addition & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lazy-pages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lazy-pages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ pub fn init_with_handler<H: UserSignalHandler, S: LazyPagesStorage + 'static>(
})
});

// 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::<H>()? }

unsafe { sys::init_for_thread().map_err(InitForThread)? }
Expand Down
2 changes: 0 additions & 2 deletions sandbox/sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,6 +47,5 @@ std = [
"wasmer-vm",
"wasmer-compiler",
"gear-wasmer-cache",
"ctor",
]
strict = []
18 changes: 12 additions & 6 deletions sandbox/sandbox/src/embedded_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"));
Expand Down Expand Up @@ -202,6 +198,11 @@ impl<T> Store<T> {
fn engine(&self) -> &Engine {
self.inner.engine()
}

fn trap_handler() -> bool {
log::trace!("`wasmer::Store::set_trap_handler` call");
false
}
}

impl<T: Send + 'static> SandboxStore for Store<T> {
Expand All @@ -212,6 +213,11 @@ impl<T: Send + 'static> SandboxStore for Store<T> {
.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));

Expand Down
2 changes: 2 additions & 0 deletions sandbox/sandbox/src/host_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 152b0ec

Please sign in to comment.