diff --git a/src/wasmtime/crates/lind-multi-process/src/lib.rs b/src/wasmtime/crates/lind-multi-process/src/lib.rs index 7076c7f3..22ce284f 100644 --- a/src/wasmtime/crates/lind-multi-process/src/lib.rs +++ b/src/wasmtime/crates/lind-multi-process/src/lib.rs @@ -11,7 +11,7 @@ use std::path::Path; use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; use std::sync::{Arc, Barrier}; use std::thread; -use wasmtime::{AsContext, AsContextMut, Caller, ExternType, Linker, Module, SharedMemory, Store, Val, OnCalledAction, RewindingReturn, StoreOpaque, InstanceId}; +use wasmtime::{AsContext, AsContextMut, Caller, Engine, ExternType, InstanceId, Linker, Module, OnCalledAction, RewindingReturn, SharedMemory, Store, StoreOpaque, Val}; use wasmtime_environ::MemoryIndex; @@ -316,6 +316,8 @@ impl Store { self.inner.set_epoch_deadline(ticks_beyond_current); } + // get current epoch deadline + pub fn get_epoch_deadline(&self) -> u64 { + self.inner.get_epoch_deadline() + } + /// Configures epoch-deadline expiration to trap. /// /// When epoch-interruption-instrumented code is executed on this diff --git a/src/wasmtime/src/commands/run.rs b/src/wasmtime/src/commands/run.rs index 57abdc0d..de7e00a3 100644 --- a/src/wasmtime/src/commands/run.rs +++ b/src/wasmtime/src/commands/run.rs @@ -19,7 +19,7 @@ use std::sync::atomic::AtomicU64; use std::sync::{Arc, Mutex}; use std::thread; use wasi_common::sync::{ambient_authority, Dir, TcpListener, WasiCtxBuilder}; -use wasmtime::{AsContextMut, Engine, Func, Module, Store, StoreLimits, Val, ValType}; +use wasmtime::{AsContextMut, Engine, Func, Module, Store, StoreLimits, UpdateDeadline, Val, ValType}; use wasmtime_wasi::WasiView; use wasmtime_lind_utils::LindCageManager; @@ -424,6 +424,10 @@ impl RunCommand { thread::sleep(timeout); engine.increment_epoch(); }); + // if epoch_interruption is enabled, we need to set the epoch deadline to at least 1 + // otherwise the wasm process will be interrupted immediately once started as the default deadline is 0 + } else if self.run.common.wasm.epoch_interruption.is_some() { + store.set_epoch_deadline(1); } Ok(Box::new(|_store| {}))