Files
wasmtime/crates/fuzzing/wasm-spec-interpreter/src/without_library.rs
Andrew Brown c3f8415ac7 fuzz: improve the spec interpreter (#4881)
* fuzz: improve the API of the `wasm-spec-interpreter` crate

This change addresses key parts of #4852 by improving the bindings to
the OCaml spec interpreter. The new API allows users to `instantiate` a
module, `interpret` named functions on that instance, and `export`
globals and memories from that instance. This currently leaves the
existing implementation ("instantiate and interpret the first function in
a module") present under a new name: `interpret_legacy`.

* fuzz: adapt the differential spec engine to the new API

This removes the legacy uses in the differential spec engine, replacing
them with the new `instantiate`-`interpret`-`export` API from the
`wasm-spec-interpreter` crate.

* fix: make instance access thread-safe

This changes the OCaml-side definition of the instance so that each
instance carries round a reference to a "global store" that's specific
to that instantiation. Because everything is updated by reference there
should be no visible behavioural change on the Rust side, apart from
everything suddenly being thread-safe (modulo the fact that access to
the OCaml runtime still needs to be locked). This fix will need to be
generalised slightly in future if we want to allow multiple modules to
be instantiated in the same store.

Co-authored-by: conrad-watt <cnrdwtt@gmail.com>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2022-09-12 14:23:03 -07:00

46 lines
1.1 KiB
Rust

//! Panic when interpreting WebAssembly modules; see the rationale for this in
//! `lib.rs`.
//!
//! ```should_panic
//! # use wasm_spec_interpreter::instantiate;
//! let _ = instantiate(&[]);
//! ```
use crate::{SpecExport, SpecInstance, SpecValue};
#[allow(dead_code)]
pub fn instantiate(_module: &[u8]) -> Result<SpecInstance, String> {
fail_at_runtime()
}
#[allow(dead_code)]
pub fn interpret(
_instance: &SpecInstance,
_name: &str,
_parameters: Option<Vec<SpecValue>>,
) -> Result<Vec<SpecValue>, String> {
fail_at_runtime()
}
#[allow(dead_code)]
pub fn interpret_legacy(
_module: &[u8],
_parameters: Option<Vec<SpecValue>>,
) -> Result<Vec<SpecValue>, String> {
fail_at_runtime()
}
pub fn export(_instance: &SpecInstance, _name: &str) -> Result<SpecExport, String> {
fail_at_runtime()
}
fn fail_at_runtime() -> ! {
panic!(
"wasm-spec-interpreter was built without its Rust-to-OCaml shim \
library; re-compile with the dependencies listed in its README.md."
);
}
#[allow(dead_code)]
pub fn setup_ocaml_runtime() {}