Skip to content
2 changes: 1 addition & 1 deletion crates/bench-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl BenchState {
config.wasm_simd(true);
// NB: do not configure a code cache.

let engine = Engine::new(&config);
let engine = Engine::new(&config)?;
let store = Store::new(&engine);

let mut linker = Linker::new(&store);
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
let config = c.config;
Box::new(wasm_engine_t {
engine: Engine::new(&config),
engine: Engine::new(&config).unwrap(),
})
}
14 changes: 7 additions & 7 deletions crates/fuzzing/src/oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn instantiate_with_config(
Timeout::Fuel(_) => true,
_ => false,
});
let engine = Engine::new(&config);
let engine = Engine::new(&config).unwrap();
let store = Store::new(&engine);

let mut timeout_state = SignalOnDrop::default();
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn instantiate_with_config(
pub fn compile(wasm: &[u8], strategy: Strategy) {
crate::init_fuzzing();

let engine = Engine::new(&crate::fuzz_default_config(strategy).unwrap());
let engine = Engine::new(&crate::fuzz_default_config(strategy).unwrap()).unwrap();
log_wasm(wasm);
let _ = Module::new(&engine, wasm);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ pub fn differential_execution(
log_wasm(&wasm);

for config in &configs {
let engine = Engine::new(config);
let engine = Engine::new(config).unwrap();
let store = Store::new(&engine);

let module = Module::new(&engine, &wasm).unwrap();
Expand Down Expand Up @@ -320,7 +320,7 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
ApiCall::EngineNew => {
log::trace!("creating engine");
assert!(engine.is_none());
engine = Some(Engine::new(config.as_ref().unwrap()));
engine = Some(Engine::new(config.as_ref().unwrap()).unwrap());
}

ApiCall::StoreNew => {
Expand Down Expand Up @@ -416,7 +416,7 @@ pub fn spectest(fuzz_config: crate::generators::Config, test: crate::generators:
let mut config = fuzz_config.to_wasmtime();
config.wasm_reference_types(false);
config.wasm_bulk_memory(false);
let store = Store::new(&Engine::new(&config));
let store = Store::new(&Engine::new(&config).unwrap());
if fuzz_config.consume_fuel {
store.add_fuel(u64::max_value()).unwrap();
}
Expand All @@ -439,7 +439,7 @@ pub fn table_ops(
{
let mut config = fuzz_config.to_wasmtime();
config.wasm_reference_types(true);
let engine = Engine::new(&config);
let engine = Engine::new(&config).unwrap();
let store = Store::new(&engine);
if fuzz_config.consume_fuel {
store.add_fuel(u64::max_value()).unwrap();
Expand Down Expand Up @@ -554,7 +554,7 @@ pub fn differential_wasmi_execution(wasm: &[u8], config: &crate::generators::Con
// Instantiate wasmtime module and instance.
let mut wasmtime_config = config.to_wasmtime();
wasmtime_config.cranelift_nan_canonicalization(true);
let wasmtime_engine = Engine::new(&wasmtime_config);
let wasmtime_engine = Engine::new(&wasmtime_config).unwrap();
let wasmtime_store = Store::new(&wasmtime_engine);
if config.consume_fuel {
wasmtime_store.add_fuel(u64::max_value()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/fuzzing/src/oracles/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ mod tests {
let mut config = Config::default();
config.wasm_module_linking(true);
config.wasm_multi_memory(true);
let engine = wasmtime::Engine::new(&config);
let engine = wasmtime::Engine::new(&config).unwrap();
Store::new(&engine)
}

Expand Down
3 changes: 0 additions & 3 deletions crates/runtime/src/instance/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,6 @@ unsafe impl InstanceAllocator for OnDemandInstanceAllocator {
&self,
mut req: InstanceAllocationRequest,
) -> Result<InstanceHandle, InstantiationError> {
debug_assert!(!req.externref_activations_table.is_null());
debug_assert!(!req.stack_map_registry.is_null());

let memories = self.create_memories(&req.module)?;
let tables = Self::create_tables(&req.module);

Expand Down
26 changes: 11 additions & 15 deletions crates/runtime/src/traphandlers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! WebAssembly trap handling, which is built on top of the lower-level
//! signalhandling mechanisms.

use crate::VMContext;
use crate::VMInterrupts;
use backtrace::Backtrace;
use std::any::Any;
use std::cell::Cell;
Expand Down Expand Up @@ -445,19 +445,15 @@ impl Trap {
/// returning them as a `Result`.
///
/// Highly unsafe since `closure` won't have any dtors run.
pub unsafe fn catch_traps<F>(
vmctx: *mut VMContext,
trap_info: &impl TrapInfo,
mut closure: F,
) -> Result<(), Trap>
pub unsafe fn catch_traps<F>(trap_info: &impl TrapInfo, mut closure: F) -> Result<(), Trap>
where
F: FnMut(),
{
// Ensure that we have our sigaltstack installed.
#[cfg(unix)]
setup_unix_sigaltstack()?;

return CallThreadState::new(vmctx, trap_info).with(|cx| {
return CallThreadState::new(trap_info).with(|cx| {
RegisterSetjmp(
cx.jmp_buf.as_ptr(),
call_closure::<F>,
Expand Down Expand Up @@ -493,7 +489,6 @@ pub fn out_of_gas() {
pub struct CallThreadState<'a> {
unwind: Cell<UnwindReason>,
jmp_buf: Cell<*const u8>,
vmctx: *mut VMContext,
handling_trap: Cell<bool>,
trap_info: &'a (dyn TrapInfo + 'a),
}
Expand Down Expand Up @@ -526,6 +521,9 @@ pub unsafe trait TrapInfo {
///
/// This function may return, and it may also `raise_lib_trap`.
fn out_of_gas(&self);

/// Returns the VM interrupts to use for interrupting Wasm code.
fn interrupts(&self) -> &VMInterrupts;
}

enum UnwindReason {
Expand All @@ -537,10 +535,9 @@ enum UnwindReason {
}

impl<'a> CallThreadState<'a> {
fn new(vmctx: *mut VMContext, trap_info: &'a (dyn TrapInfo + 'a)) -> CallThreadState<'a> {
fn new(trap_info: &'a (dyn TrapInfo + 'a)) -> CallThreadState<'a> {
CallThreadState {
unwind: Cell::new(UnwindReason::None),
vmctx,
jmp_buf: Cell::new(ptr::null()),
handling_trap: Cell::new(false),
trap_info,
Expand All @@ -562,10 +559,9 @@ impl<'a> CallThreadState<'a> {
UnwindReason::LibTrap(trap) => Err(trap),
UnwindReason::JitTrap { backtrace, pc } => {
debug_assert_eq!(ret, 0);
let maybe_interrupted = unsafe {
let interrupts = (*self.vmctx).instance().interrupts();
(**interrupts).stack_limit.load(SeqCst) == wasmtime_environ::INTERRUPTED
};
let interrupts = self.trap_info.interrupts();
let maybe_interrupted =
interrupts.stack_limit.load(SeqCst) == wasmtime_environ::INTERRUPTED;
Err(Trap::Jit {
pc,
backtrace,
Expand Down Expand Up @@ -622,7 +618,7 @@ impl<'a> CallThreadState<'a> {
// (a million bytes) the slop shouldn't matter too much.
let wasm_stack_limit = psm::stack_pointer() as usize - self.trap_info.max_wasm_stack();

let interrupts = unsafe { &**(&*self.vmctx).instance().interrupts() };
let interrupts = self.trap_info.interrupts();
let reset_stack_limit = match interrupts.stack_limit.compare_exchange(
usize::max_value(),
wasm_stack_limit,
Expand Down
11 changes: 10 additions & 1 deletion crates/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use std::cell::RefCell;
use std::rc::Rc;
pub use wasi_common::{Error, WasiCtx, WasiCtxBuilder, WasiDir, WasiFile};
use wasmtime::{Linker, Store};
use wasmtime::{Config, Linker, Store};

/// An instantiated instance of all available wasi exports. Presently includes
/// both the "preview1" snapshot and the "unstable" (preview0) snapshot.
Expand All @@ -34,6 +34,15 @@ impl Wasi {
self.preview_0.add_to_linker(linker)?;
Ok(())
}
pub fn add_to_config(config: &mut Config) {
snapshots::preview_1::Wasi::add_to_config(config);
snapshots::preview_0::Wasi::add_to_config(config);
}
pub fn set_context(store: &Store, context: WasiCtx) -> Result<(), WasiCtx> {
// It doesn't matter which underlying `Wasi` type this gets called on as the
// implementations are identical
snapshots::preview_1::Wasi::set_context(store, context)
}
}

pub mod snapshots {
Expand Down
Loading