From d9b20bcd0d6006eb365224b0509d44ef38611d46 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 2 Aug 2026 19:59:10 +0200 Subject: feat: add validate feature Signed-off-by: Henry --- crates/parser/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/parser/Cargo.toml') diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 3e71403..561ac45 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -13,10 +13,11 @@ categories.workspace = true [dependencies] log = { workspace = true, optional = true } tinywasm-types = { workspace = true } -wasmparser = { workspace = true, features = ["features", "simd", "validate"] } +wasmparser = { workspace = true, features = ["simd"] } [features] -default = ["log", "parallel", "std"] +default = ["log", "parallel", "std", "validate"] log = ["dep:log"] parallel = ["std"] std = ["tinywasm-types/std", "wasmparser/std"] +validate = ["wasmparser/features", "wasmparser/validate"] -- cgit v1.3.1 From e5f234b1604511d0463252ee173caee6e9cd18f4 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 25 Aug 2026 18:05:11 +0200 Subject: feat: add support for portable-atomic, add send feature Signed-off-by: Henry --- CHANGELOG.md | 2 ++ Cargo.lock | 18 ++++++++++ README.md | 3 +- crates/parser/Cargo.toml | 11 ++++++ crates/parser/src/lib.rs | 3 +- crates/parser/src/module.rs | 16 ++++----- crates/parser/src/parallel.rs | 5 ++- crates/tinywasm/Cargo.toml | 7 ++++ crates/tinywasm/src/engine.rs | 15 ++++++--- crates/tinywasm/src/func/context.rs | 3 +- crates/tinywasm/src/func/host.rs | 52 +++++++++++++++++++++++------ crates/tinywasm/src/func/mod.rs | 16 +++++---- crates/tinywasm/src/func/resume.rs | 13 ++++---- crates/tinywasm/src/instance.rs | 11 +++--- crates/tinywasm/src/interpreter/executor.rs | 35 +++++++++---------- crates/tinywasm/src/lib.rs | 6 +++- crates/tinywasm/src/reference/managed.rs | 25 ++++---------- crates/tinywasm/src/shared.rs | 9 +++++ crates/tinywasm/src/store/function.rs | 7 ++-- crates/tinywasm/src/store/gc/object.rs | 13 ++++---- crates/tinywasm/src/store/gc/roots.rs | 11 +++--- crates/tinywasm/src/store/mod.rs | 12 +++---- crates/tinywasm/src/store/state.rs | 4 +-- crates/tinywasm/tests/managed_exceptions.rs | 3 +- crates/tinywasm/tests/memory.rs | 22 +++++------- crates/types/Cargo.toml | 15 +++++++-- crates/types/src/archive.rs | 21 ++++++------ crates/types/src/lib.rs | 28 +++++++++++++--- crates/types/src/types.rs | 6 ++-- 29 files changed, 244 insertions(+), 148 deletions(-) create mode 100644 crates/tinywasm/src/shared.rs (limited to 'crates/parser/Cargo.toml') diff --git a/CHANGELOG.md b/CHANGELOG.md index bad8caf..a786aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `ResourceLimiter` callbacks for memory and table allocation or growth - A default `validate` Cargo feature & parser option to skip wasm validation - Optional parse-time operand deduplication to reduce `.twasm` archive size +- Optional `send` support for moving stores and store-local handles across threads +- Optional portable atomic shared pointers and counters for targets without native compare-and-swap ### Changed diff --git a/Cargo.lock b/Cargo.lock index ac0895a..1663c7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -570,6 +570,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" +dependencies = [ + "portable-atomic", + "serde", +] + [[package]] name = "postcard" version = "1.1.3" @@ -864,6 +880,7 @@ version = "0.11.0-pre.0" dependencies = [ "libm", "log", + "portable-atomic", "tinywasm-cli", "tinywasm-parser", "tinywasm-types", @@ -919,6 +936,7 @@ name = "tinywasm-types" version = "0.11.0-pre.0" dependencies = [ "log", + "portable-atomic-util", "postcard", "serde", ] diff --git a/README.md b/README.md index 70578dd..8b400de 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,10 @@ See the [examples](./examples) directory and [documentation](https://docs.rs/tin - **`debug`:** Derives `Debug` for runtime types. Enabled by default. - **`parallel-parser`:** Parallelizes function parsing when `std` is enabled. Enabled by default. - **`guest-debug`:** Exposes module-internal by-index inspection APIs (`*_by_index`). +- **`send`:** Makes stores and store-local handles movable across threads - **`simd-x86`:** Enables x86-specific SIMD intrinsics and uses `unsafe` internally. -With default features disabled, `tinywasm` depends only on `core`, `alloc`, and `libm`, making it usable in `no_std + alloc` environments. +With default features disabled, `tinywasm` supports `no_std + alloc` and depends only on `libm`. Use [`Engine`](https://docs.rs/tinywasm/latest/tinywasm/engine/struct.Engine.html) and [`engine::Config`](https://docs.rs/tinywasm/latest/tinywasm/engine/struct.Config.html) for non-default fuel accounting, stack sizing, or GC collection thresholds. A configured `ResourceLimiter` can allow, reject, or trap memory and table allocation or growth requests, and GC object allocations. diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 561ac45..042eeda 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -17,7 +17,18 @@ wasmparser = { workspace = true, features = ["simd"] } [features] default = ["log", "parallel", "std", "validate"] + +# enable integration with the log crate log = ["dep:log"] + +# parse and validate function bodies in parallel (requires std) parallel = ["std"] + +# support targets without native atomic CAS +portable-atomic = ["tinywasm-types/portable-atomic"] + +# enable standard library support std = ["tinywasm-types/std", "wasmparser/std"] + +# validate WebAssembly while parsing validate = ["wasmparser/features", "wasmparser/validate"] diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 262cc07..3369f7b 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -292,7 +292,8 @@ impl Parser { } let section_end = buffer_offset + section_size; - let section_bytes = alloc::sync::Arc::<[u8]>::from(buffer[buffer_offset..section_end].to_vec()); + let section_bytes = + tinywasm_types::Shared::<[u8]>::from(buffer[buffer_offset..section_end].to_vec()); reader.queue_owned_code_section(count, parser.offset(), section_bytes, validator.as_mut())?; parser.skip_section(); buffer_offset = section_end; diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs index c076035..bfb28ce 100644 --- a/crates/parser/src/module.rs +++ b/crates/parser/src/module.rs @@ -3,7 +3,7 @@ use crate::log::debug; use crate::validation::{FuncToValidate, ValidatorResources}; use crate::validation::{FuncValidatorAllocations, Validator}; use crate::{ParseError, ParserOptions, Result, conversion::*, optimize}; -use alloc::{boxed::Box, format, string::ToString, sync::Arc, vec::Vec}; +use alloc::{boxed::Box, format, string::ToString, vec::Vec}; use core::marker::PhantomData; use core::ops::Range; use tinywasm_types::*; @@ -37,7 +37,7 @@ pub(crate) fn optimize_function_code( pub(crate) struct ModuleReader<'a> { func_validator_allocations: Option, operators_reader_allocations: Option, - translation_metadata: Option>, + translation_metadata: Option, has_code_section: bool, has_type_section: bool, @@ -48,7 +48,7 @@ pub(crate) struct ModuleReader<'a> { pub(crate) types: TypeSection, pub(crate) code_type_addrs: Box<[u32]>, code_results: Box<[ValueCounts]>, - pub(crate) exports: Arc<[Export]>, + pub(crate) exports: Shared<[Export]>, pub(crate) code: Vec, pub(crate) globals: Box<[Global]>, pub(crate) tables: Box<[TableDefinition]>, @@ -68,7 +68,7 @@ pub(crate) struct ModuleReader<'a> { impl<'a> ModuleReader<'a> { fn translation_metadata(&mut self) -> &crate::visit::ModuleMetadata { if self.translation_metadata.is_none() { - self.translation_metadata = Some(Arc::new(crate::visit::ModuleMetadata::new( + self.translation_metadata = Some(crate::visit::ModuleMetadata::new( &self.types, &self.code_type_addrs, &self.imports, @@ -76,9 +76,9 @@ impl<'a> ModuleReader<'a> { &self.memory_types, &self.tables, &self.tags, - ))); + )); } - self.translation_metadata.as_deref().unwrap() + self.translation_metadata.as_ref().unwrap() } pub(crate) fn process_payload(&mut self, payload: Payload<'_>, validator: Option<&mut Validator>) -> Result<()> { @@ -435,7 +435,7 @@ impl<'a> ModuleReader<'a> { &mut self, count: u32, body_offset: u64, - section_bytes: Arc<[u8]>, + section_bytes: Shared<[u8]>, validator: Option<&mut Validator>, ) -> Result<()> { #[cfg(feature = "validate")] @@ -545,7 +545,7 @@ impl<'a> ModuleReader<'a> { self.types.get(ty_idx).and_then(SubType::as_func).expect("function type was checked while parsing"); let params = ValueCounts::from_iter(ty.params()); - Ok(Arc::new(WasmFunction { + Ok(Shared::new(WasmFunction { instructions: code.instructions.into_boxed_slice(), data: code.data, locals: code.locals, diff --git a/crates/parser/src/parallel.rs b/crates/parser/src/parallel.rs index 9b96c7a..4ad16cf 100644 --- a/crates/parser/src/parallel.rs +++ b/crates/parser/src/parallel.rs @@ -1,10 +1,9 @@ use crate::module::{OptimizedFunctionCode, optimize_function_code}; use crate::validation::{FuncToValidate, FuncValidatorAllocations, ValidatorResources}; use crate::{ParseError, ParserOptions, Result, conversion}; -use alloc::sync::Arc; use alloc::vec::Vec; use core::ops::Range; -use tinywasm_types::ValueCounts; +use tinywasm_types::{Shared, ValueCounts}; use wasmparser::OperatorsReaderAllocations; pub(crate) enum FunctionBodyInput<'a> { @@ -15,7 +14,7 @@ pub(crate) enum FunctionBodyInput<'a> { pub(crate) struct OwnedFunctionBody { // A deferred stream code section is copied once, then shared by all queued // function jobs from that section. - pub section_bytes: Arc<[u8]>, + pub section_bytes: Shared<[u8]>, pub body_range: Range, pub body_offset: u64, } diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index eb5dd94..954ae40 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -88,6 +88,7 @@ name = "test-wasm-wide-arithmetic" [dependencies] libm = { version = "0.2", default-features = false } log = { workspace = true, optional = true } +portable-atomic = { version = "1.15.0", default-features = false, optional = true } tinywasm-parser = { workspace = true, optional = true } tinywasm-types = { workspace = true } @@ -111,6 +112,9 @@ default = [ log = ["dep:log", "tinywasm-parser?/log", "tinywasm-types/log"] std = ["tinywasm-parser?/std", "tinywasm-types/std"] +# make stores, instances, references, and host callbacks movable across threads +send = [] + # support for parsing WebAssembly parser = ["dep:tinywasm-parser"] @@ -120,6 +124,9 @@ validate = ["parser", "tinywasm-parser/validate"] # parallelize function parsing/validation across threads (requires std) parallel-parser = ["parser", "tinywasm-parser?/parallel"] +# support targets without native atomic CAS +portable-atomic = ["dep:portable-atomic", "tinywasm-parser?/portable-atomic", "tinywasm-types/portable-atomic"] + # support for "archiving" tinywasm bytecode archive = ["tinywasm-types/archive"] diff --git a/crates/tinywasm/src/engine.rs b/crates/tinywasm/src/engine.rs index f1feae6..4fc74d5 100644 --- a/crates/tinywasm/src/engine.rs +++ b/crates/tinywasm/src/engine.rs @@ -1,10 +1,12 @@ -use alloc::sync::Arc; +use alloc::boxed::Box; use crate::ResourceLimiter; +use crate::shared::StoreShared; /// Global configuration for the WebAssembly interpreter /// -/// Can be cheaply cloned and shared across multiple executions and threads. +/// Can be cheaply cloned across stores. With the `send` feature, it can also be +/// moved and shared across threads. /// /// ## Example /// ```rust @@ -117,7 +119,7 @@ pub struct Config { /// Fuel accounting policy used by budgeted execution. Defaults to [`FuelPolicy::PerInstruction`]. pub fuel_policy: FuelPolicy, /// Resource limiter shared across all stores created from this engine. Defaults to `None`. - pub resource_limiter: Option>, + pub resource_limiter: Option>, /// Initial number of GC heap bytes that triggers collection. /// Defaults to 1 MiB. pub gc_collection_threshold: usize, @@ -168,8 +170,11 @@ impl Config { } /// Set the resource limiter shared across all stores created from this engine. - pub fn with_resource_limiter(mut self, limiter: Arc) -> Self { - self.resource_limiter = Some(limiter); + /// + /// The limiter is converted to TinyWasm's internal shared pointer. Pass the + /// limiter value directly rather than wrapping it in `Rc` or `Arc`. + pub fn with_resource_limiter(mut self, limiter: impl ResourceLimiter + 'static) -> Self { + self.resource_limiter = Some(StoreShared::from(Box::new(limiter) as Box)); self } diff --git a/crates/tinywasm/src/func/context.rs b/crates/tinywasm/src/func/context.rs index 7e289f6..0b9e1f9 100644 --- a/crates/tinywasm/src/func/context.rs +++ b/crates/tinywasm/src/func/context.rs @@ -119,7 +119,8 @@ impl FuncContext<'_> { } func.func.item.validate_store(self.store)?; let func_instance = self.store.state.get_func(func.func.addr()).clone(); - if matches!(&func_instance.kind, crate::store::FunctionKind::Host(host) if host.typed_callback().is_none()) { + if matches!(&func_instance.inner, crate::store::FunctionInstanceInner::Host(host) if host.typed_callback().is_none()) + { let ty = self.store.state.get_canonical_func_type(func_instance.type_addr); let (param_count, result_count) = (ty.params().len(), ty.results().len()); self.store.with_scratch_values(param_count + result_count, |store, values| { diff --git a/crates/tinywasm/src/func/host.rs b/crates/tinywasm/src/func/host.rs index 8f36761..1dcf3c1 100644 --- a/crates/tinywasm/src/func/host.rs +++ b/crates/tinywasm/src/func/host.rs @@ -1,18 +1,38 @@ -use alloc::{boxed::Box, sync::Arc, vec::Vec}; +use alloc::{boxed::Box, vec::Vec}; use tinywasm_types::{FuncType, ModuleInstanceId, TypeAddr, WasmType}; use super::{FromWasmValues, FuncContext, IntoWasmValues, ToWasmTypes}; +use crate::shared::StoreShared; use crate::store::FuncValueTypes; use crate::{Function, FunctionInstance, Result, Store, WasmValue}; +/// Trait bounds required for a host callback in the current build mode. +#[doc(hidden)] +#[cfg(not(feature = "send"))] +pub trait HostFunctionCallback {} +#[cfg(not(feature = "send"))] +impl HostFunctionCallback for T {} + +/// Trait bounds required for a host callback in the current build mode. +#[doc(hidden)] +#[cfg(feature = "send")] +pub trait HostFunctionCallback: Send + Sync {} +#[cfg(feature = "send")] +impl HostFunctionCallback for T {} + /// A reusable host function definition. +/// +/// Host functions accept thread-local callback state by default. With the +/// `send` feature, callbacks must implement `Send + Sync` and host function +/// definitions can be moved and shared across threads. #[derive(Clone)] -pub struct HostFunction(Arc); +pub struct HostFunction(StoreShared); impl HostFunction { /// Instantiates the function with an already registered canonical type. pub(crate) fn instantiate_registered(&self, store: &mut Store, type_addr: TypeAddr) -> Function { - let addr = store.add_func(FunctionInstance { type_addr, kind: crate::store::FunctionKind::Host(self.clone()) }); + let addr = store + .add_func(FunctionInstance { type_addr, inner: crate::store::FunctionInstanceInner::Host(self.clone()) }); Function { item: crate::StoreItem::new(store.store_id(), addr), module_id: 0 } } @@ -155,11 +175,11 @@ impl HostFunction { /// # Ok(()) /// # } /// ``` - pub fn from_untyped( - ty: &FuncType, - func: impl Fn(FuncContext<'_>, &[WasmValue], &mut [WasmValue]) -> Result<()> + Send + Sync + 'static, - ) -> Self { - Self(Arc::new(HostFunctionInner { ty: ty.clone(), callback: HostCallback::Untyped(Box::new(func)) })) + pub fn from_untyped(ty: &FuncType, func: F) -> Self + where + F: Fn(FuncContext<'_>, &[WasmValue], &mut [WasmValue]) -> Result<()> + HostFunctionCallback + 'static, + { + Self(StoreShared::new(HostFunctionInner { ty: ty.clone(), callback: HostCallback::Untyped(Box::new(func)) })) } /// Create a new typed host function. @@ -190,14 +210,15 @@ impl HostFunction { /// # Ok(()) /// # } /// ``` - pub fn from(func: impl Fn(FuncContext<'_>, P) -> Result + Send + Sync + 'static) -> Self + pub fn from(func: F) -> Self where + F: Fn(FuncContext<'_>, P) -> Result + HostFunctionCallback + 'static, P: FromWasmValues + ToWasmTypes + 'static, R: IntoWasmValues + ToWasmTypes + 'static, { let ty = FuncType::new(&P::wasm_types(), &R::wasm_types()); let func = TypedHostCallbackImpl { func, marker: core::marker::PhantomData }; - Self(Arc::new(HostFunctionInner { ty, callback: HostCallback::Typed(Box::new(func)) })) + Self(StoreShared::new(HostFunctionInner { ty, callback: HostCallback::Typed(Box::new(func)) })) } } @@ -211,8 +232,17 @@ enum HostCallback { Typed(Box), } +#[cfg(not(feature = "send"))] +type UntypedHostCallback = dyn Fn(FuncContext<'_>, &[WasmValue], &mut [WasmValue]) -> Result<()>; +#[cfg(feature = "send")] type UntypedHostCallback = dyn Fn(FuncContext<'_>, &[WasmValue], &mut [WasmValue]) -> Result<()> + Send + Sync; +#[cfg(not(feature = "send"))] +pub(crate) trait TypedHostCallback { + fn call(&self, ctx: FuncContext<'_>, args: &[WasmValue], results: &mut [WasmValue]) -> Result<()>; + fn call_stack(&self, store: &mut Store, module_id: ModuleInstanceId, type_addr: TypeAddr) -> Result<()>; +} +#[cfg(feature = "send")] pub(crate) trait TypedHostCallback: Send + Sync { fn call(&self, ctx: FuncContext<'_>, args: &[WasmValue], results: &mut [WasmValue]) -> Result<()>; fn call_stack(&self, store: &mut Store, module_id: ModuleInstanceId, type_addr: TypeAddr) -> Result<()>; @@ -225,7 +255,7 @@ struct TypedHostCallbackImpl { impl TypedHostCallback for TypedHostCallbackImpl where - F: Fn(FuncContext<'_>, P) -> Result + Send + Sync, + F: Fn(FuncContext<'_>, P) -> Result + HostFunctionCallback, P: FromWasmValues, R: IntoWasmValues, { diff --git a/crates/tinywasm/src/func/mod.rs b/crates/tinywasm/src/func/mod.rs index c29b3db..2fbc22f 100644 --- a/crates/tinywasm/src/func/mod.rs +++ b/crates/tinywasm/src/func/mod.rs @@ -13,6 +13,8 @@ mod resume; mod values; pub use context::FuncContext; pub use host::HostFunction; +#[doc(hidden)] +pub use host::HostFunctionCallback; pub use resume::{ExecProgress, FuncExecution, FuncExecutionTyped}; pub use values::{FromWasmValues, IntoWasmValues, ToWasmType, ToWasmTypes}; @@ -122,12 +124,12 @@ impl Function { ) -> Result<()> { let instance = store.state.get_func(self.addr()); let type_addr = instance.type_addr; - match &instance.kind { - crate::store::FunctionKind::Host(host) => { + match &instance.inner { + crate::store::FunctionInstanceInner::Host(host) => { let host = host.clone(); host.call_values(store, self.module_id, type_addr, params, results) } - crate::store::FunctionKind::Wasm(wasm) => { + crate::store::FunctionInstanceInner::Wasm(wasm) => { let wasm_params = wasm.func.params; let wasm_locals = wasm.func.locals; store @@ -156,15 +158,15 @@ impl Function { stack_base: StackBase, ) -> Result> { store.push_typed_values::(instance.type_addr, params, stack_base)?; - match &instance.kind { - crate::store::FunctionKind::Wasm(wasm) => { + match &instance.inner { + crate::store::FunctionInstanceInner::Wasm(wasm) => { let locals_base = store .value_stack .enter_locals(&wasm.func.params, &wasm.func.locals) .inspect_err(|_| store.value_stack.truncate_to_base(stack_base))?; Ok(Some(CallFrame::new(self.addr(), locals_base, wasm.func.locals))) } - crate::store::FunctionKind::Host(host) => { + crate::store::FunctionInstanceInner::Host(host) => { host.typed_callback() .expect("typed host function") .call_stack(store, self.module_id, instance.type_addr) @@ -209,7 +211,7 @@ impl FunctionTyped { pub fn call(&self, store: &mut Store, params: P) -> Result { self.func.item.validate_store(store)?; let func = store.state.get_func(self.func.addr()).clone(); - if matches!(&func.kind, crate::store::FunctionKind::Host(host) if host.typed_callback().is_none()) { + if matches!(&func.inner, crate::store::FunctionInstanceInner::Host(host) if host.typed_callback().is_none()) { let ty = store.state.get_canonical_func_type(func.type_addr); let (param_count, result_count) = (ty.params().len(), ty.results().len()); store.with_scratch_values(param_count + result_count, |store, values| { diff --git a/crates/tinywasm/src/func/resume.rs b/crates/tinywasm/src/func/resume.rs index 6772eb8..cc461a7 100644 --- a/crates/tinywasm/src/func/resume.rs +++ b/crates/tinywasm/src/func/resume.rs @@ -62,18 +62,17 @@ impl Function { store.enter_execution()?; let result: Result = (|| { let func_instance = store.state.get_func(self.addr()).clone(); - match &func_instance.kind { - crate::store::FunctionKind::Host(host_func) => { + match &func_instance.inner { + crate::store::FunctionInstanceInner::Host(host_func) => { host_func.clone().call_values(store, self.module_id, func_instance.type_addr, params, results)?; Ok(FuncExecutionState::Completed(Some(CallResult::Written))) } - crate::store::FunctionKind::Wasm(wasm_func) => { + crate::store::FunctionInstanceInner::Wasm(wasm_func) => { store.call_stack.clear(); store.value_stack.clear(); - let locals = wasm_func.func.locals; store.push_wasm_values(params.iter().cloned())?; - let locals_base = store.value_stack.enter_locals(&wasm_func.func.params, &locals)?; - let callframe = CallFrame::new(self.addr(), locals_base, locals); + let locals_base = store.value_stack.enter_locals(&wasm_func.func.params, &wasm_func.func.locals)?; + let callframe = CallFrame::new(self.addr(), locals_base, wasm_func.func.locals); Ok(FuncExecutionState::Running { callframe, root_func_addr: self.addr() }) } @@ -205,7 +204,7 @@ impl FunctionTyped { pub fn call_resumable<'store>(&self, store: &'store mut Store, params: P) -> Result> { self.func.item.validate_store(store)?; let func = store.state.get_func(self.func.addr()).clone(); - if matches!(&func.kind, crate::store::FunctionKind::Host(host) if host.typed_callback().is_none()) { + if matches!(&func.inner, crate::store::FunctionInstanceInner::Host(host) if host.typed_callback().is_none()) { let result = self.call(store, params)?; let execution = ExecutionCore { store, state: FuncExecutionState::Completed(None) }; return Ok(FuncExecutionTyped { execution, result: Some(result) }); diff --git a/crates/tinywasm/src/instance.rs b/crates/tinywasm/src/instance.rs index 4a92212..bd78a57 100644 --- a/crates/tinywasm/src/instance.rs +++ b/crates/tinywasm/src/instance.rs @@ -1,9 +1,10 @@ -use alloc::{boxed::Box, format, rc::Rc, sync::Arc}; +use alloc::{boxed::Box, format}; use core::hint::cold_path; use tinywasm_types::*; use crate::func::{FromWasmValues, IntoWasmValues, ToWasmTypes}; use crate::reference::StoreId; +use crate::shared::StoreShared; use crate::store::MemoryInstance; use crate::{ Error, Function, FunctionTyped, Global, Imports, Memory, Result, Store, StoreItem, Table, Tag, Trap, WasmValue, @@ -41,12 +42,12 @@ pub enum ExternItem { /// # } /// ``` /// -/// Backed by an Rc, so cloning is cheap +/// Cloning an instance handle is cheap. /// /// See #[derive(Clone)] #[cfg_attr(feature = "debug", derive(Debug))] -pub struct ModuleInstance(Rc); +pub struct ModuleInstance(StoreShared); #[cfg_attr(feature = "debug", derive(Debug))] struct ModuleInstanceInner { @@ -61,7 +62,7 @@ struct ModuleInstanceInner { elem_addrs: Box<[ElemAddr]>, data_addrs: Box<[DataAddr]>, func_start: Option, - exports: Arc<[Export]>, + exports: Shared<[Export]>, } impl ModuleInstance { @@ -206,7 +207,7 @@ impl ModuleInstance { exports: module.exports.clone(), }; - let instance = ModuleInstance(Rc::new(instance)); + let instance = ModuleInstance(StoreShared::new(instance)); store.add_instance(instance.clone()); if let Some(trap) = elem_trapped.or(data_trapped) { diff --git a/crates/tinywasm/src/interpreter/executor.rs b/crates/tinywasm/src/interpreter/executor.rs index 76c6364..4824b63 100644 --- a/crates/tinywasm/src/interpreter/executor.rs +++ b/crates/tinywasm/src/interpreter/executor.rs @@ -8,7 +8,6 @@ use super::no_std_floats::NoStdFloatExt; use alloc::boxed::Box; use alloc::vec::Vec; -use alloc::sync::Arc; use interpreter::stack::CallFrame; use tinywasm_types::*; @@ -24,7 +23,7 @@ const FUEL_COST_CALL_TOTAL: u32 = 5; pub(crate) struct Executor<'store, const BUDGETED: bool> { cf: CallFrame, - func: Arc, + func: Shared, module: ModuleInstance, store: &'store mut Store, call_stack_base: u32, @@ -1020,7 +1019,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { fn exec_call( &mut self, - wasm_func: Arc, + wasm_func: Shared, owner: ModuleInstanceId, func_addr: FuncAddr, return_instr_ptr: usize, @@ -1030,11 +1029,10 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { }; self.store.call_stack.push(self.cf, return_instr_ptr)?; - let locals = wasm_func.locals; - if !Arc::ptr_eq(&self.func, &wasm_func) { + self.cf = CallFrame::new(func_addr, locals_base, wasm_func.locals); + if !Shared::ptr_eq(&self.func, &wasm_func) { self.func = wasm_func; } - self.cf = CallFrame::new(func_addr, locals_base, locals); if owner != self.module.id() { self.set_module(owner); } @@ -1044,7 +1042,7 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { fn exec_return_call( &mut self, - wasm_func: Arc, + wasm_func: Shared, owner: ModuleInstanceId, func_addr: FuncAddr, ) -> Result<(), Trap> { @@ -1052,11 +1050,10 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { let Ok(locals_base) = self.store.value_stack.enter_locals(&wasm_func.params, &wasm_func.locals) else { return cold!(Err(Trap::CallStackOverflow)); }; - let locals = wasm_func.locals; - if !Arc::ptr_eq(&self.func, &wasm_func) { + self.cf = CallFrame::new(func_addr, locals_base, wasm_func.locals); + if !Shared::ptr_eq(&self.func, &wasm_func) { self.func = wasm_func; } - self.cf = CallFrame::new(func_addr, locals_base, locals); if owner != self.module.id() { self.set_module(owner); } @@ -1108,12 +1105,12 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { self.charge_call_fuel(FUEL_COST_CALL_TOTAL); let addr = self.module.resolve_func_addr(v); let func = self.store.state.get_func(addr); - match &func.kind { - crate::store::FunctionKind::Wasm(wasm_func) => { + match &func.inner { + crate::store::FunctionInstanceInner::Wasm(wasm_func) => { self.exec_call(wasm_func.func.clone(), wasm_func.owner, addr, return_instr_ptr)?; Ok(ControlFlow::Continue(0)) } - crate::store::FunctionKind::Host(host_func) => { + crate::store::FunctionInstanceInner::Host(host_func) => { self.exec_call_host::(host_func.clone(), func.type_addr, return_instr_ptr) } } @@ -1123,12 +1120,12 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { self.charge_call_fuel(FUEL_COST_CALL_TOTAL); let addr = self.module.resolve_func_addr(v); let func = self.store.state.get_func(addr); - match &func.kind { - crate::store::FunctionKind::Wasm(wasm_func) => { + match &func.inner { + crate::store::FunctionInstanceInner::Wasm(wasm_func) => { self.exec_return_call(wasm_func.func.clone(), wasm_func.owner, addr)?; Ok(ControlFlow::Continue(0)) } - crate::store::FunctionKind::Host(host_func) => { + crate::store::FunctionInstanceInner::Host(host_func) => { self.exec_call_host::(host_func.clone(), func.type_addr, 0) } } @@ -1192,12 +1189,12 @@ impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { expected: Box::new(self.store.state.get_canonical_func_type(expected_type_addr).clone()), })); } - match &func.kind { - crate::store::FunctionKind::Wasm(wasm_func) => match IS_RETURN_CALL { + match &func.inner { + crate::store::FunctionInstanceInner::Wasm(wasm_func) => match IS_RETURN_CALL { true => self.exec_return_call(wasm_func.func.clone(), wasm_func.owner, func_addr), false => self.exec_call(wasm_func.func.clone(), wasm_func.owner, func_addr, return_instr_ptr), }, - crate::store::FunctionKind::Host(host_func) => { + crate::store::FunctionInstanceInner::Host(host_func) => { return self.exec_call_host::(host_func.clone(), func.type_addr, return_instr_ptr); } }?; diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs index 15ccd0e..d89bfa1 100644 --- a/crates/tinywasm/src/lib.rs +++ b/crates/tinywasm/src/lib.rs @@ -90,6 +90,9 @@ mod macros; mod std; extern crate alloc; +#[cfg(all(not(feature = "portable-atomic"), not(target_has_atomic = "32")))] +compile_error!("tinywasm requires native 32-bit atomics; enable the `portable-atomic` feature"); + // log for logging (optional). #[cfg(feature = "log")] #[expect(clippy::single_component_path_imports)] @@ -111,7 +114,7 @@ mod error; pub use error::*; pub use func::{ ExecProgress, FromWasmValues, FuncContext, FuncExecution, FuncExecutionTyped, Function, FunctionTyped, - HostFunction, IntoWasmValues, ToWasmType, ToWasmTypes, + HostFunction, HostFunctionCallback, IntoWasmValues, ToWasmType, ToWasmTypes, }; pub use imports::*; pub use instance::{ExternItem, ModuleInstance}; @@ -122,6 +125,7 @@ mod func; mod imports; mod instance; mod reference; +mod shared; mod store; mod interpreter; diff --git a/crates/tinywasm/src/reference/managed.rs b/crates/tinywasm/src/reference/managed.rs index 1e5f38a..79bd0b9 100644 --- a/crates/tinywasm/src/reference/managed.rs +++ b/crates/tinywasm/src/reference/managed.rs @@ -1,7 +1,7 @@ -use alloc::sync::Arc; -use core::sync::atomic::{AtomicU32, Ordering}; +use tinywasm_types::Shared; use crate::interpreter::ValueRef; +use crate::shared::{AtomicU32, Ordering}; use crate::{Result, Store, Trap}; #[derive(Clone, Copy, PartialEq, Eq, Hash)] @@ -10,7 +10,9 @@ pub(crate) struct StoreId(u32); impl StoreId { pub(crate) fn fresh() -> Self { static NEXT: AtomicU32 = AtomicU32::new(0); - next_store_id(&NEXT) + let id = NEXT.fetch_add(1, Ordering::Relaxed); + assert_ne!(id, u32::MAX, "Store identity space exhausted"); + StoreId(id) } pub(crate) const fn get(self) -> u32 { @@ -18,13 +20,6 @@ impl StoreId { } } -fn next_store_id(counter: &AtomicU32) -> StoreId { - let id = counter - .try_update(Ordering::Relaxed, Ordering::Relaxed, |id| id.checked_add(1)) - .expect("Store identity space exhausted"); - StoreId(id) -} - #[cfg(feature = "debug")] impl core::fmt::Debug for StoreId { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -47,7 +42,7 @@ pub(crate) struct RootedItem { pub(crate) store: StoreId, pub(crate) value: ValueRef, pub(crate) kind: ReferentKind, - pub(crate) _token: Option>, + pub(crate) _token: Option>, } impl PartialEq for RootedItem { @@ -220,14 +215,6 @@ mod tests { extern crate std; use super::*; - #[test] - fn exhausted_store_identity_counter_never_wraps() { - let counter = AtomicU32::new(u32::MAX - 1); - assert_eq!(next_store_id(&counter).get(), u32::MAX - 1); - assert!(std::panic::catch_unwind(|| next_store_id(&counter)).is_err()); - assert!(std::panic::catch_unwind(|| next_store_id(&counter)).is_err()); - } - #[test] fn host_reference_key_fits_internal_encoding() { assert!(ValueRef::try_from_host_any((1 << 30) - 2).is_some()); diff --git a/crates/tinywasm/src/shared.rs b/crates/tinywasm/src/shared.rs new file mode 100644 index 0000000..97f42b7 --- /dev/null +++ b/crates/tinywasm/src/shared.rs @@ -0,0 +1,9 @@ +#[cfg(not(feature = "send"))] +pub(crate) use alloc::rc::Rc as StoreShared; +#[cfg(feature = "send")] +pub(crate) use tinywasm_types::Shared as StoreShared; + +#[cfg(not(feature = "portable-atomic"))] +pub(crate) use core::sync::atomic::{AtomicU32, Ordering}; +#[cfg(feature = "portable-atomic")] +pub(crate) use portable_atomic::{AtomicU32, Ordering}; diff --git a/crates/tinywasm/src/store/function.rs b/crates/tinywasm/src/store/function.rs index 3c716a7..88fff5d 100644 --- a/crates/tinywasm/src/store/function.rs +++ b/crates/tinywasm/src/store/function.rs @@ -1,4 +1,3 @@ -use alloc::sync::Arc; use tinywasm_types::*; use crate::func::HostFunction; @@ -10,12 +9,12 @@ use crate::func::HostFunction; #[cfg_attr(feature = "debug", derive(Debug))] pub(crate) struct FunctionInstance { pub(crate) type_addr: TypeAddr, - pub(crate) kind: FunctionKind, + pub(crate) inner: FunctionInstanceInner, } #[derive(Clone)] #[cfg_attr(feature = "debug", derive(Debug))] -pub(crate) enum FunctionKind { +pub(crate) enum FunctionInstanceInner { /// A host function Host(HostFunction), @@ -26,6 +25,6 @@ pub(crate) enum FunctionKind { #[derive(Clone)] #[cfg_attr(feature = "debug", derive(Debug))] pub(crate) struct WasmFunctionInstance { - pub(crate) func: Arc, + pub(crate) func: Shared, pub(crate) owner: ModuleInstanceId, } diff --git a/crates/tinywasm/src/store/gc/object.rs b/crates/tinywasm/src/store/gc/object.rs index cf27cd5..b92e07a 100644 --- a/crates/tinywasm/src/store/gc/object.rs +++ b/crates/tinywasm/src/store/gc/object.rs @@ -1,11 +1,11 @@ -use alloc::{boxed::Box, sync::Arc, vec::Vec}; +use alloc::{boxed::Box, vec::Vec}; use core::mem::size_of; -use core::sync::atomic::{AtomicU32, Ordering}; use tinywasm_types::{TagAddr, TypeAddr}; use crate::engine::Config; use crate::interpreter::{RuntimeValue, ValueRef}; +use crate::shared::{AtomicU32, Ordering, StoreShared}; use crate::{ResourceLimiter, Trap}; use super::{AllocError, Arena, Handle, Trace}; @@ -35,7 +35,7 @@ impl Trace for GcObject { pub(crate) struct GcHeap { objects: Arena, directory: Vec<(u32, Handle)>, - resource_limiter: Option>, + resource_limiter: Option>, } impl Default for GcHeap { @@ -114,11 +114,10 @@ impl GcHeap { ) -> Result { let element_size = size_of::() + if trace_references { size_of::>() } else { 0 }; let out_of_line_bytes = values.len().checked_mul(element_size).ok_or(Trap::OutOfMemory)?; - let key = - NEXT_GC_REF.try_update(Ordering::Relaxed, Ordering::Relaxed, |key| (key < (1 << 30)).then_some(key + 1)); - let Ok(key) = key else { + let key = NEXT_GC_REF.fetch_add(1, Ordering::Relaxed); + if key >= 1 << 30 { return Err(Trap::OutOfMemory); - }; + } let references = if trace_references { let mut references = Vec::new(); references.try_reserve_exact(values.len()).map_err(|_| Trap::OutOfMemory)?; diff --git a/crates/tinywasm/src/store/gc/roots.rs b/crates/tinywasm/src/store/gc/roots.rs index 7107295..ea6c47a 100644 --- a/crates/tinywasm/src/store/gc/roots.rs +++ b/crates/tinywasm/src/store/gc/roots.rs @@ -1,4 +1,5 @@ -use alloc::{sync::Arc, sync::Weak, vec::Vec}; +use alloc::vec::Vec; +use tinywasm_types::{Shared, WeakShared}; use crate::Trap; use crate::interpreter::ValueRef; @@ -10,7 +11,7 @@ pub(crate) struct Roots { struct Root { value: ValueRef, - token: Weak<()>, + token: WeakShared<()>, } impl Roots { @@ -24,7 +25,7 @@ impl Roots { self.entries.try_reserve(needed).map_err(|_| Trap::OutOfMemory) } - pub(crate) fn insert(&mut self, value: ValueRef) -> Result, Trap> { + pub(crate) fn insert(&mut self, value: ValueRef) -> Result, Trap> { if self.free.is_empty() && self.entries.len() == self.entries.capacity() { self.remove_dead(); } @@ -37,8 +38,8 @@ impl Roots { index }; - let token = Arc::new(()); - self.entries[index as usize] = Some(Root { value, token: Arc::downgrade(&token) }); + let token = Shared::new(()); + self.entries[index as usize] = Some(Root { value, token: Shared::downgrade(&token) }); Ok(token) } diff --git a/crates/tinywasm/src/store/mod.rs b/crates/tinywasm/src/store/mod.rs index 91895b4..57c7575 100644 --- a/crates/tinywasm/src/store/mod.rs +++ b/crates/tinywasm/src/store/mod.rs @@ -41,7 +41,6 @@ pub(crate) use {data::*, element::*, function::*, global::*, table::*, tag::*}; /// /// # Example /// ```rust -/// use std::sync::Arc; /// use tinywasm::engine::Config; /// use tinywasm::types::{MemoryArch, MemoryType}; /// use tinywasm::{Engine, Memory, ResourceLimiter, Store}; @@ -59,7 +58,7 @@ pub(crate) use {data::*, element::*, function::*, global::*, table::*, tag::*}; /// } /// } /// -/// let config = Config::new().with_resource_limiter(Arc::new(MemoryLimit(64 * 1024))); +/// let config = Config::new().with_resource_limiter(MemoryLimit(64 * 1024)); /// let mut store = Store::new(Engine::new(config)); /// let memory = Memory::try_new(&mut store, MemoryType::new(MemoryArch::I32, 1, None, None))?; /// assert_eq!(memory.grow(&mut store, 1)?, None); @@ -506,7 +505,7 @@ impl Store { /// Add functions to the store, returning their addresses in the store pub(crate) fn init_funcs( &mut self, - funcs: &[alloc::sync::Arc], + funcs: &[Shared], owner: ModuleInstanceId, module_type_idxs: &[TypeAddr], type_addrs: &[TypeAddr], @@ -516,9 +515,10 @@ impl Store { self.state.funcs.reserve_exact(funcs.len()); for (func, &type_idx) in funcs.iter().cloned().zip(module_type_idxs) { let type_addr = type_addrs[type_idx as usize]; - self.state - .funcs - .push(FunctionInstance { type_addr, kind: FunctionKind::Wasm(WasmFunctionInstance { func, owner }) }); + self.state.funcs.push(FunctionInstance { + type_addr, + inner: FunctionInstanceInner::Wasm(WasmFunctionInstance { func, owner }), + }); } start..start + funcs.len() as FuncAddr } diff --git a/crates/tinywasm/src/store/state.rs b/crates/tinywasm/src/store/state.rs index 11ea70d..769fc8b 100644 --- a/crates/tinywasm/src/store/state.rs +++ b/crates/tinywasm/src/store/state.rs @@ -309,8 +309,8 @@ impl State { /// Get a wasm function at the actual index in the store, panicking if it's a host function (which should be guaranteed by the validator) pub(crate) fn get_wasm_func(&self, addr: FuncAddr) -> &WasmFunctionInstance { - match self.funcs.get(addr as usize).map(|func| &func.kind) { - Some(FunctionKind::Wasm(wasm_func)) => wasm_func, + match self.funcs.get(addr as usize).map(|func| &func.inner) { + Some(FunctionInstanceInner::Wasm(wasm_func)) => wasm_func, _ => unreachable!("invalid wasm function address: {addr}"), } } diff --git a/crates/tinywasm/tests/managed_exceptions.rs b/crates/tinywasm/tests/managed_exceptions.rs index bb75459..ecb6a12 100644 --- a/crates/tinywasm/tests/managed_exceptions.rs +++ b/crates/tinywasm/tests/managed_exceptions.rs @@ -125,8 +125,7 @@ impl ResourceLimiter for GcUsage { #[test] fn dropped_exception_roots_release_counted_gc_bytes() { let usage = Arc::new(Mutex::new(Vec::new())); - let config = - Config::new().with_gc_collection_threshold(usize::MAX).with_resource_limiter(Arc::new(GcUsage(usage.clone()))); + let config = Config::new().with_gc_collection_threshold(usize::MAX).with_resource_limiter(GcUsage(usage.clone())); let mut store = Store::new(Engine::new(config)); let instance = instantiate(&mut store); let catch = instance.func_untyped(&store, "catch-scalar").unwrap(); diff --git a/crates/tinywasm/tests/memory.rs b/crates/tinywasm/tests/memory.rs index 819fe85..608b9e1 100644 --- a/crates/tinywasm/tests/memory.rs +++ b/crates/tinywasm/tests/memory.rs @@ -1,14 +1,10 @@ -extern crate alloc; - -use alloc::sync::Arc; - use tinywasm::engine::Config; use tinywasm::types::{MemoryArch, MemoryType, RefType, RefValue, TableType}; use tinywasm::{Engine, Memory, ModuleInstance, ResourceLimiter, Store, Table, Trap}; type TestResult = Result>; -fn store_with_limiter(limiter: Arc) -> Store { +fn store_with_limiter(limiter: impl ResourceLimiter + 'static) -> Store { let engine = Engine::new(Config::new().with_resource_limiter(limiter)); Store::new(engine) } @@ -83,7 +79,7 @@ impl ResourceLimiter for TrapGrowth { #[test] fn resource_limiter_can_reject_growth() -> TestResult { - let mut store = store_with_limiter(Arc::new(DenyGrowth)); + let mut store = store_with_limiter(DenyGrowth); let memory = Memory::try_new(&mut store, MemoryType::new(MemoryArch::I32, 1, None, None))?; assert_eq!(memory.grow(&mut store, 1)?, None); @@ -103,7 +99,7 @@ fn resource_limiter_rejects_guest_memory_grow() -> TestResult { "#, )?; let module = tinywasm::parse_bytes(&wasm)?; - let mut store = store_with_limiter(Arc::new(DenyGrowth)); + let mut store = store_with_limiter(DenyGrowth); let instance = ModuleInstance::instantiate(&mut store, &module, None)?; let grow = instance.func::<(), i32>(&store, "grow")?; @@ -123,7 +119,7 @@ fn resource_limiter_can_trap_guest_memory_grow() -> TestResult { "#, )?; let module = tinywasm::parse_bytes(&wasm)?; - let mut store = store_with_limiter(Arc::new(TrapGrowth)); + let mut store = store_with_limiter(TrapGrowth); let instance = ModuleInstance::instantiate(&mut store, &module, None)?; let grow = instance.func::<(), i32>(&store, "grow")?; @@ -133,7 +129,7 @@ fn resource_limiter_can_trap_guest_memory_grow() -> TestResult { #[test] fn resource_limiter_rejects_host_memory_initial_size() { - let mut store = store_with_limiter(Arc::new(DenyAll)); + let mut store = store_with_limiter(DenyAll); let result = Memory::try_new(&mut store, MemoryType::new(MemoryArch::I32, 1, None, None)); assert!(matches!(result, Err(tinywasm::Error::Trap(Trap::OutOfMemory)))); @@ -143,7 +139,7 @@ fn resource_limiter_rejects_host_memory_initial_size() { fn resource_limiter_rejects_module_memory_initial_size() -> TestResult { let wasm = wat::parse_str("(module (memory 1))")?; let module = tinywasm::parse_bytes(&wasm)?; - let mut store = store_with_limiter(Arc::new(DenyAll)); + let mut store = store_with_limiter(DenyAll); let result = ModuleInstance::instantiate(&mut store, &module, None); assert!(matches!(result, Err(tinywasm::Error::Trap(Trap::OutOfMemory)))); @@ -152,7 +148,7 @@ fn resource_limiter_rejects_module_memory_initial_size() -> TestResult { #[test] fn resource_limiter_rejects_table_initial_size() { - let mut store = store_with_limiter(Arc::new(DenyAll)); + let mut store = store_with_limiter(DenyAll); let result = Table::try_new(&mut store, TableType::new(RefType::FUNCREF, 1, None), RefValue::Null.into()); assert!(matches!(result, Err(tinywasm::Error::Trap(Trap::OutOfMemory)))); @@ -168,7 +164,7 @@ fn table_rejects_initial_size_above_maximum() { #[test] fn resource_limiter_can_reject_table_growth() -> TestResult { - let mut store = store_with_limiter(Arc::new(DenyGrowth)); + let mut store = store_with_limiter(DenyGrowth); let table = Table::try_new(&mut store, TableType::new(RefType::FUNCREF, 1, None), RefValue::Null.into())?; assert_eq!(table.grow(&mut store, 1, RefValue::Null.into())?, None); @@ -178,7 +174,7 @@ fn resource_limiter_can_reject_table_growth() -> TestResult { #[test] fn resource_limiter_can_trap_table_growth() -> TestResult { - let mut store = store_with_limiter(Arc::new(TrapGrowth)); + let mut store = store_with_limiter(TrapGrowth); let table = Table::try_new(&mut store, TableType::new(RefType::FUNCREF, 1, None), RefValue::Null.into())?; assert!(matches!(table.grow(&mut store, 1, RefValue::Null.into()), Err(tinywasm::Error::Trap(Trap::Unreachable)))); diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 3587143..7f701cf 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -12,13 +12,24 @@ categories.workspace = true [dependencies] log = { workspace = true, optional = true } +portable-atomic-util = { version = "0.2.7", default-features = false, features = ["alloc"], optional = true } postcard = { version = "1.1", default-features = false, features = ["alloc"], optional = true } -serde = { version = "1.0", default-features = false, features = ["alloc", "rc"], optional = true } +serde = { version = "1.0", default-features = false, features = ["alloc"], optional = true } [features] default = ["archive", "debug", "log", "std"] -archive = ["dep:postcard", "dep:serde"] +# support serializing and deserializing twasm archives +archive = ["dep:postcard", "dep:serde", "serde/rc", "portable-atomic-util?/serde"] + +# derive Debug for runtime and module types debug = [] + +# enable integration with the log crate log = ["dep:log"] + +# enable standard library support std = ["serde?/std"] + +# support targets without native atomic CAS +portable-atomic = ["dep:portable-atomic-util"] diff --git a/crates/types/src/archive.rs b/crates/types/src/archive.rs index b568155..db13ab0 100644 --- a/crates/types/src/archive.rs +++ b/crates/types/src/archive.rs @@ -66,10 +66,10 @@ mod tests { use super::*; use crate::{ AbstractHeapType, ConstInstruction, Global, GlobalType, Instruction, ModuleFuncIdx, ModuleInner, RefType, - V128Operand, WasmFunction, WasmType, + Shared, V128Operand, WasmFunction, WasmType, }; use crate::{OperandIdx, OperandType}; - use alloc::{boxed::Box, sync::Arc, vec}; + use alloc::boxed::Box; #[test] fn test_invalid_magic() { @@ -92,9 +92,9 @@ mod tests { let bytes = [0x00, 0x01, 0x02, 0x03, 0x7f, 0x80, 0xfe, 0xff, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x90]; let mut function = WasmFunction::default(); let constant = OperandIdx::new(0); - function.data.operands128 = vec![V128Operand { value: bytes }.encode()].into_boxed_slice(); - function.instructions = vec![Instruction::Const128(constant), Instruction::I8x16Shuffle(constant)].into(); - let module = Module::from(ModuleInner { funcs: Box::new([Arc::new(function)]), ..ModuleInner::default() }); + function.data.operands128 = Box::new([V128Operand { value: bytes }.encode()]); + function.instructions = Box::new([Instruction::Const128(constant), Instruction::I8x16Shuffle(constant)]); + let module = Module::from(ModuleInner { funcs: Box::new([Shared::new(function)]), ..ModuleInner::default() }); let archive = module.serialize_twasm().expect("serialize archive"); assert_eq!(&archive[..6], b"TWAS06"); @@ -114,21 +114,20 @@ mod tests { fn const_reference_expressions_round_trip_archive() { let null_type = RefType::new_abstract(true, AbstractHeapType::Extern); let module = Module::from(ModuleInner { - globals: vec![ + globals: Box::new([ Global { ty: GlobalType::new(WasmType::Ref(null_type), false), - init: vec![ConstInstruction::RefNull(null_type)].into_boxed_slice(), + init: Box::new([ConstInstruction::RefNull(null_type)]), }, Global { ty: GlobalType::new(WasmType::Ref(RefType::FUNCREF), false), - init: vec![ConstInstruction::RefFunc(ModuleFuncIdx::new(7))].into_boxed_slice(), + init: Box::new([ConstInstruction::RefFunc(ModuleFuncIdx::new(7))]), }, Global { ty: GlobalType::new(WasmType::Ref(RefType::new_abstract(false, AbstractHeapType::I31)), false), - init: vec![ConstInstruction::I32Const(42), ConstInstruction::RefI31].into_boxed_slice(), + init: Box::new([ConstInstruction::I32Const(42), ConstInstruction::RefI31]), }, - ] - .into_boxed_slice(), + ]), ..ModuleInner::default() }); diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 686433d..9f363d3 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -9,9 +9,27 @@ //! Types used by [`tinywasm`](https://docs.rs/tinywasm) and [`tinywasm_parser`](https://docs.rs/tinywasm_parser). extern crate alloc; -use alloc::{boxed::Box, sync::Arc}; +use alloc::boxed::Box; use core::ops::{Deref, Range}; +#[cfg(all(not(feature = "portable-atomic"), not(target_has_atomic = "ptr")))] +compile_error!( + "this target does not support atomic operations, enable the `portable-atomic` feature to use `portable-atomic`" +); + +/// An atomically reference-counted pointer. +#[cfg(not(feature = "portable-atomic"))] +pub use alloc::sync::Arc as Shared; +/// A non-owning pointer paired with [`Shared`]. +#[cfg(not(feature = "portable-atomic"))] +pub use alloc::sync::Weak as WeakShared; +/// An atomically reference-counted pointer. +#[cfg(feature = "portable-atomic")] +pub use portable_atomic_util::Arc as Shared; +/// A non-owning pointer paired with [`Shared`]. +#[cfg(feature = "portable-atomic")] +pub use portable_atomic_util::Weak as WeakShared; + // Memory defaults const MEM_PAGE_SIZE: u64 = 65536; const fn max_page_count(arch: MemoryArch, page_size: u64) -> u64 { @@ -56,11 +74,11 @@ pub mod archive { #[derive(Clone, Default, PartialEq)] #[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] -pub struct Module(Arc); +pub struct Module(Shared); impl From for Module { fn from(inner: ModuleInner) -> Self { - Self(Arc::new(inner)) + Self(Shared::new(inner)) } } @@ -85,7 +103,7 @@ pub struct ModuleInner { /// Optimized WebAssembly functions /// /// Contains data from to the `code`, `func`, and `type` sections of the original WebAssembly module. - pub funcs: Box<[Arc]>, + pub funcs: Box<[Shared]>, /// The dense type definitions, indexed by `TypeAddr`. /// @@ -98,7 +116,7 @@ pub struct ModuleInner { /// Exported items of the WebAssembly module. /// /// Corresponds to the `export` section of the original WebAssembly module. - pub exports: Arc<[Export]>, + pub exports: Shared<[Export]>, /// Global components of the WebAssembly module. /// diff --git a/crates/types/src/types.rs b/crates/types/src/types.rs index 12386f1..273c762 100644 --- a/crates/types/src/types.rs +++ b/crates/types/src/types.rs @@ -1,6 +1,6 @@ -use alloc::{boxed::Box, sync::Arc}; +use alloc::boxed::Box; -use crate::{TypeAddr, WasmType}; +use crate::{Shared, TypeAddr, WasmType}; /// The dense type index space of a WebAssembly module. /// @@ -106,7 +106,7 @@ impl CompositeType { #[cfg_attr(feature = "debug", derive(Debug))] #[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))] pub struct FuncType { - data: Arc<[WasmType]>, + data: Shared<[WasmType]>, param_count: u16, } -- cgit v1.3.1 From c67ce64bfc88eada4d2b611e30b2dd307a7f7526 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 29 Aug 2026 22:20:03 +0200 Subject: feat: add nightly tail-call interpreter dispatch Signed-off-by: Henry --- .github/workflows/test.yaml | 8 + CHANGELOG.md | 1 + README.md | 8 +- crates/cli/src/wast_runner.rs | 22 +- crates/parser/Cargo.toml | 3 + crates/tinywasm/Cargo.toml | 3 + crates/tinywasm/src/interpreter/executor.rs | 2289 -------------------- .../tinywasm/src/interpreter/executor/dispatch.rs | 90 + .../src/interpreter/executor/dispatch_become.rs | 189 ++ .../src/interpreter/executor/instructions.rs | 690 ++++++ crates/tinywasm/src/interpreter/executor/mod.rs | 1561 +++++++++++++ crates/tinywasm/src/interpreter/mod.rs | 6 +- .../tinywasm/src/interpreter/stack/value_stack.rs | 12 +- crates/tinywasm/src/lib.rs | 9 +- crates/tinywasm/tests/resume_execution.rs | 4 +- examples/rust/src/print.twasm | Bin 155 -> 155 bytes 16 files changed, 2577 insertions(+), 2318 deletions(-) delete mode 100644 crates/tinywasm/src/interpreter/executor.rs create mode 100644 crates/tinywasm/src/interpreter/executor/dispatch.rs create mode 100644 crates/tinywasm/src/interpreter/executor/dispatch_become.rs create mode 100644 crates/tinywasm/src/interpreter/executor/instructions.rs create mode 100644 crates/tinywasm/src/interpreter/executor/mod.rs (limited to 'crates/parser/Cargo.toml') diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e950c47..e623fef 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -54,6 +54,10 @@ jobs: - os: ubuntu-latest rust: nightly name: "Linux x86 (nightly)" + - os: ubuntu-latest + rust: nightly + name: "Linux x86 (nightly tail calls)" + args: "--features tinywasm/nightly-tail-calls" - os: ubuntu-latest rust: stable name: "Linux x86 (stable, no default features)" @@ -62,6 +66,10 @@ jobs: rust: nightly name: "Linux x86 (nightly, no default features)" args: "--no-default-features" + - os: ubuntu-latest + rust: nightly + name: "Linux x86 (nightly tail calls, no default features)" + args: "--no-default-features --features tinywasm/nightly-tail-calls" - os: macos-14 rust: stable name: "macOS arm64 (Apple M1)" diff --git a/CHANGELOG.md b/CHANGELOG.md index a24ba43..d674c30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Optional parse-time operand deduplication to reduce `.twasm` archive size - Optional `send` support for moving stores and store-local handles across threads - Optional portable atomic shared pointers and counters for targets without native compare-and-swap +- Optional `nightly-tail-calls` backend using Rust's unstable explicit tail calls for interpreter dispatch ### Changed diff --git a/README.md b/README.md index 20c432a..383b007 100644 --- a/README.md +++ b/README.md @@ -50,15 +50,17 @@ See the [examples](./examples) directory and [documentation](https://docs.rs/tin - **`full`:** Enables `archive`, `parallel-parser`, `parser`, and `validate`. Enabled by default. - **`std`:** Enables `std` and parsing from files and streams. Enabled by default. -- **`log`:** Enables integration with the `log` crate. Enabled by default. - **`parser`:** Enables `tinywasm-parser` and top-level parse helpers. Enabled by default. - **`validate`:** Enables WebAssembly validation while parsing. Enabled by default and configurable through [`ParserOptions`](https://docs.rs/tinywasm/latest/tinywasm/parser/struct.ParserOptions.html). +- **`parallel-parser`:** Parallelizes function parsing when `std` is enabled. Enabled by default. - **`archive`:** Enables serialization and deserialization of the internal `twasm` format. Enabled by default. +- **`log`:** Enables integration with the `log` crate. Enabled by default. +- **`send`:** Makes stores and store-local handles movable across threads. +- **`portable-atomic`:** Supports targets without native atomic compare-and-swap. - **`canonicalize-nans`:** Uses a [canonical NaN](https://en.wikipedia.org/wiki/NaN#Canonical_NaN) for normalized NaN results. Enabled by default. - **`debug`:** Derives `Debug` for runtime types. Enabled by default. -- **`parallel-parser`:** Parallelizes function parsing when `std` is enabled. Enabled by default. - **`guest-debug`:** Exposes module-internal by-index inspection APIs (`*_by_index`). -- **`send`:** Makes stores and store-local handles movable across threads +- **`nightly-tail-calls`:** Uses Rust's unstable explicit tail calls for interpreter dispatch. Requires nightly Rust (recommended for maximum performance). - **`simd-x86`:** Enables x86-specific SIMD intrinsics and uses `unsafe` internally. With default features disabled, `tinywasm` supports `no_std + alloc` and depends only on `libm`. diff --git a/crates/cli/src/wast_runner.rs b/crates/cli/src/wast_runner.rs index 02add87..4ebdc6c 100644 --- a/crates/cli/src/wast_runner.rs +++ b/crates/cli/src/wast_runner.rs @@ -50,10 +50,8 @@ impl ModuleRegistry { } fn definition(&self, id: Option>) -> Option { - match id { - Some(id) => self.definitions.get(id.name()).cloned(), - None => self.last_definition.clone(), - } + let Some(id) = id else { return self.last_definition.clone() }; + self.definitions.get(id.name()).cloned() } fn update_last_instance(&mut self, instance: ModuleInstance, name: Option) { @@ -71,21 +69,13 @@ impl ModuleRegistry { } fn get_idx(&self, module_id: Option>) -> Option { - match module_id { - Some(module) => { - self.registered.get(module.name()).or_else(|| self.instances.get(module.name())).map(ModuleInstance::id) - } - None => self.last_instance.as_ref().map(ModuleInstance::id), - } + let Some(module_id) = module_id else { return self.last_instance.as_ref().map(ModuleInstance::id) }; + self.registered.get(module_id.name()).or_else(|| self.instances.get(module_id.name())).map(ModuleInstance::id) } fn get(&self, module_id: Option>) -> Option { - match module_id { - Some(module_id) => { - self.registered.get(module_id.name()).or_else(|| self.instances.get(module_id.name())).cloned() - } - None => self.last_instance.clone(), - } + let Some(module_id) = module_id else { return self.last_instance.clone() }; + self.registered.get(module_id.name()).or_else(|| self.instances.get(module_id.name())).cloned() } } diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 042eeda..7d781a4 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -32,3 +32,6 @@ std = ["tinywasm-types/std", "wasmparser/std"] # validate WebAssembly while parsing validate = ["wasmparser/features", "wasmparser/validate"] + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ["cfg(rust_analyzer)"] } diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index e20f6c6..3d78fca 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -122,6 +122,9 @@ debug = ["tinywasm-types/debug"] # expose module-internal by-index inspection APIs for non-exported entities (for testing and debugging) guest-debug = [] +# use explicit tail calls for interpreter dispatch (requires nightly Rust) +nightly-tail-calls = [] + # enable x86-specific SIMD intrinsics in Value128 (uses unsafe code) # note: for x86 backend selection, compile with x86-64-v3 target features # (for example: `RUSTFLAGS="-C target-cpu=x86-64-v3"`) diff --git a/crates/tinywasm/src/interpreter/executor.rs b/crates/tinywasm/src/interpreter/executor.rs deleted file mode 100644 index 5266084..0000000 --- a/crates/tinywasm/src/interpreter/executor.rs +++ /dev/null @@ -1,2289 +0,0 @@ -use core::{convert::identity, ops::ControlFlow}; - -#[cfg(not(feature = "std"))] -#[allow(unused_imports)] -use super::no_std_floats::NoStdFloatExt; - -use alloc::boxed::Box; -use alloc::vec::Vec; - -use interpreter::stack::{CallFrame, ValueStack}; -use tinywasm_types::*; - -use super::ExecState; -use super::num_helpers::*; -use super::values::*; -use crate::engine::FuelPolicy; -use crate::func::HostFunction; -use crate::interpreter::Value128; -use crate::*; - -const FUEL_COST_CALL_TOTAL: u32 = 5; - -pub(crate) struct Executor<'store, const BUDGETED: bool> { - cf: CallFrame, - func: Shared, - module: ModuleInstance, - store: &'store mut Store, - call_stack_base: u32, - mem0: MemAddr, -} - -impl<'store, const BUDGETED: bool> Executor<'store, BUDGETED> { - pub(crate) fn new(store: &'store mut Store, cf: CallFrame, call_stack_base: u32) -> Self { - let wasm_func = store.state.funcs.wasm(cf.func_addr); - let module = store.get_module_instance(wasm_func.owner).expect("invalid module instance").clone(); - let mem0 = module.mem0_addr(); - Self { module, cf, func: wasm_func.func.clone(), store, call_stack_base, mem0 } - } - - #[inline(always)] - fn exec(&mut self, instr_ptr: usize) -> Result> { - macro_rules! exec_op { - (binary_fallible $ty:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ - fn exec_binary_fallible(value_stack: &mut ValueStack) -> Result<(), Trap> { - let $rhs = <$ty>::stack_pop(value_stack); - let $lhs = <$ty>::stack_pop(value_stack); - <$ty>::stack_push(value_stack, $expr?) - } - exec_binary_fallible(&mut self.store.value_stack)?; - }}; - (unary $from:ty => $to:ty, |$v:ident| $expr:expr) => {{ - fn exec_unary(value_stack: &mut ValueStack) -> Result<(), Trap> { - let $v = <$from>::stack_pop(value_stack); - <$to>::stack_push(value_stack, $expr) - } - exec_unary(&mut self.store.value_stack)?; - }}; - (binary $from:ty => $to:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ - fn exec_binary(value_stack: &mut ValueStack) -> Result<(), Trap> { - let $rhs = <$from>::stack_pop(value_stack); - let $lhs = <$from>::stack_pop(value_stack); - <$to>::stack_push(value_stack, $expr) - } - exec_binary(&mut self.store.value_stack)?; - }}; - (binary $lhs_ty:ty, $rhs_ty:ty => $res:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ - fn exec_binary(value_stack: &mut ValueStack) -> Result<(), Trap> { - let $rhs = <$rhs_ty>::stack_pop(value_stack); - let $lhs = <$lhs_ty>::stack_pop(value_stack); - <$res>::stack_push(value_stack, $expr) - } - exec_binary(&mut self.store.value_stack)?; - }}; - (ternary $from:ty => $to:ty, |$a:ident, $b:ident, $c:ident| $expr:expr) => {{ - fn exec_ternary(value_stack: &mut ValueStack) -> Result<(), Trap> { - let $c = <$from>::stack_pop(value_stack); - let $b = <$from>::stack_pop(value_stack); - let $a = <$from>::stack_pop(value_stack); - <$to>::stack_push(value_stack, $expr) - } - exec_ternary(&mut self.store.value_stack)?; - }}; - } - - use tinywasm_types::Instruction::*; - #[rustfmt::skip] - match &self.func.instructions[instr_ptr] { - Unreachable => return cold!(Err(Trap::Unreachable.into())), - Drop32 => { _ = Value32::stack_pop(&mut self.store.value_stack)}, - Drop64 => { _ = Value64::stack_pop(&mut self.store.value_stack)}, - Drop128 => { _ = Value128::stack_pop(&mut self.store.value_stack)}, - Select32 => Value32::stack_select(&mut self.store.value_stack), - Select64 => Value64::stack_select(&mut self.store.value_stack), - Select128 => Value128::stack_select(&mut self.store.value_stack), - SelectStore32(idx) => self.exec_select_store::(idx.resolve(&self.func.data))?, - SelectStore64(idx) => self.exec_select_store::(idx.resolve(&self.func.data))?, - SelectMulti(counts) => self.store.value_stack.select_multi(*counts), - Call(v) => return self.exec_call_direct(*v, instr_ptr + 1), - CallSelf => return self.exec_call_self(instr_ptr + 1), - CallIndirect(idx) => return self.exec_call_indirect::(*idx, instr_ptr + 1), - CallRef(ty) => return self.exec_call_ref::(*ty, instr_ptr + 1), - ReturnCall(v) => return self.exec_return_call_direct(*v), - ReturnCallSelf => return self.exec_return_call_self(), - ReturnCallIndirect(idx) => return self.exec_call_indirect::(*idx, instr_ptr + 1), - ReturnCallRef(ty) => return self.exec_call_ref::(*ty, instr_ptr + 1), - Throw(tag) => return self.exec_throw(*tag, instr_ptr), - ThrowRef => return self.exec_throw_ref(instr_ptr), - Jump(ip) => return Ok(ControlFlow::Continue(*ip as usize)), - JumpIfZero32(ip) => if i32::stack_pop(&mut self.store.value_stack) == 0 { return Ok(ControlFlow::Continue(*ip as usize)) }, - JumpIfNonZero32(ip) => if i32::stack_pop(&mut self.store.value_stack) != 0 { return Ok(ControlFlow::Continue(*ip as usize)) }, - JumpIfZero64(ip) => if i64::stack_pop(&mut self.store.value_stack) == 0 { return Ok(ControlFlow::Continue(*ip as usize)) }, - JumpIfNonZero64(ip) => if i64::stack_pop(&mut self.store.value_stack) != 0 { return Ok(ControlFlow::Continue(*ip as usize)) }, - JumpIfRefNull(ip) => { let ip = *ip; if self.exec_jump_if_ref::() { return Ok(ControlFlow::Continue(ip as usize)) } }, - JumpIfRefNonNull(ip) => { let ip = *ip; if self.exec_jump_if_ref::() { return Ok(ControlFlow::Continue(ip as usize)) } }, - BrOnCast(idx) => if let Some(ip) = self.exec_br_on_cast::(*idx) { return Ok(ControlFlow::Continue(ip)) }, - BrOnCastFail(idx) => if let Some(ip) = self.exec_br_on_cast::(*idx) { return Ok(ControlFlow::Continue(ip)) }, - JumpIfLocalZero32(arg) => if self.exec_jump_if_local::(arg.local) { return Ok(ControlFlow::Continue(arg.target_ip as usize)) }, - JumpIfLocalNonZero32(arg) => if self.exec_jump_if_local::(arg.local) { return Ok(ControlFlow::Continue(arg.target_ip as usize)) }, - JumpIfLocalZero64(arg) => if self.exec_jump_if_local::(arg.local) { return Ok(ControlFlow::Continue(arg.target_ip as usize)) }, - JumpIfLocalNonZero64(arg) => if self.exec_jump_if_local::(arg.local) { return Ok(ControlFlow::Continue(arg.target_ip as usize)) }, - JumpCmpStackConst32(packed) => if let Some(ip) = self.exec_jump_cmp_stack_const32(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpStackConst64(packed) => if let Some(ip) = self.exec_jump_cmp_stack_const64(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpStackLocal32(packed) => if let Some(ip) = self.exec_jump_cmp_stack_local32(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpStackLocal64(packed) => if let Some(ip) = self.exec_jump_cmp_stack_local64(*packed) { return Ok(ControlFlow::Continue(ip)) }, - BinOpLocalConstJump32(packed) => if let Some(ip) = self.exec_binop_local_const_jump(*packed) { return Ok(ControlFlow::Continue(ip)) }, - BinOpLocalConstJumpCmpLocal32(packed) => if let Some(ip) = self.exec_binop_local_const_jump_cmp_local(*packed) { return Ok(ControlFlow::Continue(ip)) }, - BinOpStackConstTeeLocalJump32(packed) => if let Some(ip) = self.exec_binop_stack_const_tee_local_jump(*packed)? { return Ok(ControlFlow::Continue(ip)) }, - BinOpGlobalConstJump32(packed) => if let Some(ip) = self.exec_binop_global_const_jump(*packed) { return Ok(ControlFlow::Continue(ip)) }, - IncLocalJump32(idx) => if let Some(ip) = self.exec_inc_local_jump(*idx) { return Ok(ControlFlow::Continue(ip)) }, - IncStackTeeLocalJump32(idx) => if let Some(ip) = self.exec_inc_stack_tee_local_jump(*idx)? { return Ok(ControlFlow::Continue(ip)) }, - IncGlobalJump32(idx) => if let Some(ip) = self.exec_inc_global_jump(*idx) { return Ok(ControlFlow::Continue(ip)) }, - IncLocalJumpCmpLocal32(packed) => if let Some(ip) = self.exec_inc_local_jump_cmp_local(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpLocalConst32(packed) => if let Some(ip) = self.exec_jump_cmp_local_const32(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpLocalConst64(packed) => if let Some(ip) = self.exec_jump_cmp_local_const64(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpLocalLocal32(packed) => if let Some(ip) = self.exec_jump_cmp_local_local32(*packed) { return Ok(ControlFlow::Continue(ip)) }, - JumpCmpLocalLocal64(packed) => if let Some(ip) = self.exec_jump_cmp_local_local64(*packed) { return Ok(ControlFlow::Continue(ip)) }, - DropKeep32 { base, keep } => self.store.value_stack.stack_32.truncate_keep((self.cf.stack_base().s32 + u32::from(*base)) as usize, *keep as usize), - DropKeep64 { base, keep } => self.store.value_stack.stack_64.truncate_keep((self.cf.stack_base().s64 + u32::from(*base)) as usize, *keep as usize), - DropKeep128 { base, keep } => self.store.value_stack.stack_128.truncate_keep((self.cf.stack_base().s128 + u32::from(*base)) as usize, *keep as usize), - BranchTable(idx) => return Ok(ControlFlow::Continue(self.exec_branch_table(*idx))), - Return => return Ok(self.exec_return()), - ReturnVoid => return Ok(self.exec_return_void()), - Return32 => return Ok(self.exec_return_32()), - Return64 => return Ok(self.exec_return_64()), - Return128 => return Ok(self.exec_return_128()), - LocalGet32(local_index) => Value32::local_push(&mut self.store.value_stack, &self.cf, *local_index)?, - LocalGet64(local_index) => Value64::local_push(&mut self.store.value_stack, &self.cf, *local_index)?, - LocalGet128(local_index) => Value128::local_push(&mut self.store.value_stack, &self.cf, *local_index)?, - LocalSet32(local_index) => self.exec_local_set_pop::(*local_index), - LocalSet64(local_index) => self.exec_local_set_pop::(*local_index), - LocalSet128(local_index) => self.exec_local_set_pop::(*local_index), - LocalCopy32(from, to) => Value32::local_copy(&mut self.store.value_stack, &self.cf, *from, *to), - LocalCopy64(from, to) => Value64::local_copy(&mut self.store.value_stack, &self.cf, *from, *to), - LocalCopy128(from, to) => Value128::local_copy(&mut self.store.value_stack, &self.cf, *from, *to), - AddConst32(c) => { i32::stack_update(&mut self.store.value_stack, |value| value.wrapping_add(*c)); }, - AndConst32(c) => { i32::stack_update(&mut self.store.value_stack, |value| value & *c); }, - XorConst32(c) => { i32::stack_update(&mut self.store.value_stack, |value| value ^ *c); }, - ShrUConst32(c) => { u32::stack_update(&mut self.store.value_stack, |value| value.wrapping_shr(*c as u32)); }, - AddConst64(idx) => { let rhs = idx.resolve(&self.func.data).value(); i64::stack_update(&mut self.store.value_stack, |value| value.wrapping_add(rhs)); }, - BinOpStackConst32(op, rhs) => { u32::stack_update(&mut self.store.value_stack, |lhs| op.exec(lhs, *rhs as u32)); }, - BinOpStackConst64(packed) => { let rhs = packed.index.resolve(&self.func.data).value() as u64; u64::stack_update(&mut self.store.value_stack, |lhs| packed.op.exec(lhs, rhs)); }, - IncLocal32(arg) => { i32::local_update(&mut self.store.value_stack, &self.cf, arg.local, |value| value.wrapping_add(arg.value)); }, - IncLocal64(packed) => { let rhs = packed.index.resolve(&self.func.data).value(); i64::local_update(&mut self.store.value_stack, &self.cf, packed.op, |value| value.wrapping_add(rhs)); }, - I32Add3 => exec_op!(ternary i32 => i32, |a, b, c| a.wrapping_add(b).wrapping_add(c)), - I64Add3 => exec_op!(ternary i64 => i64, |a, b, c| a.wrapping_add(b).wrapping_add(c)), - MulAccLocal32(acc) => self.exec_mul_acc_local::(*acc, i32::wrapping_mul, i32::wrapping_add), - MulAccLocal64(acc) => self.exec_mul_acc_local::(*acc, i64::wrapping_mul, i64::wrapping_add), - FMulAccLocal32(acc) => self.exec_mul_acc_local::(*acc, #[inline(always)] |a, b| a * b, #[inline(always)] |a, b| a + b), - FMulAccLocal64(acc) => self.exec_mul_acc_local::(*acc, #[inline(always)] |a, b| a * b, #[inline(always)] |a, b| a + b), - BinOpLocalLocal32(op, a, b) => self.exec_binop_local_local::(*a, *b, None, *op)?, - BinOpLocalLocal64(op, a, b) => self.exec_binop_local_local::(*a, *b, None, *op)?, - BinOpLocalLocal128(op, a, b) => self.exec_binop_local_local::(*a, *b, None, *op)?, - CmpLocalLocal32(op, a, b) => self.exec_cmp_local_local::(*a, *b, *op)?, - CmpLocalLocal64(op, a, b) => self.exec_cmp_local_local::(*a, *b, *op)?, - AddLocalLocalSet32(arg) => self.exec_binop_local_local::(arg.left, arg.right, Some(arg.dst), BinOp::IAdd)?, - AddLocalLocalTee32(arg) => self.exec_binop_local_local::(arg.left, arg.right, Some(arg.dst), BinOp::IAdd)?, - BinOpLocalLocalSet32(packed) => self.exec_binop_local_local_indexed::(packed.index, packed.op)?, - BinOpLocalLocalSet64(packed) => self.exec_binop_local_local_indexed::(packed.index, packed.op)?, - BinOpLocalLocalSet128(packed) => self.exec_binop_local_local_indexed::(packed.index, packed.op)?, - BinOpLocalLocalTee32(packed) => self.exec_binop_local_local_indexed::(packed.index, packed.op)?, - BinOpLocalLocalTee64(packed) => self.exec_binop_local_local_indexed::(packed.index, packed.op)?, - BinOpLocalLocalTee128(packed) => self.exec_binop_local_local_indexed::(packed.index, packed.op)?, - AddLocalConst32(arg) => self.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IAdd)?, - SubLocalConst32(arg) => self.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::ISub)?, - MulLocalConst32(arg) => self.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IMul)?, - AndLocalConst32(arg) => self.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IAnd)?, - ShrULocalConst32(arg) => self.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IShrU)?, - BinOpLocalConst32(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_local_const::(v.a(), v.b(), None, packed.op)?; }, - BinOpLocalConst64(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_local_const::(v.a(), v.b(), None, packed.op)?; }, - BinOpLocalConst128(packed) => { let v = packed.index.resolve(&self.func.data); let rhs = Value128(v.b().resolve(&self.func.data).value()); self.exec_binop_local_const::(v.a(), rhs, None, packed.op)?; }, - BinOpLocalConstSet32(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, - BinOpLocalConstTee32(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, - BinOpLocalConstSet64(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, - BinOpLocalConstTee64(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, - BinOpLocalConstSet128(packed) => { let v = packed.index.resolve(&self.func.data); let rhs = Value128(v.c().resolve(&self.func.data).value()); self.exec_binop_local_const::(v.a(), rhs, Some(v.b()), packed.op)?; }, - BinOpLocalConstTee128(packed) => { let v = packed.index.resolve(&self.func.data); let rhs = Value128(v.c().resolve(&self.func.data).value()); self.exec_binop_local_const::(v.a(), rhs, Some(v.b()), packed.op)?; }, - BinOpStackLocal32(op, local) => self.exec_binop_stack_local::(*local, None, *op)?, - BinOpStackLocalSet32(op, local, dst) => self.exec_binop_stack_local::(*local, Some(*dst), *op)?, - BinOpStackLocalTee32(op, local, dst) => self.exec_binop_stack_local::(*local, Some(*dst), *op)?, - BinOpStackLocal128(op, local) => self.exec_binop_stack_local::(*local, None, *op)?, - BinOpStackGlobal32(op, global_index) => self.exec_binop_stack_global::(*global_index, *op)?, - BinOpStackGlobal64(op, global_index) => self.exec_binop_stack_global::(*global_index, *op)?, - BinOpGlobalConst32(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_global_const::(v.a(), v.b(), packed.op)?; }, - BinOpGlobalConst64(packed) => { let v = packed.index.resolve(&self.func.data); self.exec_binop_global_const::(v.a(), v.b(), packed.op)?; }, - BinOpGlobalConst128(packed) => { let v = packed.index.resolve(&self.func.data); let rhs = Value128(v.b().resolve(&self.func.data).value()); self.exec_binop_global_const::(v.a(), rhs, packed.op)?; }, - SetLocalConst32(arg) => i32::local_set(&mut self.store.value_stack, &self.cf, arg.local, arg.value), - SetLocalConst64(packed) => { let v = packed.index.resolve(&self.func.data).value(); i64::local_set(&mut self.store.value_stack, &self.cf, packed.op, v); }, - SetLocalConst128(packed) => Value128::local_set(&mut self.store.value_stack, &self.cf, packed.op, Value128(packed.index.resolve(&self.func.data).value())), - IncMemoryLocal32(arg) => self.exec_inc_memory_local::(arg.memory_arg_idx, arg.local1, #[inline(always)] |v| v.wrapping_add(1))?, - IncMemoryLocal64(arg) => self.exec_inc_memory_local::(arg.memory_arg_idx, arg.local1, #[inline(always)] |v| v.wrapping_add(1))?, - StoreLocalLocal32(arg) => self.exec_store_local_local::(arg.memory_arg_idx, arg.local1, arg.local2)?, - StoreLocalLocal64(arg) => self.exec_store_local_local::(arg.memory_arg_idx, arg.local1, arg.local2)?, - StoreLocalLocal128(arg) => self.exec_store_local_local::(arg.memory_arg_idx, arg.local1, arg.local2)?, - LoadLocal32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, identity)?, - LoadLocal64(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, identity)?, - LoadLocal8S32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, - LoadLocal8U32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, - LoadLocal16S32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, - LoadLocal16U32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, - LoadLocalTee32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, - LoadLocalSet32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, - LoadLocalTee8S32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalTee8U32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalTee16S32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalTee16U32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalSet8S32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalSet8U32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalSet16S32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalSet16U32(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, - LoadLocalTee128(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, - LoadLocalSet128(arg) => self.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, - AndConstTee32(arg) => self.exec_binop_const_tee::(arg.value as u32, arg.local, BinOp::IAnd)?, - SubConstTee32(arg) => self.exec_binop_const_tee::(arg.value as u32, arg.local, BinOp::ISub)?, - AndConstTee64(packed) => self.exec_binop_const_tee::(packed.index.resolve(&self.func.data).value() as u64, packed.op, BinOp::IAnd)?, - SubConstTee64(packed) => self.exec_binop_const_tee::(packed.index.resolve(&self.func.data).value() as u64, packed.op, BinOp::ISub)?, - LocalTee32(local_index) => self.exec_local_tee::(*local_index), - LocalTee64(local_index) => self.exec_local_tee::(*local_index), - LocalTee128(local_index) => self.exec_local_tee::(*local_index), - GlobalGet32(global_index) => self.exec_global_get::(*global_index)?, - GlobalGet64(global_index) => self.exec_global_get::(*global_index)?, - GlobalGet128(global_index) => self.exec_global_get::(*global_index)?, - GlobalSet32(global_index) => self.exec_global_set::(*global_index), - GlobalSet64(global_index) => self.exec_global_set::(*global_index), - GlobalSet128(global_index) => self.exec_global_set::(*global_index), - GlobalTee32(global_index) => self.exec_global_tee::(*global_index), - GlobalTee64(global_index) => self.exec_global_tee::(*global_index), - GlobalTee128(global_index) => self.exec_global_tee::(*global_index), - Const32(val) => i32::stack_push(&mut self.store.value_stack, *val)?, - Const64Imm(val) => i64::stack_push(&mut self.store.value_stack, i64::from(*val))?, - Const64(idx) => i64::stack_push(&mut self.store.value_stack, idx.resolve(&self.func.data).value())?, - Const128Imm(val) => Value128::stack_push(&mut self.store.value_stack, Value128(u128::from(*val).to_le_bytes()))?, - I64Eqz => exec_op!(unary i64 => i32, |v| i32::from(v == 0)), - I32Eqz => exec_op!(unary i32 => i32, |v| i32::from(v == 0)), - I32Eq => exec_op!(binary i32 => i32, |a, b| i32::from(a == b)), - I64Eq => exec_op!(binary i64 => i32, |a, b| i32::from(a == b)), - F32Eq => exec_op!(binary f32 => i32, |a, b| i32::from(a == b)), - F64Eq => exec_op!(binary f64 => i32, |a, b| i32::from(a == b)), - I32Ne => exec_op!(binary i32 => i32, |a, b| i32::from(a != b)), - I64Ne => exec_op!(binary i64 => i32, |a, b| i32::from(a != b)), - F32Ne => exec_op!(binary f32 => i32, |a, b| i32::from(a != b)), - F64Ne => exec_op!(binary f64 => i32, |a, b| i32::from(a != b)), - I32LtS => exec_op!(binary i32 => i32, |a, b| i32::from(a < b)), - I64LtS => exec_op!(binary i64 => i32, |a, b| i32::from(a < b)), - I32LtU => exec_op!(binary u32 => i32, |a, b| i32::from(a < b)), - I64LtU => exec_op!(binary u64 => i32, |a, b| i32::from(a < b)), - F32Lt => exec_op!(binary f32 => i32, |a, b| i32::from(a < b)), - F64Lt => exec_op!(binary f64 => i32, |a, b| i32::from(a < b)), - I32LeS => exec_op!(binary i32 => i32, |a, b| i32::from(a <= b)), - I64LeS => exec_op!(binary i64 => i32, |a, b| i32::from(a <= b)), - I32LeU => exec_op!(binary u32 => i32, |a, b| i32::from(a <= b)), - I64LeU => exec_op!(binary u64 => i32, |a, b| i32::from(a <= b)), - F32Le => exec_op!(binary f32 => i32, |a, b| i32::from(a <= b)), - F64Le => exec_op!(binary f64 => i32, |a, b| i32::from(a <= b)), - I32GeS => exec_op!(binary i32 => i32, |a, b| i32::from(a >= b)), - I64GeS => exec_op!(binary i64 => i32, |a, b| i32::from(a >= b)), - I32GeU => exec_op!(binary u32 => i32, |a, b| i32::from(a >= b)), - I64GeU => exec_op!(binary u64 => i32, |a, b| i32::from(a >= b)), - F32Ge => exec_op!(binary f32 => i32, |a, b| i32::from(a >= b)), - F64Ge => exec_op!(binary f64 => i32, |a, b| i32::from(a >= b)), - I32GtS => exec_op!(binary i32 => i32, |a, b| i32::from(a > b)), - I64GtS => exec_op!(binary i64 => i32, |a, b| i32::from(a > b)), - I32GtU => exec_op!(binary u32 => i32, |a, b| i32::from(a > b)), - I64GtU => exec_op!(binary u64 => i32, |a, b| i32::from(a > b)), - F32Gt => exec_op!(binary f32 => i32, |a, b| i32::from(a > b)), - F64Gt => exec_op!(binary f64 => i32, |a, b| i32::from(a > b)), - I32Add => exec_op!(binary i32 => i32, |a, b| a.wrapping_add(b)), - I64Add => exec_op!(binary i64 => i64, |a, b| a.wrapping_add(b)), - F32Add => exec_op!(binary f32 => f32, |a, b| a + b), - F64Add => exec_op!(binary f64 => f64, |a, b| a + b), - I32Sub => exec_op!(binary i32 => i32, |a, b| a.wrapping_sub(b)), - I64Sub => exec_op!(binary i64 => i64, |a, b| a.wrapping_sub(b)), - F32Sub => exec_op!(binary f32 => f32, |a, b| a - b), - F64Sub => exec_op!(binary f64 => f64, |a, b| a - b), - F32Div => exec_op!(binary f32 => f32, |a, b| a / b), - F64Div => exec_op!(binary f64 => f64, |a, b| a / b), - I32Mul => exec_op!(binary i32 => i32, |a, b| a.wrapping_mul(b)), - I64Mul => exec_op!(binary i64 => i64, |a, b| a.wrapping_mul(b)), - F32Mul => exec_op!(binary f32 => f32, |a, b| a * b), - F64Mul => exec_op!(binary f64 => f64, |a, b| a * b), - I32DivS => exec_op!(binary_fallible i32, |a, b| a.tw_checked_div(b)), - I64DivS => exec_op!(binary_fallible i64, |a, b| a.tw_checked_div(b)), - I32DivU => exec_op!(binary_fallible u32, |a, b| a.checked_div(b).ok_or(Trap::DivisionByZero)), - I64DivU => exec_op!(binary_fallible u64, |a, b| a.checked_div(b).ok_or(Trap::DivisionByZero)), - I32RemS => exec_op!(binary_fallible i32, |a, b| a.tw_checked_wrapping_rem(b)), - I64RemS => exec_op!(binary_fallible i64, |a, b| a.tw_checked_wrapping_rem(b)), - I32RemU => exec_op!(binary_fallible u32, |a, b| a.tw_checked_wrapping_rem(b)), - I64RemU => exec_op!(binary_fallible u64, |a, b| a.tw_checked_wrapping_rem(b)), - I32And => exec_op!(binary i32 => i32, |a, b| a & b), - I64And => exec_op!(binary i64 => i64, |a, b| a & b), - I32Or => exec_op!(binary i32 => i32, |a, b| a | b), - I64Or => exec_op!(binary i64 => i64, |a, b| a | b), - I32Xor => exec_op!(binary i32 => i32, |a, b| a ^ b), - I64Xor => exec_op!(binary i64 => i64, |a, b| a ^ b), - I32Shl => exec_op!(binary i32 => i32, |a, b| a.wrapping_shl(b as u32)), - I64Shl => exec_op!(binary i64 => i64, |a, b| a.wrapping_shl(b as u32)), - I32ShrS => exec_op!(binary i32 => i32, |a, b| a.wrapping_shr(b as u32)), - I64ShrS => exec_op!(binary i64 => i64, |a, b| a.wrapping_shr(b as u32)), - I32ShrU => exec_op!(binary u32 => u32, |a, b| a.wrapping_shr(b)), - I64ShrU => exec_op!(binary u64 => u64, |a, b| a.wrapping_shr(b as u32)), - I32Rotl => exec_op!(binary i32 => i32, |a, b| a.rotate_left(b as u32)), - I64Rotl => exec_op!(binary i64 => i64, |a, b| a.rotate_left(b as u32)), - I32Rotr => exec_op!(binary i32 => i32, |a, b| a.rotate_right(b as u32)), - I64Rotr => exec_op!(binary i64 => i64, |a, b| a.rotate_right(b as u32)), - I64Add128 => self.exec_i64_add128()?, - I64Sub128 => self.exec_i64_sub128()?, - I64MulWideS => self.exec_i64_mul_wide_s()?, - I64MulWideU => self.exec_i64_mul_wide_u()?, - I32Clz => exec_op!(unary i32 => i32, |v| v.leading_zeros() as i32), - I64Clz => exec_op!(unary i64 => i64, |v| i64::from(v.leading_zeros())), - I32Ctz => exec_op!(unary i32 => i32, |v| v.trailing_zeros() as i32), - I64Ctz => exec_op!(unary i64 => i64, |v| i64::from(v.trailing_zeros())), - I32Popcnt => exec_op!(unary i32 => i32, |v| v.count_ones() as i32), - I64Popcnt => exec_op!(unary i64 => i64, |v| i64::from(v.count_ones())), - - // Reference types - RefFunc(func_idx) => ValueRef::stack_push(&mut self.store.value_stack, ValueRef::from_category_addr(self.module.resolve_func_addr(*func_idx)))?, - RefNull(_) => ValueRef::stack_push(&mut self.store.value_stack, ValueRef::NULL)?, - RefIsNull => self.exec_ref_is_null()?, - RefAsNonNull => self.exec_ref_as_non_null()?, - RefI31 => exec_op!(unary i32 => ValueRef, |v| ValueRef::from_i31(v)), - I31GetS => self.exec_i31_get(true)?, - I31GetU => self.exec_i31_get(false)?, - RefEq => exec_op!(binary ValueRef => i32, |a, b| i32::from(a == b)), - RefTest(ty) => self.exec_ref_test(*ty)?, - RefCast(ty) => self.exec_ref_cast(*ty)?, - - // GC objects - StructNew(ty) => self.exec_struct_new(*ty, false)?, - StructNewDefault(ty) => self.exec_struct_new(*ty, true)?, - StructGet(idx) => self.exec_struct_get(*idx, None)?, - StructGetS(idx) => self.exec_struct_get(*idx, Some(true))?, - StructGetU(idx) => self.exec_struct_get(*idx, Some(false))?, - StructSet(idx) => self.exec_struct_set(*idx)?, - ArrayNew(ty) => self.exec_array_new(*ty, false)?, - ArrayNewDefault(ty) => self.exec_array_new(*ty, true)?, - ArrayNewFixed(idx) => self.exec_array_new_fixed(*idx)?, - ArrayNewData(idx) => self.exec_array_new_data(*idx)?, - ArrayNewElem(idx) => self.exec_array_new_elem(*idx)?, - ArrayGet(ty) => self.exec_array_get(*ty, None)?, - ArrayGetS(ty) => self.exec_array_get(*ty, Some(true))?, - ArrayGetU(ty) => self.exec_array_get(*ty, Some(false))?, - ArraySet(ty) => self.exec_array_set(*ty)?, - ArrayLen => self.exec_array_len()?, - ArrayFill(ty) => self.exec_array_fill(*ty)?, - ArrayCopy(idx) => self.exec_array_copy(*idx)?, - ArrayInitData(idx) => self.exec_array_init_data(*idx)?, - ArrayInitElem(idx) => self.exec_array_init_elem(*idx)?, - MemorySize(addr) => self.exec_memory_size(*addr)?, - MemoryGrow(addr) => self.exec_memory_grow(*addr)?, - - // Bulk memory operations - MemoryCopy(idx) => self.exec_memory_copy(*idx)?, - MemoryFill(addr) => self.exec_memory_fill(*addr)?, - MemoryFillConst(idx) => self.exec_memory_fill_const(*idx)?, - MemoryInit(idx) => self.exec_memory_init(*idx)?, - DataDrop(data_index) => self.store.state.get_data_mut(self.module.resolve_data_addr(*data_index)).drop(), - ElemDrop(elem_index) => self.store.state.get_elem_mut(self.module.resolve_elem_addr(*elem_index)).drop(), - - // Table instructions - TableGet(table_idx) => self.exec_table_get(*table_idx)?, - TableSet(table_idx) => self.exec_table_set(*table_idx)?, - TableSize(table_idx) => self.exec_table_size(*table_idx)?, - TableInit(idx) => self.exec_table_init(*idx)?, - TableGrow(table_idx) => self.exec_table_grow(*table_idx)?, - TableFill(table_idx) => self.exec_table_fill(*table_idx)?, - TableCopy(idx) => self.exec_table_copy(*idx)?, - - // Core memory load/store operations - I32Store(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), identity)?, - I64Store(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), identity)?, - F32Store(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), identity)?, - F64Store(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), identity)?, - FMaStoreF32(m) => self.exec_fma_store::(*m)?, - FMaStoreF64(m) => self.exec_fma_store::(*m)?, - I32Store8(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), #[inline(always)] |v| v as i8)?, - I32Store16(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), #[inline(always)] |v| v as i16)?, - I64Store8(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), #[inline(always)] |v| v as i8)?, - I64Store16(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), #[inline(always)] |v| v as i16)?, - I64Store32(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), #[inline(always)] |v| v as i32)?, - I32Load(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), identity)?, - I64Load(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), identity)?, - F32Load(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), identity)?, - F64Load(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), identity)?, - I32Load8S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i32::from)?, - I32Load8U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i32::from)?, - I32Load16S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i32::from)?, - I32Load16U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i32::from)?, - I64Load8S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i64::from)?, - I64Load8U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i64::from)?, - I64Load16S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i64::from)?, - I64Load16U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i64::from)?, - I64Load32S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i64::from)?, - I64Load32U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), i64::from)?, - - // Numeric conversion operations - F32ConvertI32S => exec_op!(unary i32 => f32, |v| v as f32), - F32ConvertI64S => exec_op!(unary i64 => f32, |v| v as f32), - F64ConvertI32S => exec_op!(unary i32 => f64, |v| f64::from(v)), - F64ConvertI64S => exec_op!(unary i64 => f64, |v| v as f64), - F32ConvertI32U => exec_op!(unary u32 => f32, |v| v as f32), - F32ConvertI64U => exec_op!(unary u64 => f32, |v| v as f32), - F64ConvertI32U => exec_op!(unary u32 => f64, |v| f64::from(v)), - F64ConvertI64U => exec_op!(unary u64 => f64, |v| v as f64), - - // Sign-extension operations - I32Extend8S => exec_op!(unary i32 => i32, |v| i32::from(v as i8)), - I32Extend16S => exec_op!(unary i32 => i32, |v| i32::from(v as i16)), - I64Extend8S => exec_op!(unary i64 => i64, |v| i64::from(v as i8)), - I64Extend16S => exec_op!(unary i64 => i64, |v| i64::from(v as i16)), - I64Extend32S => exec_op!(unary i64 => i64, |v| i64::from(v as i32)), - I64ExtendI32U => exec_op!(unary u32 => i64, |v| i64::from(v)), - I64ExtendI32S => exec_op!(unary i32 => i64, |v| i64::from(v)), - I32WrapI64 => exec_op!(unary i64 => i32, |v| v as i32), - F32DemoteF64 => exec_op!(unary f64 => f32, |v| v as f32), - F64PromoteF32 => exec_op!(unary f32 => f64, |v| f64::from(v)), - F32Abs => exec_op!(unary f32 => f32, |v| v.abs()), - F64Abs => exec_op!(unary f64 => f64, |v| v.abs()), - F32Neg => exec_op!(unary f32 => f32, |v| -v), - F64Neg => exec_op!(unary f64 => f64, |v| -v), - F32Ceil => exec_op!(unary f32 => f32, |v| v.ceil()), - F64Ceil => exec_op!(unary f64 => f64, |v| v.ceil()), - F32Floor => exec_op!(unary f32 => f32, |v| v.floor()), - F64Floor => exec_op!(unary f64 => f64, |v| v.floor()), - F32Trunc => exec_op!(unary f32 => f32, |v| v.trunc()), - F64Trunc => exec_op!(unary f64 => f64, |v| v.trunc()), - F32Nearest => exec_op!(unary f32 => f32, |v| v.tw_nearest()), - F64Nearest => exec_op!(unary f64 => f64, |v| v.tw_nearest()), - F32Sqrt => exec_op!(unary f32 => f32, |v| v.sqrt()), - F64Sqrt => exec_op!(unary f64 => f64, |v| v.sqrt()), - F32Min => exec_op!(binary f32 => f32, |a, b| a.tw_minimum(b)), - F64Min => exec_op!(binary f64 => f64, |a, b| a.tw_minimum(b)), - F32Max => exec_op!(binary f32 => f32, |a, b| a.tw_maximum(b)), - F64Max => exec_op!(binary f64 => f64, |a, b| a.tw_maximum(b)), - F32Copysign => exec_op!(binary f32 => f32, |a, b| a.copysign(b)), - F64Copysign => exec_op!(binary f64 => f64, |a, b| a.copysign(b)), - I32TruncF32S => checked_conv_float!(f32, i32, self), - I32TruncF64S => checked_conv_float!(f64, i32, self), - I32TruncF32U => checked_conv_float!(f32, u32, i32, self), - I32TruncF64U => checked_conv_float!(f64, u32, i32, self), - I64TruncF32S => checked_conv_float!(f32, i64, self), - I64TruncF64S => checked_conv_float!(f64, i64, self), - I64TruncF32U => checked_conv_float!(f32, u64, i64, self), - I64TruncF64U => checked_conv_float!(f64, u64, i64, self), - - // Non-trapping float-to-int conversions - I32TruncSatF32S => exec_op!(unary f32 => i32, |v| v.trunc() as i32), - I32TruncSatF32U => exec_op!(unary f32 => u32, |v| v.trunc() as u32), - I32TruncSatF64S => exec_op!(unary f64 => i32, |v| v.trunc() as i32), - I32TruncSatF64U => exec_op!(unary f64 => u32, |v| v.trunc() as u32), - I64TruncSatF32S => exec_op!(unary f32 => i64, |v| v.trunc() as i64), - I64TruncSatF32U => exec_op!(unary f32 => u64, |v| v.trunc() as u64), - I64TruncSatF64S => exec_op!(unary f64 => i64, |v| v.trunc() as i64), - I64TruncSatF64U => exec_op!(unary f64 => u64, |v| v.trunc() as u64), - - // SIMD extension - V128Not => exec_op!(unary Value128 => Value128, |v| v.v128_not()), - V128And => exec_op!(binary Value128 => Value128, |a, b| a.v128_and(b)), - V128AndNot => exec_op!(binary Value128 => Value128, |a, b| a.v128_andnot(b)), - V128Or => exec_op!(binary Value128 => Value128, |a, b| a.v128_or(b)), - V128Xor => exec_op!(binary Value128 => Value128, |a, b| a.v128_xor(b)), - V128Bitselect => exec_op!(ternary Value128 => Value128, |a, b, c| Value128::v128_bitselect(a, b, c)), - V128AnyTrue => exec_op!(unary Value128 => i32, |v| v.v128_any_true() as i32), - I8x16Swizzle => exec_op!(binary Value128 => Value128, |a, s| a.i8x16_swizzle(s)), - I8x16RelaxedSwizzle => exec_op!(binary Value128 => Value128, |a, s| a.i8x16_relaxed_swizzle(s)), - V128Load(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), identity)?, - V128Load8x8S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::v128_load8x8_s(v.to_le_bytes()))?, - V128Load8x8U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::v128_load8x8_u(v.to_le_bytes()))?, - V128Load16x4S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::v128_load16x4_s(v.to_le_bytes()))?, - V128Load16x4U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::v128_load16x4_u(v.to_le_bytes()))?, - V128Load32x2S(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::v128_load32x2_s(v.to_le_bytes()))?, - V128Load32x2U(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::v128_load32x2_u(v.to_le_bytes()))?, - V128Load8Splat(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), Value128::splat_i8)?, - V128Load16Splat(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), Value128::splat_i16)?, - V128Load32Splat(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), Value128::splat_i32)?, - V128Load64Splat(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), Value128::splat_i64)?, - V128Store(idx) => self.exec_mem_store::(idx.resolve(&self.func.data), identity)?, - V128Store8Lane(arg) => self.exec_mem_store_lane::(*arg)?, - V128Store16Lane(arg) => self.exec_mem_store_lane::(*arg)?, - V128Store32Lane(arg) => self.exec_mem_store_lane::(*arg)?, - V128Store64Lane(arg) => self.exec_mem_store_lane::(*arg)?, - V128Load32Zero(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::from_i32x4([v, 0, 0, 0]))?, - V128Load64Zero(idx) => self.exec_mem_load::(idx.resolve(&self.func.data), |v| Value128::from_i64x2([v, 0]))?, - Const128(arg) => Value128::stack_push(&mut self.store.value_stack, Value128(arg.resolve(&self.func.data).value()))?, - I8x16ExtractLaneS(lane) => self.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_i8(lane) as i32)?, - I8x16ExtractLaneU(lane) => self.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_u8(lane) as i32)?, - I16x8ExtractLaneS(lane) => self.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_i16(lane) as i32)?, - I16x8ExtractLaneU(lane) => self.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_u16(lane) as i32)?, - I32x4ExtractLane(lane) => self.exec_simd_extract_lane::(*lane, Value128::extract_lane_i32)?, - I64x2ExtractLane(lane) => self.exec_simd_extract_lane::(*lane, Value128::extract_lane_i64)?, - F32x4ExtractLane(lane) => self.exec_simd_extract_lane::(*lane, Value128::extract_lane_f32)?, - F64x2ExtractLane(lane) => self.exec_simd_extract_lane::(*lane, Value128::extract_lane_f64)?, - V128Load8Lane(arg) => self.exec_mem_load_lane::(*arg)?, - V128Load16Lane(arg) => self.exec_mem_load_lane::(*arg)?, - V128Load32Lane(arg) => self.exec_mem_load_lane::(*arg)?, - V128Load64Lane(arg) => self.exec_mem_load_lane::(*arg)?, - I8x16ReplaceLane(lane) => self.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i8x16_replace_lane(lane, value as i8))?, - I16x8ReplaceLane(lane) => self.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i16x8_replace_lane(lane, value as i16))?, - I32x4ReplaceLane(lane) => self.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i32x4_replace_lane(lane, value))?, - I64x2ReplaceLane(lane) => self.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i64x2_replace_lane(lane, value))?, - F32x4ReplaceLane(lane) => self.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.f32x4_replace_lane(lane, value))?, - F64x2ReplaceLane(lane) => self.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.f64x2_replace_lane(lane, value))?, - I8x16Splat => exec_op!(unary i32 => Value128, |v| Value128::splat_i8(v as i8)), - I16x8Splat => exec_op!(unary i32 => Value128, |v| Value128::splat_i16(v as i16)), - I32x4Splat => exec_op!(unary i32 => Value128, |v| Value128::splat_i32(v)), - I64x2Splat => exec_op!(unary i64 => Value128, |v| Value128::splat_i64(v)), - F32x4Splat => exec_op!(unary f32 => Value128, |v| Value128::splat_f32(v)), - F64x2Splat => exec_op!(unary f64 => Value128, |v| Value128::splat_f64(v)), - I8x16Eq => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_eq(b)), - I16x8Eq => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_eq(b)), - I32x4Eq => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_eq(b)), - I64x2Eq => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_eq(b)), - F32x4Eq => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_eq(b)), - F64x2Eq => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_eq(b)), - I8x16Ne => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_ne(b)), - I16x8Ne => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_ne(b)), - I32x4Ne => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_ne(b)), - I64x2Ne => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_ne(b)), - F32x4Ne => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_ne(b)), - F64x2Ne => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_ne(b)), - I8x16LtS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_lt_s(b)), - I16x8LtS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_lt_s(b)), - I32x4LtS => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_lt_s(b)), - I64x2LtS => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_lt_s(b)), - I8x16LtU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_lt_u(b)), - I16x8LtU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_lt_u(b)), - I32x4LtU => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_lt_u(b)), - F32x4Lt => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_lt(b)), - F64x2Lt => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_lt(b)), - F32x4Gt => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_gt(b)), - F64x2Gt => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_gt(b)), - I8x16GtS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_gt_s(b)), - I16x8GtS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_gt_s(b)), - I32x4GtS => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_gt_s(b)), - I64x2GtS => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_gt_s(b)), - I64x2LeS => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_le_s(b)), - F32x4Le => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_le(b)), - F64x2Le => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_le(b)), - I8x16GtU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_gt_u(b)), - I16x8GtU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_gt_u(b)), - I32x4GtU => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_gt_u(b)), - F32x4Ge => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_ge(b)), - F64x2Ge => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_ge(b)), - I8x16LeS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_le_s(b)), - I16x8LeS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_le_s(b)), - I32x4LeS => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_le_s(b)), - I8x16LeU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_le_u(b)), - I16x8LeU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_le_u(b)), - I32x4LeU => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_le_u(b)), - I8x16GeS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_ge_s(b)), - I16x8GeS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_ge_s(b)), - I32x4GeS => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_ge_s(b)), - I64x2GeS => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_ge_s(b)), - I8x16GeU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_ge_u(b)), - I16x8GeU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_ge_u(b)), - I32x4GeU => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_ge_u(b)), - I8x16Abs => exec_op!(unary Value128 => Value128, |a| a.i8x16_abs()), - I16x8Abs => exec_op!(unary Value128 => Value128, |a| a.i16x8_abs()), - I32x4Abs => exec_op!(unary Value128 => Value128, |a| a.i32x4_abs()), - I64x2Abs => exec_op!(unary Value128 => Value128, |a| a.i64x2_abs()), - I8x16Neg => exec_op!(unary Value128 => Value128, |a| a.i8x16_neg()), - I16x8Neg => exec_op!(unary Value128 => Value128, |a| a.i16x8_neg()), - I32x4Neg => exec_op!(unary Value128 => Value128, |a| a.i32x4_neg()), - I64x2Neg => exec_op!(unary Value128 => Value128, |a| a.i64x2_neg()), - I8x16AllTrue => exec_op!(unary Value128 => i32, |v| v.i8x16_all_true() as i32), - I16x8AllTrue => exec_op!(unary Value128 => i32, |v| v.i16x8_all_true() as i32), - I32x4AllTrue => exec_op!(unary Value128 => i32, |v| v.i32x4_all_true() as i32), - I64x2AllTrue => exec_op!(unary Value128 => i32, |v| v.i64x2_all_true() as i32), - I8x16Bitmask => exec_op!(unary Value128 => i32, |v| v.i8x16_bitmask() as i32), - I16x8Bitmask => exec_op!(unary Value128 => i32, |v| v.i16x8_bitmask() as i32), - I32x4Bitmask => exec_op!(unary Value128 => i32, |v| v.i32x4_bitmask() as i32), - I64x2Bitmask => exec_op!(unary Value128 => i32, |v| v.i64x2_bitmask() as i32), - I8x16Shl => exec_op!(binary i32, Value128 => Value128, |a, b| b.i8x16_shl(a as u32)), - I16x8Shl => exec_op!(binary i32, Value128 => Value128, |a, b| b.i16x8_shl(a as u32)), - I32x4Shl => exec_op!(binary i32, Value128 => Value128, |a, b| b.i32x4_shl(a as u32)), - I64x2Shl => exec_op!(binary i32, Value128 => Value128, |a, b| b.i64x2_shl(a as u32)), - I8x16ShrS => exec_op!(binary i32, Value128 => Value128, |a, b| b.i8x16_shr_s(a as u32)), - I16x8ShrS => exec_op!(binary i32, Value128 => Value128, |a, b| b.i16x8_shr_s(a as u32)), - I32x4ShrS => exec_op!(binary i32, Value128 => Value128, |a, b| b.i32x4_shr_s(a as u32)), - I64x2ShrS => exec_op!(binary i32, Value128 => Value128, |a, b| b.i64x2_shr_s(a as u32)), - I8x16ShrU => exec_op!(binary i32, Value128 => Value128, |a, b| b.i8x16_shr_u(a as u32)), - I16x8ShrU => exec_op!(binary i32, Value128 => Value128, |a, b| b.i16x8_shr_u(a as u32)), - I32x4ShrU => exec_op!(binary i32, Value128 => Value128, |a, b| b.i32x4_shr_u(a as u32)), - I64x2ShrU => exec_op!(binary i32, Value128 => Value128, |a, b| b.i64x2_shr_u(a as u32)), - I8x16Add => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_add(b)), - I16x8Add => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_add(b)), - I32x4Add => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_add(b)), - I64x2Add => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_add(b)), - I8x16Sub => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_sub(b)), - I16x8Sub => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_sub(b)), - I32x4Sub => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_sub(b)), - I64x2Sub => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_sub(b)), - I8x16MinS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_min_s(b)), - I16x8MinS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_min_s(b)), - I32x4MinS => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_min_s(b)), - I8x16MinU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_min_u(b)), - I16x8MinU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_min_u(b)), - I32x4MinU => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_min_u(b)), - I8x16MaxS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_max_s(b)), - I16x8MaxS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_max_s(b)), - I32x4MaxS => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_max_s(b)), - I8x16MaxU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_max_u(b)), - I16x8MaxU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_max_u(b)), - I32x4MaxU => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_max_u(b)), - I64x2Mul => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_mul(b)), - I16x8Mul => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_mul(b)), - I32x4Mul => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_mul(b)), - I8x16NarrowI16x8S => exec_op!(binary Value128 => Value128, |a, b| Value128::i8x16_narrow_i16x8_s(a, b)), - I8x16NarrowI16x8U => exec_op!(binary Value128 => Value128, |a, b| Value128::i8x16_narrow_i16x8_u(a, b)), - I16x8NarrowI32x4S => exec_op!(binary Value128 => Value128, |a, b| Value128::i16x8_narrow_i32x4_s(a, b)), - I16x8NarrowI32x4U => exec_op!(binary Value128 => Value128, |a, b| Value128::i16x8_narrow_i32x4_u(a, b)), - I8x16AddSatS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_add_sat_s(b)), - I16x8AddSatS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_add_sat_s(b)), - I8x16AddSatU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_add_sat_u(b)), - I16x8AddSatU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_add_sat_u(b)), - I8x16SubSatS => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_sub_sat_s(b)), - I16x8SubSatS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_sub_sat_s(b)), - I8x16SubSatU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_sub_sat_u(b)), - I16x8SubSatU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_sub_sat_u(b)), - I8x16AvgrU => exec_op!(binary Value128 => Value128, |a, b| a.i8x16_avgr_u(b)), - I16x8AvgrU => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_avgr_u(b)), - I16x8ExtAddPairwiseI8x16S => exec_op!(unary Value128 => Value128, |a| a.i16x8_extadd_pairwise_i8x16_s()), - I16x8ExtAddPairwiseI8x16U => exec_op!(unary Value128 => Value128, |a| a.i16x8_extadd_pairwise_i8x16_u()), - I32x4ExtAddPairwiseI16x8S => exec_op!(unary Value128 => Value128, |a| a.i32x4_extadd_pairwise_i16x8_s()), - I32x4ExtAddPairwiseI16x8U => exec_op!(unary Value128 => Value128, |a| a.i32x4_extadd_pairwise_i16x8_u()), - I16x8ExtMulLowI8x16S => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_extmul_low_i8x16_s(b)), - I16x8ExtMulLowI8x16U => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_extmul_low_i8x16_u(b)), - I16x8ExtMulHighI8x16S => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_extmul_high_i8x16_s(b)), - I16x8ExtMulHighI8x16U => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_extmul_high_i8x16_u(b)), - I32x4ExtMulLowI16x8S => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_extmul_low_i16x8_s(b)), - I32x4ExtMulLowI16x8U => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_extmul_low_i16x8_u(b)), - I32x4ExtMulHighI16x8S => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_extmul_high_i16x8_s(b)), - I32x4ExtMulHighI16x8U => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_extmul_high_i16x8_u(b)), - I64x2ExtMulLowI32x4S => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_extmul_low_i32x4_s(b)), - I64x2ExtMulLowI32x4U => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_extmul_low_i32x4_u(b)), - I64x2ExtMulHighI32x4S => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_extmul_high_i32x4_s(b)), - I64x2ExtMulHighI32x4U => exec_op!(binary Value128 => Value128, |a, b| a.i64x2_extmul_high_i32x4_u(b)), - I16x8ExtendLowI8x16S => exec_op!(unary Value128 => Value128, |a| a.i16x8_extend_low_i8x16_s()), - I16x8ExtendLowI8x16U => exec_op!(unary Value128 => Value128, |a| a.i16x8_extend_low_i8x16_u()), - I16x8ExtendHighI8x16S => exec_op!(unary Value128 => Value128, |a| a.i16x8_extend_high_i8x16_s()), - I16x8ExtendHighI8x16U => exec_op!(unary Value128 => Value128, |a| a.i16x8_extend_high_i8x16_u()), - I32x4ExtendLowI16x8S => exec_op!(unary Value128 => Value128, |a| a.i32x4_extend_low_i16x8_s()), - I32x4ExtendLowI16x8U => exec_op!(unary Value128 => Value128, |a| a.i32x4_extend_low_i16x8_u()), - I32x4ExtendHighI16x8S => exec_op!(unary Value128 => Value128, |a| a.i32x4_extend_high_i16x8_s()), - I32x4ExtendHighI16x8U => exec_op!(unary Value128 => Value128, |a| a.i32x4_extend_high_i16x8_u()), - I64x2ExtendLowI32x4S => exec_op!(unary Value128 => Value128, |a| a.i64x2_extend_low_i32x4_s()), - I64x2ExtendLowI32x4U => exec_op!(unary Value128 => Value128, |a| a.i64x2_extend_low_i32x4_u()), - I64x2ExtendHighI32x4S => exec_op!(unary Value128 => Value128, |a| a.i64x2_extend_high_i32x4_s()), - I64x2ExtendHighI32x4U => exec_op!(unary Value128 => Value128, |a| a.i64x2_extend_high_i32x4_u()), - I8x16Popcnt => exec_op!(unary Value128 => Value128, |v| v.i8x16_popcnt()), - I8x16Shuffle(idx) => self.exec_simd_shuffle(Value128(idx.resolve(&self.func.data).value()))?, - I16x8Q15MulrSatS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_q15mulr_sat_s(b)), - I32x4DotI16x8S => exec_op!(binary Value128 => Value128, |a, b| a.i32x4_dot_i16x8_s(b)), - I8x16RelaxedLaneselect => exec_op!(ternary Value128 => Value128, |a, b, c| Value128::i8x16_relaxed_laneselect(a, b, c)), - I16x8RelaxedLaneselect => exec_op!(ternary Value128 => Value128, |a, b, c| Value128::i16x8_relaxed_laneselect(a, b, c)), - I32x4RelaxedLaneselect => exec_op!(ternary Value128 => Value128, |a, b, c| Value128::i32x4_relaxed_laneselect(a, b, c)), - I64x2RelaxedLaneselect => exec_op!(ternary Value128 => Value128, |a, b, c| Value128::i64x2_relaxed_laneselect(a, b, c)), - I16x8RelaxedQ15mulrS => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_relaxed_q15mulr_s(b)), - I16x8RelaxedDotI8x16I7x16S => exec_op!(binary Value128 => Value128, |a, b| a.i16x8_relaxed_dot_i8x16_i7x16_s(b)), - I32x4RelaxedDotI8x16I7x16AddS => exec_op!(ternary Value128 => Value128, |a, b, c| a.i32x4_relaxed_dot_i8x16_i7x16_add_s(b, c)), - F32x4Ceil => exec_op!(unary Value128 => Value128, |v| v.f32x4_ceil()), - F64x2Ceil => exec_op!(unary Value128 => Value128, |v| v.f64x2_ceil()), - F32x4Floor => exec_op!(unary Value128 => Value128, |v| v.f32x4_floor()), - F64x2Floor => exec_op!(unary Value128 => Value128, |v| v.f64x2_floor()), - F32x4Trunc => exec_op!(unary Value128 => Value128, |v| v.f32x4_trunc()), - F64x2Trunc => exec_op!(unary Value128 => Value128, |v| v.f64x2_trunc()), - F32x4Nearest => exec_op!(unary Value128 => Value128, |v| v.f32x4_nearest()), - F64x2Nearest => exec_op!(unary Value128 => Value128, |v| v.f64x2_nearest()), - F32x4Abs => exec_op!(unary Value128 => Value128, |v| v.f32x4_abs()), - F64x2Abs => exec_op!(unary Value128 => Value128, |v| v.f64x2_abs()), - F32x4Neg => exec_op!(unary Value128 => Value128, |v| v.f32x4_neg()), - F64x2Neg => exec_op!(unary Value128 => Value128, |v| v.f64x2_neg()), - F32x4Sqrt => exec_op!(unary Value128 => Value128, |v| v.f32x4_sqrt()), - F64x2Sqrt => exec_op!(unary Value128 => Value128, |v| v.f64x2_sqrt()), - F32x4Add => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_add(b)), - F64x2Add => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_add(b)), - F32x4Sub => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_sub(b)), - F64x2Sub => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_sub(b)), - F32x4Mul => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_mul(b)), - F64x2Mul => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_mul(b)), - F32x4Div => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_div(b)), - F64x2Div => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_div(b)), - F32x4Min => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_min(b)), - F64x2Min => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_min(b)), - F32x4Max => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_max(b)), - F64x2Max => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_max(b)), - F32x4PMin => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_pmin(b)), - F32x4PMax => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_pmax(b)), - F64x2PMin => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_pmin(b)), - F64x2PMax => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_pmax(b)), - F32x4RelaxedMadd => exec_op!(ternary Value128 => Value128, |a, b, c| a.f32x4_relaxed_madd(b, c)), - F32x4RelaxedNmadd => exec_op!(ternary Value128 => Value128, |a, b, c| a.f32x4_relaxed_nmadd(b, c)), - F64x2RelaxedMadd => exec_op!(ternary Value128 => Value128, |a, b, c| a.f64x2_relaxed_madd(b, c)), - F64x2RelaxedNmadd => exec_op!(ternary Value128 => Value128, |a, b, c| a.f64x2_relaxed_nmadd(b, c)), - F32x4RelaxedMin => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_relaxed_min(b)), - F32x4RelaxedMax => exec_op!(binary Value128 => Value128, |a, b| a.f32x4_relaxed_max(b)), - F64x2RelaxedMin => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_relaxed_min(b)), - F64x2RelaxedMax => exec_op!(binary Value128 => Value128, |a, b| a.f64x2_relaxed_max(b)), - I32x4TruncSatF32x4S => exec_op!(unary Value128 => Value128, |v| v.i32x4_trunc_sat_f32x4_s()), - I32x4TruncSatF32x4U => exec_op!(unary Value128 => Value128, |v| v.i32x4_trunc_sat_f32x4_u()), - F32x4ConvertI32x4S => exec_op!(unary Value128 => Value128, |v| v.f32x4_convert_i32x4_s()), - F32x4ConvertI32x4U => exec_op!(unary Value128 => Value128, |v| v.f32x4_convert_i32x4_u()), - F64x2ConvertLowI32x4S => exec_op!(unary Value128 => Value128, |v| v.f64x2_convert_low_i32x4_s()), - F64x2ConvertLowI32x4U => exec_op!(unary Value128 => Value128, |v| v.f64x2_convert_low_i32x4_u()), - F32x4DemoteF64x2Zero => exec_op!(unary Value128 => Value128, |v| v.f32x4_demote_f64x2_zero()), - F64x2PromoteLowF32x4 => exec_op!(unary Value128 => Value128, |v| v.f64x2_promote_low_f32x4()), - I32x4TruncSatF64x2SZero => exec_op!(unary Value128 => Value128, |v| v.i32x4_trunc_sat_f64x2_s_zero()), - I32x4TruncSatF64x2UZero => exec_op!(unary Value128 => Value128, |v| v.i32x4_trunc_sat_f64x2_u_zero()), - I32x4RelaxedTruncF32x4S => exec_op!(unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f32x4_s()), - I32x4RelaxedTruncF32x4U => exec_op!(unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f32x4_u()), - I32x4RelaxedTruncF64x2SZero => exec_op!(unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f64x2_s_zero()), - I32x4RelaxedTruncF64x2UZero => exec_op!(unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f64x2_u_zero()), - }; - - Ok(ControlFlow::Continue(instr_ptr + 1)) - } - - /// Resolves a module-local memory index to its store address, caching the common memory-0 case. - #[inline(always)] - fn mem_addr(&self, idx: MemAddr) -> MemAddr { - if idx == 0 { self.mem0 } else { self.module.resolve_mem_addr(idx) } - } - - /// Switches the executor to another module, keeping the cached memory-0 address in sync. - #[inline] - fn set_module(&mut self, owner: ModuleInstanceId) { - self.module = self.store.get_module_instance(owner).expect("invalid module instance").clone(); - self.mem0 = self.module.mem0_addr(); - } - - #[inline(always)] - fn charge_call_fuel(&mut self, total_fuel_cost: u32) { - if BUDGETED { - let extra = match self.store.engine.config().fuel_policy { - FuelPolicy::PerInstruction => 0, - FuelPolicy::Weighted => total_fuel_cost.saturating_sub(1), - }; - - self.store.execution_fuel = self.store.execution_fuel.saturating_sub(extra); - } - } - - #[inline(always)] - fn exec_jump_if_ref(&mut self) -> bool { - let is_null = ValueRef::stack_peek(&self.store.value_stack).is_null(); - if is_null { - ValueRef::stack_pop(&mut self.store.value_stack); - } - is_null == ON_NULL - } - - #[inline(always)] - fn exec_br_on_cast(&self, index: Operand64Idx<(u32, u32)>) -> Option { - let operand = index.resolve(&self.func.data); - let ty = RefType::from_bits(operand.b()).expect("invalid ref type"); - (self.exec_ref_matches(ty) == ON_MATCH).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_if_local( - &self, - local: LocalAddr, - ) -> bool { - (T::local_get(&self.store.value_stack, &self.cf, local) == T::default()) == ON_ZERO - } - - #[inline(always)] - fn exec_jump_cmp_stack_const32(&mut self, packed: PackedOp64) -> Option { - let operand = packed.index.resolve(&self.func.data); - packed.op.cmp(i32::stack_pop(&mut self.store.value_stack), operand.b()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_stack_const64(&mut self, packed: PackedOp128) -> Option { - let operand = packed.index.resolve(&self.func.data); - packed.op.cmp(i64::stack_pop(&mut self.store.value_stack), operand.b()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_stack_local32(&mut self, packed: PackedOp64) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i32::stack_pop(&mut self.store.value_stack); - let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.b()); - packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_stack_local64(&mut self, packed: PackedOp64) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i64::stack_pop(&mut self.store.value_stack); - let rhs = i64::local_get(&self.store.value_stack, &self.cf, operand.b()); - packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_binop_local_const_jump(&mut self, packed: PackedOp128) -> Option { - let operand = packed.index.resolve(&self.func.data); - let value = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { - packed.op.exec(value as u32, operand.value() as u32) as i32 - }); - ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_binop_local_const_jump_cmp_local( - &mut self, - packed: PackedOp128<(BinOp, CmpOp), LocalUpdateCmpOperand>, - ) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { - packed.op.0.exec(value as u32, operand.value() as u32) as i32 - }); - let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.right()); - packed.op.1.cmp(lhs, rhs).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_binop_stack_const_tee_local_jump( - &mut self, - packed: PackedOp128, - ) -> Result, Trap> { - let operand = packed.index.resolve(&self.func.data); - let value = i32::stack_update(&mut self.store.value_stack, |lhs| { - packed.op.exec(lhs as u32, operand.value() as u32) as i32 - }); - i32::local_set(&mut self.store.value_stack, &self.cf, operand.local(), value); - Ok(((value == 0) == operand.on_zero()).then_some(operand.target() as usize)) - } - - #[inline(always)] - fn exec_binop_global_const_jump(&mut self, packed: PackedOp128) -> Option { - let operand = packed.index.resolve(&self.func.data); - let global = self.module.resolve_global_addr(operand.global()); - let value = i32::global_update(&mut self.store.state.globals, global, |value| { - packed.op.exec(value as u32, operand.value() as u32) as i32 - }); - ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_inc_local_jump(&mut self, index: Operand128Idx) -> Option { - let operand = index.resolve(&self.func.data); - let value = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { - value.wrapping_add(operand.value()) - }); - ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_inc_stack_tee_local_jump( - &mut self, - index: Operand128Idx, - ) -> Result, Trap> { - let operand = index.resolve(&self.func.data); - let value = i32::stack_update(&mut self.store.value_stack, |value| value.wrapping_add(operand.value())); - i32::local_set(&mut self.store.value_stack, &self.cf, operand.local(), value); - Ok(((value == 0) == operand.on_zero()).then_some(operand.target() as usize)) - } - - #[inline(always)] - fn exec_inc_global_jump(&mut self, index: Operand128Idx) -> Option { - let operand = index.resolve(&self.func.data); - let global = self.module.resolve_global_addr(operand.global()); - let value = - i32::global_update(&mut self.store.state.globals, global, |value| value.wrapping_add(operand.value())); - ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_inc_local_jump_cmp_local(&mut self, packed: PackedOp128) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { - value.wrapping_add(operand.value()) - }); - let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.right()); - packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_local_const32(&self, packed: PackedOp128) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i32::local_get(&self.store.value_stack, &self.cf, operand.c()); - packed.op.cmp(lhs, operand.b()).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_local_const64(&self, packed: PackedOp128) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i64::local_get(&self.store.value_stack, &self.cf, operand.c()); - packed.op.cmp(lhs, i64::from(operand.b())).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_local_local32(&self, packed: PackedOp64) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i32::local_get(&self.store.value_stack, &self.cf, operand.b()); - let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.c()); - packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) - } - - #[inline(always)] - fn exec_jump_cmp_local_local64(&self, packed: PackedOp64) -> Option { - let operand = packed.index.resolve(&self.func.data); - let lhs = i64::local_get(&self.store.value_stack, &self.cf, operand.b()); - let rhs = i64::local_get(&self.store.value_stack, &self.cf, operand.c()); - packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) - } - - fn exec_i64_add128(&mut self) -> Result<(), Trap> { - let b_hi = i64::stack_pop(&mut self.store.value_stack); - let b_lo = i64::stack_pop(&mut self.store.value_stack); - let a_hi = i64::stack_pop(&mut self.store.value_stack); - let a_lo = i64::stack_pop(&mut self.store.value_stack); - let lo = a_lo.wrapping_add(b_lo); - let carry = u64::from((lo as u64) < (a_lo as u64)); - let hi = a_hi.wrapping_add(b_hi).wrapping_add(carry as i64); - i64::stack_push(&mut self.store.value_stack, lo)?; - i64::stack_push(&mut self.store.value_stack, hi) - } - - fn exec_i64_sub128(&mut self) -> Result<(), Trap> { - let b_hi = i64::stack_pop(&mut self.store.value_stack); - let b_lo = i64::stack_pop(&mut self.store.value_stack); - let a_hi = i64::stack_pop(&mut self.store.value_stack); - let a_lo = i64::stack_pop(&mut self.store.value_stack); - let lo = a_lo.wrapping_sub(b_lo); - let borrow = u64::from((a_lo as u64) < (b_lo as u64)); - let hi = a_hi.wrapping_sub(b_hi).wrapping_sub(borrow as i64); - i64::stack_push(&mut self.store.value_stack, lo)?; - i64::stack_push(&mut self.store.value_stack, hi) - } - - fn exec_i64_mul_wide_s(&mut self) -> Result<(), Trap> { - let rhs = i64::stack_pop(&mut self.store.value_stack); - let lhs = i64::stack_pop(&mut self.store.value_stack); - let product = (lhs as i128).wrapping_mul(rhs as i128); - i64::stack_push(&mut self.store.value_stack, product as i64)?; - i64::stack_push(&mut self.store.value_stack, (product >> 64) as i64) - } - - fn exec_i64_mul_wide_u(&mut self) -> Result<(), Trap> { - let rhs = i64::stack_pop(&mut self.store.value_stack); - let lhs = i64::stack_pop(&mut self.store.value_stack); - let product = (lhs as u64 as u128).wrapping_mul(rhs as u64 as u128); - i64::stack_push(&mut self.store.value_stack, product as u64 as i64)?; - i64::stack_push(&mut self.store.value_stack, (product >> 64) as u64 as i64) - } - - #[inline(always)] - fn exec_simd_extract_lane( - &mut self, - lane: u8, - operation: impl FnOnce(Value128, u8) -> TO, - ) -> Result<(), Trap> { - let vector = Value128::stack_pop(&mut self.store.value_stack); - TO::stack_push(&mut self.store.value_stack, operation(vector, lane)) - } - - #[inline(always)] - fn exec_simd_replace_lane( - &mut self, - lane: u8, - operation: impl FnOnce(VALUE, Value128, u8) -> Value128, - ) -> Result<(), Trap> { - let vector = Value128::stack_pop(&mut self.store.value_stack); - let value = VALUE::stack_pop(&mut self.store.value_stack); - Value128::stack_push(&mut self.store.value_stack, operation(value, vector, lane)) - } - - fn exec_simd_shuffle(&mut self, lanes: Value128) -> Result<(), Trap> { - let rhs = Value128::stack_pop(&mut self.store.value_stack); - let lhs = Value128::stack_pop(&mut self.store.value_stack); - Value128::stack_push(&mut self.store.value_stack, Value128::i8x16_shuffle(lhs, rhs, lanes)) - } - - #[inline(always)] - fn exec_local_set_pop(&mut self, local: LocalAddr) { - let value = T::stack_pop(&mut self.store.value_stack); - T::local_set(&mut self.store.value_stack, &self.cf, local, value); - } - - #[inline(always)] - fn exec_local_tee(&mut self, local: LocalAddr) { - let value = T::stack_peek(&self.store.value_stack); - T::local_set(&mut self.store.value_stack, &self.cf, local, value); - } - - #[inline(always)] - fn exec_global_get(&mut self, global: GlobalAddr) -> Result<(), Trap> { - let addr = self.module.resolve_global_addr(global); - let value = T::global_get(&self.store.state.globals, addr); - T::stack_push(&mut self.store.value_stack, value) - } - - #[inline(always)] - fn exec_global_set(&mut self, global: GlobalAddr) { - let addr = self.module.resolve_global_addr(global); - let value = T::stack_pop(&mut self.store.value_stack); - T::global_set(&mut self.store.state.globals, addr, value); - } - - #[inline(always)] - fn exec_global_tee(&mut self, global: GlobalAddr) { - let addr = self.module.resolve_global_addr(global); - let value = T::stack_peek(&self.store.value_stack); - T::global_set(&mut self.store.state.globals, addr, value); - } - - #[inline(always)] - fn exec_binop_result( - &mut self, - dst: Option, - val: T, - ) -> Result<(), Trap> { - if let Some(dst) = dst { - T::local_set(&mut self.store.value_stack, &self.cf, dst, val); - } - if PUSH { T::stack_push(&mut self.store.value_stack, val) } else { Ok(()) } - } - - #[inline(always)] - fn exec_binop_local_local( - &mut self, - lhs: LocalAddr, - rhs: LocalAddr, - destination: Option, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let lhs = T::local_get(&self.store.value_stack, &self.cf, lhs); - let rhs = T::local_get(&self.store.value_stack, &self.cf, rhs); - self.exec_binop_result::(destination, op.exec(lhs, rhs)) - } - - #[inline(always)] - fn exec_binop_local_local_indexed( - &mut self, - index: Operand64Idx<(u16, u16, u16)>, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let operands = index.resolve(&self.func.data); - self.exec_binop_local_local::(operands.a(), operands.b(), Some(operands.c()), op) - } - - #[inline(always)] - fn exec_binop_local_const( - &mut self, - lhs: LocalAddr, - rhs: T, - destination: Option, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let lhs = T::local_get(&self.store.value_stack, &self.cf, lhs); - self.exec_binop_result::(destination, op.exec(lhs, rhs)) - } - - #[inline(always)] - fn exec_binop_global_const( - &mut self, - lhs: GlobalAddr, - rhs: T, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let lhs = T::global_get(&self.store.state.globals, self.module.resolve_global_addr(lhs)); - T::stack_push(&mut self.store.value_stack, op.exec(lhs, rhs)) - } - - #[inline(always)] - fn exec_cmp_local_local(&mut self, lhs: LocalAddr, rhs: LocalAddr, op: CmpOp) -> Result<(), Trap> - where - T: InternalValue, - CmpOp: CmpOpExt, - { - let lhs = T::local_get(&self.store.value_stack, &self.cf, lhs); - let rhs = T::local_get(&self.store.value_stack, &self.cf, rhs); - i32::stack_push(&mut self.store.value_stack, i32::from(op.cmp(lhs, rhs))) - } - - #[inline(always)] - fn exec_binop_stack_global( - &mut self, - global: GlobalAddr, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let addr = self.module.resolve_global_addr(global); - let rhs = T::global_get(&self.store.state.globals, addr); - T::stack_update(&mut self.store.value_stack, |lhs| op.exec(lhs, rhs)); - Ok(()) - } - - #[inline(always)] - fn exec_binop_stack_local( - &mut self, - local: LocalAddr, - destination: Option, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let rhs = T::local_get(&self.store.value_stack, &self.cf, local); - let lhs = T::stack_pop(&mut self.store.value_stack); - self.exec_binop_result::(destination, op.exec(lhs, rhs)) - } - - #[inline(always)] - fn exec_binop_const_tee( - &mut self, - rhs: T, - destination: LocalAddr, - op: impl BinOpExt, - ) -> Result<(), Trap> { - let value = T::stack_update(&mut self.store.value_stack, |lhs| op.exec(lhs, rhs)); - T::local_set(&mut self.store.value_stack, &self.cf, destination, value); - Ok(()) - } - - #[inline(always)] - fn exec_mul_acc_local( - &mut self, - accumulator: LocalAddr, - multiply: fn(T, T) -> T, - add: fn(T, T) -> T, - ) { - let rhs = T::stack_pop(&mut self.store.value_stack); - let lhs = T::stack_pop(&mut self.store.value_stack); - let product = multiply(lhs, rhs); - T::local_update(&mut self.store.value_stack, &self.cf, accumulator, |value| add(product, value)); - } - - fn exec_branch_table(&mut self, index: Operand128Idx) -> usize { - let v = index.resolve(&self.func.data); - let idx = ::stack_pop(&mut self.store.value_stack); - let target_ip = if idx >= 0 && (idx as u32) < v.size() { - self.func.data.branch_table_targets.get((v.start() + idx as u32) as usize).copied().unwrap_or(v.target()) - } else { - v.target() - }; - - target_ip as usize - } - - fn create_exception(&mut self, tag_index: TagAddr) -> Result { - let tag_addr = self.module.resolve_tag_addr(tag_index); - let type_addr = self.store.state.get_tag(tag_addr).type_addr; - let payload_len = self.store.state.get_canonical_func_type(type_addr).params().len(); - self.store.state.gc.check_allocation(payload_len, true)?; - let mut payload = Vec::new(); - cold_err!(payload.try_reserve_exact(payload_len)).map_err(|_| Trap::OutOfMemory)?; - let value_stack = &mut self.store.value_stack; - for index in (0..payload_len).rev() { - let ty = self.store.state.get_canonical_func_type(type_addr).params()[index]; - payload.push(match ty { - WasmType::I32 | WasmType::F32 => RuntimeValue::Value32(Value32::stack_pop(value_stack)), - WasmType::I64 | WasmType::F64 => RuntimeValue::Value64(Value64::stack_pop(value_stack)), - WasmType::V128 => RuntimeValue::Value128(Value128::stack_pop(value_stack)), - WasmType::Ref(_) => RuntimeValue::ValueRef(ValueRef::stack_pop(value_stack)), - }); - } - payload.reverse(); - let roots = (&self.store.value_stack.stack_32).into_iter().copied().map(ValueRef::from_raw); - self.store.state.alloc_exception(tag_addr, payload, roots) - } - - fn exec_throw(&mut self, tag_index: TagAddr, instr_ptr: usize) -> Result> { - let exception = self.create_exception(tag_index)?; - self.throw_exception(exception, instr_ptr) - } - - fn exec_throw_ref(&mut self, instr_ptr: usize) -> Result> { - let exception = ValueRef::stack_pop(&mut self.store.value_stack); - if exception.is_null() { - return Err(Trap::NullReference.into()); - } - self.throw_exception(exception, instr_ptr) - } - - fn throw_exception(&mut self, exception: ValueRef, protected_ip: usize) -> Result> { - match self.dispatch_exception(exception, protected_ip)? { - Some(landing_pad) => Ok(ControlFlow::Continue(landing_pad)), - None => self.store.root_exception(exception).and_then(|exception| Err(Error::Exception(exception))), - } - } - - fn matching_catch(&self, protected_ip: usize, tag_addr: TagAddr) -> Option { - let handlers = &self.func.data.exception_handlers; - let end = handlers.partition_point(|handler| handler.start_ip as usize <= protected_ip); - handlers[..end] - .iter() - .rev() - .filter(|handler| protected_ip < handler.end_ip as usize) - .flat_map(|handler| handler.catches.iter().copied()) - .find(|catch| match catch { - ExceptionCatch::Tag { tag, .. } => self.module.resolve_tag_addr(*tag) == tag_addr, - ExceptionCatch::All { .. } => true, - }) - } - - #[inline(always)] - fn switch_to_frame(&mut self, frame: CallFrame) { - let previous = core::mem::replace(&mut self.cf, frame); - if previous.func_addr == self.cf.func_addr { - return; - } - - let wasm_func = self.store.state.funcs.wasm(self.cf.func_addr); - if !Shared::ptr_eq(&self.func, &wasm_func.func) { - self.func = wasm_func.func.clone(); - } - if wasm_func.owner != self.module.id() { - self.set_module(wasm_func.owner); - } - } - - fn dispatch_exception(&mut self, exception: ValueRef, mut protected_ip: usize) -> Result, Trap> { - let object = self.store.state.gc.get(exception).ok_or(Trap::InvalidReference)?; - let crate::store::GcObjectKind::Exception(tag_addr) = object.kind else { - return Err(Trap::InvalidReference); - }; - loop { - if let Some(catch) = self.matching_catch(protected_ip, tag_addr) { - let (landing_pad, base, with_ref, include_payload) = match catch { - ExceptionCatch::Tag { landing_pad, base, with_ref, .. } => (landing_pad, base, with_ref, true), - ExceptionCatch::All { landing_pad, base, with_ref } => (landing_pad, base, with_ref, false), - }; - let stack_base = self.cf.stack_base(); - let target = interpreter::stack::StackBase { - s32: stack_base.s32 + base.c32 as u32, - s64: stack_base.s64 + base.c64 as u32, - s128: stack_base.s128 + base.c128 as u32, - }; - self.store.value_stack.truncate_to_base(target); - if include_payload { - let Store { state, value_stack, .. } = self.store; - let object = state.gc.get(exception).ok_or(Trap::InvalidReference)?; - for value in object.values.iter().copied() { - value_stack.push_dyn(value)?; - } - } - if with_ref { - ValueRef::stack_push(&mut self.store.value_stack, exception)?; - } - return Ok(Some(landing_pad as usize)); - } - - self.store.value_stack.truncate_to_base(self.cf.locals_base); - let Some(caller) = self.store.call_stack.pop_frame(self.call_stack_base) else { - return Ok(None); - }; - self.switch_to_frame(caller); - protected_ip = self.cf.instr_ptr.checked_sub(1).expect("invalid caller IP"); - } - } - - fn exec_call_host( - &mut self, - host_func: HostFunction, - type_addr: TypeAddr, - return_instr_ptr: usize, - ) -> Result> { - if let Some(host_func) = host_func.typed_callback() { - cold_err!(host_func.call_stack(self.store, self.module.id(), type_addr)) - .map_err(|error| Trap::HostFunction(Box::new(error)))?; - if TAIL { - return Ok(self.exec_return()); - } - return Ok(ControlFlow::Continue(return_instr_ptr)); - } - - let (param_count, result_count, base) = { - let ty = self.store.state.get_canonical_func_type(type_addr); - (ty.params().len(), ty.results().len(), self.store.value_stack.base_before(ty.params().iter().collect())) - }; - let module_id = self.module.id(); - self.store - .with_scratch_values(param_count + result_count, |store, values| { - let host_values = store.stack_value_iter(type_addr, crate::store::FuncValueTypes::Params, base)?; - for (slot, value) in values[..param_count].iter_mut().zip(host_values) { - *slot = value; - } - store.value_stack.truncate_to_base(base); - let (params, results) = values.split_at_mut(param_count); - host_func - .call_values(store, module_id, type_addr, params, results) - .map_err(|error| Error::Trap(Trap::HostFunction(Box::new(error))))?; - store.push_wasm_values(results) - }) - .map_err(|error| match error { - Error::Trap(trap) => trap, - other => Trap::HostFunction(Box::new(other)), - })?; - if TAIL { Ok(self.exec_return()) } else { Ok(ControlFlow::Continue(return_instr_ptr)) } - } - - fn exec_call_direct(&mut self, v: u32, return_instr_ptr: usize) -> Result> { - self.charge_call_fuel(FUEL_COST_CALL_TOTAL); - let addr = self.module.resolve_func_addr(v); - if self.store.state.funcs.is_host(addr) { - let host_func = self.store.state.funcs.host(addr); - let type_addr = host_func.type_addr; - let host_func = host_func.func.clone(); - self.exec_call_host::(host_func, type_addr, return_instr_ptr) - } else { - let wasm_func = self.store.state.funcs.wasm(addr); - let Ok(locals_base) = self.store.value_stack.enter_locals(&wasm_func.func.params, &wasm_func.func.locals) - else { - return cold!(Err(Trap::CallStackOverflow.into())); - }; - - self.store.call_stack.push(self.cf, return_instr_ptr)?; - self.cf = CallFrame::new(addr, locals_base, wasm_func.func.locals); - if !Shared::ptr_eq(&self.func, &wasm_func.func) { - self.func = wasm_func.func.clone(); - } - if wasm_func.owner != self.module.id() { - self.set_module(wasm_func.owner); - } - Ok(ControlFlow::Continue(0)) - } - } - - fn exec_return_call_direct(&mut self, v: u32) -> Result> { - self.charge_call_fuel(FUEL_COST_CALL_TOTAL); - let addr = self.module.resolve_func_addr(v); - if self.store.state.funcs.is_host(addr) { - let host_func = self.store.state.funcs.host(addr); - let type_addr = host_func.type_addr; - let host_func = host_func.func.clone(); - self.exec_call_host::(host_func, type_addr, 0) - } else { - let wasm_func = self.store.state.funcs.wasm(addr); - let (params, locals, owner, next_func) = { - let next_func = (!Shared::ptr_eq(&self.func, &wasm_func.func)).then(|| wasm_func.func.clone()); - (wasm_func.func.params, wasm_func.func.locals, wasm_func.owner, next_func) - }; - self.store.value_stack.truncate_keep_counts(self.cf.locals_base, params); - let Ok(locals_base) = self.store.value_stack.enter_locals(¶ms, &locals) else { - return cold!(Err(Trap::CallStackOverflow.into())); - }; - self.cf = CallFrame::new(addr, locals_base, locals); - if let Some(next_func) = next_func { - self.func = next_func; - } - if owner != self.module.id() { - self.set_module(owner); - } - Ok(ControlFlow::Continue(0)) - } - } - - fn exec_call_self(&mut self, return_instr_ptr: usize) -> Result> { - self.charge_call_fuel(FUEL_COST_CALL_TOTAL); - let Ok(locals_base) = self.store.value_stack.enter_locals(&self.func.params, &self.func.locals) else { - return cold!(Err(Trap::CallStackOverflow.into())); - }; - let new = CallFrame::new(self.cf.func_addr, locals_base, self.func.locals); - self.store.call_stack.push(core::mem::replace(&mut self.cf, new), return_instr_ptr)?; - Ok(ControlFlow::Continue(0)) - } - - fn exec_return_call_self(&mut self) -> Result> { - self.charge_call_fuel(FUEL_COST_CALL_TOTAL); - - self.store.value_stack.truncate_keep_counts(self.cf.locals_base, self.func.params); - let Ok(locals_base) = self.store.value_stack.enter_locals(&self.func.params, &self.func.locals) else { - return cold!(Err(Trap::CallStackOverflow.into())); - }; - self.cf = CallFrame::new(self.cf.func_addr, locals_base, self.func.locals); - Ok(ControlFlow::Continue(0)) - } - - fn exec_call_indirect( - &mut self, - index: Operand64Idx<(u32, u32)>, - return_instr_ptr: usize, - ) -> Result> { - let operand = index.resolve(&self.func.data); - let type_addr = operand.a(); - let table_addr = operand.b(); - self.charge_call_fuel(FUEL_COST_CALL_TOTAL); - // verify that the table is of the right type, this should be validated by the parser already - let table_addr = self.module.resolve_table_addr(table_addr); - let table_idx = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; - let table = self.store.state.get_table(table_addr); - - let Ok(table) = table.get(table_idx) else { - return cold!(Err(Trap::UndefinedElement { index: table_idx }.into())); - }; - - let Some(func_ref) = table.addr() else { - return cold!(Err(Trap::UninitializedElement { index: table_idx }.into())); - }; - - self.exec_typed_call::(func_ref, self.module.resolve_type_addr(type_addr), return_instr_ptr) - } - - fn exec_typed_call( - &mut self, - func_addr: FuncAddr, - expected_type_addr: TypeAddr, - return_instr_ptr: usize, - ) -> Result> { - if self.store.state.funcs.is_host(func_addr) { - let host_func = self.store.state.funcs.host(func_addr); - let type_addr = host_func.type_addr; - if !self.store.state.type_addr_is_subtype(type_addr, expected_type_addr) { - return cold!(Err(Trap::IndirectCallTypeMismatch { - actual: Box::new(self.store.state.get_canonical_func_type(type_addr).clone()), - expected: Box::new(self.store.state.get_canonical_func_type(expected_type_addr).clone()), - } - .into())); - } - let host_func = host_func.func.clone(); - return self.exec_call_host::(host_func, type_addr, return_instr_ptr); - } - - let wasm_func = self.store.state.funcs.wasm(func_addr); - let type_addr = wasm_func.type_addr; - if !self.store.state.type_addr_is_subtype(type_addr, expected_type_addr) { - return cold!(Err(Trap::IndirectCallTypeMismatch { - actual: Box::new(self.store.state.get_canonical_func_type(type_addr).clone()), - expected: Box::new(self.store.state.get_canonical_func_type(expected_type_addr).clone()), - } - .into())); - } - let (params, locals, owner, next_func) = { - let next_func = (!Shared::ptr_eq(&self.func, &wasm_func.func)).then(|| wasm_func.func.clone()); - (wasm_func.func.params, wasm_func.func.locals, wasm_func.owner, next_func) - }; - let locals_base = if IS_RETURN_CALL { - self.store.value_stack.truncate_keep_counts(self.cf.locals_base, params); - self.store.value_stack.enter_locals(¶ms, &locals) - } else { - self.store.value_stack.enter_locals(¶ms, &locals) - }?; - if IS_RETURN_CALL { - self.cf = CallFrame::new(func_addr, locals_base, locals); - } else { - self.store.call_stack.push(self.cf, return_instr_ptr)?; - self.cf = CallFrame::new(func_addr, locals_base, locals); - } - if let Some(next_func) = next_func { - self.func = next_func; - } - if owner != self.module.id() { - self.set_module(owner); - } - Ok(ControlFlow::Continue(0)) - } - - fn exec_call_ref( - &mut self, - type_addr: u32, - return_instr_ptr: usize, - ) -> Result> { - self.charge_call_fuel(FUEL_COST_CALL_TOTAL); - let func_ref = ValueRef::stack_pop(&mut self.store.value_stack); - let Some(func_addr) = func_ref.addr() else { - return cold!(Err(Trap::NullFunctionReference.into())); - }; - - self.exec_typed_call::(func_addr, self.module.resolve_type_addr(type_addr), return_instr_ptr) - } - - fn exec_return(&mut self) -> ControlFlow<(), usize> { - self.store.value_stack.truncate_keep_counts(self.cf.locals_base, self.func.results); - self.finish_return() - } - - #[inline(always)] - fn finish_return(&mut self) -> ControlFlow<(), usize> { - let Some(caller) = self.store.call_stack.pop_frame(self.call_stack_base) else { - return ControlFlow::Break(()); - }; - let instr_ptr = caller.instr_ptr; - if caller.func_addr == self.cf.func_addr { - self.cf = caller; - } else { - self.switch_to_frame(caller); - } - ControlFlow::Continue(instr_ptr) - } - - fn exec_return_void(&mut self) -> ControlFlow<(), usize> { - self.store.value_stack.truncate_to_base(self.cf.locals_base); - self.finish_return() - } - - fn exec_return_32(&mut self) -> ControlFlow<(), usize> { - self.store.value_stack.stack_32.truncate_to_one_tail(self.cf.locals_base.s32 as usize); - self.store.value_stack.stack_64.truncate_to(self.cf.locals_base.s64 as usize); - self.store.value_stack.stack_128.truncate_to(self.cf.locals_base.s128 as usize); - self.finish_return() - } - - fn exec_return_64(&mut self) -> ControlFlow<(), usize> { - self.store.value_stack.stack_32.truncate_to(self.cf.locals_base.s32 as usize); - self.store.value_stack.stack_64.truncate_to_one_tail(self.cf.locals_base.s64 as usize); - self.store.value_stack.stack_128.truncate_to(self.cf.locals_base.s128 as usize); - self.finish_return() - } - - fn exec_return_128(&mut self) -> ControlFlow<(), usize> { - self.store.value_stack.stack_32.truncate_to(self.cf.locals_base.s32 as usize); - self.store.value_stack.stack_64.truncate_to(self.cf.locals_base.s64 as usize); - self.store.value_stack.stack_128.truncate_to_one_tail(self.cf.locals_base.s128 as usize); - self.finish_return() - } - - fn exec_store_local_local, const N: usize>( - &mut self, - index: Operand64Idx, - addr_local: u8, - value_local: u8, - ) -> Result<(), Trap> { - let memarg = index.resolve(&self.func.data); - let value = T::local_get(&self.store.value_stack, &self.cf, u16::from(value_local)); - let mem_addr = self.mem_addr(MemAddr::from(memarg.memory())); - let mem = self.store.state.get_mem_mut(mem_addr); - let addr = if mem.is_64bit() { - let base = u64::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); - let base = cold_err!(usize::try_from(base).map_err(|_| Trap::MemoryOutOfBounds { - offset: usize::MAX, - len: N, - max: mem.inner.len(), - }))?; - cold_err!(mem.effective_addr::(base, u64::from(memarg.offset())))? - } else { - let base = u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); - cold_err!(mem.effective_addr::(base as usize, u64::from(memarg.offset())))? - }; - value.store_at(&mut mem.inner, addr) - } - - fn exec_inc_memory_local, const N: usize>( - &mut self, - index: Operand64Idx, - addr_local: u8, - increment: impl FnOnce(T) -> T, - ) -> Result<(), Trap> { - let memarg = index.resolve(&self.func.data); - let mem_addr = self.mem_addr(MemAddr::from(memarg.memory())); - let mem = self.store.state.get_mem_mut(mem_addr); - let addr = if mem.is_64bit() { - let base = i64::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)) as u64; - let base = cold_err!(usize::try_from(base).map_err(|_| Trap::MemoryOutOfBounds { - offset: usize::MAX, - len: N, - max: mem.inner.len(), - }))?; - cold_err!(mem.effective_addr::(base, u64::from(memarg.offset())))? - } else { - let base = u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); - cold_err!(mem.effective_addr::(base as usize, u64::from(memarg.offset())))? - }; - - let value = cold_err!(T::load_at(&mem.inner, addr))?; - increment(value).store_at(&mut mem.inner, addr) - } - - fn exec_fma_store< - T: InternalValue + MemValue + core::ops::Add + core::ops::Mul, - const N: usize, - >( - &mut self, - m: CompactMemoryArg, - ) -> Result<(), Trap> { - let rhs = T::stack_pop(&mut self.store.value_stack); - let lhs = T::stack_pop(&mut self.store.value_stack); - let acc = T::stack_pop(&mut self.store.value_stack); - let fma = acc + lhs * rhs; - let mem_addr = self.mem_addr(m.mem_addr()); - let mem = self.store.state.get_mem_mut(mem_addr); - let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; - let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; - cold_err!(fma.store_at(&mut mem.inner, addr)) - } - - fn exec_load_local< - LOAD: MemValue, - const N: usize, - TARGET: InternalValue, - const SET_LOCAL: bool, - const TEE: bool, - >( - &mut self, - index: Operand64Idx, - addr_local: u8, - dst_local: u8, - cast: impl Fn(LOAD) -> TARGET, - ) -> Result<(), Trap> { - let memarg = index.resolve(&self.func.data); - - let mem = self.store.state.get_mem(self.mem_addr(MemAddr::from(memarg.memory()))); - let base = if mem.is_64bit() { - let base = i64::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)) as u64; - cold_err!(usize::try_from(base)).map_err(|_| Trap::MemoryOutOfBounds { - offset: usize::MAX, - len: N, - max: mem.inner.len(), - })? - } else { - u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)) as usize - }; - - let addr = cold_err!(mem.effective_addr::(base, u64::from(memarg.offset())))?; - let value = cast(cold_err!(LOAD::load_at(&mem.inner, addr))?); - - if SET_LOCAL { - TARGET::local_set(&mut self.store.value_stack, &self.cf, u16::from(dst_local), value); - } - if !SET_LOCAL || TEE { - TARGET::stack_push(&mut self.store.value_stack, value)?; - } - Ok(()) - } - - fn exec_ref_is_null(&mut self) -> Result<(), Trap> { - let is_null = i32::from(ValueRef::stack_pop(&mut self.store.value_stack).is_null()); - i32::stack_push(&mut self.store.value_stack, is_null) - } - - fn exec_ref_as_non_null(&mut self) -> Result<(), Trap> { - if ValueRef::stack_peek(&self.store.value_stack).is_null() { - return cold!(Err(Trap::NullReference)); - } - Ok(()) - } - - fn canonical_ref_type(&self, ty: RefType) -> RefType { - let Some(type_index) = ty.type_index() else { return ty }; - RefType::new_concrete(ty.is_nullable(), self.module.resolve_type_addr(type_index)) - } - - fn exec_ref_matches(&self, ty: RefType) -> bool { - let value = ValueRef::stack_peek(&self.store.value_stack); - self.store.state.value_ref_matches(value, self.canonical_ref_type(ty)) - } - - fn exec_ref_test(&mut self, ty: RefType) -> Result<(), Trap> { - let value = ValueRef::stack_pop(&mut self.store.value_stack); - let matches = self.store.state.value_ref_matches(value, self.canonical_ref_type(ty)); - i32::stack_push(&mut self.store.value_stack, i32::from(matches)) - } - - fn exec_ref_cast(&self, ty: RefType) -> Result<(), Trap> { - if !self.exec_ref_matches(ty) { - return cold!(Err(Trap::CastFailure)); - } - Ok(()) - } - - fn exec_i31_get(&mut self, signed: bool) -> Result<(), Trap> { - let value = ValueRef::stack_pop(&mut self.store.value_stack); - if value.is_null() { - return cold!(Err(Trap::NullI31Reference)); - } - let value = if signed { - value.i31_s().expect("validated i31.get operand") - } else { - value.i31_u().expect("validated i31.get operand") as i32 - }; - i32::stack_push(&mut self.store.value_stack, value) - } - - fn push_gc_object(&mut self, type_addr: TypeAddr, values: Vec) -> Result<(), Trap> { - let roots = (&self.store.value_stack.stack_32).into_iter().copied().map(ValueRef::from_raw); - let reference = self.store.state.alloc_gc_object(type_addr, values, roots)?; - ValueRef::stack_push(&mut self.store.value_stack, reference) - } - - fn exec_struct_new(&mut self, type_index: TypeAddr, default: bool) -> Result<(), Trap> { - let type_addr = self.module.resolve_type_addr(type_index); - let field_count = - self.store.state.get_type(type_addr).as_struct().expect("validated struct.new type").fields.len(); - self.store.state.check_gc_allocation(type_addr, field_count)?; - let mut values = Vec::new(); - cold_err!(values.try_reserve_exact(field_count)).map_err(|_| Trap::OutOfMemory)?; - if default { - values.extend( - self.store - .state - .get_type(type_addr) - .as_struct() - .expect("validated struct.new type") - .fields - .iter() - .map(|field| default_value(field.storage)), - ); - } else { - for index in (0..field_count).rev() { - let storage = self.store.state.get_type(type_addr).as_struct().unwrap().fields[index].storage; - values.push(pop_value(&mut self.store.value_stack, storage)); - } - values.reverse(); - } - self.push_gc_object(type_addr, values) - } - - fn exec_struct_get(&mut self, index: Operand64Idx<(u32, u32)>, signed: Option) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let field_index = operand.b(); - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_struct().expect("validated struct.get type").fields - [field_index as usize] - .storage; - let object = self.store.state.gc_object(reference, type_addr)?; - let object = self.store.state.gc.get_handle(object).ok_or(Trap::Other("invalid GC reference"))?; - let value = *object.values.get(field_index as usize).expect("validated struct field index"); - push_value(&mut self.store.value_stack, value, storage, signed) - } - - fn exec_struct_set(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let field_index = operand.b(); - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_struct().expect("validated struct.set type").fields - [field_index as usize] - .storage; - let value = pop_value(&mut self.store.value_stack, storage); - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let object = self.store.state.gc_object(reference, type_addr)?; - self.store.state.gc.set(object, field_index as usize, value).expect("live struct field"); - Ok(()) - } - - fn exec_array_new(&mut self, type_index: TypeAddr, default: bool) -> Result<(), Trap> { - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.new type").field.storage; - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - self.store.state.check_gc_allocation(type_addr, len)?; - let value = if default { default_value(storage) } else { pop_value(&mut self.store.value_stack, storage) }; - let mut values = Vec::new(); - cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; - values.resize(len, value); - self.push_gc_object(type_addr, values) - } - - fn exec_array_new_fixed(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let len = operand.b(); - let type_addr = self.module.resolve_type_addr(type_index); - let storage = - self.store.state.get_type(type_addr).as_array().expect("validated array.new_fixed type").field.storage; - let len = len as usize; - self.store.state.check_gc_allocation(type_addr, len)?; - let mut values = Vec::new(); - cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; - for _ in 0..len { - values.push(pop_value(&mut self.store.value_stack, storage)); - } - values.reverse(); - self.push_gc_object(type_addr, values) - } - - fn exec_array_get(&mut self, type_index: TypeAddr, signed: Option) -> Result<(), Trap> { - let index = u32::stack_pop(&mut self.store.value_stack) as usize; - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.get type").field.storage; - let object = self.store.state.gc_object(reference, type_addr)?; - let object = self.store.state.gc.get_handle(object).ok_or(Trap::Other("invalid GC reference"))?; - let value = *object.values.get(index).ok_or(Trap::ArrayOutOfBounds)?; - push_value(&mut self.store.value_stack, value, storage, signed) - } - - fn exec_array_set(&mut self, type_index: TypeAddr) -> Result<(), Trap> { - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.set type").field.storage; - let value = pop_value(&mut self.store.value_stack, storage); - let index = u32::stack_pop(&mut self.store.value_stack) as usize; - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let object = self.store.state.gc_object(reference, type_addr)?; - self.store.state.gc.set(object, index, value).ok_or(Trap::ArrayOutOfBounds) - } - - fn exec_array_len(&mut self) -> Result<(), Trap> { - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - if reference.is_null() { - return Err(Trap::NullArrayReference); - } - let object = self.store.state.gc.get(reference).ok_or(Trap::Other("invalid GC reference"))?; - let crate::store::GcObjectKind::Composite(type_addr) = object.kind else { - return Err(Trap::Other("GC reference is not an array")); - }; - if self.store.state.get_type(type_addr).as_array().is_none() { - return Err(Trap::Other("GC reference is not an array")); - } - i32::stack_push(&mut self.store.value_stack, object.values.len() as i32) - } - - fn exec_array_fill(&mut self, type_index: TypeAddr) -> Result<(), Trap> { - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.fill type").field.storage; - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - let value = pop_value(&mut self.store.value_stack, storage); - let index = u32::stack_pop(&mut self.store.value_stack) as usize; - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let object = self.store.state.gc_object(reference, type_addr)?; - let object_ref = self.store.state.gc.get_handle(object).ok_or(Trap::Other("invalid GC reference"))?; - let end = index.checked_add(len).filter(|end| *end <= object_ref.values.len()).ok_or(Trap::ArrayOutOfBounds)?; - self.store.state.gc.fill(object, index..end, value).expect("live array range"); - Ok(()) - } - - fn exec_array_copy(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let dst_type = operand.a(); - let src_type = operand.b(); - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - let src_index = u32::stack_pop(&mut self.store.value_stack) as usize; - let src = ValueRef::stack_pop(&mut self.store.value_stack); - let dst_index = u32::stack_pop(&mut self.store.value_stack) as usize; - let dst = ValueRef::stack_pop(&mut self.store.value_stack); - let dst_type = self.module.resolve_type_addr(dst_type); - let src_type = self.module.resolve_type_addr(src_type); - let dst_handle = self.store.state.gc_object(dst, dst_type)?; - let dst_len = self.store.state.gc.get_handle(dst_handle).expect("validated array").values.len(); - let src_handle = self.store.state.gc_object(src, src_type)?; - let src_object = self.store.state.gc.get_handle(src_handle).expect("validated array"); - let src_end = - src_index.checked_add(len).filter(|end| *end <= src_object.values.len()).ok_or(Trap::ArrayOutOfBounds)?; - dst_index.checked_add(len).filter(|end| *end <= dst_len).ok_or(Trap::ArrayOutOfBounds)?; - if src_handle == dst_handle { - self.store.state.gc.copy_within(dst_handle, src_index..src_end, dst_index).expect("live array range"); - return Ok(()); - } - self.store - .state - .gc - .copy_between(src_handle, src_index..src_end, dst_handle, dst_index) - .expect("live array ranges"); - Ok(()) - } - - fn exec_array_new_data(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let data_index = operand.b(); - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - let src = u32::stack_pop(&mut self.store.value_stack) as usize; - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_array().expect("validated array type").field.storage; - let data_addr = self.module.resolve_data_addr(data_index); - let data = self.store.state.data[data_addr as usize].data.as_deref().unwrap_or(&[]); - data_range(storage, data, src, len)?; - self.store.state.check_gc_allocation(type_addr, len)?; - let values = decode_data(storage, data, src, len)?; - self.push_gc_object(type_addr, values) - } - - fn exec_array_new_elem(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let elem_index = operand.b(); - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - let src = u32::stack_pop(&mut self.store.value_stack) as usize; - let type_addr = self.module.resolve_type_addr(type_index); - let elem_addr = self.module.resolve_elem_addr(elem_index); - let items = self.store.state.elements[elem_addr as usize].items_range(src, len)?; - self.store.state.check_gc_allocation(type_addr, len)?; - let mut values = Vec::new(); - cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; - values.extend(items.iter().copied().map(RuntimeValue::ValueRef)); - self.push_gc_object(type_addr, values) - } - - fn exec_array_init_data(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let data_index = operand.b(); - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - let src = u32::stack_pop(&mut self.store.value_stack) as usize; - let dst = u32::stack_pop(&mut self.store.value_stack) as usize; - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let type_addr = self.module.resolve_type_addr(type_index); - let storage = self.store.state.get_type(type_addr).as_array().expect("validated array type").field.storage; - let object = self.store.state.gc_object(reference, type_addr)?; - let object_len = self.store.state.gc.get_handle(object).expect("validated array").values.len(); - dst.checked_add(len).filter(|end| *end <= object_len).ok_or(Trap::ArrayOutOfBounds)?; - let data = - self.store.state.data[self.module.resolve_data_addr(data_index) as usize].data.as_deref().unwrap_or(&[]); - let values = decode_data(storage, data, src, len)?; - self.store.state.gc.set_slice(object, dst, &values).expect("live array range"); - Ok(()) - } - - fn exec_array_init_elem(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let type_index = operand.a(); - let elem_index = operand.b(); - let len = u32::stack_pop(&mut self.store.value_stack) as usize; - let src = u32::stack_pop(&mut self.store.value_stack) as usize; - let dst = u32::stack_pop(&mut self.store.value_stack) as usize; - let reference = ValueRef::stack_pop(&mut self.store.value_stack); - let type_addr = self.module.resolve_type_addr(type_index); - let object = self.store.state.gc_object(reference, type_addr)?; - let object_len = self.store.state.gc.get_handle(object).expect("validated array").values.len(); - dst.checked_add(len).filter(|end| *end <= object_len).ok_or(Trap::ArrayOutOfBounds)?; - let items = - self.store.state.elements[self.module.resolve_elem_addr(elem_index) as usize].items_range(src, len)?; - let mut values = Vec::new(); - cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; - values.extend(items.iter().copied().map(RuntimeValue::ValueRef)); - self.store.state.gc.set_slice(object, dst, &values).expect("live array range"); - Ok(()) - } - - fn exec_memory_size(&mut self, addr: u32) -> Result<(), Trap> { - let mem = self.store.state.get_mem(self.mem_addr(addr)); - match mem.is_64bit() { - true => i64::stack_push(&mut self.store.value_stack, mem.page_count as i64), - false => i32::stack_push(&mut self.store.value_stack, mem.page_count as i32), - } - } - - fn exec_memory_grow(&mut self, addr: u32) -> Result<(), Trap> { - let mem_addr = self.mem_addr(addr); - let limiter = self.store.engine.config().resource_limiter.as_deref(); - let mem = self.store.state.get_mem_mut(mem_addr); - let is_64bit = mem.is_64bit(); - let pages_delta = match is_64bit { - true => i64::stack_pop(&mut self.store.value_stack), - false => i64::from(i32::stack_pop(&mut self.store.value_stack)), - }; - - let size = mem.grow(pages_delta, limiter)?.unwrap_or(-1); - match is_64bit { - true => i64::stack_push(&mut self.store.value_stack, size)?, - false => i32::stack_push(&mut self.store.value_stack, size as i32)?, - }; - - Ok(()) - } - - fn exec_memory_copy(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let dst_mem = operand.a(); - let src_mem = operand.b(); - let dst_mem_addr = self.mem_addr(dst_mem); - let src_mem_addr = self.mem_addr(src_mem); - let dst_arch = self.store.state.get_mem(dst_mem_addr).kind.arch(); - let src_arch = self.store.state.get_mem(src_mem_addr).kind.arch(); - let len_arch = - if dst_arch == MemoryArch::I32 || src_arch == MemoryArch::I32 { MemoryArch::I32 } else { MemoryArch::I64 }; - let size = self.store.value_stack.pop_memory_operand(len_arch)?; - let src = self.store.value_stack.pop_memory_operand(src_arch)?; - let dst = self.store.value_stack.pop_memory_operand(dst_arch)?; - - if dst_mem_addr == src_mem_addr { - // copy within the same memory - let mem = self.store.state.get_mem_mut(dst_mem_addr); - mem.copy_within(dst, src, size)?; - } else { - // copy between two memories - let (dst_memory, src_memory) = self.store.state.get_mems_mut(dst_mem_addr, src_mem_addr); - dst_memory.copy_from_memory(dst, src_memory, src, size)?; - } - Ok(()) - } - - fn exec_memory_fill(&mut self, addr: u32) -> Result<(), Trap> { - let mem_addr = self.mem_addr(addr); - let arch = self.store.state.get_mem(mem_addr).kind.arch(); - let size = self.store.value_stack.pop_memory_operand(arch)?; - let val = i32::stack_pop(&mut self.store.value_stack); - let dst = self.store.value_stack.pop_memory_operand(arch)?; - self.exec_memory_fill_impl(mem_addr, dst, val as u8, size) - } - - fn exec_memory_fill_const(&mut self, index: Operand128Idx) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let mem_addr = self.mem_addr(operand.memory()); - let arch = self.store.state.get_mem(mem_addr).kind.arch(); - let dst = self.store.value_stack.pop_memory_operand(arch)?; - self.exec_memory_fill_impl(mem_addr, dst, operand.byte(), operand.value() as u32 as usize) - } - - fn exec_memory_fill_impl(&mut self, mem_addr: MemAddr, dst: usize, val: u8, size: usize) -> Result<(), Trap> { - let mem = self.store.state.get_mem_mut(mem_addr); - let max = mem.inner.len(); - if mem.inner.fill(dst, size, val).is_none() { - return cold!(Err(Trap::MemoryOutOfBounds { offset: dst, len: size, max })); - } - Ok(()) - } - - fn exec_memory_init(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let data_index = operand.a(); - let mem_index = operand.b(); - let size = u32::stack_pop(&mut self.store.value_stack) as usize; - let offset = u32::stack_pop(&mut self.store.value_stack) as usize; - let mem_addr = self.mem_addr(mem_index); - let arch = self.store.state.get_mem(mem_addr).kind.arch(); - let dst = self.store.value_stack.pop_memory_operand(arch)?; - - let data = &self.store.state.data[self.module.resolve_data_addr(data_index) as usize]; - let mem = &mut self.store.state.memories[mem_addr as usize]; - let data_len = data.data.as_ref().map_or(0, |d| d.len()); - let mem_len = mem.inner.len(); - if offset.checked_add(size).is_none_or(|end| end > data_len) { - return cold!(Err(Trap::MemoryOutOfBounds { offset, len: size, max: data_len })); - } - if dst.checked_add(size).is_none_or(|end| end > mem_len) { - return cold!(Err(Trap::MemoryOutOfBounds { offset: dst, len: size, max: mem_len })); - } - - if size == 0 { - return Ok(()); - } - - let Some(data) = &data.data else { - return cold!(Err(Trap::MemoryOutOfBounds { offset: 0, len: 0, max: 0 })); - }; - - if mem.inner.write_all(dst, &data[offset..offset + size]).is_none() { - return cold!(Err(Trap::MemoryOutOfBounds { offset: dst, len: size, max: mem_len })); - } - Ok(()) - } - - fn exec_table_copy(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let dst_table = operand.a(); - let src_table = operand.b(); - let dst_table_addr = self.module.resolve_table_addr(dst_table); - let src_table_addr = self.module.resolve_table_addr(src_table); - let dst_arch = self.store.state.get_table(dst_table_addr).kind.arch(); - let src_arch = self.store.state.get_table(src_table_addr).kind.arch(); - let len_arch = - if dst_arch == MemoryArch::I32 || src_arch == MemoryArch::I32 { MemoryArch::I32 } else { MemoryArch::I64 }; - let size = self.pop_table_operand(len_arch)?; - let src = self.pop_table_operand(src_arch)?; - let dst = self.pop_table_operand(dst_arch)?; - - if dst_table_addr == src_table_addr { - // copy within the same table - self.store.state.get_table_mut(dst_table_addr).copy_within(dst, src, size) - } else { - // copy between two tables - let (dst_table_ref, src_table_ref) = self.store.state.get_tables_mut(dst_table_addr, src_table_addr); - dst_table_ref.copy_from_slice(dst, src_table_ref.load(src, size)?) - } - } - - fn exec_mem_load_lane, const LOAD_SIZE: usize>( - &mut self, - arg: MemoryLaneArg, - ) -> Result<(), Trap> { - let m = arg.memory_arg_idx.resolve(&self.func.data); - let mem = self.store.state.get_mem(self.mem_addr(m.memory())); - let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; - let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; - let val = cold_err!(LOAD::load_at(&mem.inner, addr))?; - let offset = arg.lane as usize * LOAD_SIZE; - Value128::stack_update(&mut self.store.value_stack, |value| { - let mut bytes = value.to_mem_bytes(); - bytes[offset..offset + LOAD_SIZE].copy_from_slice(&val.to_mem_bytes()); - Value128(bytes) - }); - Ok(()) - } - - #[inline(always)] - fn exec_mem_load, const LOAD_SIZE: usize, TARGET: InternalValue>( - &mut self, - m: Operand128, - cast: impl Fn(LOAD) -> TARGET, - ) -> Result<(), Trap> { - let mem = self.store.state.get_mem(self.mem_addr(m.memory())); - let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; - let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; - let value = cold_err!(LOAD::load_at(&mem.inner, addr))?; - TARGET::stack_push(&mut self.store.value_stack, cast(value)) - } - - #[inline(always)] - fn exec_mem_store_lane + Copy, const N: usize>(&mut self, arg: MemoryLaneArg) -> Result<(), Trap> { - let bytes = Value128::stack_pop(&mut self.store.value_stack).to_mem_bytes(); - let lane_offset = arg.lane as usize * N; - let mut val_bytes = [0u8; N]; - val_bytes.copy_from_slice(&bytes[lane_offset..lane_offset + N]); - let val = U::from_mem_bytes(val_bytes); - let m = arg.memory_arg_idx.resolve(&self.func.data); - let mem_addr = self.mem_addr(m.memory()); - let mem = self.store.state.get_mem_mut(mem_addr); - let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; - let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; - cold_err!(val.store_at(&mut mem.inner, addr))?; - Ok(()) - } - - #[inline(always)] - fn exec_mem_store, const N: usize>( - &mut self, - memory: Operand128, - cast: impl Fn(T) -> U, - ) -> Result<(), Trap> { - let val = cast(::stack_pop(&mut self.store.value_stack)); - self.exec_mem_store_value(self.mem_addr(memory.memory()), memory.offset(), val) - } - - #[inline(always)] - fn exec_select_store, const N: usize>( - &mut self, - memory: Operand128, - ) -> Result<(), Trap> { - let condition = Value32::stack_pop(&mut self.store.value_stack); - let false_value = T::stack_pop(&mut self.store.value_stack); - let true_value = T::stack_pop(&mut self.store.value_stack); - let value = if condition == 0 { false_value } else { true_value }; - self.exec_mem_store_value(self.mem_addr(memory.memory()), memory.offset(), value) - } - - #[inline(always)] - fn exec_mem_store_value, const N: usize>( - &mut self, - memory_addr: MemAddr, - offset: u64, - val: U, - ) -> Result<(), Trap> { - let mem = self.store.state.get_mem_mut(memory_addr); - let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; - let addr = cold_err!(mem.effective_addr::(base, offset))?; - cold_err!(val.store_at(&mut mem.inner, addr)) - } - - fn exec_table_get(&mut self, table_index: u32) -> Result<(), Trap> { - let table_addr = self.module.resolve_table_addr(table_index); - let idx = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; - let value = *self.store.state.get_table(table_addr).get(idx)?; - ValueRef::stack_push(&mut self.store.value_stack, value) - } - - fn exec_table_set(&mut self, table_index: u32) -> Result<(), Trap> { - let val = ValueRef::stack_pop(&mut self.store.value_stack); - let table_addr = self.module.resolve_table_addr(table_index); - let idx = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; - let table = self.store.state.get_table_mut(table_addr); - table.set(idx, val) - } - - fn exec_table_size(&mut self, table_index: u32) -> Result<(), Trap> { - let table = self.store.state.get_table(self.module.resolve_table_addr(table_index)); - match table.kind.arch() { - MemoryArch::I32 => i32::stack_push(&mut self.store.value_stack, table.size() as i32), - MemoryArch::I64 => i64::stack_push(&mut self.store.value_stack, table.size() as i64), - } - } - - fn exec_table_init(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { - let operand = index.resolve(&self.func.data); - let elem_index = operand.a(); - let table_index = operand.b(); - let size = self.pop_table_operand(MemoryArch::I32)?; // n - let offset = self.pop_table_operand(MemoryArch::I32)?; // s - let table_addr = self.module.resolve_table_addr(table_index); - let dst = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; // d - let elem_addr = self.module.resolve_elem_addr(elem_index) as usize; - let elem = self.store.state.elements.get(elem_addr).ok_or_else(|| Trap::Other("element not found"))?; - let items = elem.items_range(offset, size)?; - - let table = - self.store.state.tables.get_mut(table_addr as usize).ok_or_else(|| Trap::Other("table not found"))?; - table.init(dst, items) - } - - fn exec_table_grow(&mut self, table_index: u32) -> Result<(), Trap> { - let table_addr = self.module.resolve_table_addr(table_index); - let arch = self.store.state.get_table(table_addr).kind.arch(); - let n = self.pop_table_operand(arch)?; - let val = ValueRef::stack_pop(&mut self.store.value_stack); - let limiter = self.store.engine.config().resource_limiter.as_deref(); - let table = self.store.state.get_table_mut(table_addr); - let sz = table.size(); - let grew = table.grow(n, val, limiter)?; - match (arch, grew) { - (MemoryArch::I32, true) => i32::stack_push(&mut self.store.value_stack, sz as i32), - (MemoryArch::I32, false) => i32::stack_push(&mut self.store.value_stack, -1), - (MemoryArch::I64, true) => i64::stack_push(&mut self.store.value_stack, sz as i64), - (MemoryArch::I64, false) => i64::stack_push(&mut self.store.value_stack, -1), - } - } - - fn exec_table_fill(&mut self, table_index: u32) -> Result<(), Trap> { - let table_addr = self.module.resolve_table_addr(table_index); - let arch = self.store.state.get_table(table_addr).kind.arch(); - let n = self.pop_table_operand(arch)?; - let val = ValueRef::stack_pop(&mut self.store.value_stack); - let i = self.pop_table_operand(arch)?; - self.store.state.get_table_mut(table_addr).fill(i, n, val) - } - - fn pop_table_operand(&mut self, arch: MemoryArch) -> Result { - let value = match arch { - MemoryArch::I32 => i32::stack_pop(&mut self.store.value_stack) as u32 as u64, - MemoryArch::I64 => i64::stack_pop(&mut self.store.value_stack) as u64, - }; - cold_err!(usize::try_from(value).map_err(|_| Trap::TableOutOfBounds { - offset: usize::MAX, - len: 1, - max: usize::MAX, - })) - } -} - -impl<'store> Executor<'store, false> { - #[inline(always)] - pub(crate) fn run_to_completion(mut self) -> Result<()> { - let mut instr_ptr = self.cf.instr_ptr; - loop { - match self.exec(instr_ptr)? { - ControlFlow::Continue(next_instr_ptr) => instr_ptr = next_instr_ptr, - ControlFlow::Break(()) => return cold!(Ok(())), - } - } - } - - #[cfg(feature = "std")] - #[inline(always)] - pub(crate) fn run_with_time_budget(mut self, time_budget: core::time::Duration) -> Result { - use crate::std::time::Instant; - let start = Instant::now(); - if time_budget.is_zero() { - return Ok(ExecState::Suspended(self.cf)); - } - - let mut instr_ptr = self.cf.instr_ptr; - loop { - for _ in 0..128 { - match self.exec(instr_ptr)? { - ControlFlow::Continue(next_instr_ptr) => instr_ptr = next_instr_ptr, - ControlFlow::Break(()) => return Ok(ExecState::Completed), - } - } - - if start.elapsed() >= time_budget { - self.cf.instr_ptr = instr_ptr; - return Ok(ExecState::Suspended(self.cf)); - } - } - } -} - -impl<'store> Executor<'store, true> { - #[inline(always)] - pub(crate) fn run_with_fuel(mut self, fuel: u32) -> Result { - self.store.execution_fuel = fuel; - if self.store.execution_fuel == 0 { - return Ok(ExecState::Suspended(self.cf)); - } - - let mut instr_ptr = self.cf.instr_ptr; - loop { - for _ in 0..128 { - match self.exec(instr_ptr)? { - ControlFlow::Continue(next_instr_ptr) => instr_ptr = next_instr_ptr, - ControlFlow::Break(()) => return Ok(ExecState::Completed), - } - } - - self.store.execution_fuel = self.store.execution_fuel.saturating_sub(128); - if self.store.execution_fuel == 0 { - self.cf.instr_ptr = instr_ptr; - return Ok(ExecState::Suspended(self.cf)); - } - } - } -} diff --git a/crates/tinywasm/src/interpreter/executor/dispatch.rs b/crates/tinywasm/src/interpreter/executor/dispatch.rs new file mode 100644 index 0000000..57efc54 --- /dev/null +++ b/crates/tinywasm/src/interpreter/executor/dispatch.rs @@ -0,0 +1,90 @@ +use super::*; + +macro_rules! define_stable_dispatch { + ($executor:ident, $instr_ptr:ident, $dispatch_next:ident, $dispatch_flow:ident; + $($variant:ident $(($($arg:pat),*))? $({ $($field:ident),* })? => $body:expr),* $(,)?) => { + #[inline(always)] + fn exec_step($executor: &mut Self, $instr_ptr: usize) -> ExecResult { + macro_rules! $dispatch_next { + ($next_instr_ptr:expr) => {{ + return Ok(ExecFlow::next($next_instr_ptr)); + }}; + } + macro_rules! $dispatch_flow { + ($flow:expr) => {{ + return Ok($flow); + }}; + } + use tinywasm_types::Instruction::*; + match &$executor.func.instructions[$instr_ptr] { + $($variant $(($($arg),*))? $({ $($field),* })? => $body,)* + } + Ok(ExecFlow::next($instr_ptr + 1)) + } + }; +} + +impl Executor<'_> { + instruction_handlers!(define_stable_dispatch); + + #[inline(always)] + pub(crate) fn run_to_completion(mut self) -> Result<()> { + let mut instr_ptr = self.cf.instr_ptr; + loop { + match Self::exec_step(&mut self, instr_ptr)?.next_instr_ptr() { + Some(next_instr_ptr) => instr_ptr = next_instr_ptr, + None => return cold!(Ok(())), + } + } + } + + #[cfg(feature = "std")] + #[inline(always)] + pub(crate) fn run_with_time_budget(mut self, time_budget: core::time::Duration) -> Result { + use crate::std::time::Instant; + + if time_budget.is_zero() { + return Ok(ExecState::Suspended(self.cf)); + } + let start = Instant::now(); + let mut instr_ptr = self.cf.instr_ptr; + loop { + for _ in 0..CHECKPOINT_INTERVAL { + match Self::exec_step(&mut self, instr_ptr)?.next_instr_ptr() { + Some(next_instr_ptr) => instr_ptr = next_instr_ptr, + None => return Ok(ExecState::Completed), + } + } + + if start.elapsed() >= time_budget { + self.cf.instr_ptr = instr_ptr; + return Ok(ExecState::Suspended(self.cf)); + } + } + } + + #[inline(always)] + pub(crate) fn run_with_fuel(mut self, fuel: u32) -> Result { + self.fuel_metered = true; + self.store.execution_fuel = fuel; + if self.store.execution_fuel == 0 { + return Ok(ExecState::Suspended(self.cf)); + } + + let mut instr_ptr = self.cf.instr_ptr; + loop { + for _ in 0..CHECKPOINT_INTERVAL { + match Self::exec_step(&mut self, instr_ptr)?.next_instr_ptr() { + Some(next_instr_ptr) => instr_ptr = next_instr_ptr, + None => return Ok(ExecState::Completed), + } + } + + self.store.execution_fuel = self.store.execution_fuel.saturating_sub(CHECKPOINT_INTERVAL); + if self.store.execution_fuel == 0 { + self.cf.instr_ptr = instr_ptr; + return Ok(ExecState::Suspended(self.cf)); + } + } + } +} diff --git a/crates/tinywasm/src/interpreter/executor/dispatch_become.rs b/crates/tinywasm/src/interpreter/executor/dispatch_become.rs new file mode 100644 index 0000000..66cbb51 --- /dev/null +++ b/crates/tinywasm/src/interpreter/executor/dispatch_become.rs @@ -0,0 +1,189 @@ +use super::*; + +struct Unbudgeted; +struct Bounded; + +type UnbudgetedHandler = for<'store> fn(&mut Executor<'store>, usize, Instruction) -> ExecResult<()>; +type BoundedHandler = for<'store> fn(&mut Executor<'store>, usize, Instruction, u32) -> ExecResult<()>; + +#[cold] +#[inline(never)] +fn instruction_handler_mismatch() -> ! { + unreachable!("instruction handler mismatch") +} + +macro_rules! define_unbudgeted_tail_dispatch { + ($executor:ident, $instr_ptr:ident, $dispatch_next:ident, $dispatch_flow:ident; + $($variant:ident $(($($arg:pat),*))? $({ $($field:ident),* })? => $body:expr),* $(,)?) => { + #[inline(always)] + fn handler_for(instruction: &Instruction) -> UnbudgetedHandler { + use tinywasm_types::Instruction::*; + + match instruction { + $($variant { .. } => Self::$variant,)* + } + } + + $( + #[allow(non_snake_case, unreachable_code, unused_imports, unused_macros, unused_variables)] + fn $variant( + $executor: &mut Executor<'_>, + $instr_ptr: usize, + instruction: Instruction, + ) -> ExecResult<()> { + macro_rules! $dispatch_next { + ($next_instr_ptr:expr) => {{ + let next_instr_ptr = $next_instr_ptr; + let instruction = $executor.func.instructions[next_instr_ptr]; + let handler = Self::handler_for(&instruction); + become handler($executor, next_instr_ptr, instruction); + }}; + } + macro_rules! $dispatch_flow { + ($flow:expr) => {{ + match $flow.next_instr_ptr() { + Some(next_instr_ptr) => $dispatch_next!(next_instr_ptr), + None => return cold!(Ok(())), + } + }}; + } + use tinywasm_types::Instruction::*; + $(let $variant($($arg),*) = &instruction else { + cold!(instruction_handler_mismatch()) + };)? + $(let $variant { $($field),* } = &instruction else { + cold!(instruction_handler_mismatch()) + };)? + $body; + $dispatch_next!($instr_ptr + 1) + } + )* + }; +} + +macro_rules! define_bounded_tail_dispatch { + ($executor:ident, $instr_ptr:ident, $dispatch_next:ident, $dispatch_flow:ident; + $($variant:ident $(($($arg:pat),*))? $({ $($field:ident),* })? => $body:expr),* $(,)?) => { + #[inline(always)] + fn handler_for(instruction: &Instruction) -> BoundedHandler { + use tinywasm_types::Instruction::*; + + match instruction { + $($variant { .. } => Self::$variant,)* + } + } + + $( + #[allow(non_snake_case, unreachable_code, unused_imports, unused_macros, unused_variables)] + fn $variant( + $executor: &mut Executor<'_>, + $instr_ptr: usize, + instruction: Instruction, + instructions_until_checkpoint: u32, + ) -> ExecResult<()> { + macro_rules! $dispatch_next { + ($next_instr_ptr:expr) => {{ + let next_instr_ptr = $next_instr_ptr; + if instructions_until_checkpoint == 0 { + return cold!({ + $executor.cf.instr_ptr = next_instr_ptr; + Ok(()) + }); + } + + let instruction = $executor.func.instructions[next_instr_ptr]; + let handler = Self::handler_for(&instruction); + become handler($executor, next_instr_ptr, instruction, instructions_until_checkpoint - 1); + }}; + } + macro_rules! $dispatch_flow { + ($flow:expr) => {{ + match $flow.next_instr_ptr() { + Some(next_instr_ptr) => $dispatch_next!(next_instr_ptr), + None => return cold!({ + $executor.completed = true; + Ok(()) + }), + } + }}; + } + use tinywasm_types::Instruction::*; + $(let $variant($($arg),*) = &instruction else { + cold!(instruction_handler_mismatch()) + };)? + $(let $variant { $($field),* } = &instruction else { + cold!(instruction_handler_mismatch()) + };)? + $body; + $dispatch_next!($instr_ptr + 1) + } + )* + }; +} + +impl Unbudgeted { + instruction_handlers!(define_unbudgeted_tail_dispatch); +} + +impl Bounded { + instruction_handlers!(define_bounded_tail_dispatch); + + #[inline(always)] + fn run(executor: &mut Executor<'_>) -> ExecResult<()> { + let instr_ptr = executor.cf.instr_ptr; + let instruction = executor.func.instructions[instr_ptr]; + let handler = Self::handler_for(&instruction); + handler(executor, instr_ptr, instruction, CHECKPOINT_INTERVAL - 1) + } +} + +impl<'store> Executor<'store> { + #[inline(always)] + pub(crate) fn run_to_completion(mut self) -> Result<()> { + let instr_ptr = self.cf.instr_ptr; + let instruction = self.func.instructions[instr_ptr]; + let handler = Unbudgeted::handler_for(&instruction); + Ok(handler(&mut self, instr_ptr, instruction)?) + } + + #[cfg(feature = "std")] + #[inline(always)] + pub(crate) fn run_with_time_budget(mut self, time_budget: core::time::Duration) -> Result { + use crate::std::time::Instant; + + if time_budget.is_zero() { + return Ok(ExecState::Suspended(self.cf)); + } + let start = Instant::now(); + + loop { + Bounded::run(&mut self)?; + if self.completed { + return cold!(Ok(ExecState::Completed)); + } + if start.elapsed() >= time_budget { + return cold!(Ok(ExecState::Suspended(self.cf))); + } + } + } + + #[inline(always)] + pub(crate) fn run_with_fuel(mut self, fuel: u32) -> Result { + self.fuel_metered = true; + self.store.execution_fuel = fuel; + if self.store.execution_fuel == 0 { + return Ok(ExecState::Suspended(self.cf)); + } + + loop { + Bounded::run(&mut self)?; + if self.completed { + return cold!(Ok(ExecState::Completed)); + } + self.store.execution_fuel = self.store.execution_fuel.saturating_sub(CHECKPOINT_INTERVAL); + if self.store.execution_fuel == 0 { + return cold!(Ok(ExecState::Suspended(self.cf))); + } + } + } +} diff --git a/crates/tinywasm/src/interpreter/executor/instructions.rs b/crates/tinywasm/src/interpreter/executor/instructions.rs new file mode 100644 index 0000000..587d776 --- /dev/null +++ b/crates/tinywasm/src/interpreter/executor/instructions.rs @@ -0,0 +1,690 @@ +macro_rules! exec_op { + ($executor:ident; binary_fallible $ty:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ + fn exec_binary_fallible(value_stack: &mut ValueStack) -> Result<(), Trap> { + let $rhs = <$ty>::stack_pop(value_stack); + let $lhs = <$ty>::stack_pop(value_stack); + <$ty>::stack_push(value_stack, $expr?) + } + exec_binary_fallible(&mut $executor.store.value_stack)?; + }}; + ($executor:ident; unary $from:ty => $to:ty, |$v:ident| $expr:expr) => {{ + fn exec_unary(value_stack: &mut ValueStack) -> Result<(), Trap> { + let $v = <$from>::stack_pop(value_stack); + <$to>::stack_push(value_stack, $expr) + } + exec_unary(&mut $executor.store.value_stack)?; + }}; + ($executor:ident; binary $from:ty => $to:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ + exec_op!($executor; binary $from, $from => $to, |$lhs, $rhs| $expr) + }}; + ($executor:ident; binary $lhs_ty:ty, $rhs_ty:ty => $res:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ + fn exec_binary(value_stack: &mut ValueStack) -> Result<(), Trap> { + let $rhs = <$rhs_ty>::stack_pop(value_stack); + let $lhs = <$lhs_ty>::stack_pop(value_stack); + <$res>::stack_push(value_stack, $expr) + } + exec_binary(&mut $executor.store.value_stack)?; + }}; + ($executor:ident; ternary $from:ty => $to:ty, |$a:ident, $b:ident, $c:ident| $expr:expr) => {{ + fn exec_ternary(value_stack: &mut ValueStack) -> Result<(), Trap> { + let $c = <$from>::stack_pop(value_stack); + let $b = <$from>::stack_pop(value_stack); + let $a = <$from>::stack_pop(value_stack); + <$to>::stack_push(value_stack, $expr) + } + exec_ternary(&mut $executor.store.value_stack)?; + }}; +} + +// This list is the single source for stable instruction stepping and nightly tail handlers. +#[rustfmt::skip] +macro_rules! instruction_handlers { + ($emit:ident) => { + $emit! { executor, instr_ptr, dispatch_next, dispatch_flow; + Unreachable => { return cold!(Err(Trap::Unreachable.into())); }, + Drop32 => { _ = Value32::stack_pop(&mut executor.store.value_stack)}, + Drop64 => { _ = Value64::stack_pop(&mut executor.store.value_stack)}, + Drop128 => { _ = Value128::stack_pop(&mut executor.store.value_stack)}, + Select32 => Value32::stack_select(&mut executor.store.value_stack), + Select64 => Value64::stack_select(&mut executor.store.value_stack), + Select128 => Value128::stack_select(&mut executor.store.value_stack), + SelectStore32(idx) => executor.exec_select_store::(idx.resolve(&executor.func.data))?, + SelectStore64(idx) => executor.exec_select_store::(idx.resolve(&executor.func.data))?, + SelectMulti(counts) => executor.store.value_stack.select_multi(*counts), + Call(v) => dispatch_flow!(executor.exec_call_direct(*v, instr_ptr + 1)?), + CallSelf => { executor.exec_call_self(instr_ptr + 1)?; dispatch_next!(0); }, + CallIndirect(idx) => dispatch_flow!(executor.exec_call_indirect::(*idx, instr_ptr + 1)?), + CallRef(ty) => dispatch_flow!(executor.exec_call_ref::(*ty, instr_ptr + 1)?), + ReturnCall(v) => dispatch_flow!(executor.exec_return_call_direct(*v)?), + ReturnCallSelf => { executor.exec_return_call_self()?; dispatch_next!(0); }, + ReturnCallIndirect(idx) => dispatch_flow!(executor.exec_call_indirect::(*idx, instr_ptr + 1)?), + ReturnCallRef(ty) => dispatch_flow!(executor.exec_call_ref::(*ty, instr_ptr + 1)?), + Throw(tag) => dispatch_flow!(executor.exec_throw(*tag, instr_ptr)?), + ThrowRef => dispatch_flow!(executor.exec_throw_ref(instr_ptr)?), + Jump(ip) => dispatch_next!(*ip as usize), + JumpIfZero32(ip) => if i32::stack_pop(&mut executor.store.value_stack) == 0 { dispatch_next!(*ip as usize) }, + JumpIfNonZero32(ip) => if i32::stack_pop(&mut executor.store.value_stack) != 0 { dispatch_next!(*ip as usize) }, + JumpIfZero64(ip) => if i64::stack_pop(&mut executor.store.value_stack) == 0 { dispatch_next!(*ip as usize) }, + JumpIfNonZero64(ip) => if i64::stack_pop(&mut executor.store.value_stack) != 0 { dispatch_next!(*ip as usize) }, + JumpIfRefNull(ip) => { let ip = *ip; if executor.exec_jump_if_ref::() { dispatch_next!(ip as usize) } }, + JumpIfRefNonNull(ip) => { let ip = *ip; if executor.exec_jump_if_ref::() { dispatch_next!(ip as usize) } }, + BrOnCast(idx) => if let Some(ip) = executor.exec_br_on_cast::(*idx) { dispatch_next!(ip) }, + BrOnCastFail(idx) => if let Some(ip) = executor.exec_br_on_cast::(*idx) { dispatch_next!(ip) }, + JumpIfLocalZero32(arg) => if executor.exec_jump_if_local::(arg.local) { dispatch_next!(arg.target_ip as usize) }, + JumpIfLocalNonZero32(arg) => if executor.exec_jump_if_local::(arg.local) { dispatch_next!(arg.target_ip as usize) }, + JumpIfLocalZero64(arg) => if executor.exec_jump_if_local::(arg.local) { dispatch_next!(arg.target_ip as usize) }, + JumpIfLocalNonZero64(arg) => if executor.exec_jump_if_local::(arg.local) { dispatch_next!(arg.target_ip as usize) }, + JumpCmpStackConst32(packed) => if let Some(ip) = executor.exec_jump_cmp_stack_const32(*packed) { dispatch_next!(ip) }, + JumpCmpStackConst64(packed) => if let Some(ip) = executor.exec_jump_cmp_stack_const64(*packed) { dispatch_next!(ip) }, + JumpCmpStackLocal32(packed) => if let Some(ip) = executor.exec_jump_cmp_stack_local32(*packed) { dispatch_next!(ip) }, + JumpCmpStackLocal64(packed) => if let Some(ip) = executor.exec_jump_cmp_stack_local64(*packed) { dispatch_next!(ip) }, + BinOpLocalConstJump32(packed) => if let Some(ip) = executor.exec_binop_local_const_jump(*packed) { dispatch_next!(ip) }, + BinOpLocalConstJumpCmpLocal32(packed) => if let Some(ip) = executor.exec_binop_local_const_jump_cmp_local(*packed) { dispatch_next!(ip) }, + BinOpStackConstTeeLocalJump32(packed) => if let Some(ip) = executor.exec_binop_stack_const_tee_local_jump(*packed)? { dispatch_next!(ip) }, + BinOpGlobalConstJump32(packed) => if let Some(ip) = executor.exec_binop_global_const_jump(*packed) { dispatch_next!(ip) }, + IncLocalJump32(idx) => if let Some(ip) = executor.exec_inc_local_jump(*idx) { dispatch_next!(ip) }, + IncStackTeeLocalJump32(idx) => if let Some(ip) = executor.exec_inc_stack_tee_local_jump(*idx)? { dispatch_next!(ip) }, + IncGlobalJump32(idx) => if let Some(ip) = executor.exec_inc_global_jump(*idx) { dispatch_next!(ip) }, + IncLocalJumpCmpLocal32(packed) => if let Some(ip) = executor.exec_inc_local_jump_cmp_local(*packed) { dispatch_next!(ip) }, + JumpCmpLocalConst32(packed) => if let Some(ip) = executor.exec_jump_cmp_local_const32(*packed) { dispatch_next!(ip) }, + JumpCmpLocalConst64(packed) => if let Some(ip) = executor.exec_jump_cmp_local_const64(*packed) { dispatch_next!(ip) }, + JumpCmpLocalLocal32(packed) => if let Some(ip) = executor.exec_jump_cmp_local_local32(*packed) { dispatch_next!(ip) }, + JumpCmpLocalLocal64(packed) => if let Some(ip) = executor.exec_jump_cmp_local_local64(*packed) { dispatch_next!(ip) }, + DropKeep32 { base, keep } => executor.store.value_stack.stack_32.truncate_keep((executor.cf.stack_base().s32 + u32::from(*base)) as usize, *keep as usize), + DropKeep64 { base, keep } => executor.store.value_stack.stack_64.truncate_keep((executor.cf.stack_base().s64 + u32::from(*base)) as usize, *keep as usize), + DropKeep128 { base, keep } => executor.store.value_stack.stack_128.truncate_keep((executor.cf.stack_base().s128 + u32::from(*base)) as usize, *keep as usize), + BranchTable(idx) => dispatch_next!(executor.exec_branch_table(*idx)), + Return => dispatch_flow!(executor.exec_return()), + ReturnVoid => dispatch_flow!(executor.exec_return_void()), + Return32 => dispatch_flow!(executor.exec_return_32()), + Return64 => dispatch_flow!(executor.exec_return_64()), + Return128 => dispatch_flow!(executor.exec_return_128()), + LocalGet32(local_index) => Value32::local_push(&mut executor.store.value_stack, &executor.cf, *local_index)?, + LocalGet64(local_index) => Value64::local_push(&mut executor.store.value_stack, &executor.cf, *local_index)?, + LocalGet128(local_index) => Value128::local_push(&mut executor.store.value_stack, &executor.cf, *local_index)?, + LocalSet32(local_index) => executor.exec_local_set_pop::(*local_index), + LocalSet64(local_index) => executor.exec_local_set_pop::(*local_index), + LocalSet128(local_index) => executor.exec_local_set_pop::(*local_index), + LocalCopy32(from, to) => Value32::local_copy(&mut executor.store.value_stack, &executor.cf, *from, *to), + LocalCopy64(from, to) => Value64::local_copy(&mut executor.store.value_stack, &executor.cf, *from, *to), + LocalCopy128(from, to) => Value128::local_copy(&mut executor.store.value_stack, &executor.cf, *from, *to), + AddConst32(c) => { i32::stack_update(&mut executor.store.value_stack, |value| value.wrapping_add(*c)); }, + AndConst32(c) => { i32::stack_update(&mut executor.store.value_stack, |value| value & *c); }, + XorConst32(c) => { i32::stack_update(&mut executor.store.value_stack, |value| value ^ *c); }, + ShrUConst32(c) => { u32::stack_update(&mut executor.store.value_stack, |value| value.wrapping_shr(*c as u32)); }, + AddConst64(idx) => { let rhs = idx.resolve(&executor.func.data).value(); i64::stack_update(&mut executor.store.value_stack, |value| value.wrapping_add(rhs)); }, + BinOpStackConst32(op, rhs) => { u32::stack_update(&mut executor.store.value_stack, |lhs| op.exec(lhs, *rhs as u32)); }, + BinOpStackConst64(packed) => { let rhs = packed.index.resolve(&executor.func.data).value() as u64; u64::stack_update(&mut executor.store.value_stack, |lhs| packed.op.exec(lhs, rhs)); }, + IncLocal32(arg) => { i32::local_update(&mut executor.store.value_stack, &executor.cf, arg.local, |value| value.wrapping_add(arg.value)); }, + IncLocal64(packed) => { let rhs = packed.index.resolve(&executor.func.data).value(); i64::local_update(&mut executor.store.value_stack, &executor.cf, packed.op, |value| value.wrapping_add(rhs)); }, + I32Add3 => exec_op!(executor; ternary i32 => i32, |a, b, c| a.wrapping_add(b).wrapping_add(c)), + I64Add3 => exec_op!(executor; ternary i64 => i64, |a, b, c| a.wrapping_add(b).wrapping_add(c)), + MulAccLocal32(acc) => executor.exec_mul_acc_local::(*acc, i32::wrapping_mul, i32::wrapping_add), + MulAccLocal64(acc) => executor.exec_mul_acc_local::(*acc, i64::wrapping_mul, i64::wrapping_add), + FMulAccLocal32(acc) => executor.exec_mul_acc_local::(*acc, #[inline(always)] |a, b| a * b, #[inline(always)] |a, b| a + b), + FMulAccLocal64(acc) => executor.exec_mul_acc_local::(*acc, #[inline(always)] |a, b| a * b, #[inline(always)] |a, b| a + b), + BinOpLocalLocal32(op, a, b) => executor.exec_binop_local_local::(*a, *b, None, *op)?, + BinOpLocalLocal64(op, a, b) => executor.exec_binop_local_local::(*a, *b, None, *op)?, + BinOpLocalLocal128(op, a, b) => executor.exec_binop_local_local::(*a, *b, None, *op)?, + CmpLocalLocal32(op, a, b) => executor.exec_cmp_local_local::(*a, *b, *op)?, + CmpLocalLocal64(op, a, b) => executor.exec_cmp_local_local::(*a, *b, *op)?, + AddLocalLocalSet32(arg) => executor.exec_binop_local_local::(arg.left, arg.right, Some(arg.dst), BinOp::IAdd)?, + AddLocalLocalTee32(arg) => executor.exec_binop_local_local::(arg.left, arg.right, Some(arg.dst), BinOp::IAdd)?, + BinOpLocalLocalSet32(packed) => executor.exec_binop_local_local_indexed::(packed.index, packed.op)?, + BinOpLocalLocalSet64(packed) => executor.exec_binop_local_local_indexed::(packed.index, packed.op)?, + BinOpLocalLocalSet128(packed) => executor.exec_binop_local_local_indexed::(packed.index, packed.op)?, + BinOpLocalLocalTee32(packed) => executor.exec_binop_local_local_indexed::(packed.index, packed.op)?, + BinOpLocalLocalTee64(packed) => executor.exec_binop_local_local_indexed::(packed.index, packed.op)?, + BinOpLocalLocalTee128(packed) => executor.exec_binop_local_local_indexed::(packed.index, packed.op)?, + AddLocalConst32(arg) => executor.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IAdd)?, + SubLocalConst32(arg) => executor.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::ISub)?, + MulLocalConst32(arg) => executor.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IMul)?, + AndLocalConst32(arg) => executor.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IAnd)?, + ShrULocalConst32(arg) => executor.exec_binop_local_const::(arg.local, arg.value as u32, None, BinOp::IShrU)?, + BinOpLocalConst32(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_local_const::(v.a(), v.b(), None, packed.op)?; }, + BinOpLocalConst64(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_local_const::(v.a(), v.b(), None, packed.op)?; }, + BinOpLocalConst128(packed) => { let v = packed.index.resolve(&executor.func.data); let rhs = Value128(v.b().resolve(&executor.func.data).value()); executor.exec_binop_local_const::(v.a(), rhs, None, packed.op)?; }, + BinOpLocalConstSet32(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, + BinOpLocalConstTee32(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, + BinOpLocalConstSet64(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, + BinOpLocalConstTee64(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_local_const::(v.a(), v.c(), Some(v.b()), packed.op)?; }, + BinOpLocalConstSet128(packed) => { let v = packed.index.resolve(&executor.func.data); let rhs = Value128(v.c().resolve(&executor.func.data).value()); executor.exec_binop_local_const::(v.a(), rhs, Some(v.b()), packed.op)?; }, + BinOpLocalConstTee128(packed) => { let v = packed.index.resolve(&executor.func.data); let rhs = Value128(v.c().resolve(&executor.func.data).value()); executor.exec_binop_local_const::(v.a(), rhs, Some(v.b()), packed.op)?; }, + BinOpStackLocal32(op, local) => executor.exec_binop_stack_local::(*local, None, *op)?, + BinOpStackLocalSet32(op, local, dst) => executor.exec_binop_stack_local::(*local, Some(*dst), *op)?, + BinOpStackLocalTee32(op, local, dst) => executor.exec_binop_stack_local::(*local, Some(*dst), *op)?, + BinOpStackLocal128(op, local) => executor.exec_binop_stack_local::(*local, None, *op)?, + BinOpStackGlobal32(op, global_index) => executor.exec_binop_stack_global::(*global_index, *op)?, + BinOpStackGlobal64(op, global_index) => executor.exec_binop_stack_global::(*global_index, *op)?, + BinOpGlobalConst32(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_global_const::(v.a(), v.b(), packed.op)?; }, + BinOpGlobalConst64(packed) => { let v = packed.index.resolve(&executor.func.data); executor.exec_binop_global_const::(v.a(), v.b(), packed.op)?; }, + BinOpGlobalConst128(packed) => { let v = packed.index.resolve(&executor.func.data); let rhs = Value128(v.b().resolve(&executor.func.data).value()); executor.exec_binop_global_const::(v.a(), rhs, packed.op)?; }, + SetLocalConst32(arg) => i32::local_set(&mut executor.store.value_stack, &executor.cf, arg.local, arg.value), + SetLocalConst64(packed) => { let v = packed.index.resolve(&executor.func.data).value(); i64::local_set(&mut executor.store.value_stack, &executor.cf, packed.op, v); }, + SetLocalConst128(packed) => Value128::local_set(&mut executor.store.value_stack, &executor.cf, packed.op, Value128(packed.index.resolve(&executor.func.data).value())), + IncMemoryLocal32(arg) => executor.exec_inc_memory_local::(arg.memory_arg_idx, arg.local1, #[inline(always)] |v| v.wrapping_add(1))?, + IncMemoryLocal64(arg) => executor.exec_inc_memory_local::(arg.memory_arg_idx, arg.local1, #[inline(always)] |v| v.wrapping_add(1))?, + StoreLocalLocal32(arg) => executor.exec_store_local_local::(arg.memory_arg_idx, arg.local1, arg.local2)?, + StoreLocalLocal64(arg) => executor.exec_store_local_local::(arg.memory_arg_idx, arg.local1, arg.local2)?, + StoreLocalLocal128(arg) => executor.exec_store_local_local::(arg.memory_arg_idx, arg.local1, arg.local2)?, + LoadLocal32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, identity)?, + LoadLocal64(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, identity)?, + LoadLocal8S32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, + LoadLocal8U32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, + LoadLocal16S32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, + LoadLocal16U32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, 0, i32::from)?, + LoadLocalTee32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, + LoadLocalSet32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, + LoadLocalTee8S32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalTee8U32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalTee16S32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalTee16U32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalSet8S32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalSet8U32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalSet16S32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalSet16U32(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, i32::from)?, + LoadLocalTee128(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, + LoadLocalSet128(arg) => executor.exec_load_local::(arg.memory_arg_idx, arg.local1, arg.local2, identity)?, + AndConstTee32(arg) => executor.exec_binop_const_tee::(arg.value as u32, arg.local, BinOp::IAnd)?, + SubConstTee32(arg) => executor.exec_binop_const_tee::(arg.value as u32, arg.local, BinOp::ISub)?, + AndConstTee64(packed) => executor.exec_binop_const_tee::(packed.index.resolve(&executor.func.data).value() as u64, packed.op, BinOp::IAnd)?, + SubConstTee64(packed) => executor.exec_binop_const_tee::(packed.index.resolve(&executor.func.data).value() as u64, packed.op, BinOp::ISub)?, + LocalTee32(local_index) => executor.exec_local_tee::(*local_index), + LocalTee64(local_index) => executor.exec_local_tee::(*local_index), + LocalTee128(local_index) => executor.exec_local_tee::(*local_index), + GlobalGet32(global_index) => executor.exec_global_get::(*global_index)?, + GlobalGet64(global_index) => executor.exec_global_get::(*global_index)?, + GlobalGet128(global_index) => executor.exec_global_get::(*global_index)?, + GlobalSet32(global_index) => executor.exec_global_set::(*global_index), + GlobalSet64(global_index) => executor.exec_global_set::(*global_index), + GlobalSet128(global_index) => executor.exec_global_set::(*global_index), + GlobalTee32(global_index) => executor.exec_global_tee::(*global_index), + GlobalTee64(global_index) => executor.exec_global_tee::(*global_index), + GlobalTee128(global_index) => executor.exec_global_tee::(*global_index), + Const32(val) => i32::stack_push(&mut executor.store.value_stack, *val)?, + Const64Imm(val) => i64::stack_push(&mut executor.store.value_stack, i64::from(*val))?, + Const64(idx) => i64::stack_push(&mut executor.store.value_stack, idx.resolve(&executor.func.data).value())?, + Const128Imm(val) => Value128::stack_push(&mut executor.store.value_stack, Value128(u128::from(*val).to_le_bytes()))?, + I64Eqz => exec_op!(executor; unary i64 => i32, |v| i32::from(v == 0)), + I32Eqz => exec_op!(executor; unary i32 => i32, |v| i32::from(v == 0)), + I32Eq => exec_op!(executor; binary i32 => i32, |a, b| i32::from(a == b)), + I64Eq => exec_op!(executor; binary i64 => i32, |a, b| i32::from(a == b)), + F32Eq => exec_op!(executor; binary f32 => i32, |a, b| i32::from(a == b)), + F64Eq => exec_op!(executor; binary f64 => i32, |a, b| i32::from(a == b)), + I32Ne => exec_op!(executor; binary i32 => i32, |a, b| i32::from(a != b)), + I64Ne => exec_op!(executor; binary i64 => i32, |a, b| i32::from(a != b)), + F32Ne => exec_op!(executor; binary f32 => i32, |a, b| i32::from(a != b)), + F64Ne => exec_op!(executor; binary f64 => i32, |a, b| i32::from(a != b)), + I32LtS => exec_op!(executor; binary i32 => i32, |a, b| i32::from(a < b)), + I64LtS => exec_op!(executor; binary i64 => i32, |a, b| i32::from(a < b)), + I32LtU => exec_op!(executor; binary u32 => i32, |a, b| i32::from(a < b)), + I64LtU => exec_op!(executor; binary u64 => i32, |a, b| i32::from(a < b)), + F32Lt => exec_op!(executor; binary f32 => i32, |a, b| i32::from(a < b)), + F64Lt => exec_op!(executor; binary f64 => i32, |a, b| i32::from(a < b)), + I32LeS => exec_op!(executor; binary i32 => i32, |a, b| i32::from(a <= b)), + I64LeS => exec_op!(executor; binary i64 => i32, |a, b| i32::from(a <= b)), + I32LeU => exec_op!(executor; binary u32 => i32, |a, b| i32::from(a <= b)), + I64LeU => exec_op!(executor; binary u64 => i32, |a, b| i32::from(a <= b)), + F32Le => exec_op!(executor; binary f32 => i32, |a, b| i32::from(a <= b)), + F64Le => exec_op!(executor; binary f64 => i32, |a, b| i32::from(a <= b)), + I32GeS => exec_op!(executor; binary i32 => i32, |a, b| i32::from(a >= b)), + I64GeS => exec_op!(executor; binary i64 => i32, |a, b| i32::from(a >= b)), + I32GeU => exec_op!(executor; binary u32 => i32, |a, b| i32::from(a >= b)), + I64GeU => exec_op!(executor; binary u64 => i32, |a, b| i32::from(a >= b)), + F32Ge => exec_op!(executor; binary f32 => i32, |a, b| i32::from(a >= b)), + F64Ge => exec_op!(executor; binary f64 => i32, |a, b| i32::from(a >= b)), + I32GtS => exec_op!(executor; binary i32 => i32, |a, b| i32::from(a > b)), + I64GtS => exec_op!(executor; binary i64 => i32, |a, b| i32::from(a > b)), + I32GtU => exec_op!(executor; binary u32 => i32, |a, b| i32::from(a > b)), + I64GtU => exec_op!(executor; binary u64 => i32, |a, b| i32::from(a > b)), + F32Gt => exec_op!(executor; binary f32 => i32, |a, b| i32::from(a > b)), + F64Gt => exec_op!(executor; binary f64 => i32, |a, b| i32::from(a > b)), + I32Add => exec_op!(executor; binary i32 => i32, |a, b| a.wrapping_add(b)), + I64Add => exec_op!(executor; binary i64 => i64, |a, b| a.wrapping_add(b)), + F32Add => exec_op!(executor; binary f32 => f32, |a, b| a + b), + F64Add => exec_op!(executor; binary f64 => f64, |a, b| a + b), + I32Sub => exec_op!(executor; binary i32 => i32, |a, b| a.wrapping_sub(b)), + I64Sub => exec_op!(executor; binary i64 => i64, |a, b| a.wrapping_sub(b)), + F32Sub => exec_op!(executor; binary f32 => f32, |a, b| a - b), + F64Sub => exec_op!(executor; binary f64 => f64, |a, b| a - b), + F32Div => exec_op!(executor; binary f32 => f32, |a, b| a / b), + F64Div => exec_op!(executor; binary f64 => f64, |a, b| a / b), + I32Mul => exec_op!(executor; binary i32 => i32, |a, b| a.wrapping_mul(b)), + I64Mul => exec_op!(executor; binary i64 => i64, |a, b| a.wrapping_mul(b)), + F32Mul => exec_op!(executor; binary f32 => f32, |a, b| a * b), + F64Mul => exec_op!(executor; binary f64 => f64, |a, b| a * b), + I32DivS => exec_op!(executor; binary_fallible i32, |a, b| a.tw_checked_div(b)), + I64DivS => exec_op!(executor; binary_fallible i64, |a, b| a.tw_checked_div(b)), + I32DivU => exec_op!(executor; binary_fallible u32, |a, b| a.checked_div(b).ok_or(Trap::DivisionByZero)), + I64DivU => exec_op!(executor; binary_fallible u64, |a, b| a.checked_div(b).ok_or(Trap::DivisionByZero)), + I32RemS => exec_op!(executor; binary_fallible i32, |a, b| a.tw_checked_wrapping_rem(b)), + I64RemS => exec_op!(executor; binary_fallible i64, |a, b| a.tw_checked_wrapping_rem(b)), + I32RemU => exec_op!(executor; binary_fallible u32, |a, b| a.tw_checked_wrapping_rem(b)), + I64RemU => exec_op!(executor; binary_fallible u64, |a, b| a.tw_checked_wrapping_rem(b)), + I32And => exec_op!(executor; binary i32 => i32, |a, b| a & b), + I64And => exec_op!(executor; binary i64 => i64, |a, b| a & b), + I32Or => exec_op!(executor; binary i32 => i32, |a, b| a | b), + I64Or => exec_op!(executor; binary i64 => i64, |a, b| a | b), + I32Xor => exec_op!(executor; binary i32 => i32, |a, b| a ^ b), + I64Xor => exec_op!(executor; binary i64 => i64, |a, b| a ^ b), + I32Shl => exec_op!(executor; binary i32 => i32, |a, b| a.wrapping_shl(b as u32)), + I64Shl => exec_op!(executor; binary i64 => i64, |a, b| a.wrapping_shl(b as u32)), + I32ShrS => exec_op!(executor; binary i32 => i32, |a, b| a.wrapping_shr(b as u32)), + I64ShrS => exec_op!(executor; binary i64 => i64, |a, b| a.wrapping_shr(b as u32)), + I32ShrU => exec_op!(executor; binary u32 => u32, |a, b| a.wrapping_shr(b)), + I64ShrU => exec_op!(executor; binary u64 => u64, |a, b| a.wrapping_shr(b as u32)), + I32Rotl => exec_op!(executor; binary i32 => i32, |a, b| a.rotate_left(b as u32)), + I64Rotl => exec_op!(executor; binary i64 => i64, |a, b| a.rotate_left(b as u32)), + I32Rotr => exec_op!(executor; binary i32 => i32, |a, b| a.rotate_right(b as u32)), + I64Rotr => exec_op!(executor; binary i64 => i64, |a, b| a.rotate_right(b as u32)), + I64Add128 => executor.exec_i64_add128()?, + I64Sub128 => executor.exec_i64_sub128()?, + I64MulWideS => executor.exec_i64_mul_wide_s()?, + I64MulWideU => executor.exec_i64_mul_wide_u()?, + I32Clz => exec_op!(executor; unary i32 => i32, |v| v.leading_zeros() as i32), + I64Clz => exec_op!(executor; unary i64 => i64, |v| i64::from(v.leading_zeros())), + I32Ctz => exec_op!(executor; unary i32 => i32, |v| v.trailing_zeros() as i32), + I64Ctz => exec_op!(executor; unary i64 => i64, |v| i64::from(v.trailing_zeros())), + I32Popcnt => exec_op!(executor; unary i32 => i32, |v| v.count_ones() as i32), + I64Popcnt => exec_op!(executor; unary i64 => i64, |v| i64::from(v.count_ones())), + + // Reference types + RefFunc(func_idx) => ValueRef::stack_push(&mut executor.store.value_stack, ValueRef::from_category_addr(executor.module.resolve_func_addr(*func_idx)))?, + RefNull(_) => ValueRef::stack_push(&mut executor.store.value_stack, ValueRef::NULL)?, + RefIsNull => executor.exec_ref_is_null()?, + RefAsNonNull => executor.exec_ref_as_non_null()?, + RefI31 => exec_op!(executor; unary i32 => ValueRef, |v| ValueRef::from_i31(v)), + I31GetS => executor.exec_i31_get(true)?, + I31GetU => executor.exec_i31_get(false)?, + RefEq => exec_op!(executor; binary ValueRef => i32, |a, b| i32::from(a == b)), + RefTest(ty) => executor.exec_ref_test(*ty)?, + RefCast(ty) => executor.exec_ref_cast(*ty)?, + + // GC objects + StructNew(ty) => executor.exec_struct_new(*ty, false)?, + StructNewDefault(ty) => executor.exec_struct_new(*ty, true)?, + StructGet(idx) => executor.exec_struct_get(*idx, None)?, + StructGetS(idx) => executor.exec_struct_get(*idx, Some(true))?, + StructGetU(idx) => executor.exec_struct_get(*idx, Some(false))?, + StructSet(idx) => executor.exec_struct_set(*idx)?, + ArrayNew(ty) => executor.exec_array_new(*ty, false)?, + ArrayNewDefault(ty) => executor.exec_array_new(*ty, true)?, + ArrayNewFixed(idx) => executor.exec_array_new_fixed(*idx)?, + ArrayNewData(idx) => executor.exec_array_new_data(*idx)?, + ArrayNewElem(idx) => executor.exec_array_new_elem(*idx)?, + ArrayGet(ty) => executor.exec_array_get(*ty, None)?, + ArrayGetS(ty) => executor.exec_array_get(*ty, Some(true))?, + ArrayGetU(ty) => executor.exec_array_get(*ty, Some(false))?, + ArraySet(ty) => executor.exec_array_set(*ty)?, + ArrayLen => executor.exec_array_len()?, + ArrayFill(ty) => executor.exec_array_fill(*ty)?, + ArrayCopy(idx) => executor.exec_array_copy(*idx)?, + ArrayInitData(idx) => executor.exec_array_init_data(*idx)?, + ArrayInitElem(idx) => executor.exec_array_init_elem(*idx)?, + MemorySize(addr) => executor.exec_memory_size(*addr)?, + MemoryGrow(addr) => executor.exec_memory_grow(*addr)?, + + // Bulk memory operations + MemoryCopy(idx) => executor.exec_memory_copy(*idx)?, + MemoryFill(addr) => executor.exec_memory_fill(*addr)?, + MemoryFillConst(idx) => executor.exec_memory_fill_const(*idx)?, + MemoryInit(idx) => executor.exec_memory_init(*idx)?, + DataDrop(data_index) => executor.store.state.get_data_mut(executor.module.resolve_data_addr(*data_index)).drop(), + ElemDrop(elem_index) => executor.store.state.get_elem_mut(executor.module.resolve_elem_addr(*elem_index)).drop(), + + // Table instructions + TableGet(table_idx) => executor.exec_table_get(*table_idx)?, + TableSet(table_idx) => executor.exec_table_set(*table_idx)?, + TableSize(table_idx) => executor.exec_table_size(*table_idx)?, + TableInit(idx) => executor.exec_table_init(*idx)?, + TableGrow(table_idx) => executor.exec_table_grow(*table_idx)?, + TableFill(table_idx) => executor.exec_table_fill(*table_idx)?, + TableCopy(idx) => executor.exec_table_copy(*idx)?, + + // Core memory load/store operations + I32Store(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), identity)?, + I64Store(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), identity)?, + F32Store(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), identity)?, + F64Store(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), identity)?, + FMaStoreF32(m) => executor.exec_fma_store::(*m)?, + FMaStoreF64(m) => executor.exec_fma_store::(*m)?, + I32Store8(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), #[inline(always)] |v| v as i8)?, + I32Store16(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), #[inline(always)] |v| v as i16)?, + I64Store8(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), #[inline(always)] |v| v as i8)?, + I64Store16(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), #[inline(always)] |v| v as i16)?, + I64Store32(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), #[inline(always)] |v| v as i32)?, + I32Load(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), identity)?, + I64Load(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), identity)?, + F32Load(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), identity)?, + F64Load(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), identity)?, + I32Load8S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i32::from)?, + I32Load8U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i32::from)?, + I32Load16S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i32::from)?, + I32Load16U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i32::from)?, + I64Load8S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i64::from)?, + I64Load8U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i64::from)?, + I64Load16S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i64::from)?, + I64Load16U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i64::from)?, + I64Load32S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i64::from)?, + I64Load32U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), i64::from)?, + + // Numeric conversion operations + F32ConvertI32S => exec_op!(executor; unary i32 => f32, |v| v as f32), + F32ConvertI64S => exec_op!(executor; unary i64 => f32, |v| v as f32), + F64ConvertI32S => exec_op!(executor; unary i32 => f64, |v| f64::from(v)), + F64ConvertI64S => exec_op!(executor; unary i64 => f64, |v| v as f64), + F32ConvertI32U => exec_op!(executor; unary u32 => f32, |v| v as f32), + F32ConvertI64U => exec_op!(executor; unary u64 => f32, |v| v as f32), + F64ConvertI32U => exec_op!(executor; unary u32 => f64, |v| f64::from(v)), + F64ConvertI64U => exec_op!(executor; unary u64 => f64, |v| v as f64), + + // Sign-extension operations + I32Extend8S => exec_op!(executor; unary i32 => i32, |v| i32::from(v as i8)), + I32Extend16S => exec_op!(executor; unary i32 => i32, |v| i32::from(v as i16)), + I64Extend8S => exec_op!(executor; unary i64 => i64, |v| i64::from(v as i8)), + I64Extend16S => exec_op!(executor; unary i64 => i64, |v| i64::from(v as i16)), + I64Extend32S => exec_op!(executor; unary i64 => i64, |v| i64::from(v as i32)), + I64ExtendI32U => exec_op!(executor; unary u32 => i64, |v| i64::from(v)), + I64ExtendI32S => exec_op!(executor; unary i32 => i64, |v| i64::from(v)), + I32WrapI64 => exec_op!(executor; unary i64 => i32, |v| v as i32), + F32DemoteF64 => exec_op!(executor; unary f64 => f32, |v| v as f32), + F64PromoteF32 => exec_op!(executor; unary f32 => f64, |v| f64::from(v)), + F32Abs => exec_op!(executor; unary f32 => f32, |v| v.abs()), + F64Abs => exec_op!(executor; unary f64 => f64, |v| v.abs()), + F32Neg => exec_op!(executor; unary f32 => f32, |v| -v), + F64Neg => exec_op!(executor; unary f64 => f64, |v| -v), + F32Ceil => exec_op!(executor; unary f32 => f32, |v| v.ceil()), + F64Ceil => exec_op!(executor; unary f64 => f64, |v| v.ceil()), + F32Floor => exec_op!(executor; unary f32 => f32, |v| v.floor()), + F64Floor => exec_op!(executor; unary f64 => f64, |v| v.floor()), + F32Trunc => exec_op!(executor; unary f32 => f32, |v| v.trunc()), + F64Trunc => exec_op!(executor; unary f64 => f64, |v| v.trunc()), + F32Nearest => exec_op!(executor; unary f32 => f32, |v| v.tw_nearest()), + F64Nearest => exec_op!(executor; unary f64 => f64, |v| v.tw_nearest()), + F32Sqrt => exec_op!(executor; unary f32 => f32, |v| v.sqrt()), + F64Sqrt => exec_op!(executor; unary f64 => f64, |v| v.sqrt()), + F32Min => exec_op!(executor; binary f32 => f32, |a, b| a.tw_minimum(b)), + F64Min => exec_op!(executor; binary f64 => f64, |a, b| a.tw_minimum(b)), + F32Max => exec_op!(executor; binary f32 => f32, |a, b| a.tw_maximum(b)), + F64Max => exec_op!(executor; binary f64 => f64, |a, b| a.tw_maximum(b)), + F32Copysign => exec_op!(executor; binary f32 => f32, |a, b| a.copysign(b)), + F64Copysign => exec_op!(executor; binary f64 => f64, |a, b| a.copysign(b)), + I32TruncF32S => checked_conv_float!(f32, i32, executor), + I32TruncF64S => checked_conv_float!(f64, i32, executor), + I32TruncF32U => checked_conv_float!(f32, u32, i32, executor), + I32TruncF64U => checked_conv_float!(f64, u32, i32, executor), + I64TruncF32S => checked_conv_float!(f32, i64, executor), + I64TruncF64S => checked_conv_float!(f64, i64, executor), + I64TruncF32U => checked_conv_float!(f32, u64, i64, executor), + I64TruncF64U => checked_conv_float!(f64, u64, i64, executor), + + // Non-trapping float-to-int conversions + I32TruncSatF32S => exec_op!(executor; unary f32 => i32, |v| v.trunc() as i32), + I32TruncSatF32U => exec_op!(executor; unary f32 => u32, |v| v.trunc() as u32), + I32TruncSatF64S => exec_op!(executor; unary f64 => i32, |v| v.trunc() as i32), + I32TruncSatF64U => exec_op!(executor; unary f64 => u32, |v| v.trunc() as u32), + I64TruncSatF32S => exec_op!(executor; unary f32 => i64, |v| v.trunc() as i64), + I64TruncSatF32U => exec_op!(executor; unary f32 => u64, |v| v.trunc() as u64), + I64TruncSatF64S => exec_op!(executor; unary f64 => i64, |v| v.trunc() as i64), + I64TruncSatF64U => exec_op!(executor; unary f64 => u64, |v| v.trunc() as u64), + + // SIMD extension + V128Not => exec_op!(executor; unary Value128 => Value128, |v| v.v128_not()), + V128And => exec_op!(executor; binary Value128 => Value128, |a, b| a.v128_and(b)), + V128AndNot => exec_op!(executor; binary Value128 => Value128, |a, b| a.v128_andnot(b)), + V128Or => exec_op!(executor; binary Value128 => Value128, |a, b| a.v128_or(b)), + V128Xor => exec_op!(executor; binary Value128 => Value128, |a, b| a.v128_xor(b)), + V128Bitselect => exec_op!(executor; ternary Value128 => Value128, |a, b, c| Value128::v128_bitselect(a, b, c)), + V128AnyTrue => exec_op!(executor; unary Value128 => i32, |v| v.v128_any_true() as i32), + I8x16Swizzle => exec_op!(executor; binary Value128 => Value128, |a, s| a.i8x16_swizzle(s)), + I8x16RelaxedSwizzle => exec_op!(executor; binary Value128 => Value128, |a, s| a.i8x16_relaxed_swizzle(s)), + V128Load(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), identity)?, + V128Load8x8S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::v128_load8x8_s(v.to_le_bytes()))?, + V128Load8x8U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::v128_load8x8_u(v.to_le_bytes()))?, + V128Load16x4S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::v128_load16x4_s(v.to_le_bytes()))?, + V128Load16x4U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::v128_load16x4_u(v.to_le_bytes()))?, + V128Load32x2S(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::v128_load32x2_s(v.to_le_bytes()))?, + V128Load32x2U(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::v128_load32x2_u(v.to_le_bytes()))?, + V128Load8Splat(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), Value128::splat_i8)?, + V128Load16Splat(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), Value128::splat_i16)?, + V128Load32Splat(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), Value128::splat_i32)?, + V128Load64Splat(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), Value128::splat_i64)?, + V128Store(idx) => executor.exec_mem_store::(idx.resolve(&executor.func.data), identity)?, + V128Store8Lane(arg) => executor.exec_mem_store_lane::(*arg)?, + V128Store16Lane(arg) => executor.exec_mem_store_lane::(*arg)?, + V128Store32Lane(arg) => executor.exec_mem_store_lane::(*arg)?, + V128Store64Lane(arg) => executor.exec_mem_store_lane::(*arg)?, + V128Load32Zero(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::from_i32x4([v, 0, 0, 0]))?, + V128Load64Zero(idx) => executor.exec_mem_load::(idx.resolve(&executor.func.data), |v| Value128::from_i64x2([v, 0]))?, + Const128(arg) => Value128::stack_push(&mut executor.store.value_stack, Value128(arg.resolve(&executor.func.data).value()))?, + I8x16ExtractLaneS(lane) => executor.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_i8(lane) as i32)?, + I8x16ExtractLaneU(lane) => executor.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_u8(lane) as i32)?, + I16x8ExtractLaneS(lane) => executor.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_i16(lane) as i32)?, + I16x8ExtractLaneU(lane) => executor.exec_simd_extract_lane::(*lane, |v, lane| v.extract_lane_u16(lane) as i32)?, + I32x4ExtractLane(lane) => executor.exec_simd_extract_lane::(*lane, Value128::extract_lane_i32)?, + I64x2ExtractLane(lane) => executor.exec_simd_extract_lane::(*lane, Value128::extract_lane_i64)?, + F32x4ExtractLane(lane) => executor.exec_simd_extract_lane::(*lane, Value128::extract_lane_f32)?, + F64x2ExtractLane(lane) => executor.exec_simd_extract_lane::(*lane, Value128::extract_lane_f64)?, + V128Load8Lane(arg) => executor.exec_mem_load_lane::(*arg)?, + V128Load16Lane(arg) => executor.exec_mem_load_lane::(*arg)?, + V128Load32Lane(arg) => executor.exec_mem_load_lane::(*arg)?, + V128Load64Lane(arg) => executor.exec_mem_load_lane::(*arg)?, + I8x16ReplaceLane(lane) => executor.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i8x16_replace_lane(lane, value as i8))?, + I16x8ReplaceLane(lane) => executor.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i16x8_replace_lane(lane, value as i16))?, + I32x4ReplaceLane(lane) => executor.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i32x4_replace_lane(lane, value))?, + I64x2ReplaceLane(lane) => executor.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.i64x2_replace_lane(lane, value))?, + F32x4ReplaceLane(lane) => executor.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.f32x4_replace_lane(lane, value))?, + F64x2ReplaceLane(lane) => executor.exec_simd_replace_lane::(*lane, |value, vector, lane| vector.f64x2_replace_lane(lane, value))?, + I8x16Splat => exec_op!(executor; unary i32 => Value128, |v| Value128::splat_i8(v as i8)), + I16x8Splat => exec_op!(executor; unary i32 => Value128, |v| Value128::splat_i16(v as i16)), + I32x4Splat => exec_op!(executor; unary i32 => Value128, |v| Value128::splat_i32(v)), + I64x2Splat => exec_op!(executor; unary i64 => Value128, |v| Value128::splat_i64(v)), + F32x4Splat => exec_op!(executor; unary f32 => Value128, |v| Value128::splat_f32(v)), + F64x2Splat => exec_op!(executor; unary f64 => Value128, |v| Value128::splat_f64(v)), + I8x16Eq => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_eq(b)), + I16x8Eq => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_eq(b)), + I32x4Eq => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_eq(b)), + I64x2Eq => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_eq(b)), + F32x4Eq => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_eq(b)), + F64x2Eq => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_eq(b)), + I8x16Ne => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_ne(b)), + I16x8Ne => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_ne(b)), + I32x4Ne => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_ne(b)), + I64x2Ne => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_ne(b)), + F32x4Ne => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_ne(b)), + F64x2Ne => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_ne(b)), + I8x16LtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_lt_s(b)), + I16x8LtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_lt_s(b)), + I32x4LtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_lt_s(b)), + I64x2LtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_lt_s(b)), + I8x16LtU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_lt_u(b)), + I16x8LtU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_lt_u(b)), + I32x4LtU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_lt_u(b)), + F32x4Lt => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_lt(b)), + F64x2Lt => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_lt(b)), + F32x4Gt => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_gt(b)), + F64x2Gt => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_gt(b)), + I8x16GtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_gt_s(b)), + I16x8GtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_gt_s(b)), + I32x4GtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_gt_s(b)), + I64x2GtS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_gt_s(b)), + I64x2LeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_le_s(b)), + F32x4Le => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_le(b)), + F64x2Le => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_le(b)), + I8x16GtU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_gt_u(b)), + I16x8GtU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_gt_u(b)), + I32x4GtU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_gt_u(b)), + F32x4Ge => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_ge(b)), + F64x2Ge => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_ge(b)), + I8x16LeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_le_s(b)), + I16x8LeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_le_s(b)), + I32x4LeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_le_s(b)), + I8x16LeU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_le_u(b)), + I16x8LeU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_le_u(b)), + I32x4LeU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_le_u(b)), + I8x16GeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_ge_s(b)), + I16x8GeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_ge_s(b)), + I32x4GeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_ge_s(b)), + I64x2GeS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_ge_s(b)), + I8x16GeU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_ge_u(b)), + I16x8GeU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_ge_u(b)), + I32x4GeU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_ge_u(b)), + I8x16Abs => exec_op!(executor; unary Value128 => Value128, |a| a.i8x16_abs()), + I16x8Abs => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_abs()), + I32x4Abs => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_abs()), + I64x2Abs => exec_op!(executor; unary Value128 => Value128, |a| a.i64x2_abs()), + I8x16Neg => exec_op!(executor; unary Value128 => Value128, |a| a.i8x16_neg()), + I16x8Neg => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_neg()), + I32x4Neg => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_neg()), + I64x2Neg => exec_op!(executor; unary Value128 => Value128, |a| a.i64x2_neg()), + I8x16AllTrue => exec_op!(executor; unary Value128 => i32, |v| v.i8x16_all_true() as i32), + I16x8AllTrue => exec_op!(executor; unary Value128 => i32, |v| v.i16x8_all_true() as i32), + I32x4AllTrue => exec_op!(executor; unary Value128 => i32, |v| v.i32x4_all_true() as i32), + I64x2AllTrue => exec_op!(executor; unary Value128 => i32, |v| v.i64x2_all_true() as i32), + I8x16Bitmask => exec_op!(executor; unary Value128 => i32, |v| v.i8x16_bitmask() as i32), + I16x8Bitmask => exec_op!(executor; unary Value128 => i32, |v| v.i16x8_bitmask() as i32), + I32x4Bitmask => exec_op!(executor; unary Value128 => i32, |v| v.i32x4_bitmask() as i32), + I64x2Bitmask => exec_op!(executor; unary Value128 => i32, |v| v.i64x2_bitmask() as i32), + I8x16Shl => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i8x16_shl(a as u32)), + I16x8Shl => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i16x8_shl(a as u32)), + I32x4Shl => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i32x4_shl(a as u32)), + I64x2Shl => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i64x2_shl(a as u32)), + I8x16ShrS => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i8x16_shr_s(a as u32)), + I16x8ShrS => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i16x8_shr_s(a as u32)), + I32x4ShrS => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i32x4_shr_s(a as u32)), + I64x2ShrS => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i64x2_shr_s(a as u32)), + I8x16ShrU => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i8x16_shr_u(a as u32)), + I16x8ShrU => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i16x8_shr_u(a as u32)), + I32x4ShrU => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i32x4_shr_u(a as u32)), + I64x2ShrU => exec_op!(executor; binary i32, Value128 => Value128, |a, b| b.i64x2_shr_u(a as u32)), + I8x16Add => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_add(b)), + I16x8Add => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_add(b)), + I32x4Add => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_add(b)), + I64x2Add => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_add(b)), + I8x16Sub => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_sub(b)), + I16x8Sub => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_sub(b)), + I32x4Sub => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_sub(b)), + I64x2Sub => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_sub(b)), + I8x16MinS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_min_s(b)), + I16x8MinS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_min_s(b)), + I32x4MinS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_min_s(b)), + I8x16MinU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_min_u(b)), + I16x8MinU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_min_u(b)), + I32x4MinU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_min_u(b)), + I8x16MaxS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_max_s(b)), + I16x8MaxS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_max_s(b)), + I32x4MaxS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_max_s(b)), + I8x16MaxU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_max_u(b)), + I16x8MaxU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_max_u(b)), + I32x4MaxU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_max_u(b)), + I64x2Mul => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_mul(b)), + I16x8Mul => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_mul(b)), + I32x4Mul => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_mul(b)), + I8x16NarrowI16x8S => exec_op!(executor; binary Value128 => Value128, |a, b| Value128::i8x16_narrow_i16x8_s(a, b)), + I8x16NarrowI16x8U => exec_op!(executor; binary Value128 => Value128, |a, b| Value128::i8x16_narrow_i16x8_u(a, b)), + I16x8NarrowI32x4S => exec_op!(executor; binary Value128 => Value128, |a, b| Value128::i16x8_narrow_i32x4_s(a, b)), + I16x8NarrowI32x4U => exec_op!(executor; binary Value128 => Value128, |a, b| Value128::i16x8_narrow_i32x4_u(a, b)), + I8x16AddSatS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_add_sat_s(b)), + I16x8AddSatS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_add_sat_s(b)), + I8x16AddSatU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_add_sat_u(b)), + I16x8AddSatU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_add_sat_u(b)), + I8x16SubSatS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_sub_sat_s(b)), + I16x8SubSatS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_sub_sat_s(b)), + I8x16SubSatU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_sub_sat_u(b)), + I16x8SubSatU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_sub_sat_u(b)), + I8x16AvgrU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i8x16_avgr_u(b)), + I16x8AvgrU => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_avgr_u(b)), + I16x8ExtAddPairwiseI8x16S => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_extadd_pairwise_i8x16_s()), + I16x8ExtAddPairwiseI8x16U => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_extadd_pairwise_i8x16_u()), + I32x4ExtAddPairwiseI16x8S => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_extadd_pairwise_i16x8_s()), + I32x4ExtAddPairwiseI16x8U => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_extadd_pairwise_i16x8_u()), + I16x8ExtMulLowI8x16S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_extmul_low_i8x16_s(b)), + I16x8ExtMulLowI8x16U => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_extmul_low_i8x16_u(b)), + I16x8ExtMulHighI8x16S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_extmul_high_i8x16_s(b)), + I16x8ExtMulHighI8x16U => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_extmul_high_i8x16_u(b)), + I32x4ExtMulLowI16x8S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_extmul_low_i16x8_s(b)), + I32x4ExtMulLowI16x8U => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_extmul_low_i16x8_u(b)), + I32x4ExtMulHighI16x8S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_extmul_high_i16x8_s(b)), + I32x4ExtMulHighI16x8U => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_extmul_high_i16x8_u(b)), + I64x2ExtMulLowI32x4S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_extmul_low_i32x4_s(b)), + I64x2ExtMulLowI32x4U => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_extmul_low_i32x4_u(b)), + I64x2ExtMulHighI32x4S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_extmul_high_i32x4_s(b)), + I64x2ExtMulHighI32x4U => exec_op!(executor; binary Value128 => Value128, |a, b| a.i64x2_extmul_high_i32x4_u(b)), + I16x8ExtendLowI8x16S => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_extend_low_i8x16_s()), + I16x8ExtendLowI8x16U => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_extend_low_i8x16_u()), + I16x8ExtendHighI8x16S => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_extend_high_i8x16_s()), + I16x8ExtendHighI8x16U => exec_op!(executor; unary Value128 => Value128, |a| a.i16x8_extend_high_i8x16_u()), + I32x4ExtendLowI16x8S => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_extend_low_i16x8_s()), + I32x4ExtendLowI16x8U => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_extend_low_i16x8_u()), + I32x4ExtendHighI16x8S => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_extend_high_i16x8_s()), + I32x4ExtendHighI16x8U => exec_op!(executor; unary Value128 => Value128, |a| a.i32x4_extend_high_i16x8_u()), + I64x2ExtendLowI32x4S => exec_op!(executor; unary Value128 => Value128, |a| a.i64x2_extend_low_i32x4_s()), + I64x2ExtendLowI32x4U => exec_op!(executor; unary Value128 => Value128, |a| a.i64x2_extend_low_i32x4_u()), + I64x2ExtendHighI32x4S => exec_op!(executor; unary Value128 => Value128, |a| a.i64x2_extend_high_i32x4_s()), + I64x2ExtendHighI32x4U => exec_op!(executor; unary Value128 => Value128, |a| a.i64x2_extend_high_i32x4_u()), + I8x16Popcnt => exec_op!(executor; unary Value128 => Value128, |v| v.i8x16_popcnt()), + I8x16Shuffle(idx) => executor.exec_simd_shuffle(Value128(idx.resolve(&executor.func.data).value()))?, + I16x8Q15MulrSatS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_q15mulr_sat_s(b)), + I32x4DotI16x8S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i32x4_dot_i16x8_s(b)), + I8x16RelaxedLaneselect => exec_op!(executor; ternary Value128 => Value128, |a, b, c| Value128::i8x16_relaxed_laneselect(a, b, c)), + I16x8RelaxedLaneselect => exec_op!(executor; ternary Value128 => Value128, |a, b, c| Value128::i16x8_relaxed_laneselect(a, b, c)), + I32x4RelaxedLaneselect => exec_op!(executor; ternary Value128 => Value128, |a, b, c| Value128::i32x4_relaxed_laneselect(a, b, c)), + I64x2RelaxedLaneselect => exec_op!(executor; ternary Value128 => Value128, |a, b, c| Value128::i64x2_relaxed_laneselect(a, b, c)), + I16x8RelaxedQ15mulrS => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_relaxed_q15mulr_s(b)), + I16x8RelaxedDotI8x16I7x16S => exec_op!(executor; binary Value128 => Value128, |a, b| a.i16x8_relaxed_dot_i8x16_i7x16_s(b)), + I32x4RelaxedDotI8x16I7x16AddS => exec_op!(executor; ternary Value128 => Value128, |a, b, c| a.i32x4_relaxed_dot_i8x16_i7x16_add_s(b, c)), + F32x4Ceil => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_ceil()), + F64x2Ceil => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_ceil()), + F32x4Floor => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_floor()), + F64x2Floor => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_floor()), + F32x4Trunc => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_trunc()), + F64x2Trunc => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_trunc()), + F32x4Nearest => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_nearest()), + F64x2Nearest => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_nearest()), + F32x4Abs => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_abs()), + F64x2Abs => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_abs()), + F32x4Neg => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_neg()), + F64x2Neg => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_neg()), + F32x4Sqrt => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_sqrt()), + F64x2Sqrt => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_sqrt()), + F32x4Add => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_add(b)), + F64x2Add => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_add(b)), + F32x4Sub => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_sub(b)), + F64x2Sub => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_sub(b)), + F32x4Mul => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_mul(b)), + F64x2Mul => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_mul(b)), + F32x4Div => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_div(b)), + F64x2Div => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_div(b)), + F32x4Min => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_min(b)), + F64x2Min => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_min(b)), + F32x4Max => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_max(b)), + F64x2Max => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_max(b)), + F32x4PMin => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_pmin(b)), + F32x4PMax => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_pmax(b)), + F64x2PMin => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_pmin(b)), + F64x2PMax => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_pmax(b)), + F32x4RelaxedMadd => exec_op!(executor; ternary Value128 => Value128, |a, b, c| a.f32x4_relaxed_madd(b, c)), + F32x4RelaxedNmadd => exec_op!(executor; ternary Value128 => Value128, |a, b, c| a.f32x4_relaxed_nmadd(b, c)), + F64x2RelaxedMadd => exec_op!(executor; ternary Value128 => Value128, |a, b, c| a.f64x2_relaxed_madd(b, c)), + F64x2RelaxedNmadd => exec_op!(executor; ternary Value128 => Value128, |a, b, c| a.f64x2_relaxed_nmadd(b, c)), + F32x4RelaxedMin => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_relaxed_min(b)), + F32x4RelaxedMax => exec_op!(executor; binary Value128 => Value128, |a, b| a.f32x4_relaxed_max(b)), + F64x2RelaxedMin => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_relaxed_min(b)), + F64x2RelaxedMax => exec_op!(executor; binary Value128 => Value128, |a, b| a.f64x2_relaxed_max(b)), + I32x4TruncSatF32x4S => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_trunc_sat_f32x4_s()), + I32x4TruncSatF32x4U => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_trunc_sat_f32x4_u()), + F32x4ConvertI32x4S => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_convert_i32x4_s()), + F32x4ConvertI32x4U => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_convert_i32x4_u()), + F64x2ConvertLowI32x4S => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_convert_low_i32x4_s()), + F64x2ConvertLowI32x4U => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_convert_low_i32x4_u()), + F32x4DemoteF64x2Zero => exec_op!(executor; unary Value128 => Value128, |v| v.f32x4_demote_f64x2_zero()), + F64x2PromoteLowF32x4 => exec_op!(executor; unary Value128 => Value128, |v| v.f64x2_promote_low_f32x4()), + I32x4TruncSatF64x2SZero => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_trunc_sat_f64x2_s_zero()), + I32x4TruncSatF64x2UZero => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_trunc_sat_f64x2_u_zero()), + I32x4RelaxedTruncF32x4S => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f32x4_s()), + I32x4RelaxedTruncF32x4U => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f32x4_u()), + I32x4RelaxedTruncF64x2SZero => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f64x2_s_zero()), + I32x4RelaxedTruncF64x2UZero => exec_op!(executor; unary Value128 => Value128, |v| v.i32x4_relaxed_trunc_f64x2_u_zero()), + } + }; +} diff --git a/crates/tinywasm/src/interpreter/executor/mod.rs b/crates/tinywasm/src/interpreter/executor/mod.rs new file mode 100644 index 0000000..48a99a6 --- /dev/null +++ b/crates/tinywasm/src/interpreter/executor/mod.rs @@ -0,0 +1,1561 @@ +use core::convert::identity; + +#[cfg(not(feature = "std"))] +#[allow(unused_imports)] +use super::no_std_floats::NoStdFloatExt; + +use alloc::boxed::Box; +use alloc::vec::Vec; + +use interpreter::stack::{CallFrame, ValueStack}; +use tinywasm_types::*; + +use super::ExecState; +use super::num_helpers::*; +use super::values::*; +use crate::engine::FuelPolicy; +use crate::func::HostFunction; +use crate::interpreter::Value128; +use crate::*; + +#[macro_use] +mod instructions; + +#[cfg(not(feature = "nightly-tail-calls"))] +mod dispatch; +#[cfg(feature = "nightly-tail-calls")] +mod dispatch_become; + +const CHECKPOINT_INTERVAL: u32 = 128; +const FUEL_COST_CALL_TOTAL: u32 = 5; + +struct ExecError(Box); + +type ExecResult = core::result::Result; + +impl From for ExecError { + #[cold] + fn from(trap: Trap) -> Self { + Self(Box::new(Error::Trap(trap))) + } +} + +impl From for ExecError { + #[cold] + fn from(error: Error) -> Self { + Self(Box::new(error)) + } +} + +impl From for Error { + #[cold] + fn from(error: ExecError) -> Self { + *error.0 + } +} + +#[derive(Clone, Copy)] +struct ExecFlow(usize); + +impl ExecFlow { + const COMPLETE: Self = Self(usize::MAX); + + #[inline(always)] + fn next(instr_ptr: usize) -> Self { + debug_assert_ne!(instr_ptr, Self::COMPLETE.0); + Self(instr_ptr) + } + + #[inline(always)] + fn next_instr_ptr(self) -> Option { + (self.0 != Self::COMPLETE.0).then_some(self.0) + } +} + +pub(crate) struct Executor<'store> { + cf: CallFrame, + func: Shared, + module: ModuleInstance, + store: &'store mut Store, + call_stack_base: u32, + mem0: MemAddr, + fuel_metered: bool, + #[cfg(feature = "nightly-tail-calls")] + completed: bool, +} + +impl<'store> Executor<'store> { + pub(crate) fn new(store: &'store mut Store, cf: CallFrame, call_stack_base: u32) -> Self { + let wasm_func = store.state.funcs.wasm(cf.func_addr); + let module = store.get_module_instance(wasm_func.owner).expect("invalid module instance").clone(); + let mem0 = module.mem0_addr(); + Self { + module, + cf, + func: wasm_func.func.clone(), + store, + call_stack_base, + mem0, + fuel_metered: false, + #[cfg(feature = "nightly-tail-calls")] + completed: false, + } + } + + /// Resolves a module-local memory index to its store address, caching the common memory-0 case. + #[inline(always)] + fn mem_addr(&self, idx: MemAddr) -> MemAddr { + if idx == 0 { self.mem0 } else { self.module.resolve_mem_addr(idx) } + } + + /// Switches the executor to another module, keeping the cached memory-0 address in sync. + #[inline] + fn set_module(&mut self, owner: ModuleInstanceId) { + self.module = self.store.get_module_instance(owner).expect("invalid module instance").clone(); + self.mem0 = self.module.mem0_addr(); + } + + #[inline(always)] + fn charge_call_fuel(&mut self, total_fuel_cost: u32) { + if self.fuel_metered { + let extra = match self.store.engine.config().fuel_policy { + FuelPolicy::PerInstruction => 0, + FuelPolicy::Weighted => total_fuel_cost.saturating_sub(1), + }; + + self.store.execution_fuel = self.store.execution_fuel.saturating_sub(extra); + } + } + + #[inline(always)] + fn exec_jump_if_ref(&mut self) -> bool { + let is_null = ValueRef::stack_peek(&self.store.value_stack).is_null(); + if is_null { + ValueRef::stack_pop(&mut self.store.value_stack); + } + is_null == ON_NULL + } + + #[inline(always)] + fn exec_br_on_cast(&self, index: Operand64Idx<(u32, u32)>) -> Option { + let operand = index.resolve(&self.func.data); + let ty = RefType::from_bits(operand.b()).expect("invalid ref type"); + (self.exec_ref_matches(ty) == ON_MATCH).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_if_local( + &self, + local: LocalAddr, + ) -> bool { + (T::local_get(&self.store.value_stack, &self.cf, local) == T::default()) == ON_ZERO + } + + #[inline(always)] + fn exec_jump_cmp_stack_const32(&mut self, packed: PackedOp64) -> Option { + let operand = packed.index.resolve(&self.func.data); + packed.op.cmp(i32::stack_pop(&mut self.store.value_stack), operand.b()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_stack_const64(&mut self, packed: PackedOp128) -> Option { + let operand = packed.index.resolve(&self.func.data); + packed.op.cmp(i64::stack_pop(&mut self.store.value_stack), operand.b()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_stack_local32(&mut self, packed: PackedOp64) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i32::stack_pop(&mut self.store.value_stack); + let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.b()); + packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_stack_local64(&mut self, packed: PackedOp64) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i64::stack_pop(&mut self.store.value_stack); + let rhs = i64::local_get(&self.store.value_stack, &self.cf, operand.b()); + packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_binop_local_const_jump(&mut self, packed: PackedOp128) -> Option { + let operand = packed.index.resolve(&self.func.data); + let value = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { + packed.op.exec(value as u32, operand.value() as u32) as i32 + }); + ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_binop_local_const_jump_cmp_local( + &mut self, + packed: PackedOp128<(BinOp, CmpOp), LocalUpdateCmpOperand>, + ) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { + packed.op.0.exec(value as u32, operand.value() as u32) as i32 + }); + let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.right()); + packed.op.1.cmp(lhs, rhs).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_binop_stack_const_tee_local_jump( + &mut self, + packed: PackedOp128, + ) -> Result, Trap> { + let operand = packed.index.resolve(&self.func.data); + let value = i32::stack_update(&mut self.store.value_stack, |lhs| { + packed.op.exec(lhs as u32, operand.value() as u32) as i32 + }); + i32::local_set(&mut self.store.value_stack, &self.cf, operand.local(), value); + Ok(((value == 0) == operand.on_zero()).then_some(operand.target() as usize)) + } + + #[inline(always)] + fn exec_binop_global_const_jump(&mut self, packed: PackedOp128) -> Option { + let operand = packed.index.resolve(&self.func.data); + let global = self.module.resolve_global_addr(operand.global()); + let value = i32::global_update(&mut self.store.state.globals, global, |value| { + packed.op.exec(value as u32, operand.value() as u32) as i32 + }); + ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_inc_local_jump(&mut self, index: Operand128Idx) -> Option { + let operand = index.resolve(&self.func.data); + let value = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { + value.wrapping_add(operand.value()) + }); + ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_inc_stack_tee_local_jump( + &mut self, + index: Operand128Idx, + ) -> Result, Trap> { + let operand = index.resolve(&self.func.data); + let value = i32::stack_update(&mut self.store.value_stack, |value| value.wrapping_add(operand.value())); + i32::local_set(&mut self.store.value_stack, &self.cf, operand.local(), value); + Ok(((value == 0) == operand.on_zero()).then_some(operand.target() as usize)) + } + + #[inline(always)] + fn exec_inc_global_jump(&mut self, index: Operand128Idx) -> Option { + let operand = index.resolve(&self.func.data); + let global = self.module.resolve_global_addr(operand.global()); + let value = + i32::global_update(&mut self.store.state.globals, global, |value| value.wrapping_add(operand.value())); + ((value == 0) == operand.on_zero()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_inc_local_jump_cmp_local(&mut self, packed: PackedOp128) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i32::local_update(&mut self.store.value_stack, &self.cf, operand.local(), |value| { + value.wrapping_add(operand.value()) + }); + let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.right()); + packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_local_const32(&self, packed: PackedOp128) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i32::local_get(&self.store.value_stack, &self.cf, operand.c()); + packed.op.cmp(lhs, operand.b()).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_local_const64(&self, packed: PackedOp128) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i64::local_get(&self.store.value_stack, &self.cf, operand.c()); + packed.op.cmp(lhs, i64::from(operand.b())).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_local_local32(&self, packed: PackedOp64) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i32::local_get(&self.store.value_stack, &self.cf, operand.b()); + let rhs = i32::local_get(&self.store.value_stack, &self.cf, operand.c()); + packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) + } + + #[inline(always)] + fn exec_jump_cmp_local_local64(&self, packed: PackedOp64) -> Option { + let operand = packed.index.resolve(&self.func.data); + let lhs = i64::local_get(&self.store.value_stack, &self.cf, operand.b()); + let rhs = i64::local_get(&self.store.value_stack, &self.cf, operand.c()); + packed.op.cmp(lhs, rhs).then_some(operand.target() as usize) + } + + fn exec_i64_add128(&mut self) -> Result<(), Trap> { + let b_hi = i64::stack_pop(&mut self.store.value_stack); + let b_lo = i64::stack_pop(&mut self.store.value_stack); + let a_hi = i64::stack_pop(&mut self.store.value_stack); + let a_lo = i64::stack_pop(&mut self.store.value_stack); + let lo = a_lo.wrapping_add(b_lo); + let carry = u64::from((lo as u64) < (a_lo as u64)); + let hi = a_hi.wrapping_add(b_hi).wrapping_add(carry as i64); + i64::stack_push(&mut self.store.value_stack, lo)?; + i64::stack_push(&mut self.store.value_stack, hi) + } + + fn exec_i64_sub128(&mut self) -> Result<(), Trap> { + let b_hi = i64::stack_pop(&mut self.store.value_stack); + let b_lo = i64::stack_pop(&mut self.store.value_stack); + let a_hi = i64::stack_pop(&mut self.store.value_stack); + let a_lo = i64::stack_pop(&mut self.store.value_stack); + let lo = a_lo.wrapping_sub(b_lo); + let borrow = u64::from((a_lo as u64) < (b_lo as u64)); + let hi = a_hi.wrapping_sub(b_hi).wrapping_sub(borrow as i64); + i64::stack_push(&mut self.store.value_stack, lo)?; + i64::stack_push(&mut self.store.value_stack, hi) + } + + fn exec_i64_mul_wide_s(&mut self) -> Result<(), Trap> { + let rhs = i64::stack_pop(&mut self.store.value_stack); + let lhs = i64::stack_pop(&mut self.store.value_stack); + let product = (lhs as i128).wrapping_mul(rhs as i128); + i64::stack_push(&mut self.store.value_stack, product as i64)?; + i64::stack_push(&mut self.store.value_stack, (product >> 64) as i64) + } + + fn exec_i64_mul_wide_u(&mut self) -> Result<(), Trap> { + let rhs = i64::stack_pop(&mut self.store.value_stack); + let lhs = i64::stack_pop(&mut self.store.value_stack); + let product = (lhs as u64 as u128).wrapping_mul(rhs as u64 as u128); + i64::stack_push(&mut self.store.value_stack, product as u64 as i64)?; + i64::stack_push(&mut self.store.value_stack, (product >> 64) as u64 as i64) + } + + #[inline(always)] + fn exec_simd_extract_lane( + &mut self, + lane: u8, + operation: impl FnOnce(Value128, u8) -> TO, + ) -> Result<(), Trap> { + let vector = Value128::stack_pop(&mut self.store.value_stack); + TO::stack_push(&mut self.store.value_stack, operation(vector, lane)) + } + + #[inline(always)] + fn exec_simd_replace_lane( + &mut self, + lane: u8, + operation: impl FnOnce(VALUE, Value128, u8) -> Value128, + ) -> Result<(), Trap> { + let vector = Value128::stack_pop(&mut self.store.value_stack); + let value = VALUE::stack_pop(&mut self.store.value_stack); + Value128::stack_push(&mut self.store.value_stack, operation(value, vector, lane)) + } + + fn exec_simd_shuffle(&mut self, lanes: Value128) -> Result<(), Trap> { + let rhs = Value128::stack_pop(&mut self.store.value_stack); + let lhs = Value128::stack_pop(&mut self.store.value_stack); + Value128::stack_push(&mut self.store.value_stack, Value128::i8x16_shuffle(lhs, rhs, lanes)) + } + + #[inline(always)] + fn exec_local_set_pop(&mut self, local: LocalAddr) { + let value = T::stack_pop(&mut self.store.value_stack); + T::local_set(&mut self.store.value_stack, &self.cf, local, value); + } + + #[inline(always)] + fn exec_local_tee(&mut self, local: LocalAddr) { + let value = T::stack_peek(&self.store.value_stack); + T::local_set(&mut self.store.value_stack, &self.cf, local, value); + } + + #[inline(always)] + fn exec_global_get(&mut self, global: GlobalAddr) -> Result<(), Trap> { + let addr = self.module.resolve_global_addr(global); + let value = T::global_get(&self.store.state.globals, addr); + T::stack_push(&mut self.store.value_stack, value) + } + + #[inline(always)] + fn exec_global_set(&mut self, global: GlobalAddr) { + let addr = self.module.resolve_global_addr(global); + let value = T::stack_pop(&mut self.store.value_stack); + T::global_set(&mut self.store.state.globals, addr, value); + } + + #[inline(always)] + fn exec_global_tee(&mut self, global: GlobalAddr) { + let addr = self.module.resolve_global_addr(global); + let value = T::stack_peek(&self.store.value_stack); + T::global_set(&mut self.store.state.globals, addr, value); + } + + #[inline(always)] + fn exec_binop_result( + &mut self, + dst: Option, + val: T, + ) -> Result<(), Trap> { + if let Some(dst) = dst { + T::local_set(&mut self.store.value_stack, &self.cf, dst, val); + } + if PUSH { T::stack_push(&mut self.store.value_stack, val) } else { Ok(()) } + } + + #[inline(always)] + fn exec_binop_local_local( + &mut self, + lhs: LocalAddr, + rhs: LocalAddr, + destination: Option, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let lhs = T::local_get(&self.store.value_stack, &self.cf, lhs); + let rhs = T::local_get(&self.store.value_stack, &self.cf, rhs); + self.exec_binop_result::(destination, op.exec(lhs, rhs)) + } + + #[inline(always)] + fn exec_binop_local_local_indexed( + &mut self, + index: Operand64Idx<(u16, u16, u16)>, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let operands = index.resolve(&self.func.data); + self.exec_binop_local_local::(operands.a(), operands.b(), Some(operands.c()), op) + } + + #[inline(always)] + fn exec_binop_local_const( + &mut self, + lhs: LocalAddr, + rhs: T, + destination: Option, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let lhs = T::local_get(&self.store.value_stack, &self.cf, lhs); + self.exec_binop_result::(destination, op.exec(lhs, rhs)) + } + + #[inline(always)] + fn exec_binop_global_const( + &mut self, + lhs: GlobalAddr, + rhs: T, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let lhs = T::global_get(&self.store.state.globals, self.module.resolve_global_addr(lhs)); + T::stack_push(&mut self.store.value_stack, op.exec(lhs, rhs)) + } + + #[inline(always)] + fn exec_cmp_local_local(&mut self, lhs: LocalAddr, rhs: LocalAddr, op: CmpOp) -> Result<(), Trap> + where + T: InternalValue, + CmpOp: CmpOpExt, + { + let lhs = T::local_get(&self.store.value_stack, &self.cf, lhs); + let rhs = T::local_get(&self.store.value_stack, &self.cf, rhs); + i32::stack_push(&mut self.store.value_stack, i32::from(op.cmp(lhs, rhs))) + } + + #[inline(always)] + fn exec_binop_stack_global( + &mut self, + global: GlobalAddr, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let addr = self.module.resolve_global_addr(global); + let rhs = T::global_get(&self.store.state.globals, addr); + T::stack_update(&mut self.store.value_stack, |lhs| op.exec(lhs, rhs)); + Ok(()) + } + + #[inline(always)] + fn exec_binop_stack_local( + &mut self, + local: LocalAddr, + destination: Option, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let rhs = T::local_get(&self.store.value_stack, &self.cf, local); + let lhs = T::stack_pop(&mut self.store.value_stack); + self.exec_binop_result::(destination, op.exec(lhs, rhs)) + } + + #[inline(always)] + fn exec_binop_const_tee( + &mut self, + rhs: T, + destination: LocalAddr, + op: impl BinOpExt, + ) -> Result<(), Trap> { + let value = T::stack_update(&mut self.store.value_stack, |lhs| op.exec(lhs, rhs)); + T::local_set(&mut self.store.value_stack, &self.cf, destination, value); + Ok(()) + } + + #[inline(always)] + fn exec_mul_acc_local( + &mut self, + accumulator: LocalAddr, + multiply: fn(T, T) -> T, + add: fn(T, T) -> T, + ) { + let rhs = T::stack_pop(&mut self.store.value_stack); + let lhs = T::stack_pop(&mut self.store.value_stack); + let product = multiply(lhs, rhs); + T::local_update(&mut self.store.value_stack, &self.cf, accumulator, |value| add(product, value)); + } + + fn exec_branch_table(&mut self, index: Operand128Idx) -> usize { + let v = index.resolve(&self.func.data); + let idx = ::stack_pop(&mut self.store.value_stack); + let target_ip = if idx >= 0 && (idx as u32) < v.size() { + self.func.data.branch_table_targets.get((v.start() + idx as u32) as usize).copied().unwrap_or(v.target()) + } else { + v.target() + }; + + target_ip as usize + } + + fn create_exception(&mut self, tag_index: TagAddr) -> Result { + let tag_addr = self.module.resolve_tag_addr(tag_index); + let type_addr = self.store.state.get_tag(tag_addr).type_addr; + let payload_len = self.store.state.get_canonical_func_type(type_addr).params().len(); + self.store.state.gc.check_allocation(payload_len, true)?; + let mut payload = Vec::new(); + cold_err!(payload.try_reserve_exact(payload_len)).map_err(|_| Trap::OutOfMemory)?; + let value_stack = &mut self.store.value_stack; + for index in (0..payload_len).rev() { + let ty = self.store.state.get_canonical_func_type(type_addr).params()[index]; + payload.push(match ty { + WasmType::I32 | WasmType::F32 => RuntimeValue::Value32(Value32::stack_pop(value_stack)), + WasmType::I64 | WasmType::F64 => RuntimeValue::Value64(Value64::stack_pop(value_stack)), + WasmType::V128 => RuntimeValue::Value128(Value128::stack_pop(value_stack)), + WasmType::Ref(_) => RuntimeValue::ValueRef(ValueRef::stack_pop(value_stack)), + }); + } + payload.reverse(); + let roots = (&self.store.value_stack.stack_32).into_iter().copied().map(ValueRef::from_raw); + self.store.state.alloc_exception(tag_addr, payload, roots) + } + + fn exec_throw(&mut self, tag_index: TagAddr, instr_ptr: usize) -> ExecResult { + let exception = self.create_exception(tag_index)?; + self.throw_exception(exception, instr_ptr) + } + + fn exec_throw_ref(&mut self, instr_ptr: usize) -> ExecResult { + let exception = ValueRef::stack_pop(&mut self.store.value_stack); + if exception.is_null() { + return Err(Trap::NullReference.into()); + } + self.throw_exception(exception, instr_ptr) + } + + fn throw_exception(&mut self, exception: ValueRef, protected_ip: usize) -> ExecResult { + match self.dispatch_exception(exception, protected_ip)? { + Some(landing_pad) => Ok(ExecFlow::next(landing_pad)), + None => match self.store.root_exception(exception) { + Ok(exception) => Err(Error::Exception(exception).into()), + Err(error) => Err(error.into()), + }, + } + } + + fn matching_catch(&self, protected_ip: usize, tag_addr: TagAddr) -> Option { + let handlers = &self.func.data.exception_handlers; + let end = handlers.partition_point(|handler| handler.start_ip as usize <= protected_ip); + handlers[..end] + .iter() + .rev() + .filter(|handler| protected_ip < handler.end_ip as usize) + .flat_map(|handler| handler.catches.iter().copied()) + .find(|catch| match catch { + ExceptionCatch::Tag { tag, .. } => self.module.resolve_tag_addr(*tag) == tag_addr, + ExceptionCatch::All { .. } => true, + }) + } + + #[inline(always)] + fn switch_to_frame(&mut self, frame: CallFrame) { + let previous = core::mem::replace(&mut self.cf, frame); + if previous.func_addr == self.cf.func_addr { + return; + } + + let wasm_func = self.store.state.funcs.wasm(self.cf.func_addr); + if !Shared::ptr_eq(&self.func, &wasm_func.func) { + self.func = wasm_func.func.clone(); + } + if wasm_func.owner != self.module.id() { + self.set_module(wasm_func.owner); + } + } + + fn dispatch_exception(&mut self, exception: ValueRef, mut protected_ip: usize) -> Result, Trap> { + let object = self.store.state.gc.get(exception).ok_or(Trap::InvalidReference)?; + let crate::store::GcObjectKind::Exception(tag_addr) = object.kind else { + return Err(Trap::InvalidReference); + }; + loop { + if let Some(catch) = self.matching_catch(protected_ip, tag_addr) { + let (landing_pad, base, with_ref, include_payload) = match catch { + ExceptionCatch::Tag { landing_pad, base, with_ref, .. } => (landing_pad, base, with_ref, true), + ExceptionCatch::All { landing_pad, base, with_ref } => (landing_pad, base, with_ref, false), + }; + let stack_base = self.cf.stack_base(); + let target = interpreter::stack::StackBase { + s32: stack_base.s32 + base.c32 as u32, + s64: stack_base.s64 + base.c64 as u32, + s128: stack_base.s128 + base.c128 as u32, + }; + self.store.value_stack.truncate_to_base(target); + if include_payload { + let Store { state, value_stack, .. } = self.store; + let object = state.gc.get(exception).ok_or(Trap::InvalidReference)?; + for value in object.values.iter().copied() { + value_stack.push_dyn(value)?; + } + } + if with_ref { + ValueRef::stack_push(&mut self.store.value_stack, exception)?; + } + return Ok(Some(landing_pad as usize)); + } + + self.store.value_stack.truncate_to_base(self.cf.locals_base); + let Some(caller) = self.store.call_stack.pop_frame(self.call_stack_base) else { + return Ok(None); + }; + self.switch_to_frame(caller); + protected_ip = self.cf.instr_ptr.checked_sub(1).expect("invalid caller IP"); + } + } + + fn exec_call_host( + &mut self, + host_func: HostFunction, + type_addr: TypeAddr, + return_instr_ptr: usize, + ) -> ExecResult { + if let Some(host_func) = host_func.typed_callback() { + cold_err!(host_func.call_stack(self.store, self.module.id(), type_addr)) + .map_err(|error| Trap::HostFunction(Box::new(error)))?; + if TAIL { + return Ok(self.exec_return()); + } + return Ok(ExecFlow::next(return_instr_ptr)); + } + + let (param_count, result_count, base) = { + let ty = self.store.state.get_canonical_func_type(type_addr); + (ty.params().len(), ty.results().len(), self.store.value_stack.base_before(ty.params().iter().collect())) + }; + let module_id = self.module.id(); + self.store + .with_scratch_values(param_count + result_count, |store, values| { + let host_values = store.stack_value_iter(type_addr, crate::store::FuncValueTypes::Params, base)?; + for (slot, value) in values[..param_count].iter_mut().zip(host_values) { + *slot = value; + } + store.value_stack.truncate_to_base(base); + let (params, results) = values.split_at_mut(param_count); + host_func + .call_values(store, module_id, type_addr, params, results) + .map_err(|error| Error::Trap(Trap::HostFunction(Box::new(error))))?; + store.push_wasm_values(results) + }) + .map_err(|error| match error { + Error::Trap(trap) => trap, + other => Trap::HostFunction(Box::new(other)), + })?; + if TAIL { Ok(self.exec_return()) } else { Ok(ExecFlow::next(return_instr_ptr)) } + } + + fn exec_call_direct(&mut self, v: u32, return_instr_ptr: usize) -> ExecResult { + self.charge_call_fuel(FUEL_COST_CALL_TOTAL); + let addr = self.module.resolve_func_addr(v); + if self.store.state.funcs.is_host(addr) { + let host_func = self.store.state.funcs.host(addr); + let type_addr = host_func.type_addr; + let host_func = host_func.func.clone(); + self.exec_call_host::(host_func, type_addr, return_instr_ptr) + } else { + self.exec_call_wasm::(addr, return_instr_ptr) + } + } + + fn exec_return_call_direct(&mut self, v: u32) -> ExecResult { + self.charge_call_fuel(FUEL_COST_CALL_TOTAL); + let addr = self.module.resolve_func_addr(v); + if self.store.state.funcs.is_host(addr) { + let host_func = self.store.state.funcs.host(addr); + let type_addr = host_func.type_addr; + let host_func = host_func.func.clone(); + self.exec_call_host::(host_func, type_addr, 0) + } else { + self.exec_call_wasm::(addr, 0) + } + } + + fn exec_call_self(&mut self, return_instr_ptr: usize) -> ExecResult<()> { + self.charge_call_fuel(FUEL_COST_CALL_TOTAL); + let Ok(locals_base) = self.store.value_stack.enter_locals(&self.func.params, &self.func.locals) else { + return cold!(Err(Trap::CallStackOverflow.into())); + }; + let new = CallFrame::new(self.cf.func_addr, locals_base, self.func.locals); + self.store.call_stack.push(core::mem::replace(&mut self.cf, new), return_instr_ptr)?; + Ok(()) + } + + fn exec_return_call_self(&mut self) -> ExecResult<()> { + self.charge_call_fuel(FUEL_COST_CALL_TOTAL); + + self.store.value_stack.truncate_keep_counts(self.cf.locals_base, self.func.params); + let Ok(locals_base) = self.store.value_stack.enter_locals(&self.func.params, &self.func.locals) else { + return cold!(Err(Trap::CallStackOverflow.into())); + }; + self.cf = CallFrame::new(self.cf.func_addr, locals_base, self.func.locals); + Ok(()) + } + + fn exec_call_indirect( + &mut self, + index: Operand64Idx<(u32, u32)>, + return_instr_ptr: usize, + ) -> ExecResult { + let operand = index.resolve(&self.func.data); + let type_addr = operand.a(); + let table_addr = operand.b(); + self.charge_call_fuel(FUEL_COST_CALL_TOTAL); + // verify that the table is of the right type, this should be validated by the parser already + let table_addr = self.module.resolve_table_addr(table_addr); + let table_idx = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; + let table = self.store.state.get_table(table_addr); + + let Ok(table) = table.get(table_idx) else { + return cold!(Err(Trap::UndefinedElement { index: table_idx }.into())); + }; + + let Some(func_ref) = table.addr() else { + return cold!(Err(Trap::UninitializedElement { index: table_idx }.into())); + }; + + self.exec_typed_call::(func_ref, self.module.resolve_type_addr(type_addr), return_instr_ptr) + } + + fn exec_typed_call( + &mut self, + func_addr: FuncAddr, + expected_type_addr: TypeAddr, + return_instr_ptr: usize, + ) -> ExecResult { + let type_addr = self.store.state.funcs.type_addr(func_addr); + if !self.store.state.type_addr_is_subtype(type_addr, expected_type_addr) { + return cold!(Err(Trap::IndirectCallTypeMismatch { + actual: Box::new(self.store.state.get_canonical_func_type(type_addr).clone()), + expected: Box::new(self.store.state.get_canonical_func_type(expected_type_addr).clone()), + } + .into())); + } + if self.store.state.funcs.is_host(func_addr) { + let host_func = self.store.state.funcs.host(func_addr); + let host_func = host_func.func.clone(); + return self.exec_call_host::(host_func, type_addr, return_instr_ptr); + } + + self.exec_call_wasm::(func_addr, return_instr_ptr) + } + + #[inline(always)] + fn exec_call_wasm( + &mut self, + func_addr: FuncAddr, + return_instr_ptr: usize, + ) -> ExecResult { + let wasm_func = self.store.state.funcs.wasm(func_addr); + let (params, locals, owner, next_func) = { + let next_func = (!Shared::ptr_eq(&self.func, &wasm_func.func)).then(|| wasm_func.func.clone()); + (wasm_func.func.params, wasm_func.func.locals, wasm_func.owner, next_func) + }; + if TAIL { + self.store.value_stack.truncate_keep_counts(self.cf.locals_base, params); + } + let locals_base = self.store.value_stack.enter_locals(¶ms, &locals)?; + if TAIL { + self.cf = CallFrame::new(func_addr, locals_base, locals); + } else { + self.store.call_stack.push(self.cf, return_instr_ptr)?; + self.cf = CallFrame::new(func_addr, locals_base, locals); + } + if let Some(next_func) = next_func { + self.func = next_func; + } + if owner != self.module.id() { + self.set_module(owner); + } + Ok(ExecFlow::next(0)) + } + + fn exec_call_ref(&mut self, type_addr: u32, return_instr_ptr: usize) -> ExecResult { + self.charge_call_fuel(FUEL_COST_CALL_TOTAL); + let func_ref = ValueRef::stack_pop(&mut self.store.value_stack); + let Some(func_addr) = func_ref.addr() else { + return cold!(Err(Trap::NullFunctionReference.into())); + }; + + self.exec_typed_call::(func_addr, self.module.resolve_type_addr(type_addr), return_instr_ptr) + } + + fn exec_return(&mut self) -> ExecFlow { + self.store.value_stack.truncate_keep_counts(self.cf.locals_base, self.func.results); + self.finish_return() + } + + #[inline(always)] + fn finish_return(&mut self) -> ExecFlow { + let Some(caller) = self.store.call_stack.pop_frame(self.call_stack_base) else { + return ExecFlow::COMPLETE; + }; + let instr_ptr = caller.instr_ptr; + if caller.func_addr == self.cf.func_addr { + self.cf = caller; + } else { + self.switch_to_frame(caller); + } + ExecFlow::next(instr_ptr) + } + + fn exec_return_void(&mut self) -> ExecFlow { + self.store.value_stack.truncate_to_base(self.cf.locals_base); + self.finish_return() + } + + fn exec_return_32(&mut self) -> ExecFlow { + self.store.value_stack.stack_32.truncate_to_one_tail(self.cf.locals_base.s32 as usize); + self.store.value_stack.stack_64.truncate_to(self.cf.locals_base.s64 as usize); + self.store.value_stack.stack_128.truncate_to(self.cf.locals_base.s128 as usize); + self.finish_return() + } + + fn exec_return_64(&mut self) -> ExecFlow { + self.store.value_stack.stack_32.truncate_to(self.cf.locals_base.s32 as usize); + self.store.value_stack.stack_64.truncate_to_one_tail(self.cf.locals_base.s64 as usize); + self.store.value_stack.stack_128.truncate_to(self.cf.locals_base.s128 as usize); + self.finish_return() + } + + fn exec_return_128(&mut self) -> ExecFlow { + self.store.value_stack.stack_32.truncate_to(self.cf.locals_base.s32 as usize); + self.store.value_stack.stack_64.truncate_to(self.cf.locals_base.s64 as usize); + self.store.value_stack.stack_128.truncate_to_one_tail(self.cf.locals_base.s128 as usize); + self.finish_return() + } + + fn exec_store_local_local, const N: usize>( + &mut self, + index: Operand64Idx, + addr_local: u8, + value_local: u8, + ) -> Result<(), Trap> { + let memarg = index.resolve(&self.func.data); + let value = T::local_get(&self.store.value_stack, &self.cf, u16::from(value_local)); + let mem_addr = self.mem_addr(MemAddr::from(memarg.memory())); + let mem = self.store.state.get_mem_mut(mem_addr); + let addr = if mem.is_64bit() { + let base = u64::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); + let base = cold_err!(usize::try_from(base).map_err(|_| Trap::MemoryOutOfBounds { + offset: usize::MAX, + len: N, + max: mem.inner.len(), + }))?; + cold_err!(mem.effective_addr::(base, u64::from(memarg.offset())))? + } else { + let base = u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); + cold_err!(mem.effective_addr::(base as usize, u64::from(memarg.offset())))? + }; + value.store_at(&mut mem.inner, addr) + } + + fn exec_inc_memory_local, const N: usize>( + &mut self, + index: Operand64Idx, + addr_local: u8, + increment: impl FnOnce(T) -> T, + ) -> Result<(), Trap> { + let memarg = index.resolve(&self.func.data); + let mem_addr = self.mem_addr(MemAddr::from(memarg.memory())); + let mem = self.store.state.get_mem_mut(mem_addr); + let addr = if mem.is_64bit() { + let base = i64::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)) as u64; + let base = cold_err!(usize::try_from(base).map_err(|_| Trap::MemoryOutOfBounds { + offset: usize::MAX, + len: N, + max: mem.inner.len(), + }))?; + cold_err!(mem.effective_addr::(base, u64::from(memarg.offset())))? + } else { + let base = u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)); + cold_err!(mem.effective_addr::(base as usize, u64::from(memarg.offset())))? + }; + + let value = cold_err!(T::load_at(&mem.inner, addr))?; + increment(value).store_at(&mut mem.inner, addr) + } + + fn exec_fma_store< + T: InternalValue + MemValue + core::ops::Add + core::ops::Mul, + const N: usize, + >( + &mut self, + m: CompactMemoryArg, + ) -> Result<(), Trap> { + let rhs = T::stack_pop(&mut self.store.value_stack); + let lhs = T::stack_pop(&mut self.store.value_stack); + let acc = T::stack_pop(&mut self.store.value_stack); + let fma = acc + lhs * rhs; + let mem_addr = self.mem_addr(m.mem_addr()); + let mem = self.store.state.get_mem_mut(mem_addr); + let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; + let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; + cold_err!(fma.store_at(&mut mem.inner, addr)) + } + + fn exec_load_local< + LOAD: MemValue, + const N: usize, + TARGET: InternalValue, + const SET_LOCAL: bool, + const TEE: bool, + >( + &mut self, + index: Operand64Idx, + addr_local: u8, + dst_local: u8, + cast: impl Fn(LOAD) -> TARGET, + ) -> Result<(), Trap> { + let memarg = index.resolve(&self.func.data); + + let mem = self.store.state.get_mem(self.mem_addr(MemAddr::from(memarg.memory()))); + let base = if mem.is_64bit() { + let base = i64::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)) as u64; + cold_err!(usize::try_from(base)).map_err(|_| Trap::MemoryOutOfBounds { + offset: usize::MAX, + len: N, + max: mem.inner.len(), + })? + } else { + u32::local_get(&self.store.value_stack, &self.cf, u16::from(addr_local)) as usize + }; + + let addr = cold_err!(mem.effective_addr::(base, u64::from(memarg.offset())))?; + let value = cast(cold_err!(LOAD::load_at(&mem.inner, addr))?); + + if SET_LOCAL { + TARGET::local_set(&mut self.store.value_stack, &self.cf, u16::from(dst_local), value); + } + if !SET_LOCAL || TEE { + TARGET::stack_push(&mut self.store.value_stack, value)?; + } + Ok(()) + } + + fn exec_ref_is_null(&mut self) -> Result<(), Trap> { + let is_null = i32::from(ValueRef::stack_pop(&mut self.store.value_stack).is_null()); + i32::stack_push(&mut self.store.value_stack, is_null) + } + + fn exec_ref_as_non_null(&mut self) -> Result<(), Trap> { + if ValueRef::stack_peek(&self.store.value_stack).is_null() { + return cold!(Err(Trap::NullReference)); + } + Ok(()) + } + + fn canonical_ref_type(&self, ty: RefType) -> RefType { + let Some(type_index) = ty.type_index() else { return ty }; + RefType::new_concrete(ty.is_nullable(), self.module.resolve_type_addr(type_index)) + } + + fn exec_ref_matches(&self, ty: RefType) -> bool { + let value = ValueRef::stack_peek(&self.store.value_stack); + self.store.state.value_ref_matches(value, self.canonical_ref_type(ty)) + } + + fn exec_ref_test(&mut self, ty: RefType) -> Result<(), Trap> { + let value = ValueRef::stack_pop(&mut self.store.value_stack); + let matches = self.store.state.value_ref_matches(value, self.canonical_ref_type(ty)); + i32::stack_push(&mut self.store.value_stack, i32::from(matches)) + } + + fn exec_ref_cast(&self, ty: RefType) -> Result<(), Trap> { + if !self.exec_ref_matches(ty) { + return cold!(Err(Trap::CastFailure)); + } + Ok(()) + } + + fn exec_i31_get(&mut self, signed: bool) -> Result<(), Trap> { + let value = ValueRef::stack_pop(&mut self.store.value_stack); + if value.is_null() { + return cold!(Err(Trap::NullI31Reference)); + } + let value = if signed { + value.i31_s().expect("validated i31.get operand") + } else { + value.i31_u().expect("validated i31.get operand") as i32 + }; + i32::stack_push(&mut self.store.value_stack, value) + } + + fn push_gc_object(&mut self, type_addr: TypeAddr, values: Vec) -> Result<(), Trap> { + let roots = (&self.store.value_stack.stack_32).into_iter().copied().map(ValueRef::from_raw); + let reference = self.store.state.alloc_gc_object(type_addr, values, roots)?; + ValueRef::stack_push(&mut self.store.value_stack, reference) + } + + fn exec_struct_new(&mut self, type_index: TypeAddr, default: bool) -> Result<(), Trap> { + let type_addr = self.module.resolve_type_addr(type_index); + let field_count = + self.store.state.get_type(type_addr).as_struct().expect("validated struct.new type").fields.len(); + self.store.state.check_gc_allocation(type_addr, field_count)?; + let mut values = Vec::new(); + cold_err!(values.try_reserve_exact(field_count)).map_err(|_| Trap::OutOfMemory)?; + if default { + values.extend( + self.store + .state + .get_type(type_addr) + .as_struct() + .expect("validated struct.new type") + .fields + .iter() + .map(|field| default_value(field.storage)), + ); + } else { + for index in (0..field_count).rev() { + let storage = self.store.state.get_type(type_addr).as_struct().unwrap().fields[index].storage; + values.push(pop_value(&mut self.store.value_stack, storage)); + } + values.reverse(); + } + self.push_gc_object(type_addr, values) + } + + fn exec_struct_get(&mut self, index: Operand64Idx<(u32, u32)>, signed: Option) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let field_index = operand.b(); + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_struct().expect("validated struct.get type").fields + [field_index as usize] + .storage; + let object = self.store.state.gc_object(reference, type_addr)?; + let object = self.store.state.gc.get_handle(object).ok_or(Trap::Other("invalid GC reference"))?; + let value = *object.values.get(field_index as usize).expect("validated struct field index"); + push_value(&mut self.store.value_stack, value, storage, signed) + } + + fn exec_struct_set(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let field_index = operand.b(); + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_struct().expect("validated struct.set type").fields + [field_index as usize] + .storage; + let value = pop_value(&mut self.store.value_stack, storage); + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let object = self.store.state.gc_object(reference, type_addr)?; + self.store.state.gc.set(object, field_index as usize, value).expect("live struct field"); + Ok(()) + } + + fn exec_array_new(&mut self, type_index: TypeAddr, default: bool) -> Result<(), Trap> { + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.new type").field.storage; + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + self.store.state.check_gc_allocation(type_addr, len)?; + let value = if default { default_value(storage) } else { pop_value(&mut self.store.value_stack, storage) }; + let mut values = Vec::new(); + cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; + values.resize(len, value); + self.push_gc_object(type_addr, values) + } + + fn exec_array_new_fixed(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let len = operand.b(); + let type_addr = self.module.resolve_type_addr(type_index); + let storage = + self.store.state.get_type(type_addr).as_array().expect("validated array.new_fixed type").field.storage; + let len = len as usize; + self.store.state.check_gc_allocation(type_addr, len)?; + let mut values = Vec::new(); + cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; + for _ in 0..len { + values.push(pop_value(&mut self.store.value_stack, storage)); + } + values.reverse(); + self.push_gc_object(type_addr, values) + } + + fn exec_array_get(&mut self, type_index: TypeAddr, signed: Option) -> Result<(), Trap> { + let index = u32::stack_pop(&mut self.store.value_stack) as usize; + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.get type").field.storage; + let object = self.store.state.gc_object(reference, type_addr)?; + let object = self.store.state.gc.get_handle(object).ok_or(Trap::Other("invalid GC reference"))?; + let value = *object.values.get(index).ok_or(Trap::ArrayOutOfBounds)?; + push_value(&mut self.store.value_stack, value, storage, signed) + } + + fn exec_array_set(&mut self, type_index: TypeAddr) -> Result<(), Trap> { + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.set type").field.storage; + let value = pop_value(&mut self.store.value_stack, storage); + let index = u32::stack_pop(&mut self.store.value_stack) as usize; + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let object = self.store.state.gc_object(reference, type_addr)?; + self.store.state.gc.set(object, index, value).ok_or(Trap::ArrayOutOfBounds) + } + + fn exec_array_len(&mut self) -> Result<(), Trap> { + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + if reference.is_null() { + return Err(Trap::NullArrayReference); + } + let object = self.store.state.gc.get(reference).ok_or(Trap::Other("invalid GC reference"))?; + let crate::store::GcObjectKind::Composite(type_addr) = object.kind else { + return Err(Trap::Other("GC reference is not an array")); + }; + if self.store.state.get_type(type_addr).as_array().is_none() { + return Err(Trap::Other("GC reference is not an array")); + } + i32::stack_push(&mut self.store.value_stack, object.values.len() as i32) + } + + fn exec_array_fill(&mut self, type_index: TypeAddr) -> Result<(), Trap> { + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_array().expect("validated array.fill type").field.storage; + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + let value = pop_value(&mut self.store.value_stack, storage); + let index = u32::stack_pop(&mut self.store.value_stack) as usize; + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let object = self.store.state.gc_object(reference, type_addr)?; + let object_ref = self.store.state.gc.get_handle(object).ok_or(Trap::Other("invalid GC reference"))?; + let end = index.checked_add(len).filter(|end| *end <= object_ref.values.len()).ok_or(Trap::ArrayOutOfBounds)?; + self.store.state.gc.fill(object, index..end, value).expect("live array range"); + Ok(()) + } + + fn exec_array_copy(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let dst_type = operand.a(); + let src_type = operand.b(); + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + let src_index = u32::stack_pop(&mut self.store.value_stack) as usize; + let src = ValueRef::stack_pop(&mut self.store.value_stack); + let dst_index = u32::stack_pop(&mut self.store.value_stack) as usize; + let dst = ValueRef::stack_pop(&mut self.store.value_stack); + let dst_type = self.module.resolve_type_addr(dst_type); + let src_type = self.module.resolve_type_addr(src_type); + let dst_handle = self.store.state.gc_object(dst, dst_type)?; + let dst_len = self.store.state.gc.get_handle(dst_handle).expect("validated array").values.len(); + let src_handle = self.store.state.gc_object(src, src_type)?; + let src_object = self.store.state.gc.get_handle(src_handle).expect("validated array"); + let src_end = + src_index.checked_add(len).filter(|end| *end <= src_object.values.len()).ok_or(Trap::ArrayOutOfBounds)?; + dst_index.checked_add(len).filter(|end| *end <= dst_len).ok_or(Trap::ArrayOutOfBounds)?; + if src_handle == dst_handle { + self.store.state.gc.copy_within(dst_handle, src_index..src_end, dst_index).expect("live array range"); + return Ok(()); + } + self.store + .state + .gc + .copy_between(src_handle, src_index..src_end, dst_handle, dst_index) + .expect("live array ranges"); + Ok(()) + } + + fn exec_array_new_data(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let data_index = operand.b(); + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + let src = u32::stack_pop(&mut self.store.value_stack) as usize; + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_array().expect("validated array type").field.storage; + let data_addr = self.module.resolve_data_addr(data_index); + let data = self.store.state.data[data_addr as usize].data.as_deref().unwrap_or(&[]); + data_range(storage, data, src, len)?; + self.store.state.check_gc_allocation(type_addr, len)?; + let values = decode_data(storage, data, src, len)?; + self.push_gc_object(type_addr, values) + } + + fn exec_array_new_elem(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let elem_index = operand.b(); + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + let src = u32::stack_pop(&mut self.store.value_stack) as usize; + let type_addr = self.module.resolve_type_addr(type_index); + let elem_addr = self.module.resolve_elem_addr(elem_index); + let items = self.store.state.elements[elem_addr as usize].items_range(src, len)?; + self.store.state.check_gc_allocation(type_addr, len)?; + let mut values = Vec::new(); + cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; + values.extend(items.iter().copied().map(RuntimeValue::ValueRef)); + self.push_gc_object(type_addr, values) + } + + fn exec_array_init_data(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let data_index = operand.b(); + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + let src = u32::stack_pop(&mut self.store.value_stack) as usize; + let dst = u32::stack_pop(&mut self.store.value_stack) as usize; + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let type_addr = self.module.resolve_type_addr(type_index); + let storage = self.store.state.get_type(type_addr).as_array().expect("validated array type").field.storage; + let object = self.store.state.gc_object(reference, type_addr)?; + let object_len = self.store.state.gc.get_handle(object).expect("validated array").values.len(); + dst.checked_add(len).filter(|end| *end <= object_len).ok_or(Trap::ArrayOutOfBounds)?; + let data = + self.store.state.data[self.module.resolve_data_addr(data_index) as usize].data.as_deref().unwrap_or(&[]); + let values = decode_data(storage, data, src, len)?; + self.store.state.gc.set_slice(object, dst, &values).expect("live array range"); + Ok(()) + } + + fn exec_array_init_elem(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let type_index = operand.a(); + let elem_index = operand.b(); + let len = u32::stack_pop(&mut self.store.value_stack) as usize; + let src = u32::stack_pop(&mut self.store.value_stack) as usize; + let dst = u32::stack_pop(&mut self.store.value_stack) as usize; + let reference = ValueRef::stack_pop(&mut self.store.value_stack); + let type_addr = self.module.resolve_type_addr(type_index); + let object = self.store.state.gc_object(reference, type_addr)?; + let object_len = self.store.state.gc.get_handle(object).expect("validated array").values.len(); + dst.checked_add(len).filter(|end| *end <= object_len).ok_or(Trap::ArrayOutOfBounds)?; + let items = + self.store.state.elements[self.module.resolve_elem_addr(elem_index) as usize].items_range(src, len)?; + let mut values = Vec::new(); + cold_err!(values.try_reserve_exact(len)).map_err(|_| Trap::OutOfMemory)?; + values.extend(items.iter().copied().map(RuntimeValue::ValueRef)); + self.store.state.gc.set_slice(object, dst, &values).expect("live array range"); + Ok(()) + } + + fn exec_memory_size(&mut self, addr: u32) -> Result<(), Trap> { + let mem = self.store.state.get_mem(self.mem_addr(addr)); + match mem.is_64bit() { + true => i64::stack_push(&mut self.store.value_stack, mem.page_count as i64), + false => i32::stack_push(&mut self.store.value_stack, mem.page_count as i32), + } + } + + fn exec_memory_grow(&mut self, addr: u32) -> Result<(), Trap> { + let mem_addr = self.mem_addr(addr); + let limiter = self.store.engine.config().resource_limiter.as_deref(); + let mem = self.store.state.get_mem_mut(mem_addr); + let is_64bit = mem.is_64bit(); + let pages_delta = match is_64bit { + true => i64::stack_pop(&mut self.store.value_stack), + false => i64::from(i32::stack_pop(&mut self.store.value_stack)), + }; + + let size = mem.grow(pages_delta, limiter)?.unwrap_or(-1); + match is_64bit { + true => i64::stack_push(&mut self.store.value_stack, size)?, + false => i32::stack_push(&mut self.store.value_stack, size as i32)?, + }; + + Ok(()) + } + + fn exec_memory_copy(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let dst_mem = operand.a(); + let src_mem = operand.b(); + let dst_mem_addr = self.mem_addr(dst_mem); + let src_mem_addr = self.mem_addr(src_mem); + let dst_arch = self.store.state.get_mem(dst_mem_addr).kind.arch(); + let src_arch = self.store.state.get_mem(src_mem_addr).kind.arch(); + let len_arch = + if dst_arch == MemoryArch::I32 || src_arch == MemoryArch::I32 { MemoryArch::I32 } else { MemoryArch::I64 }; + let size = self.store.value_stack.pop_memory_operand(len_arch)?; + let src = self.store.value_stack.pop_memory_operand(src_arch)?; + let dst = self.store.value_stack.pop_memory_operand(dst_arch)?; + + if dst_mem_addr == src_mem_addr { + // copy within the same memory + let mem = self.store.state.get_mem_mut(dst_mem_addr); + mem.copy_within(dst, src, size)?; + } else { + // copy between two memories + let (dst_memory, src_memory) = self.store.state.get_mems_mut(dst_mem_addr, src_mem_addr); + dst_memory.copy_from_memory(dst, src_memory, src, size)?; + } + Ok(()) + } + + fn exec_memory_fill(&mut self, addr: u32) -> Result<(), Trap> { + let mem_addr = self.mem_addr(addr); + let arch = self.store.state.get_mem(mem_addr).kind.arch(); + let size = self.store.value_stack.pop_memory_operand(arch)?; + let val = i32::stack_pop(&mut self.store.value_stack); + let dst = self.store.value_stack.pop_memory_operand(arch)?; + self.exec_memory_fill_impl(mem_addr, dst, val as u8, size) + } + + fn exec_memory_fill_const(&mut self, index: Operand128Idx) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let mem_addr = self.mem_addr(operand.memory()); + let arch = self.store.state.get_mem(mem_addr).kind.arch(); + let dst = self.store.value_stack.pop_memory_operand(arch)?; + self.exec_memory_fill_impl(mem_addr, dst, operand.byte(), operand.value() as u32 as usize) + } + + fn exec_memory_fill_impl(&mut self, mem_addr: MemAddr, dst: usize, val: u8, size: usize) -> Result<(), Trap> { + let mem = self.store.state.get_mem_mut(mem_addr); + let max = mem.inner.len(); + if mem.inner.fill(dst, size, val).is_none() { + return cold!(Err(Trap::MemoryOutOfBounds { offset: dst, len: size, max })); + } + Ok(()) + } + + fn exec_memory_init(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let data_index = operand.a(); + let mem_index = operand.b(); + let size = u32::stack_pop(&mut self.store.value_stack) as usize; + let offset = u32::stack_pop(&mut self.store.value_stack) as usize; + let mem_addr = self.mem_addr(mem_index); + let arch = self.store.state.get_mem(mem_addr).kind.arch(); + let dst = self.store.value_stack.pop_memory_operand(arch)?; + + let data = &self.store.state.data[self.module.resolve_data_addr(data_index) as usize]; + let mem = &mut self.store.state.memories[mem_addr as usize]; + let data_len = data.data.as_ref().map_or(0, |d| d.len()); + let mem_len = mem.inner.len(); + if offset.checked_add(size).is_none_or(|end| end > data_len) { + return cold!(Err(Trap::MemoryOutOfBounds { offset, len: size, max: data_len })); + } + if dst.checked_add(size).is_none_or(|end| end > mem_len) { + return cold!(Err(Trap::MemoryOutOfBounds { offset: dst, len: size, max: mem_len })); + } + + if size == 0 { + return Ok(()); + } + + let Some(data) = &data.data else { + return cold!(Err(Trap::MemoryOutOfBounds { offset: 0, len: 0, max: 0 })); + }; + + if mem.inner.write_all(dst, &data[offset..offset + size]).is_none() { + return cold!(Err(Trap::MemoryOutOfBounds { offset: dst, len: size, max: mem_len })); + } + Ok(()) + } + + fn exec_table_copy(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let dst_table = operand.a(); + let src_table = operand.b(); + let dst_table_addr = self.module.resolve_table_addr(dst_table); + let src_table_addr = self.module.resolve_table_addr(src_table); + let dst_arch = self.store.state.get_table(dst_table_addr).kind.arch(); + let src_arch = self.store.state.get_table(src_table_addr).kind.arch(); + let len_arch = + if dst_arch == MemoryArch::I32 || src_arch == MemoryArch::I32 { MemoryArch::I32 } else { MemoryArch::I64 }; + let size = self.pop_table_operand(len_arch)?; + let src = self.pop_table_operand(src_arch)?; + let dst = self.pop_table_operand(dst_arch)?; + + if dst_table_addr == src_table_addr { + // copy within the same table + self.store.state.get_table_mut(dst_table_addr).copy_within(dst, src, size) + } else { + // copy between two tables + let (dst_table_ref, src_table_ref) = self.store.state.get_tables_mut(dst_table_addr, src_table_addr); + dst_table_ref.copy_from_slice(dst, src_table_ref.load(src, size)?) + } + } + + fn exec_mem_load_lane, const LOAD_SIZE: usize>( + &mut self, + arg: MemoryLaneArg, + ) -> Result<(), Trap> { + let m = arg.memory_arg_idx.resolve(&self.func.data); + let mem = self.store.state.get_mem(self.mem_addr(m.memory())); + let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; + let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; + let val = cold_err!(LOAD::load_at(&mem.inner, addr))?; + let offset = arg.lane as usize * LOAD_SIZE; + Value128::stack_update(&mut self.store.value_stack, |value| { + let mut bytes = value.to_mem_bytes(); + bytes[offset..offset + LOAD_SIZE].copy_from_slice(&val.to_mem_bytes()); + Value128(bytes) + }); + Ok(()) + } + + #[inline(always)] + fn exec_mem_load, const LOAD_SIZE: usize, TARGET: InternalValue>( + &mut self, + m: Operand128, + cast: impl Fn(LOAD) -> TARGET, + ) -> Result<(), Trap> { + let mem = self.store.state.get_mem(self.mem_addr(m.memory())); + let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; + let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; + let value = cold_err!(LOAD::load_at(&mem.inner, addr))?; + TARGET::stack_push(&mut self.store.value_stack, cast(value)) + } + + #[inline(always)] + fn exec_mem_store_lane + Copy, const N: usize>(&mut self, arg: MemoryLaneArg) -> Result<(), Trap> { + let bytes = Value128::stack_pop(&mut self.store.value_stack).to_mem_bytes(); + let lane_offset = arg.lane as usize * N; + let mut val_bytes = [0u8; N]; + val_bytes.copy_from_slice(&bytes[lane_offset..lane_offset + N]); + let val = U::from_mem_bytes(val_bytes); + let m = arg.memory_arg_idx.resolve(&self.func.data); + let mem_addr = self.mem_addr(m.memory()); + let mem = self.store.state.get_mem_mut(mem_addr); + let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; + let addr = cold_err!(mem.effective_addr::(base, m.offset()))?; + cold_err!(val.store_at(&mut mem.inner, addr))?; + Ok(()) + } + + #[inline(always)] + fn exec_mem_store, const N: usize>( + &mut self, + memory: Operand128, + cast: impl Fn(T) -> U, + ) -> Result<(), Trap> { + let val = cast(::stack_pop(&mut self.store.value_stack)); + self.exec_mem_store_value(self.mem_addr(memory.memory()), memory.offset(), val) + } + + #[inline(always)] + fn exec_select_store, const N: usize>( + &mut self, + memory: Operand128, + ) -> Result<(), Trap> { + let condition = Value32::stack_pop(&mut self.store.value_stack); + let false_value = T::stack_pop(&mut self.store.value_stack); + let true_value = T::stack_pop(&mut self.store.value_stack); + let value = if condition == 0 { false_value } else { true_value }; + self.exec_mem_store_value(self.mem_addr(memory.memory()), memory.offset(), value) + } + + #[inline(always)] + fn exec_mem_store_value, const N: usize>( + &mut self, + memory_addr: MemAddr, + offset: u64, + val: U, + ) -> Result<(), Trap> { + let mem = self.store.state.get_mem_mut(memory_addr); + let base = self.store.value_stack.pop_memory_operand(mem.kind.arch())?; + let addr = cold_err!(mem.effective_addr::(base, offset))?; + cold_err!(val.store_at(&mut mem.inner, addr)) + } + + fn exec_table_get(&mut self, table_index: u32) -> Result<(), Trap> { + let table_addr = self.module.resolve_table_addr(table_index); + let idx = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; + let value = *self.store.state.get_table(table_addr).get(idx)?; + ValueRef::stack_push(&mut self.store.value_stack, value) + } + + fn exec_table_set(&mut self, table_index: u32) -> Result<(), Trap> { + let val = ValueRef::stack_pop(&mut self.store.value_stack); + let table_addr = self.module.resolve_table_addr(table_index); + let idx = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; + let table = self.store.state.get_table_mut(table_addr); + table.set(idx, val) + } + + fn exec_table_size(&mut self, table_index: u32) -> Result<(), Trap> { + let table = self.store.state.get_table(self.module.resolve_table_addr(table_index)); + match table.kind.arch() { + MemoryArch::I32 => i32::stack_push(&mut self.store.value_stack, table.size() as i32), + MemoryArch::I64 => i64::stack_push(&mut self.store.value_stack, table.size() as i64), + } + } + + fn exec_table_init(&mut self, index: Operand64Idx<(u32, u32)>) -> Result<(), Trap> { + let operand = index.resolve(&self.func.data); + let elem_index = operand.a(); + let table_index = operand.b(); + let size = self.pop_table_operand(MemoryArch::I32)?; // n + let offset = self.pop_table_operand(MemoryArch::I32)?; // s + let table_addr = self.module.resolve_table_addr(table_index); + let dst = self.pop_table_operand(self.store.state.get_table(table_addr).kind.arch())?; // d + let elem_addr = self.module.resolve_elem_addr(elem_index) as usize; + let elem = self.store.state.elements.get(elem_addr).ok_or_else(|| Trap::Other("element not found"))?; + let items = elem.items_range(offset, size)?; + + let table = + self.store.state.tables.get_mut(table_addr as usize).ok_or_else(|| Trap::Other("table not found"))?; + table.init(dst, items) + } + + fn exec_table_grow(&mut self, table_index: u32) -> Result<(), Trap> { + let table_addr = self.module.resolve_table_addr(table_index); + let arch = self.store.state.get_table(table_addr).kind.arch(); + let n = self.pop_table_operand(arch)?; + let val = ValueRef::stack_pop(&mut self.store.value_stack); + let limiter = self.store.engine.config().resource_limiter.as_deref(); + let table = self.store.state.get_table_mut(table_addr); + let sz = table.size(); + let grew = table.grow(n, val, limiter)?; + match (arch, grew) { + (MemoryArch::I32, true) => i32::stack_push(&mut self.store.value_stack, sz as i32), + (MemoryArch::I32, false) => i32::stack_push(&mut self.store.value_stack, -1), + (MemoryArch::I64, true) => i64::stack_push(&mut self.store.value_stack, sz as i64), + (MemoryArch::I64, false) => i64::stack_push(&mut self.store.value_stack, -1), + } + } + + fn exec_table_fill(&mut self, table_index: u32) -> Result<(), Trap> { + let table_addr = self.module.resolve_table_addr(table_index); + let arch = self.store.state.get_table(table_addr).kind.arch(); + let n = self.pop_table_operand(arch)?; + let val = ValueRef::stack_pop(&mut self.store.value_stack); + let i = self.pop_table_operand(arch)?; + self.store.state.get_table_mut(table_addr).fill(i, n, val) + } + + fn pop_table_operand(&mut self, arch: MemoryArch) -> Result { + let value = match arch { + MemoryArch::I32 => i32::stack_pop(&mut self.store.value_stack) as u32 as u64, + MemoryArch::I64 => i64::stack_pop(&mut self.store.value_stack) as u64, + }; + cold_err!(usize::try_from(value).map_err(|_| Trap::TableOutOfBounds { + offset: usize::MAX, + len: 1, + max: usize::MAX, + })) + } +} diff --git a/crates/tinywasm/src/interpreter/mod.rs b/crates/tinywasm/src/interpreter/mod.rs index 6e6912c..0f7ae20 100644 --- a/crates/tinywasm/src/interpreter/mod.rs +++ b/crates/tinywasm/src/interpreter/mod.rs @@ -27,11 +27,11 @@ pub(crate) struct InterpreterRuntime; impl InterpreterRuntime { pub(crate) fn exec(store: &mut Store, cf: CallFrame, call_stack_base: u32) -> Result<()> { - executor::Executor::::new(store, cf, call_stack_base).run_to_completion() + executor::Executor::new(store, cf, call_stack_base).run_to_completion() } pub(crate) fn exec_with_fuel(store: &mut Store, cf: CallFrame, fuel: u32) -> Result { - executor::Executor::::new(store, cf, 0).run_with_fuel(fuel) + executor::Executor::new(store, cf, 0).run_with_fuel(fuel) } #[cfg(feature = "std")] @@ -40,6 +40,6 @@ impl InterpreterRuntime { cf: CallFrame, time_budget: core::time::Duration, ) -> Result { - executor::Executor::::new(store, cf, 0).run_with_time_budget(time_budget) + executor::Executor::new(store, cf, 0).run_with_time_budget(time_budget) } } diff --git a/crates/tinywasm/src/interpreter/stack/value_stack.rs b/crates/tinywasm/src/interpreter/stack/value_stack.rs index a9c86b7..2bed835 100644 --- a/crates/tinywasm/src/interpreter/stack/value_stack.rs +++ b/crates/tinywasm/src/interpreter/stack/value_stack.rs @@ -24,6 +24,12 @@ pub(crate) struct Stack { dynamic: bool, } +#[cold] +#[inline(never)] +fn stack_underflow() -> ! { + unreachable!("ValueStack underflow, this is a bug") +} + impl Stack { pub(crate) fn new(config: StackConfig) -> Self { Self { data: Vec::with_capacity(config.initial_size), max_size: config.max_size, dynamic: config.dynamic } @@ -61,7 +67,7 @@ impl Stack { pub(crate) fn pop(&mut self) -> T { match self.data.pop() { Some(value) => value, - None => cold!(unreachable!("ValueStack underflow, this is a bug")), + None => cold!(stack_underflow()), } } @@ -69,7 +75,7 @@ impl Stack { pub(crate) fn last(&self) -> &T { match self.data.last() { Some(value) => value, - None => cold!(unreachable!("ValueStack underflow, this is a bug")), + None => cold!(stack_underflow()), } } @@ -150,7 +156,7 @@ impl Stack { let needed = count.wrapping_mul(2); if len < needed { - unreachable!("Stack underflow, this is a bug"); + cold!(stack_underflow()); } if !condition { diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs index fe74fcf..b2b7eae 100644 --- a/crates/tinywasm/src/lib.rs +++ b/crates/tinywasm/src/lib.rs @@ -1,4 +1,6 @@ #![no_std] +#![cfg_attr(feature = "nightly-tail-calls", allow(incomplete_features))] +#![cfg_attr(feature = "nightly-tail-calls", feature(explicit_tail_calls))] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_assignments, unused_variables)) @@ -65,14 +67,17 @@ //! //! - **`full`:** Enables `archive`, `parallel-parser`, `parser`, and `validate`. Enabled by default. //! - **`std`:** Enables `std` and parsing from files and streams. Enabled by default. -//! - **`log`:** Enables integration with the `log` crate. Enabled by default. //! - **`parser`:** Enables `tinywasm-parser` and top-level parse helpers. Enabled by default. //! - **`validate`:** Enables WebAssembly validation while parsing. Enabled by default and configurable through `ParserOptions`. +//! - **`parallel-parser`:** Parallelizes function parsing when `std` is enabled. Enabled by default. //! - **`archive`:** Enables serialization and deserialization of the internal `twasm` format. Enabled by default. +//! - **`log`:** Enables integration with the `log` crate. Enabled by default. +//! - **`send`:** Makes stores and store-local handles movable across threads. +//! - **`portable-atomic`:** Supports targets without native atomic compare-and-swap. //! - **`canonicalize-nans`:** Uses a [canonical NaN](https://en.wikipedia.org/wiki/NaN#Canonical_NaN) for normalized NaN results. Enabled by default. //! - **`debug`:** Derives `Debug` for runtime types. Enabled by default. -//! - **`parallel-parser`:** Parallelizes function parsing when `std` is enabled. Enabled by default. //! - **`guest-debug`:** Exposes module-internal by-index inspection APIs (`*_by_index`). +//! - **`nightly-tail-calls`:** Uses Rust's unstable explicit tail calls for interpreter dispatch. Requires nightly Rust (recommended for maximum performance). //! - **`simd-x86`:** Enables x86-specific SIMD intrinsics and uses `unsafe` internally. //! //! With default features disabled, `tinywasm` depends only on `core`, `alloc`, and `libm`, diff --git a/crates/tinywasm/tests/resume_execution.rs b/crates/tinywasm/tests/resume_execution.rs index f7dff4f..431a696 100644 --- a/crates/tinywasm/tests/resume_execution.rs +++ b/crates/tinywasm/tests/resume_execution.rs @@ -70,7 +70,7 @@ fn weighted_call_fuel_requires_more_rounds() -> Result<()> { let instance_weighted = ModuleInstance::instantiate(&mut weighted_store, &module, None)?; let func_weighted = instance_weighted.func::(&weighted_store, "fibonacci_recursive")?; - let fuel = 64; + let fuel = 512; let n = 20; let mut per_exec = func_per_instr.call_resumable(&mut per_instr_store, n)?; @@ -94,7 +94,7 @@ fn weighted_call_fuel_requires_more_rounds() -> Result<()> { }; assert_eq!(weighted_result, per_result); - assert!(weighted_rounds >= per_rounds, "weighted call fuel should not use fewer rounds than per-instruction"); + assert!(weighted_rounds > per_rounds, "weighted call fuel should require more rounds than per-instruction"); Ok(()) } diff --git a/examples/rust/src/print.twasm b/examples/rust/src/print.twasm index 0fb3f39..967eda1 100644 Binary files a/examples/rust/src/print.twasm and b/examples/rust/src/print.twasm differ -- cgit v1.3.1 From ded2780129ef8c58edfc1af51ea23be2524a15b1 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 13 Sep 2026 17:45:53 +0200 Subject: chore: update deps, remove inline from dispatch handlers (closes #55) Signed-off-by: Henry --- Cargo.lock | 71 +++++++++++----------- Cargo.toml | 9 ++- crates/cli/Cargo.toml | 1 - crates/parser/Cargo.toml | 1 - crates/tinywasm/Cargo.toml | 2 +- .../src/interpreter/executor/dispatch_become.rs | 2 - crates/types/Cargo.toml | 9 +-- 7 files changed, 44 insertions(+), 51 deletions(-) (limited to 'crates/parser/Cargo.toml') diff --git a/Cargo.lock b/Cargo.lock index edc0bbf..a22eba9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,9 +105,9 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "bitflags" -version = "2.13.1" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "bstr" @@ -134,9 +134,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.4.4" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad534f4357a5264cce5019c989cf66a4f0dc4e0d1b1d15f8aacec0ff7360273" +checksum = "a3eb0f42d6c360dc3f8a821f6bf2fdea7f72bfd36b3076eb0e6d1e9e0752fff4" dependencies = [ "find-msvc-tools", "shlex", @@ -215,7 +215,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -275,9 +275,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5181e0de7b61eb03a81e347d6dd8797bae9da5146707b51077e2d71a54ec0ceb" +checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -285,18 +285,18 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.20" +version = "0.9.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f" +checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.22" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" [[package]] name = "crunchy" @@ -365,9 +365,9 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "find-msvc-tools" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" [[package]] name = "float-cmp" @@ -414,9 +414,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" [[package]] name = "humantime" @@ -445,9 +445,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.14.1" +version = "2.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07aa2048142242915a31d35844fb311e0e53fcca590c3a0a40dcf1b841fa09eb" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", "hashbrown", @@ -578,9 +578,9 @@ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" [[package]] name = "portable-atomic-util" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" dependencies = [ "portable-atomic", "serde", @@ -766,7 +766,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -807,9 +807,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.4" +version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" dependencies = [ "proc-macro2", "quote", @@ -861,7 +861,7 @@ checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -935,7 +935,6 @@ dependencies = [ name = "tinywasm-types" version = "0.11.0-pre.0" dependencies = [ - "log", "portable-atomic-util", "postcard", "serde", @@ -980,9 +979,9 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.258.0" +version = "0.259.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e974fe6821a8cf64575d51ea2194e2c8f77e7b66e9afe7419ce8a97f9ee0d251" +checksum = "b1d0246511d901aacf25d2dc9111f0054947de5e093fe662099e709ff7530dc3" dependencies = [ "leb128fmt", "wasmparser", @@ -1000,9 +999,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.258.0" +version = "0.259.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a61719f93a87b16d325921e251800c4833f8fab50fa21c7de73aed50086313" +checksum = "0f7c12eac7bb587801590f6a67ff0bc84d0748513864b71108e4b311cc3df694" dependencies = [ "bitflags", "indexmap", @@ -1011,9 +1010,9 @@ dependencies = [ [[package]] name = "wast" -version = "258.0.0" +version = "259.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97f7defc7ecca8b19ac7f824598eadd0c53985ee00c74060d65051e9da5b58a1" +checksum = "c69beba8d9da07af9a0971b559149a2ac4729895b55144de4fddbf5a02660648" dependencies = [ "bumpalo", "leb128fmt", @@ -1024,9 +1023,9 @@ dependencies = [ [[package]] name = "wat" -version = "1.258.0" +version = "1.259.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7555c008cca87f2ac58d9f83ccda7e7b44611093ce28eb28f052e7c78024b9bf" +checksum = "c6eec44b0c80391b20fb7ad9ea440c72c5d382385bdf74444bb18321c425017e" dependencies = [ "wast", ] @@ -1079,18 +1078,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.56" +version = "0.8.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb" +checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.56" +version = "0.8.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1" +checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 1d709e2..a3fdd3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,9 @@ pretty_env_logger = "0.5" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } wasm-testsuite = { version = "0.7" } -wasmparser = { version = "0.258", default-features = false } -wast = "258" -wat = "1.258" +wasmparser = { version = "0.259", default-features = false } +wast = "259" +wat = "1.259" criterion = { version = "0.8", default-features = false, features = ["cargo_bench_support", "rayon"] } @@ -65,6 +65,9 @@ tinywasm = { path = "crates/tinywasm" } tinywasm-parser.workspace = true wat.workspace = true +[lints.cargo] +unused_dependencies = "allow" # false-positive on libm + [profile.bench] opt-level = 3 debug = true diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 861d349..22f1bf8 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -5,7 +5,6 @@ edition.workspace = true rust-version.workspace = true description = "Minimal command-line interface for TinyWasm" documentation = "https://docs.rs/tinywasm-cli" -readme = "README.md" repository.workspace = true license.workspace = true keywords = ["cli", "runtime", "tinywasm", "wasm", "webassembly"] diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 7d781a4..f868beb 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -4,7 +4,6 @@ version.workspace = true edition.workspace = true rust-version.workspace = true description = "Parser and lowering pipeline for TinyWasm" -readme = "README.md" repository.workspace = true license.workspace = true keywords.workspace = true diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 3d78fca..15744a3 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -92,7 +92,7 @@ wat.workspace = true default = ["full", "std"] full = ["archive", "parallel-parser", "parser", "validate"] -log = ["dep:log", "tinywasm-parser?/log", "tinywasm-types/log"] +log = ["dep:log", "tinywasm-parser?/log"] std = ["tinywasm-parser?/std", "tinywasm-types/std"] # make stores, instances, references, and host callbacks movable across threads diff --git a/crates/tinywasm/src/interpreter/executor/dispatch_become.rs b/crates/tinywasm/src/interpreter/executor/dispatch_become.rs index 66cbb51..0dc8d5e 100644 --- a/crates/tinywasm/src/interpreter/executor/dispatch_become.rs +++ b/crates/tinywasm/src/interpreter/executor/dispatch_become.rs @@ -15,7 +15,6 @@ fn instruction_handler_mismatch() -> ! { macro_rules! define_unbudgeted_tail_dispatch { ($executor:ident, $instr_ptr:ident, $dispatch_next:ident, $dispatch_flow:ident; $($variant:ident $(($($arg:pat),*))? $({ $($field:ident),* })? => $body:expr),* $(,)?) => { - #[inline(always)] fn handler_for(instruction: &Instruction) -> UnbudgetedHandler { use tinywasm_types::Instruction::*; @@ -64,7 +63,6 @@ macro_rules! define_unbudgeted_tail_dispatch { macro_rules! define_bounded_tail_dispatch { ($executor:ident, $instr_ptr:ident, $dispatch_next:ident, $dispatch_flow:ident; $($variant:ident $(($($arg:pat),*))? $({ $($field:ident),* })? => $body:expr),* $(,)?) => { - #[inline(always)] fn handler_for(instruction: &Instruction) -> BoundedHandler { use tinywasm_types::Instruction::*; diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 091bb9f..4046896 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -4,20 +4,18 @@ version.workspace = true edition.workspace = true rust-version.workspace = true description = "Shared runtime, module, and archive types for TinyWasm" -readme = "README.md" repository.workspace = true license.workspace = true keywords.workspace = true categories.workspace = true [dependencies] -log = { workspace = true, optional = true } -portable-atomic-util = { version = "0.2.7", default-features = false, features = ["alloc"], optional = true } +portable-atomic-util = { version = "0.2.8", default-features = false, features = ["alloc"], optional = true } postcard = { version = "1.1", default-features = false, features = ["alloc"], optional = true } serde = { version = "1.0", default-features = false, features = ["alloc"], optional = true } [features] -default = ["archive", "debug", "log", "std"] +default = ["archive", "debug", "std"] # support serializing and deserializing twasm archives archive = ["dep:postcard", "dep:serde", "portable-atomic-util?/serde", "serde/rc"] @@ -25,9 +23,6 @@ archive = ["dep:postcard", "dep:serde", "portable-atomic-util?/serde", "serde/rc # derive Debug for runtime and module types debug = [] -# enable integration with the log crate -log = ["dep:log"] - # enable standard library support std = ["serde?/std"] -- cgit v1.3.1 From dc8e5732d71b6f66e730b090ab02bdccc69ec888 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 15 Sep 2026 15:23:11 +0200 Subject: feat: initial wasi p1 implementation Signed-off-by: Henry --- Cargo.lock | 308 +++++++++++++++++++++++-- Cargo.toml | 16 +- crates/cli/Cargo.toml | 4 + crates/parser/Cargo.toml | 4 +- crates/tinywasm/Cargo.toml | 3 + crates/types/Cargo.toml | 3 + crates/wasi/Cargo.toml | 25 ++ crates/wasi/README.md | 10 + crates/wasi/src/lib.rs | 4 + crates/wasi/src/p1/abi.rs | 300 ++++++++++++++++++++++++ crates/wasi/src/p1/ctx.rs | 293 +++++++++++++++++++++++ crates/wasi/src/p1/imports/clock.rs | 28 +++ crates/wasi/src/p1/imports/command.rs | 72 ++++++ crates/wasi/src/p1/imports/fd.rs | 423 ++++++++++++++++++++++++++++++++++ crates/wasi/src/p1/imports/mod.rs | 101 ++++++++ crates/wasi/src/p1/imports/path.rs | 258 +++++++++++++++++++++ crates/wasi/src/p1/imports/poll.rs | 219 ++++++++++++++++++ crates/wasi/src/p1/imports/process.rs | 20 ++ crates/wasi/src/p1/imports/random.rs | 25 ++ crates/wasi/src/p1/imports/sock.rs | 124 ++++++++++ crates/wasi/src/p1/memory.rs | 115 +++++++++ crates/wasi/src/p1/mod.rs | 22 ++ crates/wasi/tests/p1.rs | 357 ++++++++++++++++++++++++++++ examples/wasi_p1.rs | 42 ++++ 24 files changed, 2753 insertions(+), 23 deletions(-) create mode 100644 crates/wasi/Cargo.toml create mode 100644 crates/wasi/README.md create mode 100644 crates/wasi/src/lib.rs create mode 100644 crates/wasi/src/p1/abi.rs create mode 100644 crates/wasi/src/p1/ctx.rs create mode 100644 crates/wasi/src/p1/imports/clock.rs create mode 100644 crates/wasi/src/p1/imports/command.rs create mode 100644 crates/wasi/src/p1/imports/fd.rs create mode 100644 crates/wasi/src/p1/imports/mod.rs create mode 100644 crates/wasi/src/p1/imports/path.rs create mode 100644 crates/wasi/src/p1/imports/poll.rs create mode 100644 crates/wasi/src/p1/imports/process.rs create mode 100644 crates/wasi/src/p1/imports/random.rs create mode 100644 crates/wasi/src/p1/imports/sock.rs create mode 100644 crates/wasi/src/p1/memory.rs create mode 100644 crates/wasi/src/p1/mod.rs create mode 100644 crates/wasi/tests/p1.rs create mode 100644 examples/wasi_p1.rs (limited to 'crates/parser/Cargo.toml') diff --git a/Cargo.lock b/Cargo.lock index a22eba9..8db3177 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ambient-authority" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b" + [[package]] name = "anes" version = "0.1.6" @@ -62,7 +68,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -73,7 +79,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -126,6 +132,48 @@ version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +[[package]] +name = "cap-fs-ext" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ff379b70af8e08307a8f65e7040c7301cb4a572538ade16b4984f0da77847f" +dependencies = [ + "cap-primitives", + "cap-std", + "io-lifetimes 3.0.1", + "windows-sys 0.61.2", +] + +[[package]] +name = "cap-primitives" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b5f74729fd2f44701d1a8eb47e906cdb3ccd9ec0f02baad85a744b791940b18" +dependencies = [ + "ambient-authority", + "fs-set-times", + "io-extras", + "io-lifetimes 3.0.1", + "ipnet", + "maybe-owned", + "rustix", + "rustix-linux-procfs", + "windows-sys 0.61.2", + "winx", +] + +[[package]] +name = "cap-std" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ec78e242cfa2cfe276807ac2ecc00315a6c97786977414bcd1c3963b6c91b8" +dependencies = [ + "cap-primitives", + "io-extras", + "io-lifetimes 3.0.1", + "rustix", +] + [[package]] name = "cast" version = "0.3.0" @@ -177,9 +225,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.6.6" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca" +checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" dependencies = [ "clap_builder", "clap_derive", @@ -187,9 +235,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.6.6" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889" +checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" dependencies = [ "anstream", "anstyle", @@ -199,18 +247,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.6.9" +version = "4.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be2ad0423bdbbb0e25bc89add796f3559706d4a95e1bc98e4d9662a957b6a19" +checksum = "78ab9a1a7094014a0d0813f8e7c5a0058ad8fe6cf7475b9151364259f5a35d0f" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.6.4" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061" +checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" dependencies = [ "heck", "proc-macro2", @@ -220,9 +268,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" +checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" [[package]] name = "cobs" @@ -354,7 +402,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -378,6 +426,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fs-set-times" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a" +dependencies = [ + "io-lifetimes 2.0.4", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -453,6 +512,34 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "io-extras" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20fd6de4ccfcc187e38bc21cfa543cb5a302cb86a8b114eb7f0bf0dc9f8ac00f" +dependencies = [ + "io-lifetimes 3.0.1", + "windows-sys 0.60.2", +] + +[[package]] +name = "io-lifetimes" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983" + +[[package]] +name = "io-lifetimes" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0fb0570afe1fed943c5c3d4102d5358592d8625fda6a0007fdbe65a92fba96" + +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + [[package]] name = "is-terminal" version = "0.4.17" @@ -461,7 +548,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi", "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -515,6 +602,12 @@ version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" +[[package]] +name = "maybe-owned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4" + [[package]] name = "memchr" version = "2.8.3" @@ -721,7 +814,17 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustix-linux-procfs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc84bf7e9aa16c4f2c758f27412dc9841341e16aa682d9c7ac308fe3ee12056" +dependencies = [ + "once_cell", + "rustix", ] [[package]] @@ -826,7 +929,7 @@ dependencies = [ "getrandom", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -905,6 +1008,7 @@ dependencies = [ "serde_json", "tempfile", "tinywasm", + "tinywasm-wasi", "wasm-testsuite", "wast", "wat", @@ -928,6 +1032,7 @@ dependencies = [ "pretty_env_logger", "tinywasm", "tinywasm-parser", + "tinywasm-wasi", "wat", ] @@ -940,6 +1045,18 @@ dependencies = [ "serde", ] +[[package]] +name = "tinywasm-wasi" +version = "0.11.0-pre.0" +dependencies = [ + "cap-fs-ext", + "cap-std", + "getrandom", + "rustix", + "tinywasm", + "wat", +] + [[package]] name = "unicode-ident" version = "1.0.24" @@ -1052,7 +1169,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -1067,6 +1184,24 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -1076,6 +1211,145 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winx" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d" +dependencies = [ + "bitflags", + "windows-sys 0.59.0", +] + [[package]] name = "zerocopy" version = "0.8.57" diff --git a/Cargo.toml b/Cargo.toml index a3fdd3b..8f40398 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ publish = false [workspace] resolver = "3" members = ["crates/*"] -default-members = [".", "crates/parser", "crates/tinywasm", "crates/types"] +default-members = [".", "crates/parser", "crates/tinywasm", "crates/types", "crates/wasi"] [workspace.package] version = "0.11.0-pre.0" @@ -23,6 +23,7 @@ categories = ["compilers", "embedded", "no-std", "virtualization", "wasm"] tinywasm = { path = "crates/tinywasm", version = "0.11.0-pre.0", default-features = false } tinywasm-parser = { path = "crates/parser", version = "0.11.0-pre.0", default-features = false } tinywasm-types = { path = "crates/types", version = "0.11.0-pre.0", default-features = false } +tinywasm-wasi = { path = "crates/wasi", version = "0.11.0-pre.0" } anyhow = "1.0" log = "0.4" @@ -37,6 +38,12 @@ wat = "1.259" criterion = { version = "0.8", default-features = false, features = ["cargo_bench_support", "rayon"] } +[workspace.lints.cargo] +unused_dependencies = "allow" # false-positive on libm + +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ["cfg(rust_analyzer)"] } + [[example]] name = "rust" test = false @@ -61,12 +68,13 @@ name = "tinywasm_modes" anyhow.workspace = true criterion.workspace = true pretty_env_logger.workspace = true -tinywasm = { path = "crates/tinywasm" } +tinywasm = { path = "crates/tinywasm", features = ["state"] } tinywasm-parser.workspace = true +tinywasm-wasi.workspace = true wat.workspace = true -[lints.cargo] -unused_dependencies = "allow" # false-positive on libm +[lints] +workspace = true [profile.bench] opt-level = 3 diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 22f1bf8..aff21a2 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -38,6 +38,7 @@ tinywasm = { workspace = true, features = [ "log", "std", ] } +tinywasm-wasi.workspace = true wasm-testsuite = { workspace = true, optional = true } wast = { workspace = true, optional = true } wat = { workspace = true, optional = true } @@ -52,3 +53,6 @@ default = ["wast", "wat"] tests = ["dep:serde", "dep:serde_json", "dep:wasm-testsuite", "wast"] wast = ["dep:wast"] wat = ["dep:wat"] + +[lints] +workspace = true diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index f868beb..3cd3097 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -32,5 +32,5 @@ std = ["tinywasm-types/std", "wasmparser/std"] # validate WebAssembly while parsing validate = ["wasmparser/features", "wasmparser/validate"] -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ["cfg(rust_analyzer)"] } +[lints] +workspace = true diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 15b151c..9ed5fa7 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -132,3 +132,6 @@ nightly-tail-calls = [] # note: for x86 backend selection, compile with x86-64-v3 target features # (for example: `RUSTFLAGS="-C target-cpu=x86-64-v3"`) simd-x86 = [] + +[lints] +workspace = true diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 4046896..3837fdc 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -28,3 +28,6 @@ std = ["serde?/std"] # support targets without native atomic CAS portable-atomic = ["dep:portable-atomic-util"] + +[lints] +workspace = true diff --git a/crates/wasi/Cargo.toml b/crates/wasi/Cargo.toml new file mode 100644 index 0000000..e4d0ef0 --- /dev/null +++ b/crates/wasi/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "tinywasm-wasi" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +description = "WASI support for TinyWasm" +repository.workspace = true +license.workspace = true +keywords = ["tinywasm", "wasi", "wasm", "webassembly"] +categories = ["wasm"] +publish = false + +[dependencies] +cap-fs-ext = "4.0.3" +cap-std = "4.0.3" +getrandom = "0.4.3" +rustix = { version = "1.1.4", features = ["event", "fs", "net"] } +tinywasm = { workspace = true, default-features = false, features = ["state"] } + +[dev-dependencies] +tinywasm = { workspace = true, features = ["parser", "state"] } +wat.workspace = true + +[lints] +workspace = true diff --git a/crates/wasi/README.md b/crates/wasi/README.md new file mode 100644 index 0000000..1c173aa --- /dev/null +++ b/crates/wasi/README.md @@ -0,0 +1,10 @@ +# tinywasm-wasi + +Experimental WASI support for TinyWasm mainly targeting \*nix systems (Windows support is very limited). Currently unreleased. + +Some behavior is based on the Bytecode Alliance `wasi-common` and +`wasmtime-wasi` implementations. + +## Future WASI support + +Preview 2 and 3 are not planned for TinyWasm, we're probably going to wait for the final WASI 1.0 release and implement that instead. diff --git a/crates/wasi/src/lib.rs b/crates/wasi/src/lib.rs new file mode 100644 index 0000000..ef47a4d --- /dev/null +++ b/crates/wasi/src/lib.rs @@ -0,0 +1,4 @@ +//! WASI support for TinyWasm. + +/// WASI Preview 1 +pub mod p1; diff --git a/crates/wasi/src/p1/abi.rs b/crates/wasi/src/p1/abi.rs new file mode 100644 index 0000000..c331a6b --- /dev/null +++ b/crates/wasi/src/p1/abi.rs @@ -0,0 +1,300 @@ +use std::ffi::OsStr; +use std::io; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use cap_fs_ext::{MetadataExt, SystemTimeSpec}; +use cap_std::fs::Metadata; + +#[derive(Clone, Copy)] +pub(super) struct Errno(u16); + +impl From for i32 { + fn from(errno: Errno) -> Self { + i32::from(errno.0) + } +} + +pub(super) const SUCCESS: Errno = Errno(0); +pub(super) const ACCESS: Errno = Errno(2); +pub(super) const ADDRINUSE: Errno = Errno(3); +pub(super) const ADDRNOTAVAIL: Errno = Errno(4); +pub(super) const AGAIN: Errno = Errno(6); +pub(super) const BADF: Errno = Errno(8); +pub(super) const CONNABORTED: Errno = Errno(13); +pub(super) const CONNREFUSED: Errno = Errno(14); +pub(super) const CONNRESET: Errno = Errno(15); +pub(super) const EXIST: Errno = Errno(20); +pub(super) const FAULT: Errno = Errno(21); +pub(super) const FBIG: Errno = Errno(22); +pub(super) const ILSEQ: Errno = Errno(25); +pub(super) const INTR: Errno = Errno(27); +pub(super) const INVAL: Errno = Errno(28); +pub(super) const IO: Errno = Errno(29); +pub(super) const ISDIR: Errno = Errno(31); +pub(super) const LOOP: Errno = Errno(32); +pub(super) const MFILE: Errno = Errno(33); +pub(super) const MLINK: Errno = Errno(34); +pub(super) const NAMETOOLONG: Errno = Errno(37); +pub(super) const NOMEM: Errno = Errno(48); +pub(super) const NOENT: Errno = Errno(44); +pub(super) const NOSPC: Errno = Errno(51); +pub(super) const NOTCONN: Errno = Errno(53); +pub(super) const NOTDIR: Errno = Errno(54); +pub(super) const NOTEMPTY: Errno = Errno(55); +pub(super) const NOTSOCK: Errno = Errno(57); +pub(super) const NOTSUP: Errno = Errno(58); +pub(super) const OVERFLOW: Errno = Errno(61); +pub(super) const PIPE: Errno = Errno(64); +pub(super) const ROFS: Errno = Errno(69); +pub(super) const SPIPE: Errno = Errno(70); +pub(super) const TIMEDOUT: Errno = Errno(73); +pub(super) const XDEV: Errno = Errno(75); +pub(super) const NOTCAPABLE: Errno = Errno(76); + +pub(super) const FILETYPE_UNKNOWN: u8 = 0; +pub(super) const FILETYPE_BLOCK_DEVICE: u8 = 1; +pub(super) const FILETYPE_CHARACTER_DEVICE: u8 = 2; +pub(super) const FILETYPE_DIRECTORY: u8 = 3; +pub(super) const FILETYPE_REGULAR_FILE: u8 = 4; +pub(super) const FILETYPE_SOCKET_DGRAM: u8 = 5; +pub(super) const FILETYPE_SOCKET_STREAM: u8 = 6; +pub(super) const FILETYPE_SYMBOLIC_LINK: u8 = 7; + +pub(super) const FDFLAG_APPEND: u16 = 1; +pub(super) const FDFLAG_DSYNC: u16 = 2; +pub(super) const FDFLAG_NONBLOCK: u16 = 4; +pub(super) const FDFLAG_RSYNC: u16 = 8; +pub(super) const FDFLAG_SYNC: u16 = 16; +pub(super) const FDFLAGS_ALL: u16 = 31; + +pub(super) const OFLAG_CREAT: u16 = 1; +pub(super) const OFLAG_DIRECTORY: u16 = 2; +pub(super) const OFLAG_EXCL: u16 = 4; +pub(super) const OFLAG_TRUNC: u16 = 8; +pub(super) const OFLAGS_ALL: u16 = 15; +pub(super) const LOOKUP_SYMLINK_FOLLOW: u32 = 1; + +pub(super) const RIGHT_FD_DATASYNC: u64 = 1 << 0; +pub(super) const RIGHT_FD_READ: u64 = 1 << 1; +pub(super) const RIGHT_FD_SEEK: u64 = 1 << 2; +pub(super) const RIGHT_FD_FDSTAT_SET_FLAGS: u64 = 1 << 3; +pub(super) const RIGHT_FD_SYNC: u64 = 1 << 4; +pub(super) const RIGHT_FD_TELL: u64 = 1 << 5; +pub(super) const RIGHT_FD_WRITE: u64 = 1 << 6; +pub(super) const RIGHT_FD_ADVISE: u64 = 1 << 7; +pub(super) const RIGHT_FD_ALLOCATE: u64 = 1 << 8; +pub(super) const RIGHT_PATH_CREATE_DIRECTORY: u64 = 1 << 9; +pub(super) const RIGHT_PATH_CREATE_FILE: u64 = 1 << 10; +pub(super) const RIGHT_PATH_LINK_SOURCE: u64 = 1 << 11; +pub(super) const RIGHT_PATH_LINK_TARGET: u64 = 1 << 12; +pub(super) const RIGHT_PATH_OPEN: u64 = 1 << 13; +pub(super) const RIGHT_FD_READDIR: u64 = 1 << 14; +pub(super) const RIGHT_PATH_READLINK: u64 = 1 << 15; +pub(super) const RIGHT_PATH_RENAME_SOURCE: u64 = 1 << 16; +pub(super) const RIGHT_PATH_RENAME_TARGET: u64 = 1 << 17; +pub(super) const RIGHT_PATH_FILESTAT_GET: u64 = 1 << 18; +pub(super) const RIGHT_PATH_FILESTAT_SET_SIZE: u64 = 1 << 19; +pub(super) const RIGHT_PATH_FILESTAT_SET_TIMES: u64 = 1 << 20; +pub(super) const RIGHT_FD_FILESTAT_GET: u64 = 1 << 21; +pub(super) const RIGHT_FD_FILESTAT_SET_SIZE: u64 = 1 << 22; +pub(super) const RIGHT_FD_FILESTAT_SET_TIMES: u64 = 1 << 23; +pub(super) const RIGHT_PATH_SYMLINK: u64 = 1 << 24; +pub(super) const RIGHT_PATH_REMOVE_DIRECTORY: u64 = 1 << 25; +pub(super) const RIGHT_PATH_UNLINK_FILE: u64 = 1 << 26; +pub(super) const RIGHT_POLL_FD_READWRITE: u64 = 1 << 27; +pub(super) const RIGHT_SOCK_SHUTDOWN: u64 = 1 << 28; +pub(super) const RIGHT_SOCK_ACCEPT: u64 = 1 << 29; +pub(super) const FILE_RIGHTS: u64 = RIGHT_FD_DATASYNC + | RIGHT_FD_READ + | RIGHT_FD_SEEK + | RIGHT_FD_FDSTAT_SET_FLAGS + | RIGHT_FD_SYNC + | RIGHT_FD_TELL + | RIGHT_FD_WRITE + | RIGHT_FD_ADVISE + | RIGHT_FD_ALLOCATE + | RIGHT_FD_FILESTAT_GET + | RIGHT_FD_FILESTAT_SET_SIZE + | RIGHT_FD_FILESTAT_SET_TIMES + | RIGHT_POLL_FD_READWRITE; +pub(super) const DIRECTORY_RIGHTS: u64 = RIGHT_PATH_CREATE_DIRECTORY + | RIGHT_PATH_CREATE_FILE + | RIGHT_PATH_LINK_SOURCE + | RIGHT_PATH_LINK_TARGET + | RIGHT_PATH_OPEN + | RIGHT_FD_READDIR + | RIGHT_PATH_READLINK + | RIGHT_PATH_RENAME_SOURCE + | RIGHT_PATH_RENAME_TARGET + | RIGHT_PATH_FILESTAT_GET + | RIGHT_PATH_FILESTAT_SET_SIZE + | RIGHT_PATH_FILESTAT_SET_TIMES + | RIGHT_FD_FILESTAT_GET + | RIGHT_FD_FILESTAT_SET_TIMES + | RIGHT_PATH_SYMLINK + | RIGHT_PATH_REMOVE_DIRECTORY + | RIGHT_PATH_UNLINK_FILE; + +pub(super) const FSTFLAG_ATIM: u16 = 1; +pub(super) const FSTFLAG_ATIM_NOW: u16 = 2; +pub(super) const FSTFLAG_MTIM: u16 = 4; +pub(super) const FSTFLAG_MTIM_NOW: u16 = 8; +pub(super) const FSTFLAGS_ALL: u16 = 15; + +pub(super) fn io_errno(error: &io::Error) -> Errno { + use io::ErrorKind; + match error.kind() { + ErrorKind::NotFound => NOENT, + ErrorKind::PermissionDenied => ACCESS, + ErrorKind::AddrInUse => ADDRINUSE, + ErrorKind::AddrNotAvailable => ADDRNOTAVAIL, + ErrorKind::AlreadyExists => EXIST, + ErrorKind::ConnectionAborted => CONNABORTED, + ErrorKind::ConnectionRefused => CONNREFUSED, + ErrorKind::ConnectionReset => CONNRESET, + ErrorKind::InvalidInput | ErrorKind::InvalidData => INVAL, + ErrorKind::WouldBlock => AGAIN, + ErrorKind::WriteZero | ErrorKind::UnexpectedEof => IO, + ErrorKind::BrokenPipe => PIPE, + ErrorKind::StorageFull => NOSPC, + ErrorKind::NotADirectory => NOTDIR, + ErrorKind::NotConnected => NOTCONN, + ErrorKind::IsADirectory => ISDIR, + ErrorKind::DirectoryNotEmpty => NOTEMPTY, + ErrorKind::FileTooLarge => FBIG, + ErrorKind::CrossesDevices => XDEV, + ErrorKind::Interrupted => INTR, + ErrorKind::OutOfMemory => NOMEM, + ErrorKind::ReadOnlyFilesystem => ROFS, + ErrorKind::TooManyLinks => MLINK, + ErrorKind::TimedOut => TIMEDOUT, + ErrorKind::Unsupported => NOTSUP, + _ => platform_io_errno(error), + } +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +fn platform_io_errno(error: &io::Error) -> Errno { + match error.raw_os_error() { + Some(36) => NAMETOOLONG, + Some(40) => LOOP, + _ => IO, + } +} + +#[cfg(not(any(target_os = "android", target_os = "linux")))] +fn platform_io_errno(_error: &io::Error) -> Errno { + IO +} + +impl From for Errno { + fn from(error: rustix::io::Errno) -> Self { + use rustix::io::Errno as E; + match error { + E::INTR => INTR, + E::ACCESS | E::PERM => ACCESS, + E::BADF => BADF, + E::INVAL => INVAL, + E::MFILE => MFILE, + E::NOMEM => NOMEM, + E::NOSPC => NOSPC, + E::NOSYS | E::NOTSUP => NOTSUP, + E::XDEV => XDEV, + E::LOOP => LOOP, + _ => io_errno(&io::Error::from(error)), + } + } +} + +pub(super) fn path_errno(error: &io::Error) -> Errno { + if error.kind() == io::ErrorKind::PermissionDenied { NOTCAPABLE } else { io_errno(error) } +} + +pub(super) fn file_type(metadata: &Metadata) -> u8 { + use cap_fs_ext::FileTypeExt; + + let ty = metadata.file_type(); + if ty.is_dir() { + FILETYPE_DIRECTORY + } else if ty.is_file() { + FILETYPE_REGULAR_FILE + } else if ty.is_symlink() { + FILETYPE_SYMBOLIC_LINK + } else if ty.is_block_device() { + FILETYPE_BLOCK_DEVICE + } else if ty.is_char_device() { + FILETYPE_CHARACTER_DEVICE + } else if ty.is_socket() { + FILETYPE_SOCKET_STREAM + } else { + FILETYPE_UNKNOWN + } +} + +fn timestamp(time: io::Result) -> u64 { + time.ok() + .and_then(|time| time.into_std().duration_since(UNIX_EPOCH).ok()) + .and_then(|duration| u64::try_from(duration.as_nanos()).ok()) + .unwrap_or(0) +} + +pub(super) fn realtime_now() -> u64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .ok() + .and_then(|duration| u64::try_from(duration.as_nanos()).ok()) + .unwrap_or(0) +} + +pub(super) fn filestat(metadata: &Metadata) -> [u8; 64] { + let mut bytes = [0; 64]; + put(&mut bytes, 0, metadata.dev().to_le_bytes()); + put(&mut bytes, 8, metadata.ino().to_le_bytes()); + bytes[16] = file_type(metadata); + put(&mut bytes, 24, metadata.nlink().to_le_bytes()); + put(&mut bytes, 32, metadata.len().to_le_bytes()); + put(&mut bytes, 40, timestamp(metadata.accessed()).to_le_bytes()); + put(&mut bytes, 48, timestamp(metadata.modified()).to_le_bytes()); + put(&mut bytes, 56, status_change_timestamp(metadata).to_le_bytes()); + bytes +} + +fn status_change_timestamp(metadata: &Metadata) -> u64 { + #[cfg(unix)] + { + let seconds = cap_std::fs::MetadataExt::ctime(metadata); + let nanoseconds = cap_std::fs::MetadataExt::ctime_nsec(metadata); + if seconds < 0 || nanoseconds < 0 { + return 0; + } + (seconds as u64).saturating_mul(1_000_000_000).saturating_add(nanoseconds as u64) + } + #[cfg(not(unix))] + timestamp(metadata.created()) +} + +pub(super) fn time_spec(flags: u16, explicit: u16, now: u16, timestamp: u64) -> Option { + if flags & now != 0 { + Some(SystemTimeSpec::SymbolicNow) + } else if flags & explicit != 0 { + Some(SystemTimeSpec::Absolute(cap_std::time::SystemTime::from_std( + UNIX_EPOCH + Duration::from_nanos(timestamp), + ))) + } else { + None + } +} + +pub(super) fn os_bytes(value: &OsStr) -> Vec { + #[cfg(unix)] + { + use std::os::unix::ffi::OsStrExt; + value.as_bytes().to_vec() + } + #[cfg(not(unix))] + value.to_string_lossy().into_owned().into_bytes() +} + +pub(super) fn put(buffer: &mut [u8], offset: usize, bytes: [u8; N]) { + buffer[offset..offset + N].copy_from_slice(&bytes); +} diff --git a/crates/wasi/src/p1/ctx.rs b/crates/wasi/src/p1/ctx.rs new file mode 100644 index 0000000..e7b8652 --- /dev/null +++ b/crates/wasi/src/p1/ctx.rs @@ -0,0 +1,293 @@ +use std::fmt::{Display, Formatter}; +use std::net::{TcpListener, TcpStream, UdpSocket}; +use std::path::Path; + +use cap_std::ambient_authority; +use cap_std::fs::{Dir, File}; +use tinywasm::{Error, FuncContext}; + +use super::abi::*; + +pub(super) const MAX_DESCRIPTORS: usize = 4096; +const SOCKET_RIGHTS: u64 = RIGHT_FD_READ + | RIGHT_FD_WRITE + | RIGHT_FD_FDSTAT_SET_FLAGS + | RIGHT_FD_FILESTAT_GET + | RIGHT_POLL_FD_READWRITE + | RIGHT_SOCK_SHUTDOWN; + +pub(super) enum Resource { + Stdin, + Stdout, + Stderr, + File(File), + Directory(Dir), + TcpListener(TcpListener), + TcpStream(TcpStream), + UdpSocket(UdpSocket), +} + +pub(super) struct Descriptor { + pub(super) resource: Resource, + pub(super) rights: u64, + pub(super) inheriting_rights: u64, + pub(super) flags: u16, + pub(super) preopen_path: Option>, +} + +impl Descriptor { + pub(super) fn file_type(&self) -> u8 { + match &self.resource { + Resource::Stdin | Resource::Stdout | Resource::Stderr => FILETYPE_CHARACTER_DEVICE, + Resource::File(_) => FILETYPE_REGULAR_FILE, + Resource::Directory(_) => FILETYPE_DIRECTORY, + Resource::TcpListener(_) | Resource::TcpStream(_) => FILETYPE_SOCKET_STREAM, + Resource::UdpSocket(_) => FILETYPE_SOCKET_DGRAM, + } + } + + pub(super) fn require_rights(&self, rights: u64) -> Result<(), Errno> { + if self.rights & rights == rights { Ok(()) } else { Err(super::abi::NOTCAPABLE) } + } +} + +/// Configures the host resources available to a WASI Preview 1 command. +pub struct WasiCtx { + pub(super) args: Vec>, + pub(super) env: Vec>, + pub(super) descriptors: Vec>, + pub(super) exit_status: Option, + pub(super) monotonic_start: std::time::Instant, +} + +impl Default for WasiCtx { + fn default() -> Self { + Self { + args: Vec::new(), + env: Vec::new(), + descriptors: vec![None, None, None], + exit_status: None, + monotonic_start: std::time::Instant::now(), + } + } +} + +impl WasiCtx { + /// Creates an empty context without access to host standard I/O or files. + pub fn new() -> Self { + Self::default() + } + + /// Sets UTF-8 command-line arguments visible to the guest. + pub fn with_args(self, args: impl IntoIterator>) -> Result { + self.with_args_bytes(args.into_iter().map(|value| value.into().into_bytes())) + } + + /// Sets byte command-line arguments visible to the guest. + pub fn with_args_bytes(mut self, args: impl IntoIterator>>) -> Result { + self.args = args.into_iter().map(|value| validate_bytes(value.into())).collect::>()?; + Ok(self) + } + + /// Sets UTF-8 environment variables visible to the guest. + pub fn with_env( + self, + env: impl IntoIterator, impl Into)>, + ) -> Result { + self.with_env_bytes(env.into_iter().map(|(key, value)| (key.into().into_bytes(), value.into().into_bytes()))) + } + + /// Sets byte environment variables visible to the guest. + pub fn with_env_bytes( + mut self, + env: impl IntoIterator>, impl Into>)>, + ) -> Result { + self.env = env + .into_iter() + .map(|(key, value)| { + let mut entry = key.into(); + entry.push(b'='); + entry.extend(value.into()); + validate_bytes(entry) + }) + .collect::>()?; + Ok(self) + } + + /// Allows the guest to read inherited standard input. + pub fn inherit_stdin(self) -> Self { + self.inherit_fd(0, Resource::Stdin, RIGHT_FD_READ) + } + + /// Allows the guest to write inherited standard output. + pub fn inherit_stdout(self) -> Self { + self.inherit_fd(1, Resource::Stdout, RIGHT_FD_WRITE) + } + + /// Allows the guest to write inherited standard error. + pub fn inherit_stderr(self) -> Self { + self.inherit_fd(2, Resource::Stderr, RIGHT_FD_WRITE) + } + + /// Allows the guest to use inherited standard input, output, and error. + pub fn inherit_stdio(self) -> Self { + self.inherit_stdin().inherit_stdout().inherit_stderr() + } + + /// Adds a capability directory and returns it as a guest preopen at fd 3 or above. + pub fn preopen_dir( + mut self, + host_path: impl AsRef, + guest_path: impl AsRef<[u8]>, + ) -> Result { + let guest_path = validate_bytes(guest_path.as_ref().to_vec())?; + if guest_path.is_empty() { + return Err(WasiCtxError::InvalidPreopenPath); + } + let dir = Dir::open_ambient_dir(host_path, ambient_authority()).map_err(WasiCtxError::Io)?; + self.insert_descriptor(Descriptor { + resource: Resource::Directory(dir), + rights: DIRECTORY_RIGHTS, + inheriting_rights: DIRECTORY_RIGHTS | FILE_RIGHTS, + flags: 0, + preopen_path: Some(guest_path), + }) + .map_err(|_| WasiCtxError::TooManyDescriptors)?; + Ok(self) + } + + /// Inserts a TCP listener capability and returns its guest file descriptor. + pub fn insert_tcp_listener(&mut self, listener: TcpListener) -> Result { + listener.set_nonblocking(false).map_err(WasiCtxError::Io)?; + self.insert_descriptor(Descriptor { + resource: Resource::TcpListener(listener), + rights: RIGHT_FD_READ + | RIGHT_FD_FDSTAT_SET_FLAGS + | RIGHT_FD_FILESTAT_GET + | RIGHT_POLL_FD_READWRITE + | RIGHT_SOCK_ACCEPT, + inheriting_rights: SOCKET_RIGHTS, + flags: 0, + preopen_path: None, + }) + .map_err(|_| WasiCtxError::TooManyDescriptors) + } + + /// Inserts a connected TCP stream capability and returns its guest file descriptor. + pub fn insert_tcp_stream(&mut self, stream: TcpStream) -> Result { + self.insert_socket(Resource::TcpStream(stream)) + } + + /// Inserts a UDP socket capability and returns its guest file descriptor. + /// + /// `sock_send` requires the supplied socket to be connected. Receiving is + /// supported for connected and unconnected sockets. + pub fn insert_udp_socket(&mut self, socket: UdpSocket) -> Result { + self.insert_socket(Resource::UdpSocket(socket)) + } + + /// Returns the status supplied to `proc_exit`, if it was called. + pub fn exit_status(&self) -> Option { + self.exit_status + } + + /// Takes and clears the status supplied to `proc_exit`. + pub fn take_exit_status(&mut self) -> Option { + self.exit_status.take() + } + + pub(super) fn descriptor(&self, fd: i32) -> Result<&Descriptor, Errno> { + self.descriptors.get(fd as u32 as usize).and_then(Option::as_ref).ok_or(super::abi::BADF) + } + + pub(super) fn descriptor_mut(&mut self, fd: i32) -> Result<&mut Descriptor, Errno> { + self.descriptors.get_mut(fd as u32 as usize).and_then(Option::as_mut).ok_or(super::abi::BADF) + } + + pub(super) fn insert_descriptor(&mut self, descriptor: Descriptor) -> Result { + if let Some((index, slot)) = self.descriptors.iter_mut().enumerate().skip(3).find(|(_, slot)| slot.is_none()) { + *slot = Some(descriptor); + Ok(index as u32) + } else { + if self.descriptors.len() >= MAX_DESCRIPTORS { + return Err(super::abi::MFILE); + } + let fd = self.descriptors.len() as u32; + self.descriptors.push(Some(descriptor)); + Ok(fd) + } + } + + fn inherit_fd(mut self, fd: usize, resource: Resource, rights: u64) -> Self { + self.descriptors[fd] = Some(Descriptor { + resource, + rights: rights | RIGHT_FD_FILESTAT_GET | RIGHT_POLL_FD_READWRITE, + inheriting_rights: 0, + flags: 0, + preopen_path: None, + }); + self + } + + fn insert_socket(&mut self, resource: Resource) -> Result { + match &resource { + Resource::TcpStream(stream) => stream.set_nonblocking(false), + Resource::UdpSocket(socket) => socket.set_nonblocking(false), + _ => unreachable!(), + } + .map_err(WasiCtxError::Io)?; + self.insert_descriptor(Descriptor { + resource, + rights: SOCKET_RIGHTS, + inheriting_rights: 0, + flags: 0, + preopen_path: None, + }) + .map_err(|_| WasiCtxError::TooManyDescriptors) + } +} + +/// An invalid WASI context configuration. +#[derive(Debug)] +pub enum WasiCtxError { + /// An argument, environment variable, or guest path contains a nul byte. + NulByte, + /// A preopen guest path is empty. + InvalidPreopenPath, + /// A host preopen directory could not be opened. + Io(std::io::Error), + /// The context has reached its descriptor limit. + TooManyDescriptors, +} + +impl Display for WasiCtxError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Self::NulByte => f.write_str("WASI strings cannot contain nul bytes"), + Self::InvalidPreopenPath => f.write_str("WASI preopen guest paths cannot be empty"), + Self::Io(error) => write!(f, "failed to configure WASI host resource: {error}"), + Self::TooManyDescriptors => f.write_str("WASI descriptor limit reached"), + } + } +} + +impl std::error::Error for WasiCtxError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::Io(error) => Some(error), + _ => None, + } + } +} + +fn validate_bytes(value: Vec) -> Result, WasiCtxError> { + if value.contains(&0) { Err(WasiCtxError::NulByte) } else { Ok(value) } +} + +pub(super) fn state<'a>(ctx: &'a FuncContext<'_>) -> tinywasm::Result<&'a WasiCtx> { + ctx.state::().ok_or_else(|| Error::Other("WasiCtx is missing from the store".into())) +} + +pub(super) fn state_mut<'a>(ctx: &'a mut FuncContext<'_>) -> tinywasm::Result<&'a mut WasiCtx> { + ctx.state_mut::().ok_or_else(|| Error::Other("WasiCtx is missing from the store".into())) +} diff --git a/crates/wasi/src/p1/imports/clock.rs b/crates/wasi/src/p1/imports/clock.rs new file mode 100644 index 0000000..d8eedbf --- /dev/null +++ b/crates/wasi/src/p1/imports/clock.rs @@ -0,0 +1,28 @@ +use tinywasm::FuncContext; + +use crate::p1::abi::{Errno, INVAL, SUCCESS, realtime_now}; +use crate::p1::ctx::state; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +pub(super) fn clock_res_get(mut ctx: FuncContext<'_>, (clock_id, result_ptr): (i32, i32)) -> WasiResult { + if !matches!(clock_id, 0 | 1) { + return Ok(INVAL); + } + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &1_u64.to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn clock_time_get( + mut ctx: FuncContext<'_>, + (clock_id, _precision, result_ptr): (i32, i64, i32), +) -> WasiResult { + let timestamp = match clock_id { + 0 => realtime_now(), + 1 => state(&ctx)?.monotonic_start.elapsed().as_nanos().try_into().unwrap_or(u64::MAX), + _ => return Ok(INVAL), + }; + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, ×tamp.to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} diff --git a/crates/wasi/src/p1/imports/command.rs b/crates/wasi/src/p1/imports/command.rs new file mode 100644 index 0000000..129bf04 --- /dev/null +++ b/crates/wasi/src/p1/imports/command.rs @@ -0,0 +1,72 @@ +use tinywasm::FuncContext; + +use crate::p1::abi::{Errno, OVERFLOW, SUCCESS}; +use crate::p1::ctx::state; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +pub(super) fn args_sizes_get(ctx: FuncContext<'_>, pointers: (i32, i32)) -> WasiResult { + let sizes = sizes(&state(&ctx)?.args)?; + sizes_get(ctx, pointers, sizes) +} + +pub(super) fn environ_sizes_get(ctx: FuncContext<'_>, pointers: (i32, i32)) -> WasiResult { + let sizes = sizes(&state(&ctx)?.env)?; + sizes_get(ctx, pointers, sizes) +} + +fn sizes_get( + mut ctx: FuncContext<'_>, + (count_ptr, size_ptr): (i32, i32), + (count, size): (u32, u32), +) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, count_ptr as u32 as usize, 4)?; + memory.check_range(&ctx, size_ptr as u32 as usize, 4)?; + memory.write(ctx.store_mut(), count_ptr, &count.to_le_bytes())?; + Ok(memory.write(ctx.store_mut(), size_ptr, &size.to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} + +fn sizes(values: &[Vec]) -> Result<(u32, u32), Errno> { + Ok((values.len().try_into().map_err(|_| OVERFLOW)?, string_array_size(values).ok_or(OVERFLOW)?)) +} + +pub(super) fn args_get(ctx: FuncContext<'_>, pointers: (i32, i32)) -> WasiResult { + let values = state(&ctx)?.args.clone(); + array_get(ctx, pointers, values) +} + +pub(super) fn environ_get(ctx: FuncContext<'_>, pointers: (i32, i32)) -> WasiResult { + let values = state(&ctx)?.env.clone(); + array_get(ctx, pointers, values) +} + +fn array_get(mut ctx: FuncContext<'_>, (array_ptr, buffer_ptr): (i32, i32), values: Vec>) -> WasiResult { + let Some(pointer_len) = values.len().checked_mul(4) else { return Ok(OVERFLOW) }; + let Some(buffer_len) = string_array_size(&values).map(|value| value as usize) else { return Ok(OVERFLOW) }; + let array_offset = array_ptr as u32 as usize; + let buffer_offset = buffer_ptr as u32 as usize; + let mut pointers = Vec::with_capacity(pointer_len); + let mut buffer = Vec::with_capacity(buffer_len); + for value in values { + let Some(pointer) = buffer_offset.checked_add(buffer.len()).and_then(|value| u32::try_from(value).ok()) else { + return Ok(OVERFLOW); + }; + pointers.extend_from_slice(&pointer.to_le_bytes()); + buffer.extend_from_slice(&value); + buffer.push(0); + } + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, array_offset, pointers.len())?; + memory.check_range(&ctx, buffer_offset, buffer.len())?; + memory.write_at(ctx.store_mut(), array_offset, &pointers)?; + Ok(memory.write_at(ctx.store_mut(), buffer_offset, &buffer).map_or_else(|errno| errno, |()| SUCCESS)) +} + +fn string_array_size(values: &[Vec]) -> Option { + values + .iter() + .try_fold(0usize, |size, value| size.checked_add(value.len())?.checked_add(1)) + .and_then(|size| u32::try_from(size).ok()) +} diff --git a/crates/wasi/src/p1/imports/fd.rs b/crates/wasi/src/p1/imports/fd.rs new file mode 100644 index 0000000..18eb122 --- /dev/null +++ b/crates/wasi/src/p1/imports/fd.rs @@ -0,0 +1,423 @@ +use std::io::{Read, Seek, SeekFrom, Write}; + +use cap_fs_ext::{DirEntryExt, DirExt, MetadataExt}; +use cap_std::fs::FileExt; +use tinywasm::FuncContext; + +use crate::p1::abi::*; +use crate::p1::ctx::{MAX_DESCRIPTORS, Resource, state, state_mut}; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +pub(super) fn fd_close(mut ctx: FuncContext<'_>, fd: i32) -> WasiResult { + let index = fd as u32 as usize; + let Some(slot) = state_mut(&mut ctx)?.descriptors.get_mut(index) else { return Ok(BADF) }; + if slot.take().is_none() { Ok(BADF) } else { Ok(SUCCESS) } +} + +pub(super) fn fd_renumber(mut ctx: FuncContext<'_>, (from, to): (i32, i32)) -> WasiResult { + let from = from as u32 as usize; + let to = to as u32 as usize; + let wasi = state_mut(&mut ctx)?; + if from >= wasi.descriptors.len() || wasi.descriptors[from].is_none() { + return Ok(BADF); + } + if from == to { + return Ok(SUCCESS); + } + if to >= MAX_DESCRIPTORS { + return Ok(MFILE); + } + if to >= wasi.descriptors.len() { + wasi.descriptors.resize_with(to + 1, || None); + } + wasi.descriptors[to] = wasi.descriptors[from].take(); + Ok(SUCCESS) +} + +pub(super) fn fd_fdstat_get(mut ctx: FuncContext<'_>, (fd, result_ptr): (i32, i32)) -> WasiResult { + let descriptor = state(&ctx)?.descriptor(fd)?; + let mut bytes = [0; 24]; + bytes[0] = match &descriptor.resource { + Resource::File(file) => file_type(&file.metadata().map_err(|error| io_errno(&error))?), + _ => descriptor.file_type(), + }; + put(&mut bytes, 2, descriptor.flags.to_le_bytes()); + put(&mut bytes, 8, descriptor.rights.to_le_bytes()); + put(&mut bytes, 16, descriptor.inheriting_rights.to_le_bytes()); + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &bytes).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_fdstat_set_flags(mut ctx: FuncContext<'_>, (fd, flags): (i32, i32)) -> WasiResult { + let flags = flags as u32; + if flags > FDFLAGS_ALL.into() { + return Ok(INVAL); + } + if flags & u32::from(FDFLAG_DSYNC | FDFLAG_RSYNC | FDFLAG_SYNC) != 0 { + return Ok(INVAL); + } + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_FDSTAT_SET_FLAGS)?; + let flags = flags as u16; + let nonblocking = flags & FDFLAG_NONBLOCK != 0; + match &descriptor.resource { + Resource::TcpListener(listener) if flags == FDFLAG_NONBLOCK || flags == 0 => { + listener.set_nonblocking(nonblocking).map_err(|error| io_errno(&error))? + } + Resource::TcpStream(stream) if flags == FDFLAG_NONBLOCK || flags == 0 => { + stream.set_nonblocking(nonblocking).map_err(|error| io_errno(&error))? + } + Resource::UdpSocket(socket) if flags == FDFLAG_NONBLOCK || flags == 0 => { + socket.set_nonblocking(nonblocking).map_err(|error| io_errno(&error))? + } + Resource::TcpListener(_) | Resource::TcpStream(_) | Resource::UdpSocket(_) => return Ok(INVAL), + Resource::File(file) => set_file_status_flags(file, flags)?, + Resource::Stdin | Resource::Stdout | Resource::Stderr | Resource::Directory(_) => return Ok(BADF), + }; + descriptor.flags = flags; + Ok(SUCCESS) +} + +pub(super) fn fd_fdstat_set_rights( + mut ctx: FuncContext<'_>, + (fd, rights, inheriting_rights): (i32, i64, i64), +) -> WasiResult { + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + let rights = rights as u64; + let inheriting_rights = inheriting_rights as u64; + if rights & !descriptor.rights != 0 || inheriting_rights & !descriptor.inheriting_rights != 0 { + return Ok(NOTCAPABLE); + } + descriptor.rights = rights; + descriptor.inheriting_rights = inheriting_rights; + Ok(SUCCESS) +} + +pub(super) fn fd_filestat_get(mut ctx: FuncContext<'_>, (fd, result_ptr): (i32, i32)) -> WasiResult { + let descriptor = state(&ctx)?.descriptor(fd)?; + descriptor.require_rights(RIGHT_FD_FILESTAT_GET)?; + let bytes = match &descriptor.resource { + Resource::File(file) => filestat(&file.metadata().map_err(|error| io_errno(&error))?), + Resource::Directory(dir) => filestat(&dir.dir_metadata().map_err(|error| io_errno(&error))?), + Resource::Stdin + | Resource::Stdout + | Resource::Stderr + | Resource::TcpListener(_) + | Resource::TcpStream(_) + | Resource::UdpSocket(_) => { + let mut bytes = [0; 64]; + bytes[16] = descriptor.file_type(); + bytes + } + }; + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &bytes).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_filestat_set_size(mut ctx: FuncContext<'_>, (fd, size): (i32, i64)) -> WasiResult { + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_FILESTAT_SET_SIZE)?; + let Resource::File(file) = &descriptor.resource else { return Ok(ISDIR) }; + Ok(file.set_len(size as u64).map_or_else(|error| io_errno(&error), |()| SUCCESS)) +} + +pub(super) fn fd_filestat_set_times( + mut ctx: FuncContext<'_>, + (fd, atim, mtim, flags): (i32, i64, i64, i32), +) -> WasiResult { + let flags = flags as u32; + if flags > u32::from(FSTFLAGS_ALL) + || flags & u32::from(FSTFLAG_ATIM | FSTFLAG_ATIM_NOW) == u32::from(FSTFLAG_ATIM | FSTFLAG_ATIM_NOW) + || flags & u32::from(FSTFLAG_MTIM | FSTFLAG_MTIM_NOW) == u32::from(FSTFLAG_MTIM | FSTFLAG_MTIM_NOW) + { + return Ok(INVAL); + } + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_FILESTAT_SET_TIMES)?; + if flags == 0 { + return Ok(SUCCESS); + } + if let Resource::Directory(dir) = &descriptor.resource { + let atime = time_spec(flags as u16, FSTFLAG_ATIM, FSTFLAG_ATIM_NOW, atim as u64); + let mtime = time_spec(flags as u16, FSTFLAG_MTIM, FSTFLAG_MTIM_NOW, mtim as u64); + return Ok(dir.set_times(".", atime, mtime).map_or_else(|error| io_errno(&error), |()| SUCCESS)); + } + #[cfg(any(target_os = "android", target_os = "linux"))] + { + let Resource::File(file) = &descriptor.resource else { return Ok(NOTSUP) }; + let access = rustix_time(flags as u16, FSTFLAG_ATIM, FSTFLAG_ATIM_NOW, atim as u64)?; + let modification = rustix_time(flags as u16, FSTFLAG_MTIM, FSTFLAG_MTIM_NOW, mtim as u64)?; + let times = rustix::fs::Timestamps { last_access: access, last_modification: modification }; + Ok(rustix::fs::futimens(file, ×).map_or_else(Errno::from, |()| SUCCESS)) + } + #[cfg(not(any(target_os = "android", target_os = "linux")))] + { + let _ = (atim, mtim, descriptor); + Ok(NOTSUP) + } +} + +pub(super) fn fd_read(ctx: FuncContext<'_>, args: (i32, i32, i32, i32)) -> WasiResult { + read_from_fd(ctx, args, None) +} + +pub(super) fn fd_pread( + ctx: FuncContext<'_>, + (fd, iovecs_ptr, iovecs_len, offset, result_ptr): (i32, i32, i32, i64, i32), +) -> WasiResult { + read_from_fd(ctx, (fd, iovecs_ptr, iovecs_len, result_ptr), Some(offset as u64)) +} + +fn read_from_fd( + mut ctx: FuncContext<'_>, + (fd, iovecs_ptr, iovecs_len, result_ptr): (i32, i32, i32, i32), + offset: Option, +) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + let iovecs = memory.read_iovecs(&ctx, iovecs_ptr, iovecs_len)?; + memory.check_range(&ctx, result_ptr as u32 as usize, 4)?; + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_READ | if offset.is_some() { RIGHT_FD_SEEK } else { 0 })?; + let mut buffer = Vec::new(); + buffer.try_reserve_exact(iovecs.byte_len).map_err(|_| NOMEM)?; + buffer.resize(iovecs.byte_len, 0); + let read = match &mut descriptor.resource { + Resource::Stdin => std::io::stdin().lock().read(&mut buffer), + Resource::File(file) if let Some(offset) = offset => { + file.read_at(&mut buffer, checked_offset(offset, iovecs.byte_len)?) + } + Resource::File(file) => file.read(&mut buffer), + Resource::TcpStream(stream) => stream.read(&mut buffer), + Resource::UdpSocket(socket) => socket.recv(&mut buffer), + Resource::Directory(_) => return Ok(ISDIR), + _ => return Ok(BADF), + } + .map_err(|error| io_errno(&error))?; + memory.scatter(ctx.store_mut(), &iovecs, &buffer[..read])?; + Ok(memory.write(ctx.store_mut(), result_ptr, &(read as u32).to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_write(ctx: FuncContext<'_>, args: (i32, i32, i32, i32)) -> WasiResult { + write_to_fd(ctx, args, None) +} + +pub(super) fn fd_pwrite( + ctx: FuncContext<'_>, + (fd, iovecs_ptr, iovecs_len, offset, result_ptr): (i32, i32, i32, i64, i32), +) -> WasiResult { + write_to_fd(ctx, (fd, iovecs_ptr, iovecs_len, result_ptr), Some(offset as u64)) +} + +fn write_to_fd( + mut ctx: FuncContext<'_>, + (fd, iovecs_ptr, iovecs_len, result_ptr): (i32, i32, i32, i32), + offset: Option, +) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + let iovecs = memory.read_iovecs(&ctx, iovecs_ptr, iovecs_len)?; + memory.check_range(&ctx, result_ptr as u32 as usize, 4)?; + let data = memory.gather(&ctx, &iovecs)?; + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_WRITE | if offset.is_some() { RIGHT_FD_SEEK } else { 0 })?; + let written = match &mut descriptor.resource { + Resource::Stdout => std::io::stdout().lock().write(&data), + Resource::Stderr => std::io::stderr().lock().write(&data), + Resource::File(file) if let Some(offset) = offset => file.write_at(&data, checked_offset(offset, data.len())?), + Resource::File(file) => file.write(&data), + Resource::TcpStream(stream) => stream.write(&data), + Resource::UdpSocket(socket) => socket.send(&data), + Resource::Directory(_) => return Ok(ISDIR), + _ => return Ok(BADF), + } + .map_err(|error| io_errno(&error))?; + Ok(memory + .write(ctx.store_mut(), result_ptr, &(written as u32).to_le_bytes()) + .map_or_else(|errno| errno, |()| SUCCESS)) +} + +fn checked_offset(offset: u64, len: usize) -> Result { + offset.checked_add(len as u64).map(|_| offset).ok_or(OVERFLOW) +} + +#[cfg(unix)] +fn set_file_status_flags(file: &cap_std::fs::File, flags: u16) -> Result<(), Errno> { + let mut host_flags = rustix::fs::fcntl_getfl(file).map_err(Errno::from)?; + host_flags.set(rustix::fs::OFlags::APPEND, flags & FDFLAG_APPEND != 0); + host_flags.set(rustix::fs::OFlags::NONBLOCK, flags & FDFLAG_NONBLOCK != 0); + rustix::fs::fcntl_setfl(file, host_flags).map_err(Errno::from) +} + +#[cfg(not(unix))] +fn set_file_status_flags(_file: &cap_std::fs::File, _flags: u16) -> Result<(), Errno> { + Err(NOTSUP) +} + +pub(super) fn fd_seek( + mut ctx: FuncContext<'_>, + (fd, offset, whence, result_ptr): (i32, i64, i32, i32), +) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, result_ptr as u32 as usize, 8)?; + let position = match whence { + 0 if offset >= 0 => SeekFrom::Start(offset as u64), + 0 => return Ok(INVAL), + 1 => SeekFrom::Current(offset), + 2 => SeekFrom::End(offset), + _ => return Ok(INVAL), + }; + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(if whence == 1 && offset == 0 { RIGHT_FD_TELL } else { RIGHT_FD_SEEK })?; + let Resource::File(file) = &mut descriptor.resource else { return Ok(SPIPE) }; + let offset = file.seek(position).map_err(|error| io_errno(&error))?; + Ok(memory.write(ctx.store_mut(), result_ptr, &offset.to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_tell(mut ctx: FuncContext<'_>, (fd, result_ptr): (i32, i32)) -> WasiResult { + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_TELL)?; + let Resource::File(file) = &mut descriptor.resource else { return Ok(SPIPE) }; + let offset = file.stream_position().map_err(|error| io_errno(&error))?; + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &offset.to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_sync(ctx: FuncContext<'_>, fd: i32) -> WasiResult { + sync_fd(ctx, fd, false) +} + +pub(super) fn fd_datasync(ctx: FuncContext<'_>, fd: i32) -> WasiResult { + sync_fd(ctx, fd, true) +} + +fn sync_fd(mut ctx: FuncContext<'_>, fd: i32, data_only: bool) -> WasiResult { + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(if data_only { RIGHT_FD_DATASYNC } else { RIGHT_FD_SYNC })?; + let Resource::File(file) = &descriptor.resource else { return Ok(INVAL) }; + Ok((if data_only { file.sync_data() } else { file.sync_all() }).map_or_else(|error| io_errno(&error), |()| SUCCESS)) +} + +pub(super) fn fd_allocate(mut ctx: FuncContext<'_>, (fd, offset, len): (i32, i64, i64)) -> WasiResult { + let offset = offset as u64; + let len = len as u64; + if offset.checked_add(len).is_none() { + return Ok(FBIG); + } + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_ALLOCATE)?; + let Resource::File(_) = &descriptor.resource else { return Ok(BADF) }; + Ok(NOTSUP) +} + +pub(super) fn fd_advise( + mut ctx: FuncContext<'_>, + (fd, offset, len, advice): (i32, i64, i64, i32), +) -> WasiResult { + if !(0..=5).contains(&advice) { + return Ok(INVAL); + } + let descriptor = state_mut(&mut ctx)?.descriptor_mut(fd)?; + descriptor.require_rights(RIGHT_FD_ADVISE)?; + let Resource::File(file) = &descriptor.resource else { return Ok(BADF) }; + if (offset as u64).checked_add(len as u64).is_none() { + return Ok(OVERFLOW); + } + #[cfg(any(target_os = "android", target_os = "linux"))] + { + let advice = match advice { + 0 => rustix::fs::Advice::Normal, + 1 => rustix::fs::Advice::Sequential, + 2 => rustix::fs::Advice::Random, + 3 => rustix::fs::Advice::WillNeed, + 4 => rustix::fs::Advice::DontNeed, + 5 => rustix::fs::Advice::NoReuse, + _ => unreachable!(), + }; + Ok(rustix::fs::fadvise(file, offset as u64, std::num::NonZeroU64::new(len as u64), advice) + .map_or_else(Errno::from, |()| SUCCESS)) + } + #[cfg(not(any(target_os = "android", target_os = "linux")))] + { + let _ = (file, offset, len); + Ok(SUCCESS) + } +} + +pub(super) fn fd_prestat_get(mut ctx: FuncContext<'_>, (fd, result_ptr): (i32, i32)) -> WasiResult { + let descriptor = state(&ctx)?.descriptor(fd)?; + let Some(path) = &descriptor.preopen_path else { return Ok(BADF) }; + let Some(len) = u32::try_from(path.len()).ok() else { return Ok(OVERFLOW) }; + let mut bytes = [0; 8]; + put(&mut bytes, 4, len.to_le_bytes()); + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &bytes).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_prestat_dir_name( + mut ctx: FuncContext<'_>, + (fd, path_ptr, path_len): (i32, i32, i32), +) -> WasiResult { + let descriptor = state(&ctx)?.descriptor(fd)?; + let Some(path) = descriptor.preopen_path.clone() else { return Ok(BADF) }; + if path.len() > path_len as u32 as usize { + return Ok(NAMETOOLONG); + } + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), path_ptr, &path).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn fd_readdir( + mut ctx: FuncContext<'_>, + (fd, buffer_ptr, buffer_len, cookie, used_ptr): (i32, i32, i32, i64, i32), +) -> WasiResult { + let capacity = buffer_len as u32 as usize; + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, buffer_ptr as u32 as usize, buffer_len as u32 as usize)?; + memory.check_range(&ctx, used_ptr as u32 as usize, 4)?; + let descriptor = state(&ctx)?.descriptor(fd)?; + descriptor.require_rights(RIGHT_FD_READDIR)?; + let Resource::Directory(dir) = &descriptor.resource else { return Ok(NOTDIR) }; + let entries = dir.entries().map_err(|error| io_errno(&error))?; + let cookie = usize::try_from(cookie as u64).map_err(|_| OVERFLOW)?; + let mut output = Vec::new(); + output.try_reserve_exact(capacity).map_err(|_| NOMEM)?; + for (index, entry) in entries.enumerate().skip(cookie) { + let entry = entry.map_err(|error| io_errno(&error))?; + let name = os_bytes(&entry.file_name()); + let metadata = entry.full_metadata().map_err(|error| io_errno(&error))?; + let mut header = [0; 24]; + let Some(next) = u64::try_from(index).ok().and_then(|index| index.checked_add(1)) else { + return Ok(OVERFLOW); + }; + put(&mut header, 0, next.to_le_bytes()); + put(&mut header, 8, metadata.ino().to_le_bytes()); + put(&mut header, 16, u32::try_from(name.len()).unwrap_or(u32::MAX).to_le_bytes()); + header[20] = file_type(&metadata); + let remaining = capacity.saturating_sub(output.len()); + output.extend_from_slice(&header[..remaining.min(header.len())]); + let remaining = capacity.saturating_sub(output.len()); + output.extend_from_slice(&name[..remaining.min(name.len())]); + if output.len() == capacity { + break; + } + } + memory.write(ctx.store_mut(), buffer_ptr, &output)?; + Ok(memory + .write(ctx.store_mut(), used_ptr, &(output.len() as u32).to_le_bytes()) + .map_or_else(|errno| errno, |()| SUCCESS)) +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +fn rustix_time(flags: u16, explicit: u16, now: u16, timestamp: u64) -> Result { + if flags & now != 0 { + Ok(rustix::fs::Timespec { tv_sec: 0, tv_nsec: rustix::fs::UTIME_NOW }) + } else if flags & explicit != 0 { + Ok(rustix::fs::Timespec { + tv_sec: i64::try_from(timestamp / 1_000_000_000).map_err(|_| OVERFLOW)?, + tv_nsec: (timestamp % 1_000_000_000) as _, + }) + } else { + Ok(rustix::fs::Timespec { tv_sec: 0, tv_nsec: rustix::fs::UTIME_OMIT }) + } +} diff --git a/crates/wasi/src/p1/imports/mod.rs b/crates/wasi/src/p1/imports/mod.rs new file mode 100644 index 0000000..eff8d0f --- /dev/null +++ b/crates/wasi/src/p1/imports/mod.rs @@ -0,0 +1,101 @@ +mod clock; +mod command; +mod fd; +mod path; +mod poll; +mod process; +mod random; +mod sock; + +use tinywasm::{HostFunction, Imports}; + +use super::abi::Errno; + +const MODULE: &str = "wasi_snapshot_preview1"; + +type WasiResult = Result; + +enum WasiError { + Errno(Errno), + Host(tinywasm::Error), +} + +impl From for WasiError { + fn from(errno: Errno) -> Self { + Self::Errno(errno) + } +} + +impl From for WasiError { + fn from(error: tinywasm::Error) -> Self { + Self::Host(error) + } +} + +pub(super) fn register(imports: &mut Imports) { + register_import(imports, "args_get", command::args_get); + register_import(imports, "args_sizes_get", command::args_sizes_get); + register_import(imports, "environ_get", command::environ_get); + register_import(imports, "environ_sizes_get", command::environ_sizes_get); + register_import(imports, "clock_res_get", clock::clock_res_get); + register_import(imports, "clock_time_get", clock::clock_time_get); + register_import(imports, "fd_advise", fd::fd_advise); + register_import(imports, "fd_allocate", fd::fd_allocate); + register_import(imports, "fd_close", fd::fd_close); + register_import(imports, "fd_datasync", fd::fd_datasync); + register_import(imports, "fd_fdstat_get", fd::fd_fdstat_get); + register_import(imports, "fd_fdstat_set_flags", fd::fd_fdstat_set_flags); + register_import(imports, "fd_fdstat_set_rights", fd::fd_fdstat_set_rights); + register_import(imports, "fd_filestat_get", fd::fd_filestat_get); + register_import(imports, "fd_filestat_set_size", fd::fd_filestat_set_size); + register_import(imports, "fd_filestat_set_times", fd::fd_filestat_set_times); + register_import(imports, "fd_pread", fd::fd_pread); + register_import(imports, "fd_prestat_get", fd::fd_prestat_get); + register_import(imports, "fd_prestat_dir_name", fd::fd_prestat_dir_name); + register_import(imports, "fd_pwrite", fd::fd_pwrite); + register_import(imports, "fd_read", fd::fd_read); + register_import(imports, "fd_readdir", fd::fd_readdir); + register_import(imports, "fd_renumber", fd::fd_renumber); + register_import(imports, "fd_seek", fd::fd_seek); + register_import(imports, "fd_sync", fd::fd_sync); + register_import(imports, "fd_tell", fd::fd_tell); + register_import(imports, "fd_write", fd::fd_write); + register_import(imports, "path_create_directory", path::path_create_directory); + register_import(imports, "path_filestat_get", path::path_filestat_get); + register_import(imports, "path_filestat_set_times", path::path_filestat_set_times); + register_import(imports, "path_link", path::path_link); + register_import(imports, "path_open", path::path_open); + register_import(imports, "path_readlink", path::path_readlink); + register_import(imports, "path_remove_directory", path::path_remove_directory); + register_import(imports, "path_rename", path::path_rename); + register_import(imports, "path_symlink", path::path_symlink); + register_import(imports, "path_unlink_file", path::path_unlink_file); + register_import(imports, "poll_oneoff", poll::poll_oneoff); + imports.define(MODULE, "proc_exit", HostFunction::from(process::proc_exit)); + register_import(imports, "proc_raise", process::proc_raise); + register_import(imports, "sched_yield", process::sched_yield); + register_import(imports, "random_get", random::random_get); + register_import(imports, "sock_accept", sock::sock_accept); + register_import(imports, "sock_recv", sock::sock_recv); + register_import(imports, "sock_send", sock::sock_send); + register_import(imports, "sock_shutdown", sock::sock_shutdown); +} + +fn register_import

( + imports: &mut Imports, + name: &str, + function: fn(tinywasm::FuncContext<'_>, P) -> WasiResult, +) where + P: tinywasm::FromWasmValues + 'static, +{ + imports.define( + MODULE, + name, + HostFunction::from(move |ctx: tinywasm::FuncContext<'_>, args: P| -> tinywasm::Result { + match function(ctx, args) { + Ok(errno) | Err(WasiError::Errno(errno)) => Ok(errno.into()), + Err(WasiError::Host(error)) => Err(error), + } + }), + ); +} diff --git a/crates/wasi/src/p1/imports/path.rs b/crates/wasi/src/p1/imports/path.rs new file mode 100644 index 0000000..648f0cb --- /dev/null +++ b/crates/wasi/src/p1/imports/path.rs @@ -0,0 +1,258 @@ +use std::path::PathBuf; + +use cap_fs_ext::{DirExt, FollowSymlinks, OpenOptionsFollowExt, OpenOptionsMaybeDirExt, OpenOptionsSyncExt}; +use cap_std::fs::{Dir, OpenOptions}; +use tinywasm::FuncContext; + +use crate::p1::abi::*; +use crate::p1::ctx::{Descriptor, Resource, state, state_mut}; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +const MAX_PATH_BYTES: usize = 4096; + +pub(super) fn path_create_directory( + ctx: FuncContext<'_>, + (fd, path_ptr, path_len): (i32, i32, i32), +) -> WasiResult { + let path = guest_path(&ctx, path_ptr, path_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_CREATE_DIRECTORY)?; + Ok(dir.create_dir(path).map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +pub(super) fn path_remove_directory( + ctx: FuncContext<'_>, + (fd, path_ptr, path_len): (i32, i32, i32), +) -> WasiResult { + let path = guest_path(&ctx, path_ptr, path_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_REMOVE_DIRECTORY)?; + Ok(dir.remove_dir(path).map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +pub(super) fn path_unlink_file(ctx: FuncContext<'_>, (fd, path_ptr, path_len): (i32, i32, i32)) -> WasiResult { + let path = guest_path(&ctx, path_ptr, path_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_UNLINK_FILE)?; + Ok(dir.remove_file_or_symlink(path).map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +pub(super) fn path_open( + mut ctx: FuncContext<'_>, + (fd, lookup_flags, path_ptr, path_len, open_flags, rights, inheriting_rights, fd_flags, result_ptr): ( + i32, + i32, + i32, + i32, + i32, + i64, + i64, + i32, + i32, + ), +) -> WasiResult { + let lookup_flags = lookup_flags as u32; + if lookup_flags & !LOOKUP_SYMLINK_FOLLOW != 0 + || open_flags as u32 > OFLAGS_ALL.into() + || fd_flags as u32 > FDFLAGS_ALL.into() + { + return Ok(INVAL); + } + let open_flags = open_flags as u16; + let fd_flags = fd_flags as u16; + if fd_flags & (FDFLAG_DSYNC | FDFLAG_RSYNC | FDFLAG_SYNC) != 0 { + return Ok(NOTSUP); + } + let follow = lookup_flags & LOOKUP_SYMLINK_FOLLOW != 0; + let create = open_flags & OFLAG_CREAT != 0; + let exclusive = open_flags & OFLAG_EXCL != 0; + let truncate = open_flags & OFLAG_TRUNC != 0; + if exclusive && !create { + return Ok(INVAL); + } + if open_flags & OFLAG_DIRECTORY != 0 && (create || truncate) { + return Ok(ISDIR); + } + let path = guest_path(&ctx, path_ptr, path_len)?; + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, result_ptr as u32 as usize, 4)?; + let parent = state(&ctx)?.descriptor(fd)?; + parent.require_rights(RIGHT_PATH_OPEN)?; + let rights = rights as u64; + let inheriting_rights = inheriting_rights as u64; + if rights & !parent.inheriting_rights != 0 || inheriting_rights & !parent.inheriting_rights != 0 { + return Ok(NOTCAPABLE); + } + if create && parent.rights & RIGHT_PATH_CREATE_FILE == 0 { + return Ok(NOTCAPABLE); + } + if truncate && parent.rights & RIGHT_PATH_FILESTAT_SET_SIZE == 0 { + return Ok(NOTCAPABLE); + } + let Resource::Directory(parent_dir) = &parent.resource else { return Ok(NOTDIR) }; + let parent_dir = parent_dir.try_clone().map_err(|error| path_errno(&error))?; + let mut options = OpenOptions::new(); + let write = create || truncate || rights & (RIGHT_FD_WRITE | RIGHT_FD_ALLOCATE | RIGHT_FD_FILESTAT_SET_SIZE) != 0; + options + .read(rights & RIGHT_FD_READ != 0 || !write) + .write(write) + .append(write && fd_flags & FDFLAG_APPEND != 0) + .create(create) + .create_new(exclusive) + .truncate(truncate) + .follow(if follow { FollowSymlinks::Yes } else { FollowSymlinks::No }) + .nonblock(fd_flags & FDFLAG_NONBLOCK != 0) + .maybe_dir(true); + let file = parent_dir.open_with(&path, &options).map_err(|error| path_errno(&error))?; + let descriptor = if file.metadata().map_err(|error| path_errno(&error))?.is_dir() { + Descriptor { + resource: Resource::Directory(Dir::reopen_dir(&file).map_err(|error| path_errno(&error))?), + rights: rights & DIRECTORY_RIGHTS, + inheriting_rights, + flags: fd_flags, + preopen_path: None, + } + } else { + if open_flags & OFLAG_DIRECTORY != 0 { + return Ok(NOTDIR); + } + Descriptor { + resource: Resource::File(file), + rights: rights & FILE_RIGHTS, + inheriting_rights: 0, + flags: fd_flags, + preopen_path: None, + } + }; + let new_fd = state_mut(&mut ctx)?.insert_descriptor(descriptor)?; + if let Err(errno) = memory.write(ctx.store_mut(), result_ptr, &new_fd.to_le_bytes()) { + let _ = state_mut(&mut ctx)?.descriptors[new_fd as usize].take(); + return Ok(errno); + } + Ok(SUCCESS) +} + +pub(super) fn path_filestat_get( + mut ctx: FuncContext<'_>, + (fd, lookup_flags, path_ptr, path_len, result_ptr): (i32, i32, i32, i32, i32), +) -> WasiResult { + let lookup_flags = lookup_flags as u32; + if lookup_flags & !LOOKUP_SYMLINK_FOLLOW != 0 { + return Ok(INVAL); + } + let follow = lookup_flags & LOOKUP_SYMLINK_FOLLOW != 0; + let path = guest_path(&ctx, path_ptr, path_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_FILESTAT_GET)?; + let metadata = if follow { dir.metadata(&path) } else { dir.symlink_metadata(&path) }; + let metadata = metadata.map_err(|error| path_errno(&error))?; + let bytes = filestat(&metadata); + let memory = GuestMemory::new(&ctx)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &bytes).map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn path_filestat_set_times( + ctx: FuncContext<'_>, + (fd, lookup_flags, path_ptr, path_len, atim, mtim, flags): (i32, i32, i32, i32, i64, i64, i32), +) -> WasiResult { + let lookup_flags = lookup_flags as u32; + let flags = flags as u32; + if lookup_flags & !LOOKUP_SYMLINK_FOLLOW != 0 + || flags > FSTFLAGS_ALL.into() + || flags & u32::from(FSTFLAG_ATIM | FSTFLAG_ATIM_NOW) == u32::from(FSTFLAG_ATIM | FSTFLAG_ATIM_NOW) + || flags & u32::from(FSTFLAG_MTIM | FSTFLAG_MTIM_NOW) == u32::from(FSTFLAG_MTIM | FSTFLAG_MTIM_NOW) + { + return Ok(INVAL); + } + let follow = lookup_flags & LOOKUP_SYMLINK_FOLLOW != 0; + let path = guest_path(&ctx, path_ptr, path_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_FILESTAT_SET_TIMES)?; + if flags == 0 { + return Ok(SUCCESS); + } + let atime = time_spec(flags as u16, FSTFLAG_ATIM, FSTFLAG_ATIM_NOW, atim as u64); + let mtime = time_spec(flags as u16, FSTFLAG_MTIM, FSTFLAG_MTIM_NOW, mtim as u64); + let result = if follow { dir.set_times(&path, atime, mtime) } else { dir.set_symlink_times(&path, atime, mtime) }; + Ok(result.map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +pub(super) fn path_link( + ctx: FuncContext<'_>, + (old_fd, flags, old_ptr, old_len, new_fd, new_ptr, new_len): (i32, i32, i32, i32, i32, i32, i32), +) -> WasiResult { + if flags != 0 { + return Ok(INVAL); + } + let old_path = guest_path(&ctx, old_ptr, old_len)?; + let new_path = guest_path(&ctx, new_ptr, new_len)?; + let old_dir = directory(&ctx, old_fd, RIGHT_PATH_LINK_SOURCE)?; + let new_dir = directory(&ctx, new_fd, RIGHT_PATH_LINK_TARGET)?; + Ok(old_dir.hard_link(old_path, &new_dir, new_path).map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +pub(super) fn path_rename( + ctx: FuncContext<'_>, + (old_fd, old_ptr, old_len, new_fd, new_ptr, new_len): (i32, i32, i32, i32, i32, i32), +) -> WasiResult { + let old_path = guest_path(&ctx, old_ptr, old_len)?; + let new_path = guest_path(&ctx, new_ptr, new_len)?; + let old_dir = directory(&ctx, old_fd, RIGHT_PATH_RENAME_SOURCE)?; + let new_dir = directory(&ctx, new_fd, RIGHT_PATH_RENAME_TARGET)?; + Ok(old_dir.rename(old_path, &new_dir, new_path).map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +pub(super) fn path_readlink( + mut ctx: FuncContext<'_>, + (fd, path_ptr, path_len, buffer_ptr, buffer_len, used_ptr): (i32, i32, i32, i32, i32, i32), +) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, buffer_ptr as u32 as usize, buffer_len as u32 as usize)?; + memory.check_range(&ctx, used_ptr as u32 as usize, 4)?; + let path = guest_path(&ctx, path_ptr, path_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_READLINK)?; + let target = dir.read_link_contents(path).map_err(|error| path_errno(&error))?; + let bytes = os_bytes(target.as_os_str()); + let written = bytes.len().min(buffer_len as u32 as usize); + memory.write(ctx.store_mut(), buffer_ptr, &bytes[..written])?; + Ok(memory + .write(ctx.store_mut(), used_ptr, &(written as u32).to_le_bytes()) + .map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn path_symlink( + ctx: FuncContext<'_>, + (old_ptr, old_len, fd, new_ptr, new_len): (i32, i32, i32, i32, i32), +) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + if old_len as u32 as usize > MAX_PATH_BYTES { + return Ok(NAMETOOLONG); + } + let target_bytes = memory.read(&ctx, old_ptr, old_len)?; + if target_bytes.contains(&0) { + return Ok(ILSEQ); + } + let target = PathBuf::from(std::str::from_utf8(&target_bytes).map_err(|_| ILSEQ)?); + let new_path = guest_path(&ctx, new_ptr, new_len)?; + let dir = directory(&ctx, fd, RIGHT_PATH_SYMLINK)?; + Ok(DirExt::symlink(&dir, target, new_path).map_or_else(|error| path_errno(&error), |()| SUCCESS)) +} + +fn directory(ctx: &FuncContext<'_>, fd: i32, right: u64) -> Result { + let descriptor = state(ctx).map_err(|_| IO)?.descriptor(fd)?; + descriptor.require_rights(right)?; + let Resource::Directory(dir) = &descriptor.resource else { return Err(NOTDIR) }; + dir.try_clone().map_err(|error| path_errno(&error)) +} + +fn guest_path(ctx: &FuncContext<'_>, pointer: i32, len: i32) -> Result { + if len as u32 as usize > MAX_PATH_BYTES { + return Err(NAMETOOLONG); + } + let memory = GuestMemory::new(ctx).map_err(|_| IO)?; + let bytes = memory.read(ctx, pointer, len)?; + if bytes.is_empty() { + return Err(NOENT); + } + if bytes.contains(&0) { + return Err(INVAL); + } + Ok(PathBuf::from(std::str::from_utf8(&bytes).map_err(|_| ILSEQ)?)) +} diff --git a/crates/wasi/src/p1/imports/poll.rs b/crates/wasi/src/p1/imports/poll.rs new file mode 100644 index 0000000..8098b74 --- /dev/null +++ b/crates/wasi/src/p1/imports/poll.rs @@ -0,0 +1,219 @@ +use std::io::Seek; + +use rustix::event::{PollFd, PollFlags, Timespec}; +use tinywasm::FuncContext; + +use crate::p1::abi::*; +use crate::p1::ctx::{Resource, state}; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +enum Readiness { + Ready, + Clock(u64), + Poll, +} + +struct PendingEvent { + bytes: [u8; 32], + readiness: Readiness, +} + +struct PollTarget { + event_index: usize, + fd: i32, + event_type: u8, +} + +impl PendingEvent { + fn new(userdata: u64, error: Errno, event_type: u8, available: u64, readiness: Readiness) -> Self { + let mut bytes = [0; 32]; + put(&mut bytes, 0, userdata.to_le_bytes()); + put(&mut bytes, 8, (i32::from(error) as u16).to_le_bytes()); + bytes[10] = event_type; + put(&mut bytes, 16, available.to_le_bytes()); + Self { bytes, readiness } + } +} + +pub(super) fn poll_oneoff( + mut ctx: FuncContext<'_>, + (subscriptions_ptr, events_ptr, count, result_ptr): (i32, i32, i32, i32), +) -> WasiResult { + let count = count as u32 as usize; + if count == 0 || count > 1024 { + return Ok(INVAL); + } + let memory = GuestMemory::new(&ctx)?; + let subscriptions = memory.read_at(&ctx, subscriptions_ptr as u32 as usize, count * 48)?; + memory.check_range(&ctx, events_ptr as u32 as usize, count * 32)?; + memory.check_range(&ctx, result_ptr as u32 as usize, 4)?; + + let mut pending_events = Vec::with_capacity(count); + let mut poll_targets = Vec::new(); + let mut minimum_wait: Option = None; + for subscription in subscriptions.as_chunks::<48>().0 { + let userdata = u64::from_le_bytes(subscription[..8].try_into().expect("userdata")); + let event_type = subscription[8]; + if event_type == 0 { + let wait = clock_wait(&ctx, subscription)?; + minimum_wait = Some(minimum_wait.map_or(wait, |current| current.min(wait))); + pending_events.push(PendingEvent::new(userdata, SUCCESS, event_type, 0, Readiness::Clock(wait))); + } else if matches!(event_type, 1 | 2) { + let fd = u32::from_le_bytes(subscription[16..20].try_into().expect("fd")) as i32; + subscribe_fd(&ctx, fd, userdata, event_type, &mut pending_events, &mut poll_targets)?; + } else { + return Ok(INVAL); + } + } + + let immediately_ready = + pending_events.iter().any(|event| matches!(event.readiness, Readiness::Ready | Readiness::Clock(0))); + let timeout = if immediately_ready { Some(0) } else { minimum_wait }; + let elapsed = wait_for_events(&ctx, &poll_targets, &mut pending_events, timeout)?; + let mut bytes = Vec::with_capacity(pending_events.len() * 32); + for event in pending_events { + if matches!(event.readiness, Readiness::Ready) + || matches!(event.readiness, Readiness::Clock(wait) if wait <= elapsed) + { + bytes.extend_from_slice(&event.bytes); + } + } + let event_count = (bytes.len() / 32) as u32; + memory.write(ctx.store_mut(), events_ptr, &bytes)?; + Ok(memory.write(ctx.store_mut(), result_ptr, &event_count.to_le_bytes()).map_or_else(|errno| errno, |()| SUCCESS)) +} + +fn clock_wait(ctx: &FuncContext<'_>, subscription: &[u8; 48]) -> WasiResult { + let clock_id = u32::from_le_bytes(subscription[16..20].try_into().expect("clock id")); + let timeout = u64::from_le_bytes(subscription[24..32].try_into().expect("timeout")); + let flags = u16::from_le_bytes(subscription[40..42].try_into().expect("flags")); + if !matches!(clock_id, 0 | 1) || flags & !1 != 0 { + return Err(INVAL.into()); + } + let now = if clock_id == 0 { + realtime_now() + } else { + state(ctx)?.monotonic_start.elapsed().as_nanos().try_into().unwrap_or(u64::MAX) + }; + Ok(if flags & 1 != 0 { timeout.saturating_sub(now) } else { timeout }) +} + +fn subscribe_fd( + ctx: &FuncContext<'_>, + fd: i32, + userdata: u64, + event_type: u8, + pending_events: &mut Vec, + poll_targets: &mut Vec, +) -> WasiResult<()> { + let required_right = if event_type == 1 { RIGHT_FD_READ } else { RIGHT_FD_WRITE }; + let descriptor = match state(ctx)?.descriptor(fd) { + Ok(descriptor) => descriptor, + Err(errno) => { + pending_events.push(PendingEvent::new(userdata, errno, event_type, 0, Readiness::Ready)); + return Ok(()); + } + }; + if let Err(errno) = descriptor.require_rights(required_right | RIGHT_POLL_FD_READWRITE) { + pending_events.push(PendingEvent::new(userdata, errno, event_type, 0, Readiness::Ready)); + return Ok(()); + } + if let Resource::File(file) = &descriptor.resource { + let available = if event_type == 1 { + file.try_clone() + .and_then(|mut file| { + let position = file.stream_position()?; + Ok(file.metadata()?.len().saturating_sub(position)) + }) + .unwrap_or(0) + } else { + 0 + }; + pending_events.push(PendingEvent::new(userdata, SUCCESS, event_type, available, Readiness::Ready)); + return Ok(()); + } + poll_targets.push(PollTarget { event_index: pending_events.len(), fd, event_type }); + pending_events.push(PendingEvent::new(userdata, SUCCESS, event_type, 0, Readiness::Poll)); + Ok(()) +} + +fn wait_for_events( + ctx: &FuncContext<'_>, + poll_targets: &[PollTarget], + pending_events: &mut [PendingEvent], + timeout_ns: Option, +) -> WasiResult { + let started = std::time::Instant::now(); + let stdin = std::io::stdin(); + let stdout = std::io::stdout(); + let stderr = std::io::stderr(); + let wasi = state(ctx)?; + let mut poll_fds = Vec::with_capacity(poll_targets.len()); + for target in poll_targets { + let flags = if target.event_type == 1 { PollFlags::IN } else { PollFlags::OUT }; + let descriptor = wasi.descriptor(target.fd)?; + let poll_fd = match &descriptor.resource { + Resource::Stdin => PollFd::new(&stdin, flags), + Resource::Stdout => PollFd::new(&stdout, flags), + Resource::Stderr => PollFd::new(&stderr, flags), + Resource::TcpListener(listener) => PollFd::new(listener, flags), + Resource::TcpStream(stream) => PollFd::new(stream, flags), + Resource::UdpSocket(socket) => PollFd::new(socket, flags), + Resource::File(_) | Resource::Directory(_) => unreachable!(), + }; + poll_fds.push(poll_fd); + } + let timeout = timeout_ns.map(|nanoseconds| Timespec { + tv_sec: (nanoseconds / 1_000_000_000).try_into().unwrap_or(i64::MAX), + tv_nsec: (nanoseconds % 1_000_000_000) as _, + }); + if poll_fds.is_empty() { + if let Some(nanoseconds) = timeout_ns { + std::thread::sleep(std::time::Duration::from_nanos(nanoseconds)); + } + } else { + loop { + match rustix::event::poll(&mut poll_fds, timeout.as_ref()) { + Err(rustix::io::Errno::INTR) => continue, + result => { + result.map_err(Errno::from)?; + break; + } + } + } + } + for (target, poll_fd) in poll_targets.iter().zip(poll_fds) { + let flags = poll_fd.revents(); + if flags.intersects(PollFlags::IN | PollFlags::OUT | PollFlags::ERR | PollFlags::HUP | PollFlags::NVAL) { + pending_events[target.event_index].readiness = Readiness::Ready; + let error = if flags.contains(PollFlags::NVAL) { + BADF + } else if flags.contains(PollFlags::ERR) { + IO + } else { + SUCCESS + }; + put(&mut pending_events[target.event_index].bytes, 8, (i32::from(error) as u16).to_le_bytes()); + if target.event_type == 1 { + let resource = &wasi.descriptor(target.fd)?.resource; + let available = match resource { + Resource::Stdin => rustix::io::ioctl_fionread(&stdin), + Resource::TcpStream(stream) => rustix::io::ioctl_fionread(stream), + Resource::UdpSocket(socket) => rustix::io::ioctl_fionread(socket), + _ => Ok(0), + } + .unwrap_or(0); + put(&mut pending_events[target.event_index].bytes, 16, available.to_le_bytes()); + if matches!(resource, Resource::TcpStream(_)) && available == 0 { + put(&mut pending_events[target.event_index].bytes, 24, 1_u16.to_le_bytes()); + } + } + if flags.contains(PollFlags::HUP) { + put(&mut pending_events[target.event_index].bytes, 24, 1_u16.to_le_bytes()); + } + } + } + Ok(u64::try_from(started.elapsed().as_nanos()).unwrap_or(u64::MAX)) +} diff --git a/crates/wasi/src/p1/imports/process.rs b/crates/wasi/src/p1/imports/process.rs new file mode 100644 index 0000000..9d9571e --- /dev/null +++ b/crates/wasi/src/p1/imports/process.rs @@ -0,0 +1,20 @@ +use tinywasm::{Error, FuncContext}; + +use crate::p1::abi::{Errno, NOTSUP, SUCCESS}; +use crate::p1::ctx::state_mut; + +use super::WasiResult; + +pub(super) fn proc_exit(mut ctx: FuncContext<'_>, status: i32) -> tinywasm::Result<()> { + state_mut(&mut ctx)?.exit_status = Some(status as u32); + Err(Error::Other("WASI process exited".into())) +} + +pub(super) fn proc_raise(_ctx: FuncContext<'_>, _signal: i32) -> WasiResult { + Ok(NOTSUP) +} + +pub(super) fn sched_yield(_ctx: FuncContext<'_>, (): ()) -> WasiResult { + std::thread::yield_now(); + Ok(SUCCESS) +} diff --git a/crates/wasi/src/p1/imports/random.rs b/crates/wasi/src/p1/imports/random.rs new file mode 100644 index 0000000..84d06e9 --- /dev/null +++ b/crates/wasi/src/p1/imports/random.rs @@ -0,0 +1,25 @@ +use tinywasm::FuncContext; + +use crate::p1::abi::{Errno, IO, SUCCESS}; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +pub(super) fn random_get(mut ctx: FuncContext<'_>, (buffer_ptr, buffer_len): (i32, i32)) -> WasiResult { + let memory = GuestMemory::new(&ctx)?; + let offset = buffer_ptr as u32 as usize; + let len = buffer_len as u32 as usize; + memory.check_range(&ctx, offset, len)?; + + let mut chunk = [0_u8; 64 * 1024]; + let mut written = 0; + while written < len { + let chunk_len = (len - written).min(chunk.len()); + if getrandom::fill(&mut chunk[..chunk_len]).is_err() { + return Ok(IO); + } + memory.write_at(ctx.store_mut(), offset + written, &chunk[..chunk_len])?; + written += chunk_len; + } + Ok(SUCCESS) +} diff --git a/crates/wasi/src/p1/imports/sock.rs b/crates/wasi/src/p1/imports/sock.rs new file mode 100644 index 0000000..f938835 --- /dev/null +++ b/crates/wasi/src/p1/imports/sock.rs @@ -0,0 +1,124 @@ +use std::io::{IoSliceMut, Write}; + +use tinywasm::FuncContext; + +use crate::p1::abi::*; +use crate::p1::ctx::{Descriptor, Resource, state, state_mut}; +use crate::p1::memory::GuestMemory; + +use super::WasiResult; + +pub(super) fn sock_accept(mut ctx: FuncContext<'_>, (fd, flags, result_ptr): (i32, i32, i32)) -> WasiResult { + if flags as u32 > FDFLAGS_ALL.into() { + return Ok(INVAL); + } + let flags = flags as u16; + let memory = GuestMemory::new(&ctx)?; + memory.check_range(&ctx, result_ptr as u32 as usize, 4)?; + let descriptor = state(&ctx)?.descriptor(fd)?; + descriptor.require_rights(RIGHT_SOCK_ACCEPT)?; + let Resource::TcpListener(listener) = &descriptor.resource else { return Ok(NOTSOCK) }; + let rights = descriptor.inheriting_rights; + let (stream, _) = listener.accept().map_err(|error| io_errno(&error))?; + stream.set_nonblocking(flags & FDFLAG_NONBLOCK != 0).map_err(|error| io_errno(&error))?; + let new_fd = state_mut(&mut ctx)?.insert_descriptor(Descriptor { + resource: Resource::TcpStream(stream), + rights, + inheriting_rights: 0, + flags, + preopen_path: None, + })?; + if let Err(errno) = memory.write(ctx.store_mut(), result_ptr, &new_fd.to_le_bytes()) { + let _ = state_mut(&mut ctx)?.descriptors[new_fd as usize].take(); + return Ok(errno); + } + Ok(SUCCESS) +} + +pub(super) fn sock_recv( + mut ctx: FuncContext<'_>, + (fd, iovecs_ptr, iovecs_len, flags, data_len_ptr, result_flags_ptr): (i32, i32, i32, i32, i32, i32), +) -> WasiResult { + if flags as u32 & !3 != 0 { + return Ok(INVAL); + } + let memory = GuestMemory::new(&ctx)?; + let iovecs = memory.read_iovecs(&ctx, iovecs_ptr, iovecs_len)?; + memory.check_range(&ctx, data_len_ptr as u32 as usize, 4)?; + memory.check_range(&ctx, result_flags_ptr as u32 as usize, 2)?; + let mut buffer = Vec::new(); + buffer.try_reserve_exact(iovecs.byte_len).map_err(|_| NOMEM)?; + buffer.resize(iovecs.byte_len, 0); + let descriptor = state(&ctx)?.descriptor(fd)?; + descriptor.require_rights(RIGHT_FD_READ)?; + let mut recv_flags = rustix::net::RecvFlags::empty(); + if flags & 1 != 0 { + recv_flags |= rustix::net::RecvFlags::PEEK; + } + if flags & 2 != 0 { + recv_flags |= rustix::net::RecvFlags::WAITALL; + } + let (received, truncated) = match &descriptor.resource { + Resource::TcpStream(stream) => { + (rustix::net::recv(stream, &mut buffer[..], recv_flags).map_err(Errno::from)?.1, false) + } + Resource::UdpSocket(socket) => { + let mut slices = [IoSliceMut::new(&mut buffer)]; + let mut control = rustix::net::RecvAncillaryBuffer::default(); + let message = rustix::net::recvmsg(socket, &mut slices, &mut control, recv_flags).map_err(Errno::from)?; + (message.bytes, message.flags.contains(rustix::net::ReturnFlags::TRUNC)) + } + _ => return Ok(NOTSOCK), + }; + let written = received; + memory.scatter(ctx.store_mut(), &iovecs, &buffer[..written])?; + memory.write(ctx.store_mut(), data_len_ptr, &(written as u32).to_le_bytes())?; + let result_flags = u16::from(truncated); + Ok(memory + .write(ctx.store_mut(), result_flags_ptr, &result_flags.to_le_bytes()) + .map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn sock_send( + mut ctx: FuncContext<'_>, + (fd, iovecs_ptr, iovecs_len, flags, data_len_ptr): (i32, i32, i32, i32, i32), +) -> WasiResult { + if flags != 0 { + return Ok(INVAL); + } + let memory = GuestMemory::new(&ctx)?; + let iovecs = memory.read_iovecs(&ctx, iovecs_ptr, iovecs_len)?; + memory.check_range(&ctx, data_len_ptr as u32 as usize, 4)?; + let data = memory.gather(&ctx, &iovecs)?; + let descriptor = state(&ctx)?.descriptor(fd)?; + descriptor.require_rights(RIGHT_FD_WRITE)?; + let sent = match &descriptor.resource { + Resource::TcpStream(stream) => { + let mut stream = stream; + stream.write(&data) + } + Resource::UdpSocket(socket) => socket.send(&data), + _ => return Ok(NOTSOCK), + } + .map_err(|error| io_errno(&error))?; + Ok(memory + .write(ctx.store_mut(), data_len_ptr, &(sent as u32).to_le_bytes()) + .map_or_else(|errno| errno, |()| SUCCESS)) +} + +pub(super) fn sock_shutdown(ctx: FuncContext<'_>, (fd, how): (i32, i32)) -> WasiResult { + let how = match how { + 1 => rustix::net::Shutdown::Read, + 2 => rustix::net::Shutdown::Write, + 3 => rustix::net::Shutdown::Both, + _ => return Ok(INVAL), + }; + let descriptor = state(&ctx)?.descriptor(fd)?; + descriptor.require_rights(RIGHT_SOCK_SHUTDOWN)?; + let result = match &descriptor.resource { + Resource::TcpStream(stream) => rustix::net::shutdown(stream, how), + Resource::UdpSocket(socket) => rustix::net::shutdown(socket, how), + _ => return Ok(NOTSOCK), + }; + Ok(result.map_or_else(Errno::from, |()| SUCCESS)) +} diff --git a/crates/wasi/src/p1/memory.rs b/crates/wasi/src/p1/memory.rs new file mode 100644 index 0000000..38b4c6a --- /dev/null +++ b/crates/wasi/src/p1/memory.rs @@ -0,0 +1,115 @@ +use tinywasm::types::MemoryArch; +use tinywasm::{Error, FuncContext, Memory, Store}; + +use super::abi::{Errno, FAULT, INVAL, NOMEM}; + +const MAX_IOVECS: usize = 1024; +const MAX_IO_BYTES: usize = 16 * 1024 * 1024; + +/// Provides checked access to a guest's wasm32 memory. +pub(super) struct GuestMemory(Memory); + +/// A bounded and validated guest iovec array. +pub(super) struct GuestIovecs { + pub(super) entries: Vec<(usize, usize)>, + pub(super) byte_len: usize, +} + +impl GuestMemory { + /// Finds and validates the guest's exported memory. + pub(super) fn new(ctx: &FuncContext<'_>) -> tinywasm::Result { + let memory = ctx.memory("memory")?; + if memory.ty(ctx.store())?.arch() != MemoryArch::I32 { + return Err(Error::UnsupportedFeature("WASI Preview 1 requires wasm32 memory")); + } + Ok(Self(memory)) + } + + /// Reads bytes using a wasm32 pointer and length. + pub(super) fn read(&self, store: &Store, pointer: i32, len: i32) -> Result, Errno> { + let len = len as u32 as usize; + self.read_at(store, pointer as u32 as usize, len) + } + + /// Reads bytes using host-sized offsets. + pub(super) fn read_at(&self, store: &Store, offset: usize, len: usize) -> Result, Errno> { + if !self.is_valid_range(store, offset, len) { + return Err(FAULT); + } + let mut bytes = Vec::new(); + bytes.try_reserve_exact(len).map_err(|_| NOMEM)?; + bytes.resize(len, 0); + self.0.read_exact(store, offset, &mut bytes).map_err(|_| FAULT)?; + Ok(bytes) + } + + /// Writes bytes using a wasm32 pointer. + pub(super) fn write(&self, store: &mut Store, pointer: i32, bytes: &[u8]) -> Result<(), Errno> { + self.write_at(store, pointer as u32 as usize, bytes) + } + + /// Writes bytes using a host-sized offset. + pub(super) fn write_at(&self, store: &mut Store, offset: usize, bytes: &[u8]) -> Result<(), Errno> { + self.check_range(store, offset, bytes.len())?; + self.0.copy_from_slice(store, offset, bytes).map_err(|_| FAULT) + } + + /// Validates that a guest memory range is accessible. + pub(super) fn check_range(&self, store: &Store, offset: usize, len: usize) -> Result<(), Errno> { + if self.is_valid_range(store, offset, len) { Ok(()) } else { Err(FAULT) } + } + + /// Reads and validates a guest iovec array. + pub(super) fn read_iovecs(&self, store: &Store, pointer: i32, count: i32) -> Result { + let count = count as u32 as usize; + if count > MAX_IOVECS { + return Err(INVAL); + } + let table_len = count.checked_mul(8).ok_or(INVAL)?; + let table = self.read_at(store, pointer as u32 as usize, table_len)?; + let mut total = 0usize; + let mut entries = Vec::new(); + entries.try_reserve_exact(count).map_err(|_| NOMEM)?; + for entry in table.as_chunks::<8>().0 { + let offset = u32::from_le_bytes(entry[..4].try_into().expect("iovec field")) as usize; + let len = u32::from_le_bytes(entry[4..].try_into().expect("iovec field")) as usize; + total = total.checked_add(len).ok_or(INVAL)?; + if total > MAX_IO_BYTES || !self.is_valid_range(store, offset, len) { + return Err(if total > MAX_IO_BYTES { INVAL } else { FAULT }); + } + entries.push((offset, len)); + } + Ok(GuestIovecs { entries, byte_len: total }) + } + + /// Copies guest iovec contents into one contiguous buffer. + pub(super) fn gather(&self, store: &Store, iovecs: &GuestIovecs) -> Result, Errno> { + let mut bytes = Vec::new(); + bytes.try_reserve_exact(iovecs.byte_len).map_err(|_| NOMEM)?; + bytes.resize(iovecs.byte_len, 0); + let mut destination = 0; + for &(offset, len) in &iovecs.entries { + self.0.read_exact(store, offset, &mut bytes[destination..destination + len]).map_err(|_| FAULT)?; + destination += len; + } + Ok(bytes) + } + + /// Copies one contiguous buffer into guest iovecs. + pub(super) fn scatter(&self, store: &mut Store, iovecs: &GuestIovecs, bytes: &[u8]) -> Result<(), Errno> { + let mut source = 0; + for &(offset, len) in &iovecs.entries { + let len = len.min(bytes.len() - source); + self.write_at(store, offset, &bytes[source..source + len])?; + source += len; + if source == bytes.len() { + break; + } + } + Ok(()) + } + + fn is_valid_range(&self, store: &Store, offset: usize, len: usize) -> bool { + self.0.len(store).ok().is_some_and(|memory_len| offset.checked_add(len).is_some_and(|end| end <= memory_len)) + } +} diff --git a/crates/wasi/src/p1/mod.rs b/crates/wasi/src/p1/mod.rs new file mode 100644 index 0000000..8a852e8 --- /dev/null +++ b/crates/wasi/src/p1/mod.rs @@ -0,0 +1,22 @@ +//! Synchronous WASI Preview 1 command support. + +mod abi; +mod ctx; +mod imports; +mod memory; + +pub use ctx::{WasiCtx, WasiCtxError}; + +use tinywasm::Imports; + +/// Creates a new [`Imports`] object with the WASI Preview 1 namespace registered. +pub fn imports() -> Imports { + let mut imports = Imports::new(); + register(&mut imports); + imports +} + +/// Registers the frozen WASI Preview 1 namespace on an [`Imports`] object. +pub fn register(imports: &mut Imports) { + self::imports::register(imports); +} diff --git a/crates/wasi/tests/p1.rs b/crates/wasi/tests/p1.rs new file mode 100644 index 0000000..e41ca39 --- /dev/null +++ b/crates/wasi/tests/p1.rs @@ -0,0 +1,357 @@ +use tinywasm::{Imports, ModuleInstance, Store}; +use tinywasm_wasi::p1::{WasiCtx, imports, register}; + +struct TempDir(std::path::PathBuf); + +impl TempDir { + fn new(name: &str) -> Self { + let path = std::env::temp_dir().join(format!( + "tinywasm-wasi-{name}-{}-{}", + std::process::id(), + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + )); + std::fs::create_dir(&path).unwrap(); + Self(path) + } +} + +impl Drop for TempDir { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } +} + +fn module(source: &str) -> tinywasm::Module { + tinywasm::parse_bytes(&wat::parse_str(source).unwrap()).unwrap() +} + +#[test] +fn links_the_frozen_preview1_surface() -> tinywasm::Result<()> { + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "clock_res_get" (func (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_advise" (func (param i32 i64 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_allocate" (func (param i32 i64 i64) (result i32))) + (import "wasi_snapshot_preview1" "fd_close" (func (param i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_datasync" (func (param i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_fdstat_set_flags" (func (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_fdstat_set_rights" (func (param i32 i64 i64) (result i32))) + (import "wasi_snapshot_preview1" "fd_filestat_set_size" (func (param i32 i64) (result i32))) + (import "wasi_snapshot_preview1" "fd_filestat_set_times" (func (param i32 i64 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_pread" (func (param i32 i32 i32 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_pwrite" (func (param i32 i32 i32 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_readdir" (func (param i32 i32 i32 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_renumber" (func (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_seek" (func (param i32 i64 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_sync" (func (param i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_tell" (func (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_create_directory" (func (param i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_filestat_get" (func (param i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_filestat_set_times" (func (param i32 i32 i32 i32 i64 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_link" (func (param i32 i32 i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_readlink" (func (param i32 i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_remove_directory" (func (param i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_rename" (func (param i32 i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_symlink" (func (param i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_unlink_file" (func (param i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "poll_oneoff" (func (param i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "proc_raise" (func (param i32) (result i32))) + (import "wasi_snapshot_preview1" "sched_yield" (func (result i32))) + (import "wasi_snapshot_preview1" "sock_accept" (func (param i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_recv" (func (param i32 i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_send" (func (param i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_shutdown" (func (param i32 i32) (result i32))))"#, + ); + let mut store = Store::default().with_state(WasiCtx::new()); + let mut imports = Imports::new(); + register(&mut imports); + ModuleInstance::instantiate(&mut store, &module, Some(&imports))?; + Ok(()) +} + +#[test] +fn writes_arguments_and_environment() -> tinywasm::Result<()> { + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "args_sizes_get" (func $args_sizes_get (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "args_get" (func $args_get (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "environ_sizes_get" (func $environ_sizes_get (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "environ_get" (func $environ_get (param i32 i32) (result i32))) + (memory (export "memory") 1) + (func (export "run") (result i32) + i32.const 0 i32.const 4 call $args_sizes_get drop + i32.const 8 i32.const 32 call $args_get drop + i32.const 16 i32.const 20 call $environ_sizes_get drop + i32.const 24 i32.const 48 call $environ_get))"#, + ); + let wasi = WasiCtx::new().with_args(["app.wasm", "one"]).unwrap().with_env([("MODE", "test")]).unwrap(); + let mut store = Store::default().with_state(wasi); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 0); + + let memory = instance.memory("memory")?; + let mut sizes = [0; 24]; + memory.read_exact(&store, 0, &mut sizes)?; + assert_eq!(u32::from_le_bytes(sizes[0..4].try_into().unwrap()), 2); + assert_eq!(u32::from_le_bytes(sizes[4..8].try_into().unwrap()), 13); + assert_eq!(u32::from_le_bytes(sizes[16..20].try_into().unwrap()), 1); + assert_eq!(u32::from_le_bytes(sizes[20..24].try_into().unwrap()), 10); + assert_eq!(memory.read_vec(&store, 32, 13)?, b"app.wasm\0one\0"); + assert_eq!(memory.read_vec(&store, 48, 10)?, b"MODE=test\0"); + Ok(()) +} + +#[test] +fn handles_process_exit_and_unsupported_raise() -> tinywasm::Result<()> { + let exit_module = module( + r#"(module + (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) + (func (export "_start") + i32.const 7 + call $proc_exit + unreachable))"#, + ); + let mut store = Store::default().with_state(WasiCtx::new()); + let instance = ModuleInstance::instantiate(&mut store, &exit_module, Some(&imports()))?; + assert!(instance.func::<(), ()>(&store, "_start")?.call(&mut store, ()).is_err()); + let wasi = store.state_mut::().unwrap(); + assert_eq!(wasi.exit_status(), Some(7)); + assert_eq!(wasi.take_exit_status(), Some(7)); + assert_eq!(wasi.exit_status(), None); + + let raise_module = module( + r#"(module + (import "wasi_snapshot_preview1" "proc_raise" (func $proc_raise (param i32) (result i32))) + (func (export "run") (result i32) + i32.const 15 call $proc_raise))"#, + ); + let mut store = Store::default().with_state(WasiCtx::new()); + let instance = ModuleInstance::instantiate(&mut store, &raise_module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 58); + Ok(()) +} + +#[test] +fn uses_preopened_files_and_enforces_descriptor_rights() -> tinywasm::Result<()> { + let temp = TempDir::new("preopen-rights"); + std::fs::write(temp.0.join("hello.txt"), b"hello").unwrap(); + let read_module = module( + r#"(module + (import "wasi_snapshot_preview1" "fd_prestat_get" (func $prestat (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_prestat_dir_name" (func $prestat_name (param i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "path_open" (func $open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_read" (func $read (param i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_filestat_get" (func $stat (param i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 0) "\c8\00\00\00\05\00\00\00") + (data (i32.const 100) "hello.txt") + (func (export "run") (result i32) + i32.const 3 i32.const 20 call $prestat drop + i32.const 3 i32.const 32 i32.const 16 call $prestat_name drop + i32.const 3 i32.const 1 i32.const 100 i32.const 9 i32.const 0 + i64.const 2097154 i64.const 0 i32.const 0 i32.const 12 call $open drop + i32.const 12 i32.load i32.const 0 i32.const 1 i32.const 16 call $read drop + i32.const 12 i32.load i32.const 256 call $stat))"#, + ); + let wasi = WasiCtx::new().preopen_dir(&temp.0, "/sandbox").unwrap(); + let mut store = Store::default().with_state(wasi); + let instance = ModuleInstance::instantiate(&mut store, &read_module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 0); + let memory = instance.memory("memory")?; + assert_eq!(memory.read_vec(&store, 32, 8)?, b"/sandbox"); + assert_eq!(memory.read_vec(&store, 200, 5)?, b"hello"); + assert_eq!(memory.read_vec(&store, 256 + 16, 1)?, [4]); + let stat = memory.read_vec(&store, 256, 64)?; + assert_eq!(u64::from_le_bytes(stat[32..40].try_into().unwrap()), 5); + + let rights_module = module( + r#"(module + (import "wasi_snapshot_preview1" "path_open" (func $open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_fdstat_set_rights" (func $rights (param i32 i64 i64) (result i32))) + (import "wasi_snapshot_preview1" "fd_read" (func $read (param i32 i32 i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 0) "\80\00\00\00\01\00\00\00") + (data (i32.const 32) "hello.txt") + (func (export "run") (result i32) + i32.const 3 i32.const 1 i32.const 32 i32.const 9 i32.const 0 + i64.const 2 i64.const 0 i32.const 0 i32.const 64 call $open drop + i32.const 64 i32.load i64.const 0 i64.const 0 call $rights drop + i32.const 64 i32.load i32.const 0 i32.const 1 i32.const 68 call $read))"#, + ); + let wasi = WasiCtx::new().preopen_dir(&temp.0, "/").unwrap(); + let mut store = Store::default().with_state(wasi); + let instance = ModuleInstance::instantiate(&mut store, &rights_module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 76); + Ok(()) +} + +#[test] +fn prevents_preopen_capability_escape() -> tinywasm::Result<()> { + let parent = TempDir::new("escape"); + let sandbox = parent.0.join("sandbox"); + std::fs::create_dir(&sandbox).unwrap(); + std::fs::write(parent.0.join("outside.txt"), b"secret").unwrap(); + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "path_open" (func $open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 32) "../outside.txt") + (func (export "run") (result i32) + i32.const 3 i32.const 1 i32.const 32 i32.const 14 i32.const 0 + i64.const 2 i64.const 0 i32.const 0 i32.const 0 call $open))"#, + ); + let mut store = Store::default().with_state(WasiCtx::new().preopen_dir(&sandbox, "/").unwrap()); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 76); + assert_eq!(std::fs::read(parent.0.join("outside.txt")).unwrap(), b"secret"); + Ok(()) +} + +#[test] +fn provides_clocks_randomness_and_timer_polling() -> tinywasm::Result<()> { + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "clock_time_get" (func $clock (param i32 i64 i32) (result i32))) + (import "wasi_snapshot_preview1" "random_get" (func $random (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "poll_oneoff" (func $poll (param i32 i32 i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 0) "\2a\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\40\42\0f\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (func (export "run") (result i32) + i32.const 0 i32.const 64 i32.const 1 i32.const 128 call $poll drop + i32.const 0 i64.const 1 i32.const 160 call $clock drop + i32.const 1 i64.const 1 i32.const 168 call $clock drop + i32.const 192 i32.const 32 call $random))"#, + ); + let mut store = Store::default().with_state(WasiCtx::new()); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 0); + let memory = instance.memory("memory")?; + let event = memory.read_vec(&store, 64, 32)?; + assert_eq!(u64::from_le_bytes(event[0..8].try_into().unwrap()), 42); + assert_eq!(u16::from_le_bytes(event[8..10].try_into().unwrap()), 0); + assert_eq!(event[10], 0); + assert_eq!(memory.read_vec(&store, 128, 4)?, 1_u32.to_le_bytes()); + assert_ne!(u64::from_le_bytes(memory.read_vec(&store, 160, 8)?.try_into().unwrap()), 0); + assert!(memory.read_vec(&store, 192, 32)?.iter().any(|byte| *byte != 0)); + Ok(()) +} + +#[test] +fn polls_accepts_and_uses_tcp_streams() -> tinywasm::Result<()> { + use std::io::{Read, Write}; + + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let address = listener.local_addr().unwrap(); + let peer = std::thread::spawn(move || { + let mut stream = std::net::TcpStream::connect(address).unwrap(); + stream.write_all(b"hello").unwrap(); + let mut reply = [0; 5]; + stream.read_exact(&mut reply).unwrap(); + reply + }); + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "poll_oneoff" (func $poll (param i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_accept" (func $accept (param i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_recv" (func $recv (param i32 i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_send" (func $send (param i32 i32 i32 i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 0) "\64\00\00\00\05\00\00\00\78\00\00\00\05\00\00\00") + (data (i32.const 120) "world") + (data (i32.const 160) "\2a\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\03\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (func (export "run") (result i32) + i32.const 160 i32.const 224 i32.const 1 i32.const 256 call $poll drop + i32.const 3 i32.const 0 i32.const 32 call $accept drop + i32.const 32 i32.load i32.const 0 i32.const 1 i32.const 0 i32.const 16 i32.const 20 call $recv drop + i32.const 32 i32.load i32.const 8 i32.const 1 i32.const 0 i32.const 24 call $send))"#, + ); + let mut wasi = WasiCtx::new(); + assert_eq!(wasi.insert_tcp_listener(listener).unwrap(), 3); + let mut store = Store::default().with_state(wasi); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 0); + let memory = instance.memory("memory")?; + let event = memory.read_vec(&store, 224, 32)?; + assert_eq!(u64::from_le_bytes(event[0..8].try_into().unwrap()), 42); + assert_eq!(event[10], 1); + assert_eq!(memory.read_vec(&store, 256, 4)?, 1_u32.to_le_bytes()); + assert_eq!(memory.read_vec(&store, 100, 5)?, b"hello"); + assert_eq!(memory.read_vec(&store, 16, 4)?, 5_u32.to_le_bytes()); + assert_eq!(memory.read_vec(&store, 24, 4)?, 5_u32.to_le_bytes()); + assert_eq!(peer.join().unwrap(), *b"world"); + Ok(()) +} + +#[test] +fn sends_and_receives_udp_datagrams() -> tinywasm::Result<()> { + let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap(); + let peer = std::net::UdpSocket::bind("127.0.0.1:0").unwrap(); + socket.connect(peer.local_addr().unwrap()).unwrap(); + peer.connect(socket.local_addr().unwrap()).unwrap(); + peer.send(b"hello!").unwrap(); + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "fd_fdstat_set_flags" (func $set_flags (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_recv" (func $recv (param i32 i32 i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "sock_send" (func $send (param i32 i32 i32 i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 0) "\64\00\00\00\05\00\00\00\78\00\00\00\05\00\00\00") + (data (i32.const 120) "world") + (func (export "run") (result i32) + i32.const 3 i32.const 0 i32.const 1 i32.const 0 i32.const 16 i32.const 20 call $recv drop + i32.const 3 i32.const 8 i32.const 1 i32.const 0 i32.const 24 call $send) + (func (export "nonblocking_recv") (result i32) + i32.const 3 i32.const 4 call $set_flags drop + i32.const 3 i32.const 0 i32.const 1 i32.const 0 i32.const 16 i32.const 20 call $recv))"#, + ); + let mut wasi = WasiCtx::new(); + assert_eq!(wasi.insert_udp_socket(socket).unwrap(), 3); + let mut store = Store::default().with_state(wasi); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 0); + let memory = instance.memory("memory")?; + assert_eq!(memory.read_vec(&store, 100, 5)?, b"hello"); + assert_eq!(memory.read_vec(&store, 20, 2)?, 1_u16.to_le_bytes()); + let mut reply = [0; 5]; + peer.recv(&mut reply).unwrap(); + assert_eq!(reply, *b"world"); + assert_eq!(instance.func::<(), i32>(&store, "nonblocking_recv")?.call(&mut store, ())?, 6); + Ok(()) +} + +#[test] +fn performs_descriptor_io_and_lifecycle_operations() -> tinywasm::Result<()> { + let temp = TempDir::new("descriptor-lifecycle"); + let module = module( + r#"(module + (import "wasi_snapshot_preview1" "path_open" (func $open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_write" (func $write (param i32 i32 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_tell" (func $tell (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_seek" (func $seek (param i32 i64 i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_renumber" (func $renumber (param i32 i32) (result i32))) + (import "wasi_snapshot_preview1" "fd_close" (func $close (param i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 0) "\80\00\00\00\05\00\00\00\85\00\00\00\01\00\00\00") + (data (i32.const 32) "data") + (data (i32.const 128) "hello!") + (func (export "run") (result i32) + i32.const 3 i32.const 1 i32.const 32 i32.const 4 i32.const 9 + i64.const 100 i64.const 0 i32.const 0 i32.const 64 call $open drop + i32.const 64 i32.load i32.const 0 i32.const 1 i32.const 68 call $write drop + i32.const 64 i32.load i32.const 72 call $tell drop + i32.const 64 i32.load i64.const 1 i32.const 0 i32.const 80 call $seek drop + i32.const 64 i32.load i32.const 10 call $renumber drop + i32.const 10 i32.const 8 i32.const 1 i32.const 88 call $write drop + i32.const 10 call $close))"#, + ); + let mut store = Store::default().with_state(WasiCtx::new().preopen_dir(&temp.0, "/").unwrap()); + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + assert_eq!(instance.func::<(), i32>(&store, "run")?.call(&mut store, ())?, 0); + let memory = instance.memory("memory")?; + assert_eq!(memory.read_vec(&store, 68, 4)?, 5_u32.to_le_bytes()); + assert_eq!(memory.read_vec(&store, 72, 8)?, 5_u64.to_le_bytes()); + assert_eq!(memory.read_vec(&store, 80, 8)?, 1_u64.to_le_bytes()); + assert_eq!(memory.read_vec(&store, 88, 4)?, 1_u32.to_le_bytes()); + assert_eq!(std::fs::read(temp.0.join("data")).unwrap(), b"h!llo"); + Ok(()) +} diff --git a/examples/wasi_p1.rs b/examples/wasi_p1.rs new file mode 100644 index 0000000..22024dc --- /dev/null +++ b/examples/wasi_p1.rs @@ -0,0 +1,42 @@ +use anyhow::Result; +use tinywasm::{ModuleInstance, Store}; +use tinywasm_wasi::p1::{WasiCtx, imports}; + +const WASM: &str = r#" +(module + (import "wasi_snapshot_preview1" "fd_write" + (func $fd_write (param i32 i32 i32 i32) (result i32))) + (memory (export "memory") 1) + (data (i32.const 16) "Hello from WASI Preview 1!\n") + + (func (export "_start") + i32.const 0 + i32.const 16 + i32.store + i32.const 4 + i32.const 27 + i32.store + + i32.const 1 + i32.const 0 + i32.const 1 + i32.const 8 + call $fd_write + drop)) +"#; + +// Requires TinyWasm's `parser`, `std`, and `state` features. +// Run with `cargo run --example wasi_p1` from the repository root. +fn main() -> Result<()> { + let wasm = wat::parse_str(WASM)?; + let module = tinywasm::parse_bytes(&wasm)?; + + // The host explicitly chooses what the guest can observe. + let wasi = WasiCtx::new().with_args(["wasi_p1.wasm", "example"])?.with_env([("MODE", "example")])?.inherit_stdio(); + let mut store = Store::default().with_state(wasi); + + // Preview 1 imports are reusable because their state comes from the Store. + let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports()))?; + instance.func::<(), ()>(&store, "_start")?.call(&mut store, ())?; + Ok(()) +} -- cgit v1.3.1 From fa7b34fb0ad7fe8afa7e78af712a40c209923eb2 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 19 Sep 2026 22:37:35 +0200 Subject: chore: v0.11.0 Signed-off-by: Henry --- CHANGELOG.md | 2 +- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 11 ++++++----- README.md | 13 +++++-------- crates/cli/Cargo.toml | 2 +- crates/parser/Cargo.toml | 1 + crates/tinywasm/Cargo.toml | 1 + crates/tinywasm/tests/generated/wasm-1.csv | 2 +- crates/tinywasm/tests/generated/wasm-2.csv | 2 +- crates/tinywasm/tests/generated/wasm-3.csv | 2 +- .../tests/generated/wasm-custom-page-sizes.csv | 2 +- crates/tinywasm/tests/generated/wasm-gc.csv | 2 +- crates/tinywasm/tests/generated/wasm-latest.csv | 2 +- crates/tinywasm/tests/generated/wasm-memory64.csv | 2 +- .../tinywasm/tests/generated/wasm-multi-memory.csv | 2 +- .../tinywasm/tests/generated/wasm-relaxed-simd.csv | 2 +- crates/tinywasm/tests/generated/wasm-simd.csv | 2 +- .../tests/generated/wasm-wide-arithmetic.csv | 2 +- crates/types/Cargo.toml | 1 + crates/wasi/Cargo.toml | 1 + 20 files changed, 38 insertions(+), 36 deletions(-) (limited to 'crates/parser/Cargo.toml') diff --git a/CHANGELOG.md b/CHANGELOG.md index 82af4d3..0059446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.11.0] - 2026-09-19 This release adds garbage collection and typed function reference support, single-pass parsing, and an optional tail-call dispatch backend. The internal instruction representation is now 8 bytes, down from 16, and pluggable memory backends were removed for performance reasons (however, `ResourceLimiter` was added to allow, reject, or trap memory allocation and growth requests). diff --git a/Cargo.lock b/Cargo.lock index eeb9e4a..f49bf9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,9 +182,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.4.6" +version = "1.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3eb0f42d6c360dc3f8a821f6bf2fdea7f72bfd36b3076eb0e6d1e9e0752fff4" +checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313" dependencies = [ "find-msvc-tools", "shlex", @@ -413,9 +413,9 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "find-msvc-tools" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" +checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b" [[package]] name = "float-cmp" @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "tinywasm" -version = "0.11.0-beta.0" +version = "0.11.0" dependencies = [ "libm", "log", @@ -993,7 +993,7 @@ dependencies = [ [[package]] name = "tinywasm-cli" -version = "0.11.0-beta.0" +version = "0.11.0" dependencies = [ "anstream", "anyhow", @@ -1016,7 +1016,7 @@ dependencies = [ [[package]] name = "tinywasm-parser" -version = "0.11.0-beta.0" +version = "0.11.0" dependencies = [ "log", "tinywasm-types", @@ -1025,7 +1025,7 @@ dependencies = [ [[package]] name = "tinywasm-root" -version = "0.11.0-beta.0" +version = "0.11.0" dependencies = [ "anyhow", "criterion", @@ -1038,7 +1038,7 @@ dependencies = [ [[package]] name = "tinywasm-types" -version = "0.11.0-beta.0" +version = "0.11.0" dependencies = [ "portable-atomic-util", "postcard", @@ -1047,7 +1047,7 @@ dependencies = [ [[package]] name = "tinywasm-wasi" -version = "0.11.0-beta.0" +version = "0.11.0" dependencies = [ "cap-fs-ext", "cap-std", diff --git a/Cargo.toml b/Cargo.toml index 66fc96d..57526e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,19 +11,20 @@ members = ["crates/*"] default-members = [".", "crates/parser", "crates/tinywasm", "crates/types", "crates/wasi"] [workspace.package] -version = "0.11.0-beta.0" +version = "0.11.0" edition = "2024" rust-version = "1.98" +homepage = "https://tinywasm.dev" repository = "https://github.com/explodingcamera/tinywasm" license = "MIT OR Apache-2.0" keywords = ["interpreter", "no-std", "tinywasm", "wasm", "webassembly"] categories = ["compilers", "embedded", "no-std", "virtualization", "wasm"] [workspace.dependencies] -tinywasm = { path = "crates/tinywasm", version = "0.11.0-beta.0", default-features = false } -tinywasm-parser = { path = "crates/parser", version = "0.11.0-beta.0", default-features = false } -tinywasm-types = { path = "crates/types", version = "0.11.0-beta.0", default-features = false } -tinywasm-wasi = { path = "crates/wasi", version = "0.11.0-beta.0" } +tinywasm = { path = "crates/tinywasm", version = "0.11.0", default-features = false } +tinywasm-parser = { path = "crates/parser", version = "0.11.0", default-features = false } +tinywasm-types = { path = "crates/types", version = "0.11.0", default-features = false } +tinywasm-wasi = { path = "crates/wasi", version = "0.11.0" } anyhow = "1.0" log = "0.4" diff --git a/README.md b/README.md index d77abdb..6d2ca69 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -> [!WARNING] -> This is the `next` branch and contains changes for the 0.11 beta. See [`v0.10.0`](https://github.com/explodingcamera/tinywasm/tree/v0.10.0) for the latest stable version. - # `tinywasm` [![Documentation](https://img.shields.io/badge/docs-latest-blue?style=flat-square)](https://docs.rs/tinywasm/latest/tinywasm/) [![Build](https://img.shields.io/github/actions/workflow/status/explodingcamera/tinywasm/test.yaml?branch=next&style=flat-square&label=build)](https://github.com/explodingcamera/tinywasm/actions/workflows/test.yaml?query=branch%3Anext) [![Crates.io](https://img.shields.io/crates/v/tinywasm.svg?logo=rust&style=flat-square)](https://crates.io/crates/tinywasm) [![Crates.io](https://img.shields.io/crates/l/tinywasm.svg?style=flat-square)](./LICENSE-APACHE) @@ -19,7 +16,7 @@ ```toml [dependencies] -tinywasm = "0.11.0-beta.0" +tinywasm = "0.11.0" ``` ## Usage @@ -103,10 +100,10 @@ TinyWasm generally implements non-JavaScript core proposals at [phase 4](https:/ | [**Memory64**](https://github.com/WebAssembly/memory64) | 🟢 | 0.9.0 | | [**Wide Arithmetic**](https://github.com/WebAssembly/wide-arithmetic) | 🟢 | 0.9.0 | | [**Custom Page Sizes**](https://github.com/WebAssembly/custom-page-sizes) | 🟢 | 0.9.0 | -| [**Typed Function References**](https://github.com/WebAssembly/function-references) | 🟢 | `next` | -| [**Garbage Collection**](https://github.com/WebAssembly/gc) | 🟢 | `next` | -| [**Exception Handling**](https://github.com/WebAssembly/exception-handling) | 🟢 | `next` | -| [**Compact Import Section**](https://github.com/WebAssembly/compact-import-section) | 🟢 | `next` | +| [**Typed Function References**](https://github.com/WebAssembly/function-references) | 🟢 | 0.11.0 | +| [**Garbage Collection**](https://github.com/WebAssembly/gc) | 🟢 | 0.11.0 | +| [**Exception Handling**](https://github.com/WebAssembly/exception-handling) | 🟢 | 0.11.0 | +| [**Compact Import Section**](https://github.com/WebAssembly/compact-import-section) | 🟢 | 0.11.0 | | [**Stack Switching**](https://github.com/WebAssembly/stack-switching) | 🌑 | - | | [**Threads**](https://github.com/WebAssembly/threads) | 🌑 | - | diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index aff21a2..73b537f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -4,7 +4,7 @@ version.workspace = true edition.workspace = true rust-version.workspace = true description = "Minimal command-line interface for TinyWasm" -documentation = "https://docs.rs/tinywasm-cli" +homepage.workspace = true repository.workspace = true license.workspace = true keywords = ["cli", "runtime", "tinywasm", "wasm", "webassembly"] diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 3cd3097..afedeed 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -4,6 +4,7 @@ version.workspace = true edition.workspace = true rust-version.workspace = true description = "Parser and lowering pipeline for TinyWasm" +homepage.workspace = true repository.workspace = true license.workspace = true keywords.workspace = true diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 9ed5fa7..4f35466 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -5,6 +5,7 @@ edition.workspace = true rust-version.workspace = true description = "A tiny WebAssembly interpreter" readme = "../../README.md" +homepage.workspace = true repository.workspace = true license.workspace = true keywords.workspace = true diff --git a/crates/tinywasm/tests/generated/wasm-1.csv b/crates/tinywasm/tests/generated/wasm-1.csv index ae14c99..535e57c 100644 --- a/crates/tinywasm/tests/generated/wasm-1.csv +++ b/crates/tinywasm/tests/generated/wasm-1.csv @@ -9,4 +9,4 @@ 0.9.1,19241,0,[{"name":"address.wast","passed":243,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":77,"failed":0},{"name":"binary.wast","passed":67,"failed":0},{"name":"block.wast","passed":171,"failed":0},{"name":"br.wast","passed":84,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":168,"failed":0},{"name":"break-drop.wast","passed":4,"failed":0},{"name":"call.wast","passed":82,"failed":0},{"name":"call_indirect.wast","passed":152,"failed":0},{"name":"comments.wast","passed":4,"failed":0},{"name":"const.wast","passed":668,"failed":0},{"name":"conversions.wast","passed":435,"failed":0},{"name":"custom.wast","passed":10,"failed":0},{"name":"data.wast","passed":45,"failed":0},{"name":"elem.wast","passed":55,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":82,"failed":0},{"name":"f32.wast","passed":2512,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2512,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":161,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":121,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"globals.wast","passed":78,"failed":0},{"name":"i32.wast","passed":443,"failed":0},{"name":"i64.wast","passed":389,"failed":0},{"name":"if.wast","passed":151,"failed":0},{"name":"imports.wast","passed":146,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":116,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":81,"failed":0},{"name":"memory.wast","passed":71,"failed":0},{"name":"memory_grow.wast","passed":94,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":173,"failed":0},{"name":"names.wast","passed":483,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":111,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":5,"failed":0},{"name":"start.wast","passed":19,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":2,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":62,"failed":0},{"name":"unreached-invalid.wast","passed":110,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.10.0,19241,0,[{"name":"address.wast","passed":243,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":77,"failed":0},{"name":"binary.wast","passed":67,"failed":0},{"name":"block.wast","passed":171,"failed":0},{"name":"br.wast","passed":84,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":168,"failed":0},{"name":"break-drop.wast","passed":4,"failed":0},{"name":"call.wast","passed":82,"failed":0},{"name":"call_indirect.wast","passed":152,"failed":0},{"name":"comments.wast","passed":4,"failed":0},{"name":"const.wast","passed":668,"failed":0},{"name":"conversions.wast","passed":435,"failed":0},{"name":"custom.wast","passed":10,"failed":0},{"name":"data.wast","passed":45,"failed":0},{"name":"elem.wast","passed":55,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":82,"failed":0},{"name":"f32.wast","passed":2512,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2512,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":161,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":121,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"globals.wast","passed":78,"failed":0},{"name":"i32.wast","passed":443,"failed":0},{"name":"i64.wast","passed":389,"failed":0},{"name":"if.wast","passed":151,"failed":0},{"name":"imports.wast","passed":146,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":116,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":81,"failed":0},{"name":"memory.wast","passed":71,"failed":0},{"name":"memory_grow.wast","passed":94,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":173,"failed":0},{"name":"names.wast","passed":483,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":111,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":5,"failed":0},{"name":"start.wast","passed":19,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":2,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":62,"failed":0},{"name":"unreached-invalid.wast","passed":110,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.11.0-pre.0,19245,0,[{"name":"address.wast","passed":243,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":81,"failed":0},{"name":"binary.wast","passed":67,"failed":0},{"name":"block.wast","passed":171,"failed":0},{"name":"br.wast","passed":84,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":168,"failed":0},{"name":"break-drop.wast","passed":4,"failed":0},{"name":"call.wast","passed":82,"failed":0},{"name":"call_indirect.wast","passed":152,"failed":0},{"name":"comments.wast","passed":4,"failed":0},{"name":"const.wast","passed":668,"failed":0},{"name":"conversions.wast","passed":435,"failed":0},{"name":"custom.wast","passed":10,"failed":0},{"name":"data.wast","passed":45,"failed":0},{"name":"elem.wast","passed":55,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":82,"failed":0},{"name":"f32.wast","passed":2512,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2512,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":161,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":121,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"globals.wast","passed":78,"failed":0},{"name":"i32.wast","passed":443,"failed":0},{"name":"i64.wast","passed":389,"failed":0},{"name":"if.wast","passed":151,"failed":0},{"name":"imports.wast","passed":146,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":116,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":81,"failed":0},{"name":"memory.wast","passed":71,"failed":0},{"name":"memory_grow.wast","passed":94,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":173,"failed":0},{"name":"names.wast","passed":483,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":111,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":5,"failed":0},{"name":"start.wast","passed":19,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":2,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":62,"failed":0},{"name":"unreached-invalid.wast","passed":110,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] -0.11.0-beta.0,19245,0,[{"name":"address.wast","passed":243,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":81,"failed":0},{"name":"binary.wast","passed":67,"failed":0},{"name":"block.wast","passed":171,"failed":0},{"name":"br.wast","passed":84,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":168,"failed":0},{"name":"break-drop.wast","passed":4,"failed":0},{"name":"call.wast","passed":82,"failed":0},{"name":"call_indirect.wast","passed":152,"failed":0},{"name":"comments.wast","passed":4,"failed":0},{"name":"const.wast","passed":668,"failed":0},{"name":"conversions.wast","passed":435,"failed":0},{"name":"custom.wast","passed":10,"failed":0},{"name":"data.wast","passed":45,"failed":0},{"name":"elem.wast","passed":55,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":82,"failed":0},{"name":"f32.wast","passed":2512,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2512,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":161,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":121,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"globals.wast","passed":78,"failed":0},{"name":"i32.wast","passed":443,"failed":0},{"name":"i64.wast","passed":389,"failed":0},{"name":"if.wast","passed":151,"failed":0},{"name":"imports.wast","passed":146,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":116,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":81,"failed":0},{"name":"memory.wast","passed":71,"failed":0},{"name":"memory_grow.wast","passed":94,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":173,"failed":0},{"name":"names.wast","passed":483,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":111,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":5,"failed":0},{"name":"start.wast","passed":19,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":2,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":62,"failed":0},{"name":"unreached-invalid.wast","passed":110,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] +0.11.0,19245,0,[{"name":"address.wast","passed":243,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":81,"failed":0},{"name":"binary.wast","passed":67,"failed":0},{"name":"block.wast","passed":171,"failed":0},{"name":"br.wast","passed":84,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":168,"failed":0},{"name":"break-drop.wast","passed":4,"failed":0},{"name":"call.wast","passed":82,"failed":0},{"name":"call_indirect.wast","passed":152,"failed":0},{"name":"comments.wast","passed":4,"failed":0},{"name":"const.wast","passed":668,"failed":0},{"name":"conversions.wast","passed":435,"failed":0},{"name":"custom.wast","passed":10,"failed":0},{"name":"data.wast","passed":45,"failed":0},{"name":"elem.wast","passed":55,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":82,"failed":0},{"name":"f32.wast","passed":2512,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2512,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":0},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":161,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":441,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":121,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"globals.wast","passed":78,"failed":0},{"name":"i32.wast","passed":443,"failed":0},{"name":"i64.wast","passed":389,"failed":0},{"name":"if.wast","passed":151,"failed":0},{"name":"imports.wast","passed":146,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":116,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":81,"failed":0},{"name":"memory.wast","passed":71,"failed":0},{"name":"memory_grow.wast","passed":94,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":173,"failed":0},{"name":"names.wast","passed":483,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":111,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":5,"failed":0},{"name":"start.wast","passed":19,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":2,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":62,"failed":0},{"name":"unreached-invalid.wast","passed":110,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-2.csv b/crates/tinywasm/tests/generated/wasm-2.csv index 4d83eb6..ac2825c 100644 --- a/crates/tinywasm/tests/generated/wasm-2.csv +++ b/crates/tinywasm/tests/generated/wasm-2.csv @@ -14,4 +14,4 @@ 0.9.1,28008,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":162,"failed":0},{"name":"binary-leb128.wast","passed":89,"failed":0},{"name":"binary.wast","passed":128,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":117,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":98,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":178,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":88,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":104,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":16,"failed":0},{"name":"ref_null.wast","passed":3,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1728,"failed":0},{"name":"table_fill.wast","passed":45,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_init.wast","passed":780,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.10.0,28008,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":162,"failed":0},{"name":"binary-leb128.wast","passed":89,"failed":0},{"name":"binary.wast","passed":128,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":117,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":98,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":110,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":178,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":88,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":104,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":16,"failed":0},{"name":"ref_null.wast","passed":3,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1728,"failed":0},{"name":"table_fill.wast","passed":45,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_init.wast","passed":780,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.11.0-pre.0,28012,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":162,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":136,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":117,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":59,"failed":0},{"name":"elem.wast","passed":96,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":108,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":178,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":88,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":104,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":16,"failed":0},{"name":"ref_null.wast","passed":3,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1728,"failed":0},{"name":"table_fill.wast","passed":45,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_init.wast","passed":780,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] -0.11.0-beta.0,28012,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":162,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":136,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":117,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":59,"failed":0},{"name":"elem.wast","passed":96,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":108,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":178,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":88,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":104,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":16,"failed":0},{"name":"ref_null.wast","passed":3,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1728,"failed":0},{"name":"table_fill.wast","passed":45,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_init.wast","passed":780,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] +0.11.0,28012,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":162,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":136,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"bulk.wast","passed":117,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":59,"failed":0},{"name":"elem.wast","passed":96,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":96,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":172,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":108,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":178,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":132,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":88,"failed":0},{"name":"memory_copy.wast","passed":4450,"failed":0},{"name":"memory_fill.wast","passed":100,"failed":0},{"name":"memory_grow.wast","passed":104,"failed":0},{"name":"memory_init.wast","passed":240,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":16,"failed":0},{"name":"ref_null.wast","passed":3,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":148,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table-sub.wast","passed":2,"failed":0},{"name":"table.wast","passed":19,"failed":0},{"name":"table_copy.wast","passed":1728,"failed":0},{"name":"table_fill.wast","passed":45,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_init.wast","passed":780,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unreached-valid.wast","passed":7,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-3.csv b/crates/tinywasm/tests/generated/wasm-3.csv index 952c9cf..df606ee 100644 --- a/crates/tinywasm/tests/generated/wasm-3.csv +++ b/crates/tinywasm/tests/generated/wasm-3.csv @@ -1,4 +1,4 @@ 0.9.0,20776,452,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":1,"failed":11},{"name":"br_on_null.wast","passed":1,"failed":9},{"name":"br_table.wast","passed":24,"failed":162},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":4,"failed":31},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":63,"failed":2},{"name":"elem.wast","passed":149,"failed":2},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":116,"failed":8},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":198,"failed":20},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":0,"failed":23},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":142,"failed":21},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":89,"failed":1},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":12,"failed":1},{"name":"ref_as_non_null.wast","passed":1,"failed":6},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":2,"failed":20},{"name":"ref_null.wast","passed":0,"failed":34},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":47,"failed":0},{"name":"return_call_indirect.wast","passed":79,"failed":0},{"name":"return_call_ref.wast","passed":11,"failed":40},{"name":"select.wast","passed":155,"failed":2},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":37,"failed":9},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":0,"failed":2},{"name":"type-equivalence.wast","passed":12,"failed":20},{"name":"type-rec.wast","passed":10,"failed":17},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":2,"failed":11},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.10.0,20778,450,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":1,"failed":11},{"name":"br_on_null.wast","passed":1,"failed":9},{"name":"br_table.wast","passed":24,"failed":162},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":4,"failed":31},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":63,"failed":2},{"name":"elem.wast","passed":149,"failed":2},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":116,"failed":8},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":198,"failed":20},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":0,"failed":23},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":142,"failed":21},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":12,"failed":1},{"name":"ref_as_non_null.wast","passed":1,"failed":6},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":2,"failed":20},{"name":"ref_null.wast","passed":0,"failed":34},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":47,"failed":0},{"name":"return_call_indirect.wast","passed":79,"failed":0},{"name":"return_call_ref.wast","passed":11,"failed":40},{"name":"select.wast","passed":155,"failed":2},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":38,"failed":8},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":0,"failed":2},{"name":"type-equivalence.wast","passed":12,"failed":20},{"name":"type-rec.wast","passed":10,"failed":17},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":2,"failed":11},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.11.0-pre.0,21228,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":12,"failed":0},{"name":"br_on_null.wast","passed":10,"failed":0},{"name":"br_table.wast","passed":186,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":35,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":65,"failed":0},{"name":"elem.wast","passed":151,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":124,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":218,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":23,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":163,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":13,"failed":0},{"name":"ref_as_non_null.wast","passed":7,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":22,"failed":0},{"name":"ref_null.wast","passed":34,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":47,"failed":0},{"name":"return_call_indirect.wast","passed":79,"failed":0},{"name":"return_call_ref.wast","passed":51,"failed":0},{"name":"select.wast","passed":157,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":46,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":2,"failed":0},{"name":"type-equivalence.wast","passed":32,"failed":0},{"name":"type-rec.wast","passed":27,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":13,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] -0.11.0-beta.0,21228,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":12,"failed":0},{"name":"br_on_null.wast","passed":10,"failed":0},{"name":"br_table.wast","passed":186,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":35,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":65,"failed":0},{"name":"elem.wast","passed":151,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":124,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":218,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":23,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":163,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":13,"failed":0},{"name":"ref_as_non_null.wast","passed":7,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":22,"failed":0},{"name":"ref_null.wast","passed":34,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":47,"failed":0},{"name":"return_call_indirect.wast","passed":79,"failed":0},{"name":"return_call_ref.wast","passed":51,"failed":0},{"name":"select.wast","passed":157,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":46,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":2,"failed":0},{"name":"type-equivalence.wast","passed":32,"failed":0},{"name":"type-rec.wast","passed":27,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":13,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] +0.11.0,21228,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":12,"failed":0},{"name":"br_on_null.wast","passed":10,"failed":0},{"name":"br_table.wast","passed":186,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":35,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":65,"failed":0},{"name":"elem.wast","passed":151,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":124,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":218,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":23,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":163,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":120,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":13,"failed":0},{"name":"ref_as_non_null.wast","passed":7,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":22,"failed":0},{"name":"ref_null.wast","passed":34,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":47,"failed":0},{"name":"return_call_indirect.wast","passed":79,"failed":0},{"name":"return_call_ref.wast","passed":51,"failed":0},{"name":"select.wast","passed":157,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":46,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":2,"failed":0},{"name":"type-equivalence.wast","passed":32,"failed":0},{"name":"type-rec.wast","passed":27,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":13,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-custom-page-sizes.csv b/crates/tinywasm/tests/generated/wasm-custom-page-sizes.csv index 99d3ed4..c0a9ae5 100644 --- a/crates/tinywasm/tests/generated/wasm-custom-page-sizes.csv +++ b/crates/tinywasm/tests/generated/wasm-custom-page-sizes.csv @@ -3,4 +3,4 @@ 0.9.1,207,0,[{"name":"binary.wast","passed":127,"failed":0},{"name":"custom-page-sizes-invalid.wast","passed":23,"failed":0},{"name":"custom-page-sizes.wast","passed":45,"failed":0},{"name":"memory_max.wast","passed":6,"failed":0},{"name":"memory_max_i64.wast","passed":6,"failed":0}] 0.10.0,207,0,[{"name":"binary.wast","passed":127,"failed":0},{"name":"custom-page-sizes-invalid.wast","passed":23,"failed":0},{"name":"custom-page-sizes.wast","passed":45,"failed":0},{"name":"memory_max.wast","passed":6,"failed":0},{"name":"memory_max_i64.wast","passed":6,"failed":0}] 0.11.0-pre.0,207,0,[{"name":"binary.wast","passed":127,"failed":0},{"name":"custom-page-sizes-invalid.wast","passed":23,"failed":0},{"name":"custom-page-sizes.wast","passed":45,"failed":0},{"name":"memory_max.wast","passed":6,"failed":0},{"name":"memory_max_i64.wast","passed":6,"failed":0}] -0.11.0-beta.0,207,0,[{"name":"binary.wast","passed":127,"failed":0},{"name":"custom-page-sizes-invalid.wast","passed":23,"failed":0},{"name":"custom-page-sizes.wast","passed":45,"failed":0},{"name":"memory_max.wast","passed":6,"failed":0},{"name":"memory_max_i64.wast","passed":6,"failed":0}] +0.11.0,207,0,[{"name":"binary.wast","passed":127,"failed":0},{"name":"custom-page-sizes-invalid.wast","passed":23,"failed":0},{"name":"custom-page-sizes.wast","passed":45,"failed":0},{"name":"memory_max.wast","passed":6,"failed":0},{"name":"memory_max_i64.wast","passed":6,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-gc.csv b/crates/tinywasm/tests/generated/wasm-gc.csv index a75f559..0057d7a 100644 --- a/crates/tinywasm/tests/generated/wasm-gc.csv +++ b/crates/tinywasm/tests/generated/wasm-gc.csv @@ -1,4 +1,4 @@ 0.9.0,80,703,[{"name":"array.wast","passed":6,"failed":48},{"name":"array_copy.wast","passed":4,"failed":31},{"name":"array_fill.wast","passed":3,"failed":27},{"name":"array_init_data.wast","passed":2,"failed":44},{"name":"array_init_elem.wast","passed":3,"failed":33},{"name":"array_new_data.wast","passed":0,"failed":28},{"name":"array_new_elem.wast","passed":0,"failed":24},{"name":"binary-gc.wast","passed":1,"failed":0},{"name":"br_on_cast.wast","passed":6,"failed":31},{"name":"br_on_cast_fail.wast","passed":6,"failed":31},{"name":"extern.wast","passed":0,"failed":18},{"name":"i31.wast","passed":2,"failed":71},{"name":"ref_cast.wast","passed":0,"failed":45},{"name":"ref_eq.wast","passed":6,"failed":83},{"name":"ref_test.wast","passed":0,"failed":71},{"name":"struct.wast","passed":5,"failed":25},{"name":"type-subtyping.wast","passed":36,"failed":93}] 0.10.0,80,704,[{"name":"array.wast","passed":6,"failed":48},{"name":"array_copy.wast","passed":4,"failed":31},{"name":"array_fill.wast","passed":3,"failed":27},{"name":"array_init_data.wast","passed":2,"failed":44},{"name":"array_init_elem.wast","passed":3,"failed":33},{"name":"array_new_data.wast","passed":0,"failed":28},{"name":"array_new_elem.wast","passed":0,"failed":24},{"name":"binary-gc.wast","passed":1,"failed":0},{"name":"br_on_cast.wast","passed":6,"failed":31},{"name":"br_on_cast_fail.wast","passed":6,"failed":31},{"name":"extern.wast","passed":0,"failed":18},{"name":"i31.wast","passed":2,"failed":71},{"name":"ref_cast.wast","passed":0,"failed":45},{"name":"ref_eq.wast","passed":6,"failed":83},{"name":"ref_test.wast","passed":0,"failed":71},{"name":"struct.wast","passed":5,"failed":25},{"name":"type-subtyping.wast","passed":36,"failed":94}] 0.11.0-pre.0,784,0,[{"name":"array.wast","passed":54,"failed":0},{"name":"array_copy.wast","passed":35,"failed":0},{"name":"array_fill.wast","passed":30,"failed":0},{"name":"array_init_data.wast","passed":46,"failed":0},{"name":"array_init_elem.wast","passed":36,"failed":0},{"name":"array_new_data.wast","passed":28,"failed":0},{"name":"array_new_elem.wast","passed":24,"failed":0},{"name":"binary-gc.wast","passed":1,"failed":0},{"name":"br_on_cast.wast","passed":37,"failed":0},{"name":"br_on_cast_fail.wast","passed":37,"failed":0},{"name":"extern.wast","passed":18,"failed":0},{"name":"i31.wast","passed":73,"failed":0},{"name":"ref_cast.wast","passed":45,"failed":0},{"name":"ref_eq.wast","passed":89,"failed":0},{"name":"ref_test.wast","passed":71,"failed":0},{"name":"struct.wast","passed":30,"failed":0},{"name":"type-subtyping.wast","passed":130,"failed":0}] -0.11.0-beta.0,784,0,[{"name":"array.wast","passed":54,"failed":0},{"name":"array_copy.wast","passed":35,"failed":0},{"name":"array_fill.wast","passed":30,"failed":0},{"name":"array_init_data.wast","passed":46,"failed":0},{"name":"array_init_elem.wast","passed":36,"failed":0},{"name":"array_new_data.wast","passed":28,"failed":0},{"name":"array_new_elem.wast","passed":24,"failed":0},{"name":"binary-gc.wast","passed":1,"failed":0},{"name":"br_on_cast.wast","passed":37,"failed":0},{"name":"br_on_cast_fail.wast","passed":37,"failed":0},{"name":"extern.wast","passed":18,"failed":0},{"name":"i31.wast","passed":73,"failed":0},{"name":"ref_cast.wast","passed":45,"failed":0},{"name":"ref_eq.wast","passed":89,"failed":0},{"name":"ref_test.wast","passed":71,"failed":0},{"name":"struct.wast","passed":30,"failed":0},{"name":"type-subtyping.wast","passed":130,"failed":0}] +0.11.0,784,0,[{"name":"array.wast","passed":54,"failed":0},{"name":"array_copy.wast","passed":35,"failed":0},{"name":"array_fill.wast","passed":30,"failed":0},{"name":"array_init_data.wast","passed":46,"failed":0},{"name":"array_init_elem.wast","passed":36,"failed":0},{"name":"array_new_data.wast","passed":28,"failed":0},{"name":"array_new_elem.wast","passed":24,"failed":0},{"name":"binary-gc.wast","passed":1,"failed":0},{"name":"br_on_cast.wast","passed":37,"failed":0},{"name":"br_on_cast_fail.wast","passed":37,"failed":0},{"name":"extern.wast","passed":18,"failed":0},{"name":"i31.wast","passed":73,"failed":0},{"name":"ref_cast.wast","passed":45,"failed":0},{"name":"ref_eq.wast","passed":89,"failed":0},{"name":"ref_test.wast","passed":71,"failed":0},{"name":"struct.wast","passed":30,"failed":0},{"name":"type-subtyping.wast","passed":130,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-latest.csv b/crates/tinywasm/tests/generated/wasm-latest.csv index a9bbe0b..0af70c7 100644 --- a/crates/tinywasm/tests/generated/wasm-latest.csv +++ b/crates/tinywasm/tests/generated/wasm-latest.csv @@ -1,4 +1,4 @@ 0.9.0,20777,452,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":1,"failed":11},{"name":"br_on_null.wast","passed":1,"failed":9},{"name":"br_table.wast","passed":24,"failed":162},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":4,"failed":31},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":63,"failed":2},{"name":"elem.wast","passed":149,"failed":2},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":116,"failed":8},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":198,"failed":20},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":0,"failed":23},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":142,"failed":21},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":121,"failed":0},{"name":"memory.wast","passed":89,"failed":1},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":12,"failed":1},{"name":"ref_as_non_null.wast","passed":1,"failed":6},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":2,"failed":20},{"name":"ref_null.wast","passed":0,"failed":34},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":47,"failed":0},{"name":"return_call_indirect.wast","passed":79,"failed":0},{"name":"return_call_ref.wast","passed":11,"failed":40},{"name":"select.wast","passed":155,"failed":2},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":37,"failed":9},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":0,"failed":2},{"name":"type-equivalence.wast","passed":12,"failed":20},{"name":"type-rec.wast","passed":10,"failed":17},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":2,"failed":11},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.10.0,20697,536,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":1,"failed":11},{"name":"br_on_null.wast","passed":1,"failed":9},{"name":"br_table.wast","passed":24,"failed":162},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":4,"failed":31},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":63,"failed":2},{"name":"elem.wast","passed":149,"failed":2},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":116,"failed":8},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":198,"failed":20},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":0,"failed":23},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":142,"failed":21},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":121,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":12,"failed":1},{"name":"ref_as_non_null.wast","passed":1,"failed":6},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":2,"failed":20},{"name":"ref_null.wast","passed":0,"failed":34},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":14,"failed":35},{"name":"return_call_indirect.wast","passed":30,"failed":51},{"name":"return_call_ref.wast","passed":11,"failed":40},{"name":"select.wast","passed":155,"failed":2},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":38,"failed":8},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":0,"failed":2},{"name":"type-equivalence.wast","passed":12,"failed":20},{"name":"type-rec.wast","passed":10,"failed":17},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":2,"failed":11},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] 0.11.0-pre.0,21233,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":12,"failed":0},{"name":"br_on_null.wast","passed":10,"failed":0},{"name":"br_table.wast","passed":186,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":35,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":65,"failed":0},{"name":"elem.wast","passed":151,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":124,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":218,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":23,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":163,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":121,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":13,"failed":0},{"name":"ref_as_non_null.wast","passed":7,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":22,"failed":0},{"name":"ref_null.wast","passed":34,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":49,"failed":0},{"name":"return_call_indirect.wast","passed":81,"failed":0},{"name":"return_call_ref.wast","passed":51,"failed":0},{"name":"select.wast","passed":157,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":46,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":2,"failed":0},{"name":"type-equivalence.wast","passed":32,"failed":0},{"name":"type-rec.wast","passed":27,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":13,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] -0.11.0-beta.0,21233,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":12,"failed":0},{"name":"br_on_null.wast","passed":10,"failed":0},{"name":"br_table.wast","passed":186,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":35,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":65,"failed":0},{"name":"elem.wast","passed":151,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":124,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":218,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":23,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":163,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":121,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":13,"failed":0},{"name":"ref_as_non_null.wast","passed":7,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":22,"failed":0},{"name":"ref_null.wast","passed":34,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":49,"failed":0},{"name":"return_call_indirect.wast","passed":81,"failed":0},{"name":"return_call_ref.wast","passed":51,"failed":0},{"name":"select.wast","passed":157,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":46,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":2,"failed":0},{"name":"type-equivalence.wast","passed":32,"failed":0},{"name":"type-rec.wast","passed":27,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":13,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] +0.11.0,21233,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":165,"failed":0},{"name":"annotations.wast","passed":74,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":127,"failed":0},{"name":"block.wast","passed":223,"failed":0},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":119,"failed":0},{"name":"br_on_non_null.wast","passed":12,"failed":0},{"name":"br_on_null.wast","passed":10,"failed":0},{"name":"br_table.wast","passed":186,"failed":0},{"name":"call.wast","passed":91,"failed":0},{"name":"call_indirect.wast","passed":172,"failed":0},{"name":"call_ref.wast","passed":35,"failed":0},{"name":"comments.wast","passed":8,"failed":0},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":65,"failed":0},{"name":"elem.wast","passed":151,"failed":0},{"name":"endianness.wast","passed":69,"failed":0},{"name":"exports.wast","passed":97,"failed":0},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":8,"failed":0},{"name":"float_exprs.wast","passed":927,"failed":0},{"name":"float_literals.wast","passed":179,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":471,"failed":0},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":175,"failed":0},{"name":"func_ptrs.wast","passed":36,"failed":0},{"name":"global.wast","passed":124,"failed":0},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"id.wast","passed":7,"failed":0},{"name":"if.wast","passed":241,"failed":0},{"name":"imports.wast","passed":218,"failed":0},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"instance.wast","passed":23,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":29,"failed":0},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":163,"failed":0},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_init.wast","passed":10,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":98,"failed":0},{"name":"loop.wast","passed":121,"failed":0},{"name":"memory.wast","passed":90,"failed":0},{"name":"memory_grow.wast","passed":106,"failed":0},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":88,"failed":0},{"name":"obsolete-keywords.wast","passed":11,"failed":0},{"name":"ref.wast","passed":13,"failed":0},{"name":"ref_as_non_null.wast","passed":7,"failed":0},{"name":"ref_func.wast","passed":17,"failed":0},{"name":"ref_is_null.wast","passed":22,"failed":0},{"name":"ref_null.wast","passed":34,"failed":0},{"name":"return.wast","passed":84,"failed":0},{"name":"return_call.wast","passed":49,"failed":0},{"name":"return_call_indirect.wast","passed":81,"failed":0},{"name":"return_call_ref.wast","passed":51,"failed":0},{"name":"select.wast","passed":157,"failed":0},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"table.wast","passed":46,"failed":0},{"name":"table_get.wast","passed":16,"failed":0},{"name":"table_grow.wast","passed":58,"failed":0},{"name":"table_set.wast","passed":26,"failed":0},{"name":"table_size.wast","passed":39,"failed":0},{"name":"token.wast","passed":61,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type-canon.wast","passed":2,"failed":0},{"name":"type-equivalence.wast","passed":32,"failed":0},{"name":"type-rec.wast","passed":27,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":121,"failed":0},{"name":"unreached-valid.wast","passed":13,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-memory64.csv b/crates/tinywasm/tests/generated/wasm-memory64.csv index 7ebc68d..2a307a1 100644 --- a/crates/tinywasm/tests/generated/wasm-memory64.csv +++ b/crates/tinywasm/tests/generated/wasm-memory64.csv @@ -3,4 +3,4 @@ 0.9.1,1598,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"address64.wast","passed":242,"failed":0},{"name":"align64.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":93,"failed":0},{"name":"binary.wast","passed":169,"failed":0},{"name":"endianness64.wast","passed":69,"failed":0},{"name":"float_memory64.wast","passed":90,"failed":0},{"name":"load64.wast","passed":97,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory64.wast","passed":65,"failed":0},{"name":"memory_grow64.wast","passed":49,"failed":0},{"name":"memory_redundancy64.wast","passed":8,"failed":0},{"name":"memory_trap64.wast","passed":172,"failed":0},{"name":"simd_address.wast","passed":49,"failed":0}] 0.10.0,1598,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"address64.wast","passed":242,"failed":0},{"name":"align64.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":93,"failed":0},{"name":"binary.wast","passed":169,"failed":0},{"name":"endianness64.wast","passed":69,"failed":0},{"name":"float_memory64.wast","passed":90,"failed":0},{"name":"load64.wast","passed":97,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory64.wast","passed":65,"failed":0},{"name":"memory_grow64.wast","passed":49,"failed":0},{"name":"memory_redundancy64.wast","passed":8,"failed":0},{"name":"memory_trap64.wast","passed":172,"failed":0},{"name":"simd_address.wast","passed":49,"failed":0}] 0.11.0-pre.0,1606,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"address64.wast","passed":242,"failed":0},{"name":"align64.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":93,"failed":0},{"name":"binary.wast","passed":177,"failed":0},{"name":"endianness64.wast","passed":69,"failed":0},{"name":"float_memory64.wast","passed":90,"failed":0},{"name":"load64.wast","passed":97,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory64.wast","passed":65,"failed":0},{"name":"memory_grow64.wast","passed":49,"failed":0},{"name":"memory_redundancy64.wast","passed":8,"failed":0},{"name":"memory_trap64.wast","passed":172,"failed":0},{"name":"simd_address.wast","passed":49,"failed":0}] -0.11.0-beta.0,1606,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"address64.wast","passed":242,"failed":0},{"name":"align64.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":93,"failed":0},{"name":"binary.wast","passed":177,"failed":0},{"name":"endianness64.wast","passed":69,"failed":0},{"name":"float_memory64.wast","passed":90,"failed":0},{"name":"load64.wast","passed":97,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory64.wast","passed":65,"failed":0},{"name":"memory_grow64.wast","passed":49,"failed":0},{"name":"memory_redundancy64.wast","passed":8,"failed":0},{"name":"memory_trap64.wast","passed":172,"failed":0},{"name":"simd_address.wast","passed":49,"failed":0}] +0.11.0,1606,0,[{"name":"address.wast","passed":260,"failed":0},{"name":"address64.wast","passed":242,"failed":0},{"name":"align64.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":93,"failed":0},{"name":"binary.wast","passed":177,"failed":0},{"name":"endianness64.wast","passed":69,"failed":0},{"name":"float_memory64.wast","passed":90,"failed":0},{"name":"load64.wast","passed":97,"failed":0},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory64.wast","passed":65,"failed":0},{"name":"memory_grow64.wast","passed":49,"failed":0},{"name":"memory_redundancy64.wast","passed":8,"failed":0},{"name":"memory_trap64.wast","passed":172,"failed":0},{"name":"simd_address.wast","passed":49,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-multi-memory.csv b/crates/tinywasm/tests/generated/wasm-multi-memory.csv index c17d08a..145bfb4 100644 --- a/crates/tinywasm/tests/generated/wasm-multi-memory.csv +++ b/crates/tinywasm/tests/generated/wasm-multi-memory.csv @@ -3,4 +3,4 @@ 0.9.1,912,0,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":51,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_size_import.wast","passed":7,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"start0.wast","passed":9,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"store2.wast","passed":25,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] 0.10.0,912,0,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":51,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_size_import.wast","passed":7,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"start0.wast","passed":9,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"store2.wast","passed":25,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] 0.11.0-pre.0,912,0,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":51,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_size_import.wast","passed":7,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"start0.wast","passed":9,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"store2.wast","passed":25,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] -0.11.0-beta.0,912,0,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":51,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_size_import.wast","passed":7,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"start0.wast","passed":9,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"store2.wast","passed":25,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] +0.11.0,912,0,[{"name":"address0.wast","passed":92,"failed":0},{"name":"address1.wast","passed":127,"failed":0},{"name":"align0.wast","passed":5,"failed":0},{"name":"binary0.wast","passed":7,"failed":0},{"name":"data0.wast","passed":7,"failed":0},{"name":"data1.wast","passed":14,"failed":0},{"name":"data_drop0.wast","passed":11,"failed":0},{"name":"exports0.wast","passed":8,"failed":0},{"name":"float_exprs0.wast","passed":14,"failed":0},{"name":"float_exprs1.wast","passed":3,"failed":0},{"name":"float_memory0.wast","passed":30,"failed":0},{"name":"imports0.wast","passed":8,"failed":0},{"name":"imports1.wast","passed":5,"failed":0},{"name":"imports2.wast","passed":20,"failed":0},{"name":"imports3.wast","passed":10,"failed":0},{"name":"imports4.wast","passed":16,"failed":0},{"name":"linking0.wast","passed":6,"failed":0},{"name":"linking1.wast","passed":14,"failed":0},{"name":"linking2.wast","passed":11,"failed":0},{"name":"linking3.wast","passed":14,"failed":0},{"name":"load0.wast","passed":3,"failed":0},{"name":"load1.wast","passed":18,"failed":0},{"name":"load2.wast","passed":38,"failed":0},{"name":"memory-multi.wast","passed":6,"failed":0},{"name":"memory_copy0.wast","passed":29,"failed":0},{"name":"memory_copy1.wast","passed":14,"failed":0},{"name":"memory_fill0.wast","passed":16,"failed":0},{"name":"memory_grow.wast","passed":51,"failed":0},{"name":"memory_init0.wast","passed":13,"failed":0},{"name":"memory_size0.wast","passed":8,"failed":0},{"name":"memory_size1.wast","passed":15,"failed":0},{"name":"memory_size2.wast","passed":21,"failed":0},{"name":"memory_size3.wast","passed":2,"failed":0},{"name":"memory_size_import.wast","passed":7,"failed":0},{"name":"memory_trap0.wast","passed":14,"failed":0},{"name":"memory_trap1.wast","passed":168,"failed":0},{"name":"start0.wast","passed":9,"failed":0},{"name":"store0.wast","passed":5,"failed":0},{"name":"store1.wast","passed":13,"failed":0},{"name":"store2.wast","passed":25,"failed":0},{"name":"traps0.wast","passed":15,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-relaxed-simd.csv b/crates/tinywasm/tests/generated/wasm-relaxed-simd.csv index 6190168..4716ba8 100644 --- a/crates/tinywasm/tests/generated/wasm-relaxed-simd.csv +++ b/crates/tinywasm/tests/generated/wasm-relaxed-simd.csv @@ -2,4 +2,4 @@ 0.9.1,77,0,[{"name":"i16x8_relaxed_q15mulr_s.wast","passed":3,"failed":0},{"name":"i32x4_relaxed_trunc.wast","passed":1,"failed":0},{"name":"i8x16_relaxed_swizzle.wast","passed":6,"failed":0},{"name":"relaxed_dot_product.wast","passed":11,"failed":0},{"name":"relaxed_laneselect.wast","passed":12,"failed":0},{"name":"relaxed_madd_nmadd.wast","passed":19,"failed":0},{"name":"relaxed_min_max.wast","passed":25,"failed":0}] 0.10.0,77,0,[{"name":"i16x8_relaxed_q15mulr_s.wast","passed":3,"failed":0},{"name":"i32x4_relaxed_trunc.wast","passed":1,"failed":0},{"name":"i8x16_relaxed_swizzle.wast","passed":6,"failed":0},{"name":"relaxed_dot_product.wast","passed":11,"failed":0},{"name":"relaxed_laneselect.wast","passed":12,"failed":0},{"name":"relaxed_madd_nmadd.wast","passed":19,"failed":0},{"name":"relaxed_min_max.wast","passed":25,"failed":0}] 0.11.0-pre.0,77,0,[{"name":"i16x8_relaxed_q15mulr_s.wast","passed":3,"failed":0},{"name":"i32x4_relaxed_trunc.wast","passed":1,"failed":0},{"name":"i8x16_relaxed_swizzle.wast","passed":6,"failed":0},{"name":"relaxed_dot_product.wast","passed":11,"failed":0},{"name":"relaxed_laneselect.wast","passed":12,"failed":0},{"name":"relaxed_madd_nmadd.wast","passed":19,"failed":0},{"name":"relaxed_min_max.wast","passed":25,"failed":0}] -0.11.0-beta.0,77,0,[{"name":"i16x8_relaxed_q15mulr_s.wast","passed":3,"failed":0},{"name":"i32x4_relaxed_trunc.wast","passed":1,"failed":0},{"name":"i8x16_relaxed_swizzle.wast","passed":6,"failed":0},{"name":"relaxed_dot_product.wast","passed":11,"failed":0},{"name":"relaxed_laneselect.wast","passed":12,"failed":0},{"name":"relaxed_madd_nmadd.wast","passed":19,"failed":0},{"name":"relaxed_min_max.wast","passed":25,"failed":0}] +0.11.0,77,0,[{"name":"i16x8_relaxed_q15mulr_s.wast","passed":3,"failed":0},{"name":"i32x4_relaxed_trunc.wast","passed":1,"failed":0},{"name":"i8x16_relaxed_swizzle.wast","passed":6,"failed":0},{"name":"relaxed_dot_product.wast","passed":11,"failed":0},{"name":"relaxed_laneselect.wast","passed":12,"failed":0},{"name":"relaxed_madd_nmadd.wast","passed":19,"failed":0},{"name":"relaxed_min_max.wast","passed":25,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-simd.csv b/crates/tinywasm/tests/generated/wasm-simd.csv index 158668b..5921e05 100644 --- a/crates/tinywasm/tests/generated/wasm-simd.csv +++ b/crates/tinywasm/tests/generated/wasm-simd.csv @@ -3,4 +3,4 @@ 0.9.1,25990,0,[{"name":"simd_address.wast","passed":49,"failed":0},{"name":"simd_align.wast","passed":100,"failed":0},{"name":"simd_bit_shift.wast","passed":252,"failed":0},{"name":"simd_bitwise.wast","passed":169,"failed":0},{"name":"simd_boolean.wast","passed":277,"failed":0},{"name":"simd_const.wast","passed":758,"failed":0},{"name":"simd_conversions.wast","passed":282,"failed":0},{"name":"simd_f32x4.wast","passed":790,"failed":0},{"name":"simd_f32x4_arith.wast","passed":1822,"failed":0},{"name":"simd_f32x4_cmp.wast","passed":2607,"failed":0},{"name":"simd_f32x4_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f32x4_rounding.wast","passed":201,"failed":0},{"name":"simd_f64x2.wast","passed":803,"failed":0},{"name":"simd_f64x2_arith.wast","passed":1825,"failed":0},{"name":"simd_f64x2_cmp.wast","passed":2685,"failed":0},{"name":"simd_f64x2_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f64x2_rounding.wast","passed":201,"failed":0},{"name":"simd_i16x8_arith.wast","passed":194,"failed":0},{"name":"simd_i16x8_arith2.wast","passed":172,"failed":0},{"name":"simd_i16x8_cmp.wast","passed":465,"failed":0},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":21,"failed":0},{"name":"simd_i16x8_extmul_i8x16.wast","passed":117,"failed":0},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":30,"failed":0},{"name":"simd_i16x8_sat_arith.wast","passed":222,"failed":0},{"name":"simd_i32x4_arith.wast","passed":194,"failed":0},{"name":"simd_i32x4_arith2.wast","passed":149,"failed":0},{"name":"simd_i32x4_cmp.wast","passed":475,"failed":0},{"name":"simd_i32x4_dot_i16x8.wast","passed":32,"failed":0},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":21,"failed":0},{"name":"simd_i32x4_extmul_i16x8.wast","passed":117,"failed":0},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":107,"failed":0},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":107,"failed":0},{"name":"simd_i64x2_arith.wast","passed":200,"failed":0},{"name":"simd_i64x2_arith2.wast","passed":25,"failed":0},{"name":"simd_i64x2_cmp.wast","passed":113,"failed":0},{"name":"simd_i64x2_extmul_i32x4.wast","passed":117,"failed":0},{"name":"simd_i8x16_arith.wast","passed":131,"failed":0},{"name":"simd_i8x16_arith2.wast","passed":211,"failed":0},{"name":"simd_i8x16_cmp.wast","passed":445,"failed":0},{"name":"simd_i8x16_sat_arith.wast","passed":214,"failed":0},{"name":"simd_int_to_int_extend.wast","passed":253,"failed":0},{"name":"simd_lane.wast","passed":475,"failed":0},{"name":"simd_linking.wast","passed":3,"failed":0},{"name":"simd_load.wast","passed":39,"failed":0},{"name":"simd_load16_lane.wast","passed":36,"failed":0},{"name":"simd_load32_lane.wast","passed":24,"failed":0},{"name":"simd_load64_lane.wast","passed":16,"failed":0},{"name":"simd_load8_lane.wast","passed":52,"failed":0},{"name":"simd_load_extend.wast","passed":104,"failed":0},{"name":"simd_load_splat.wast","passed":126,"failed":0},{"name":"simd_load_zero.wast","passed":39,"failed":0},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_select.wast","passed":7,"failed":0},{"name":"simd_splat.wast","passed":185,"failed":0},{"name":"simd_store.wast","passed":28,"failed":0},{"name":"simd_store16_lane.wast","passed":36,"failed":0},{"name":"simd_store32_lane.wast","passed":24,"failed":0},{"name":"simd_store64_lane.wast","passed":16,"failed":0},{"name":"simd_store8_lane.wast","passed":52,"failed":0}] 0.10.0,25990,0,[{"name":"simd_address.wast","passed":49,"failed":0},{"name":"simd_align.wast","passed":100,"failed":0},{"name":"simd_bit_shift.wast","passed":252,"failed":0},{"name":"simd_bitwise.wast","passed":169,"failed":0},{"name":"simd_boolean.wast","passed":277,"failed":0},{"name":"simd_const.wast","passed":758,"failed":0},{"name":"simd_conversions.wast","passed":282,"failed":0},{"name":"simd_f32x4.wast","passed":790,"failed":0},{"name":"simd_f32x4_arith.wast","passed":1822,"failed":0},{"name":"simd_f32x4_cmp.wast","passed":2607,"failed":0},{"name":"simd_f32x4_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f32x4_rounding.wast","passed":201,"failed":0},{"name":"simd_f64x2.wast","passed":803,"failed":0},{"name":"simd_f64x2_arith.wast","passed":1825,"failed":0},{"name":"simd_f64x2_cmp.wast","passed":2685,"failed":0},{"name":"simd_f64x2_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f64x2_rounding.wast","passed":201,"failed":0},{"name":"simd_i16x8_arith.wast","passed":194,"failed":0},{"name":"simd_i16x8_arith2.wast","passed":172,"failed":0},{"name":"simd_i16x8_cmp.wast","passed":465,"failed":0},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":21,"failed":0},{"name":"simd_i16x8_extmul_i8x16.wast","passed":117,"failed":0},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":30,"failed":0},{"name":"simd_i16x8_sat_arith.wast","passed":222,"failed":0},{"name":"simd_i32x4_arith.wast","passed":194,"failed":0},{"name":"simd_i32x4_arith2.wast","passed":149,"failed":0},{"name":"simd_i32x4_cmp.wast","passed":475,"failed":0},{"name":"simd_i32x4_dot_i16x8.wast","passed":32,"failed":0},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":21,"failed":0},{"name":"simd_i32x4_extmul_i16x8.wast","passed":117,"failed":0},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":107,"failed":0},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":107,"failed":0},{"name":"simd_i64x2_arith.wast","passed":200,"failed":0},{"name":"simd_i64x2_arith2.wast","passed":25,"failed":0},{"name":"simd_i64x2_cmp.wast","passed":113,"failed":0},{"name":"simd_i64x2_extmul_i32x4.wast","passed":117,"failed":0},{"name":"simd_i8x16_arith.wast","passed":131,"failed":0},{"name":"simd_i8x16_arith2.wast","passed":211,"failed":0},{"name":"simd_i8x16_cmp.wast","passed":445,"failed":0},{"name":"simd_i8x16_sat_arith.wast","passed":214,"failed":0},{"name":"simd_int_to_int_extend.wast","passed":253,"failed":0},{"name":"simd_lane.wast","passed":475,"failed":0},{"name":"simd_linking.wast","passed":3,"failed":0},{"name":"simd_load.wast","passed":39,"failed":0},{"name":"simd_load16_lane.wast","passed":36,"failed":0},{"name":"simd_load32_lane.wast","passed":24,"failed":0},{"name":"simd_load64_lane.wast","passed":16,"failed":0},{"name":"simd_load8_lane.wast","passed":52,"failed":0},{"name":"simd_load_extend.wast","passed":104,"failed":0},{"name":"simd_load_splat.wast","passed":126,"failed":0},{"name":"simd_load_zero.wast","passed":39,"failed":0},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_select.wast","passed":7,"failed":0},{"name":"simd_splat.wast","passed":185,"failed":0},{"name":"simd_store.wast","passed":28,"failed":0},{"name":"simd_store16_lane.wast","passed":36,"failed":0},{"name":"simd_store32_lane.wast","passed":24,"failed":0},{"name":"simd_store64_lane.wast","passed":16,"failed":0},{"name":"simd_store8_lane.wast","passed":52,"failed":0}] 0.11.0-pre.0,25990,0,[{"name":"simd_address.wast","passed":49,"failed":0},{"name":"simd_align.wast","passed":100,"failed":0},{"name":"simd_bit_shift.wast","passed":252,"failed":0},{"name":"simd_bitwise.wast","passed":169,"failed":0},{"name":"simd_boolean.wast","passed":277,"failed":0},{"name":"simd_const.wast","passed":758,"failed":0},{"name":"simd_conversions.wast","passed":282,"failed":0},{"name":"simd_f32x4.wast","passed":790,"failed":0},{"name":"simd_f32x4_arith.wast","passed":1822,"failed":0},{"name":"simd_f32x4_cmp.wast","passed":2607,"failed":0},{"name":"simd_f32x4_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f32x4_rounding.wast","passed":201,"failed":0},{"name":"simd_f64x2.wast","passed":803,"failed":0},{"name":"simd_f64x2_arith.wast","passed":1825,"failed":0},{"name":"simd_f64x2_cmp.wast","passed":2685,"failed":0},{"name":"simd_f64x2_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f64x2_rounding.wast","passed":201,"failed":0},{"name":"simd_i16x8_arith.wast","passed":194,"failed":0},{"name":"simd_i16x8_arith2.wast","passed":172,"failed":0},{"name":"simd_i16x8_cmp.wast","passed":465,"failed":0},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":21,"failed":0},{"name":"simd_i16x8_extmul_i8x16.wast","passed":117,"failed":0},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":30,"failed":0},{"name":"simd_i16x8_sat_arith.wast","passed":222,"failed":0},{"name":"simd_i32x4_arith.wast","passed":194,"failed":0},{"name":"simd_i32x4_arith2.wast","passed":149,"failed":0},{"name":"simd_i32x4_cmp.wast","passed":475,"failed":0},{"name":"simd_i32x4_dot_i16x8.wast","passed":32,"failed":0},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":21,"failed":0},{"name":"simd_i32x4_extmul_i16x8.wast","passed":117,"failed":0},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":107,"failed":0},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":107,"failed":0},{"name":"simd_i64x2_arith.wast","passed":200,"failed":0},{"name":"simd_i64x2_arith2.wast","passed":25,"failed":0},{"name":"simd_i64x2_cmp.wast","passed":113,"failed":0},{"name":"simd_i64x2_extmul_i32x4.wast","passed":117,"failed":0},{"name":"simd_i8x16_arith.wast","passed":131,"failed":0},{"name":"simd_i8x16_arith2.wast","passed":211,"failed":0},{"name":"simd_i8x16_cmp.wast","passed":445,"failed":0},{"name":"simd_i8x16_sat_arith.wast","passed":214,"failed":0},{"name":"simd_int_to_int_extend.wast","passed":253,"failed":0},{"name":"simd_lane.wast","passed":475,"failed":0},{"name":"simd_linking.wast","passed":3,"failed":0},{"name":"simd_load.wast","passed":39,"failed":0},{"name":"simd_load16_lane.wast","passed":36,"failed":0},{"name":"simd_load32_lane.wast","passed":24,"failed":0},{"name":"simd_load64_lane.wast","passed":16,"failed":0},{"name":"simd_load8_lane.wast","passed":52,"failed":0},{"name":"simd_load_extend.wast","passed":104,"failed":0},{"name":"simd_load_splat.wast","passed":126,"failed":0},{"name":"simd_load_zero.wast","passed":39,"failed":0},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_select.wast","passed":7,"failed":0},{"name":"simd_splat.wast","passed":185,"failed":0},{"name":"simd_store.wast","passed":28,"failed":0},{"name":"simd_store16_lane.wast","passed":36,"failed":0},{"name":"simd_store32_lane.wast","passed":24,"failed":0},{"name":"simd_store64_lane.wast","passed":16,"failed":0},{"name":"simd_store8_lane.wast","passed":52,"failed":0}] -0.11.0-beta.0,25990,0,[{"name":"simd_address.wast","passed":49,"failed":0},{"name":"simd_align.wast","passed":100,"failed":0},{"name":"simd_bit_shift.wast","passed":252,"failed":0},{"name":"simd_bitwise.wast","passed":169,"failed":0},{"name":"simd_boolean.wast","passed":277,"failed":0},{"name":"simd_const.wast","passed":758,"failed":0},{"name":"simd_conversions.wast","passed":282,"failed":0},{"name":"simd_f32x4.wast","passed":790,"failed":0},{"name":"simd_f32x4_arith.wast","passed":1822,"failed":0},{"name":"simd_f32x4_cmp.wast","passed":2607,"failed":0},{"name":"simd_f32x4_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f32x4_rounding.wast","passed":201,"failed":0},{"name":"simd_f64x2.wast","passed":803,"failed":0},{"name":"simd_f64x2_arith.wast","passed":1825,"failed":0},{"name":"simd_f64x2_cmp.wast","passed":2685,"failed":0},{"name":"simd_f64x2_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f64x2_rounding.wast","passed":201,"failed":0},{"name":"simd_i16x8_arith.wast","passed":194,"failed":0},{"name":"simd_i16x8_arith2.wast","passed":172,"failed":0},{"name":"simd_i16x8_cmp.wast","passed":465,"failed":0},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":21,"failed":0},{"name":"simd_i16x8_extmul_i8x16.wast","passed":117,"failed":0},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":30,"failed":0},{"name":"simd_i16x8_sat_arith.wast","passed":222,"failed":0},{"name":"simd_i32x4_arith.wast","passed":194,"failed":0},{"name":"simd_i32x4_arith2.wast","passed":149,"failed":0},{"name":"simd_i32x4_cmp.wast","passed":475,"failed":0},{"name":"simd_i32x4_dot_i16x8.wast","passed":32,"failed":0},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":21,"failed":0},{"name":"simd_i32x4_extmul_i16x8.wast","passed":117,"failed":0},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":107,"failed":0},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":107,"failed":0},{"name":"simd_i64x2_arith.wast","passed":200,"failed":0},{"name":"simd_i64x2_arith2.wast","passed":25,"failed":0},{"name":"simd_i64x2_cmp.wast","passed":113,"failed":0},{"name":"simd_i64x2_extmul_i32x4.wast","passed":117,"failed":0},{"name":"simd_i8x16_arith.wast","passed":131,"failed":0},{"name":"simd_i8x16_arith2.wast","passed":211,"failed":0},{"name":"simd_i8x16_cmp.wast","passed":445,"failed":0},{"name":"simd_i8x16_sat_arith.wast","passed":214,"failed":0},{"name":"simd_int_to_int_extend.wast","passed":253,"failed":0},{"name":"simd_lane.wast","passed":475,"failed":0},{"name":"simd_linking.wast","passed":3,"failed":0},{"name":"simd_load.wast","passed":39,"failed":0},{"name":"simd_load16_lane.wast","passed":36,"failed":0},{"name":"simd_load32_lane.wast","passed":24,"failed":0},{"name":"simd_load64_lane.wast","passed":16,"failed":0},{"name":"simd_load8_lane.wast","passed":52,"failed":0},{"name":"simd_load_extend.wast","passed":104,"failed":0},{"name":"simd_load_splat.wast","passed":126,"failed":0},{"name":"simd_load_zero.wast","passed":39,"failed":0},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_select.wast","passed":7,"failed":0},{"name":"simd_splat.wast","passed":185,"failed":0},{"name":"simd_store.wast","passed":28,"failed":0},{"name":"simd_store16_lane.wast","passed":36,"failed":0},{"name":"simd_store32_lane.wast","passed":24,"failed":0},{"name":"simd_store64_lane.wast","passed":16,"failed":0},{"name":"simd_store8_lane.wast","passed":52,"failed":0}] +0.11.0,25990,0,[{"name":"simd_address.wast","passed":49,"failed":0},{"name":"simd_align.wast","passed":100,"failed":0},{"name":"simd_bit_shift.wast","passed":252,"failed":0},{"name":"simd_bitwise.wast","passed":169,"failed":0},{"name":"simd_boolean.wast","passed":277,"failed":0},{"name":"simd_const.wast","passed":758,"failed":0},{"name":"simd_conversions.wast","passed":282,"failed":0},{"name":"simd_f32x4.wast","passed":790,"failed":0},{"name":"simd_f32x4_arith.wast","passed":1822,"failed":0},{"name":"simd_f32x4_cmp.wast","passed":2607,"failed":0},{"name":"simd_f32x4_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f32x4_rounding.wast","passed":201,"failed":0},{"name":"simd_f64x2.wast","passed":803,"failed":0},{"name":"simd_f64x2_arith.wast","passed":1825,"failed":0},{"name":"simd_f64x2_cmp.wast","passed":2685,"failed":0},{"name":"simd_f64x2_pmin_pmax.wast","passed":3887,"failed":0},{"name":"simd_f64x2_rounding.wast","passed":201,"failed":0},{"name":"simd_i16x8_arith.wast","passed":194,"failed":0},{"name":"simd_i16x8_arith2.wast","passed":172,"failed":0},{"name":"simd_i16x8_cmp.wast","passed":465,"failed":0},{"name":"simd_i16x8_extadd_pairwise_i8x16.wast","passed":21,"failed":0},{"name":"simd_i16x8_extmul_i8x16.wast","passed":117,"failed":0},{"name":"simd_i16x8_q15mulr_sat_s.wast","passed":30,"failed":0},{"name":"simd_i16x8_sat_arith.wast","passed":222,"failed":0},{"name":"simd_i32x4_arith.wast","passed":194,"failed":0},{"name":"simd_i32x4_arith2.wast","passed":149,"failed":0},{"name":"simd_i32x4_cmp.wast","passed":475,"failed":0},{"name":"simd_i32x4_dot_i16x8.wast","passed":32,"failed":0},{"name":"simd_i32x4_extadd_pairwise_i16x8.wast","passed":21,"failed":0},{"name":"simd_i32x4_extmul_i16x8.wast","passed":117,"failed":0},{"name":"simd_i32x4_trunc_sat_f32x4.wast","passed":107,"failed":0},{"name":"simd_i32x4_trunc_sat_f64x2.wast","passed":107,"failed":0},{"name":"simd_i64x2_arith.wast","passed":200,"failed":0},{"name":"simd_i64x2_arith2.wast","passed":25,"failed":0},{"name":"simd_i64x2_cmp.wast","passed":113,"failed":0},{"name":"simd_i64x2_extmul_i32x4.wast","passed":117,"failed":0},{"name":"simd_i8x16_arith.wast","passed":131,"failed":0},{"name":"simd_i8x16_arith2.wast","passed":211,"failed":0},{"name":"simd_i8x16_cmp.wast","passed":445,"failed":0},{"name":"simd_i8x16_sat_arith.wast","passed":214,"failed":0},{"name":"simd_int_to_int_extend.wast","passed":253,"failed":0},{"name":"simd_lane.wast","passed":475,"failed":0},{"name":"simd_linking.wast","passed":3,"failed":0},{"name":"simd_load.wast","passed":39,"failed":0},{"name":"simd_load16_lane.wast","passed":36,"failed":0},{"name":"simd_load32_lane.wast","passed":24,"failed":0},{"name":"simd_load64_lane.wast","passed":16,"failed":0},{"name":"simd_load8_lane.wast","passed":52,"failed":0},{"name":"simd_load_extend.wast","passed":104,"failed":0},{"name":"simd_load_splat.wast","passed":126,"failed":0},{"name":"simd_load_zero.wast","passed":39,"failed":0},{"name":"simd_memory-multi.wast","passed":1,"failed":0},{"name":"simd_select.wast","passed":7,"failed":0},{"name":"simd_splat.wast","passed":185,"failed":0},{"name":"simd_store.wast","passed":28,"failed":0},{"name":"simd_store16_lane.wast","passed":36,"failed":0},{"name":"simd_store32_lane.wast","passed":24,"failed":0},{"name":"simd_store64_lane.wast","passed":16,"failed":0},{"name":"simd_store8_lane.wast","passed":52,"failed":0}] diff --git a/crates/tinywasm/tests/generated/wasm-wide-arithmetic.csv b/crates/tinywasm/tests/generated/wasm-wide-arithmetic.csv index a40fa28..d740038 100644 --- a/crates/tinywasm/tests/generated/wasm-wide-arithmetic.csv +++ b/crates/tinywasm/tests/generated/wasm-wide-arithmetic.csv @@ -2,4 +2,4 @@ 0.9.1,109,0,[{"name":"wide-arithmetic.wast","passed":109,"failed":0}] 0.10.0,109,0,[{"name":"wide-arithmetic.wast","passed":109,"failed":0}] 0.11.0-pre.0,109,0,[{"name":"wide-arithmetic.wast","passed":109,"failed":0}] -0.11.0-beta.0,109,0,[{"name":"wide-arithmetic.wast","passed":109,"failed":0}] +0.11.0,109,0,[{"name":"wide-arithmetic.wast","passed":109,"failed":0}] diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 3837fdc..2d2bf91 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -4,6 +4,7 @@ version.workspace = true edition.workspace = true rust-version.workspace = true description = "Shared runtime, module, and archive types for TinyWasm" +homepage.workspace = true repository.workspace = true license.workspace = true keywords.workspace = true diff --git a/crates/wasi/Cargo.toml b/crates/wasi/Cargo.toml index f6923d4..e93f087 100644 --- a/crates/wasi/Cargo.toml +++ b/crates/wasi/Cargo.toml @@ -4,6 +4,7 @@ version.workspace = true edition.workspace = true rust-version.workspace = true description = "WASI support for TinyWasm" +homepage.workspace = true repository.workspace = true license.workspace = true keywords = ["tinywasm", "wasi", "wasm", "webassembly"] -- cgit v1.3.1