Expose TrapCode::Interrupt on epoch based interruption (#4105)

This commit is contained in:
Saúl Cabrera
2022-05-10 11:27:30 -04:00
committed by GitHub
parent 71fc16bbeb
commit 52524d258c
5 changed files with 16 additions and 20 deletions

View File

@@ -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.
//

View File

@@ -1856,7 +1856,14 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
fn new_epoch(&mut self) -> Result<u64, anyhow::Error> {
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<T> wasmtime_runtime::Store for StoreInner<T> {
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 {}
}
}