diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index da763a5803..d30917294d 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/crates/cranelift/src/func_environ.rs @@ -593,7 +593,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { // The reason is that one can construct a "zip-bomb-like" // program with exponential-in-program-size runtime, with no // backedges (loops), by building a tree of function calls: f0 - // calls f1 ten tims, f1 calls f2 ten times, etc. E.g., nine + // calls f1 ten times, f1 calls f2 ten times, etc. E.g., nine // levels of this yields a billion function calls with no // backedges. So we can't do checks only at backedges. // diff --git a/crates/wasmtime/src/store.rs b/crates/wasmtime/src/store.rs index 67334b52f4..cb56e67822 100644 --- a/crates/wasmtime/src/store.rs +++ b/crates/wasmtime/src/store.rs @@ -1856,7 +1856,14 @@ unsafe impl wasmtime_runtime::Store for StoreInner { fn new_epoch(&mut self) -> Result { return match &self.epoch_deadline_behavior { - &EpochDeadline::Trap => Err(anyhow::Error::new(EpochDeadlineError)), + &EpochDeadline::Trap => { + let trap = Trap::new_wasm( + None, + wasmtime_environ::TrapCode::Interrupt, + wasmtime_runtime::Backtrace::new(), + ); + Err(anyhow::Error::from(trap)) + } #[cfg(feature = "async")] &EpochDeadline::YieldAndExtendDeadline { delta } => { // Do the async yield. May return a trap if future was @@ -1870,17 +1877,6 @@ unsafe impl wasmtime_runtime::Store for StoreInner { Ok(self.get_epoch_deadline()) } }; - - #[derive(Debug)] - struct EpochDeadlineError; - - impl fmt::Display for EpochDeadlineError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("epoch deadline reached during execution") - } - } - - impl std::error::Error for EpochDeadlineError {} } } diff --git a/examples/interrupt.rs b/examples/interrupt.rs index 61a2cdab75..70d7965a3a 100644 --- a/examples/interrupt.rs +++ b/examples/interrupt.rs @@ -29,7 +29,7 @@ fn main() -> Result<()> { let trap = run.call(&mut store, ()).unwrap_err(); println!("trap received..."); - assert!(trap.to_string().contains("epoch deadline reached")); + assert!(trap.trap_code().unwrap() == TrapCode::Interrupt); Ok(()) } diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs index 18875be061..42520a5238 100644 --- a/tests/all/cli_tests.rs +++ b/tests/all/cli_tests.rs @@ -175,7 +175,7 @@ fn timeout_in_start() -> Result<()> { assert_eq!(output.stdout, b""); let stderr = String::from_utf8_lossy(&output.stderr); assert!( - stderr.contains("epoch deadline reached during execution"), + stderr.contains("wasm trap: interrupt"), "bad stderr: {}", stderr ); @@ -196,7 +196,7 @@ fn timeout_in_invoke() -> Result<()> { assert_eq!(output.stdout, b""); let stderr = String::from_utf8_lossy(&output.stderr); assert!( - stderr.contains("epoch deadline reached during execution"), + stderr.contains("wasm trap: interrupt"), "bad stderr: {}", stderr ); diff --git a/tests/all/iloop.rs b/tests/all/iloop.rs index 9f1b6bbe91..1947a59c44 100644 --- a/tests/all/iloop.rs +++ b/tests/all/iloop.rs @@ -33,7 +33,7 @@ fn loops_interruptable() -> anyhow::Result<()> { store.engine().increment_epoch(); let trap = iloop.call(&mut store, ()).unwrap_err(); assert!( - trap.to_string().contains("epoch deadline reached"), + trap.trap_code().unwrap() == TrapCode::Interrupt, "bad message: {}", trap ); @@ -50,7 +50,7 @@ fn functions_interruptable() -> anyhow::Result<()> { store.engine().increment_epoch(); let trap = iloop.call(&mut store, ()).unwrap_err(); assert!( - trap.to_string().contains("epoch deadline reached"), + trap.trap_code().unwrap() == TrapCode::Interrupt, "{}", trap.to_string() ); @@ -103,7 +103,7 @@ fn loop_interrupt_from_afar() -> anyhow::Result<()> { thread.join().unwrap(); assert!(HITS.load(SeqCst) > NUM_HITS); assert!( - trap.to_string().contains("epoch deadline reached"), + trap.trap_code().unwrap() == TrapCode::Interrupt, "bad message: {}", trap.to_string() ); @@ -143,7 +143,7 @@ fn function_interrupt_from_afar() -> anyhow::Result<()> { thread.join().unwrap(); assert!(HITS.load(SeqCst) > NUM_HITS); assert!( - trap.to_string().contains("epoch deadline reached"), + trap.trap_code().unwrap() == TrapCode::Interrupt, "bad message: {}", trap.to_string() );