Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try out MiddlewareError #675

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions packages/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ serde = { version = "1.0.103", default-features = false, features = ["derive", "
serde_json = "1.0"
sha2 = "0.9.1"
thiserror = "1.0"
wasmer = { git = "https://github.com/wasmerio/wasmer", rev = "22c7bc8", default-features = false, features = ["jit", "singlepass"] }
wasmer-engine = { git = "https://github.com/wasmerio/wasmer", rev = "22c7bc8" }
wasmer-middlewares = { git = "https://github.com/wasmerio/wasmer", rev = "22c7bc8" }
wasmer = { git = "https://github.com/webmaster128/wasmer", rev = "3b856c760", default-features = false, features = ["jit", "singlepass"] }
wasmer-engine = { git = "https://github.com/webmaster128/wasmer", rev = "3b856c760" }
wasmer-middlewares = { git = "https://github.com/webmaster128/wasmer", rev = "3b856c760" }

# Wasmer local (used for quick local debugging or patching)
# wasmer = { path = "../../../wasmer/lib/api", default-features = false, features = ["jit", "singlepass"] }
Expand Down
16 changes: 8 additions & 8 deletions packages/vm/src/middleware/deterministic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use wasmer::wasmparser::{BinaryReader, Operator, Result as WpResult};
use wasmer::{FunctionMiddleware, LocalFunctionIndex, MiddlewareReaderState, ModuleMiddleware};
use wasmer::wasmparser::Operator;
use wasmer::{
FunctionMiddleware, LocalFunctionIndex, MiddlewareError, MiddlewareReaderState,
ModuleMiddleware,
};

/// A middleware that ensures only deterministic operations are used (i.e. no floats)
#[derive(Debug)]
Expand All @@ -26,7 +29,7 @@ impl FunctionMiddleware for FunctionDeterministic {
&mut self,
operator: Operator<'a>,
state: &mut MiddlewareReaderState<'a>,
) -> WpResult<()> {
) -> Result<(), MiddlewareError> {
match operator {
Operator::Unreachable
| Operator::Nop
Expand Down Expand Up @@ -140,11 +143,8 @@ impl FunctionMiddleware for FunctionDeterministic {
Ok(())
}
_ => {
// Dirty hack: create an BinaryReaderError
// See https://github.com/wasmerio/wasmer/issues/1950
let mut reader = BinaryReader::new(b"\0\0\0\0");
let error = reader.read_bytes(10).unwrap_err();
Err(error)
let msg = format!("Non-determinstic operator detected: {:?}", operator);
Err(MiddlewareError::new("Deterministic", msg))
}
}
}
Expand Down