From a146f907f43e0c09222bc658fa9724795b63a299 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 2 Dec 2024 08:34:15 -0800 Subject: [PATCH 1/4] Rely on `core::error::Error` With Wasmtime's new MSRV at 1.81 this means that `core::error::Error` is available which means that in `no_std` mode the `Error` trait can be used. This has been integrated into `anyhow::Error` already upstream and means that we can remove our own local hacks such as the `Err2Anyhow` trait. This commit removes the `Err2Anyhow` trait and all usage, going back to idiomatic Rust error propagation and conversion even in the `no_std` world. This should make code more portable by default and remove some weird idioms we had for supporting this. prtest:full --- Cargo.lock | 72 +++++++-------- Cargo.toml | 6 +- crates/environ/src/compile/mod.rs | 3 +- crates/environ/src/obj.rs | 20 ++++ crates/environ/src/prelude.rs | 58 ------------ crates/environ/src/trap_encoding.rs | 3 +- crates/environ/src/types.rs | 3 +- crates/wasmtime/src/engine/serialization.rs | 12 +-- crates/wasmtime/src/runtime/code_memory.rs | 6 +- .../src/runtime/component/component.rs | 2 +- crates/wasmtime/src/runtime/component/func.rs | 4 +- .../src/runtime/component/func/host.rs | 8 +- .../src/runtime/component/func/options.rs | 8 +- .../src/runtime/component/func/typed.rs | 37 +++----- .../wasmtime/src/runtime/component/values.rs | 8 +- crates/wasmtime/src/runtime/debug.rs | 3 +- .../wasmtime/src/runtime/externals/table.rs | 11 +-- crates/wasmtime/src/runtime/gc.rs | 3 +- .../src/runtime/gc/enabled/arrayref.rs | 4 +- .../src/runtime/gc/enabled/externref.rs | 4 - .../src/runtime/gc/enabled/structref.rs | 4 +- crates/wasmtime/src/runtime/linker.rs | 6 +- crates/wasmtime/src/runtime/module.rs | 22 ++--- crates/wasmtime/src/runtime/store.rs | 4 +- crates/wasmtime/src/runtime/trap.rs | 4 +- crates/wasmtime/src/runtime/types.rs | 1 - crates/wasmtime/src/runtime/vm/byte_count.rs | 6 +- .../src/runtime/vm/component/libcalls.rs | 2 +- crates/wasmtime/src/runtime/vm/cow.rs | 34 +++---- .../wasmtime/src/runtime/vm/gc/enabled/drc.rs | 2 +- .../src/runtime/vm/gc/enabled/free_list.rs | 1 - .../src/runtime/vm/gc/enabled/null.rs | 4 +- .../src/runtime/vm/instance/allocator.rs | 29 +++--- .../instance/allocator/pooling/table_pool.rs | 4 +- .../allocator/pooling/unix_stack_pool.rs | 2 - crates/wasmtime/src/runtime/vm/libcalls.rs | 91 +++++++------------ .../wasmtime/src/runtime/vm/memory/malloc.rs | 12 +-- crates/wasmtime/src/runtime/vm/memory/mmap.rs | 10 +- crates/wasmtime/src/runtime/vm/mmap.rs | 2 +- .../wasmtime/src/runtime/vm/sys/unix/mmap.rs | 17 ++-- crates/wasmtime/src/runtime/vm/sys/unix/vm.rs | 19 ++-- .../src/runtime/vm/sys/windows/mmap.rs | 10 +- supply-chain/audits.toml | 2 +- supply-chain/imports.lock | 4 +- 44 files changed, 214 insertions(+), 353 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8767bb186385..7372d2d717f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,9 +133,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "arbitrary" @@ -160,7 +160,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -227,7 +227,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.60", + "syn 2.0.90", "which 4.4.2", ] @@ -579,7 +579,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -627,7 +627,7 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -1086,7 +1086,7 @@ checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -2019,7 +2019,7 @@ dependencies = [ "proc-macro2", "quote", "regex-syntax 0.8.5", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -2224,12 +2224,12 @@ checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" [[package]] name = "object" -version = "0.36.0" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "crc32fast", - "hashbrown 0.14.3", + "hashbrown 0.15.2", "indexmap 2.2.6", "memchr", ] @@ -2431,14 +2431,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -2835,22 +2835,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -3077,9 +3077,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -3222,7 +3222,7 @@ checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -3313,7 +3313,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -3408,7 +3408,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -3717,7 +3717,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", "wasm-bindgen-shared", ] @@ -3739,7 +3739,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4174,7 +4174,7 @@ dependencies = [ "serde", "serde_json", "similar", - "syn 2.0.60", + "syn 2.0.90", "tracing", "wasmtime", "wasmtime-component-util", @@ -4369,7 +4369,7 @@ dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", "wasmtime-wast-util", ] @@ -4379,7 +4379,7 @@ version = "28.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -4644,7 +4644,7 @@ dependencies = [ "proc-macro2", "quote", "shellexpand", - "syn 2.0.60", + "syn 2.0.90", "witx", ] @@ -4654,7 +4654,7 @@ version = "28.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", "wiggle", "wiggle-generate", ] @@ -4747,7 +4747,7 @@ checksum = "12168c33176773b86799be25e2a2ba07c7aab9968b37541f1094dbd7a60c8946" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -4758,7 +4758,7 @@ checksum = "9d8dc32e0095a7eeccebd0e3f09e9509365ecb3fc6ac4d6f5f14a3f6392942d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] @@ -4974,7 +4974,7 @@ dependencies = [ "heck 0.5.0", "indexmap 2.2.6", "prettyplease", - "syn 2.0.60", + "syn 2.0.90", "wasm-metadata 0.220.0", "wit-bindgen-core", "wit-component 0.220.0", @@ -4990,7 +4990,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", "wit-bindgen-core", "wit-bindgen-rust", ] @@ -5109,7 +5109,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.90", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c31a6de45d4f..2ec821c79311 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -291,10 +291,10 @@ wasm-wave = "0.221.2" # Non-Bytecode Alliance maintained dependencies: # -------------------------- cc = "1.0" -object = { version = "0.36", default-features = false, features = ['read_core', 'elf'] } +object = { version = "0.36.5", default-features = false, features = ['read_core', 'elf'] } gimli = { version = "0.31.0", default-features = false, features = ['read'] } addr2line = { version = "0.24.1", default-features = false } -anyhow = { version = "1.0.22", default-features = false } +anyhow = { version = "1.0.93", default-features = false } windows-sys = "0.59.0" env_logger = "0.11.5" log = { version = "0.4.8", default-features = false } @@ -317,7 +317,7 @@ proptest = "1.0.0" rand = { version = "0.8.3", features = ["small_rng"] } sptr = "0.3.2" # serde and serde_derive must have the same version -serde = { version = "1.0.188", default-features = false, features = ['alloc'] } +serde = { version = "1.0.215", default-features = false, features = ['alloc'] } serde_derive = "1.0.188" serde_json = "1.0.80" glob = "0.3.0" diff --git a/crates/environ/src/compile/mod.rs b/crates/environ/src/compile/mod.rs index 51da11a9f672..de12ba29f3f0 100644 --- a/crates/environ/src/compile/mod.rs +++ b/crates/environ/src/compile/mod.rs @@ -59,8 +59,7 @@ impl From for CompileError { } } -#[cfg(feature = "std")] -impl std::error::Error for CompileError { +impl core::error::Error for CompileError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { CompileError::Wasm(e) => Some(e), diff --git a/crates/environ/src/obj.rs b/crates/environ/src/obj.rs index 2b904d76b48d..d50b5b1eca0a 100644 --- a/crates/environ/src/obj.rs +++ b/crates/environ/src/obj.rs @@ -1,6 +1,8 @@ //! Utilities for working with object files that operate as Wasmtime's //! serialization and intermediate format for compiled modules. +use core::fmt; + /// Filler for the `os_abi` field of the ELF header. /// /// This is just a constant that seems reasonable in the sense it's unlikely to @@ -177,3 +179,21 @@ libcalls! { FmaF64 = "libcall_fmaf64" X86Pshufb = "libcall_x86_pshufb" } + +/// Workaround to implement `core::error::Error` until +/// gimli-rs/object#747 is settled. +pub struct ObjectCrateErrorWrapper(pub object::Error); + +impl fmt::Debug for ObjectCrateErrorWrapper { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::Display for ObjectCrateErrorWrapper { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl core::error::Error for ObjectCrateErrorWrapper {} diff --git a/crates/environ/src/prelude.rs b/crates/environ/src/prelude.rs index 43168d1f1748..94d30d3b1363 100644 --- a/crates/environ/src/prelude.rs +++ b/crates/environ/src/prelude.rs @@ -26,61 +26,3 @@ pub use alloc::string::{String, ToString}; pub use alloc::vec; pub use alloc::vec::Vec; pub use wasmparser::collections::{IndexMap, IndexSet}; - -/// Convenience trait for converting `Result` into `anyhow::Result` -/// -/// Typically this is automatically done with the `?` operator in Rust and -/// by default this trait isn't necessary. With the `anyhow` crate's `std` -/// feature disabled, however, the `?` operator won't work because the `Error` -/// trait is not defined. This trait helps to bridge this gap. -/// -/// This does the same thing as `?` when the `std` feature is enabled, and when -/// `std` is disabled it'll use different trait bounds to create an -/// `anyhow::Error`. -/// -/// This trait is not suitable as a public interface because features change -/// what implements the trait. It's good enough for a wasmtime internal -/// implementation detail, however. -pub trait Err2Anyhow { - /// Convert `self` to `anyhow::Result`. - fn err2anyhow(self) -> anyhow::Result; -} - -impl Err2Anyhow for Result { - fn err2anyhow(self) -> anyhow::Result { - match self { - Ok(e) => Ok(e), - Err(e) => Err(e.into_anyhow()), - } - } -} - -/// Convenience trait to convert a value into `anyhow::Error` -/// -/// This trait is not a suitable public interface of Wasmtime so it's just an -/// internal implementation detail for now. This trait is conditionally -/// implemented on the `std` feature with different bounds. -pub trait IntoAnyhow { - /// Converts `self` into an `anyhow::Error`. - fn into_anyhow(self) -> anyhow::Error; -} - -#[cfg(feature = "std")] -impl IntoAnyhow for T -where - T: Into, -{ - fn into_anyhow(self) -> anyhow::Error { - self.into() - } -} - -#[cfg(not(feature = "std"))] -impl IntoAnyhow for T -where - T: core::fmt::Display + core::fmt::Debug + Send + Sync + 'static, -{ - fn into_anyhow(self) -> anyhow::Error { - anyhow::Error::msg(self) - } -} diff --git a/crates/environ/src/trap_encoding.rs b/crates/environ/src/trap_encoding.rs index b735f8d9e3ce..0006d3e3ec9a 100644 --- a/crates/environ/src/trap_encoding.rs +++ b/crates/environ/src/trap_encoding.rs @@ -159,8 +159,7 @@ impl fmt::Display for Trap { } } -#[cfg(feature = "std")] -impl std::error::Error for Trap {} +impl core::error::Error for Trap {} /// Decodes the provided trap information section and attempts to find the trap /// code corresponding to the `offset` specified. diff --git a/crates/environ/src/types.rs b/crates/environ/src/types.rs index 2d70bc698a6e..ed6065291e52 100644 --- a/crates/environ/src/types.rs +++ b/crates/environ/src/types.rs @@ -1887,8 +1887,7 @@ impl fmt::Display for SizeOverflow { } } -#[cfg(feature = "std")] -impl std::error::Error for SizeOverflow {} +impl core::error::Error for SizeOverflow {} impl From for Memory { fn from(ty: wasmparser::MemoryType) -> Memory { diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs index 6f42c35772ed..94b3ad37607c 100644 --- a/crates/wasmtime/src/engine/serialization.rs +++ b/crates/wasmtime/src/engine/serialization.rs @@ -57,7 +57,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R // a perf issue right now so doing that is left for another day's // refactoring. let obj = ElfFile64::::parse(mmap) - .err2anyhow() + .map_err(obj::ObjectCrateErrorWrapper) .context("failed to parse precompiled artifact as an ELF")?; let expected_e_flags = match expected { ObjectKind::Module => obj::EF_WASMTIME_MODULE, @@ -76,7 +76,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R .section_by_name(obj::ELF_WASM_ENGINE) .ok_or_else(|| anyhow!("failed to find section `{}`", obj::ELF_WASM_ENGINE))? .data() - .err2anyhow()?; + .map_err(obj::ObjectCrateErrorWrapper)?; let (first, data) = data .split_first() .ok_or_else(|| anyhow!("invalid engine section"))?; @@ -95,7 +95,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R match &engine.config().module_version { ModuleVersionStrategy::WasmtimeVersion => { - let version = core::str::from_utf8(version).err2anyhow()?; + let version = core::str::from_utf8(version)?; if version != env!("CARGO_PKG_VERSION") { bail!( "Module was compiled with incompatible Wasmtime version '{}'", @@ -104,7 +104,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R } } ModuleVersionStrategy::Custom(v) => { - let version = core::str::from_utf8(&version).err2anyhow()?; + let version = core::str::from_utf8(&version)?; if version != v { bail!( "Module was compiled with incompatible version '{}'", @@ -114,9 +114,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R } ModuleVersionStrategy::None => { /* ignore the version info, accept all */ } } - postcard::from_bytes::>(data) - .err2anyhow()? - .check_compatible(engine) + postcard::from_bytes::>(data)?.check_compatible(engine) } #[cfg(any(feature = "cranelift", feature = "winch"))] diff --git a/crates/wasmtime/src/runtime/code_memory.rs b/crates/wasmtime/src/runtime/code_memory.rs index b1eb98caef7a..8ad04f789b71 100644 --- a/crates/wasmtime/src/runtime/code_memory.rs +++ b/crates/wasmtime/src/runtime/code_memory.rs @@ -58,7 +58,7 @@ impl CodeMemory { /// `publish` method is used to actually make the memory executable. pub fn new(mmap: MmapVec) -> Result { let obj = ElfFile64::::parse(&mmap[..]) - .err2anyhow() + .map_err(obj::ObjectCrateErrorWrapper) .with_context(|| "failed to parse internal compilation artifact")?; let mut relocations = Vec::new(); @@ -75,8 +75,8 @@ impl CodeMemory { let mut info_data = 0..0; let mut wasm_dwarf = 0..0; for section in obj.sections() { - let data = section.data().err2anyhow()?; - let name = section.name().err2anyhow()?; + let data = section.data().map_err(obj::ObjectCrateErrorWrapper)?; + let name = section.name().map_err(obj::ObjectCrateErrorWrapper)?; let range = subslice_range(data, &mmap); // Double-check that sections are all aligned properly. diff --git a/crates/wasmtime/src/runtime/component/component.rs b/crates/wasmtime/src/runtime/component/component.rs index c32f319bdfb4..10af60dc94ec 100644 --- a/crates/wasmtime/src/runtime/component/component.rs +++ b/crates/wasmtime/src/runtime/component/component.rs @@ -388,7 +388,7 @@ impl Component { static_modules, } = match artifacts { Some(artifacts) => artifacts, - None => postcard::from_bytes(code_memory.wasmtime_info()).err2anyhow()?, + None => postcard::from_bytes(code_memory.wasmtime_info())?, }; // Validate that the component can be used with the current instance diff --git a/crates/wasmtime/src/runtime/component/func.rs b/crates/wasmtime/src/runtime/component/func.rs index 6643f6ecef7b..9ac5329af7ce 100644 --- a/crates/wasmtime/src/runtime/component/func.rs +++ b/crates/wasmtime/src/runtime/component/func.rs @@ -669,8 +669,8 @@ impl Func { src: &mut core::slice::Iter<'_, ValRaw>, ) -> Result<()> { // FIXME: needs to read an i64 for memory64 - let ptr = usize::try_from(src.next().unwrap().get_u32()).err2anyhow()?; - if ptr % usize::try_from(results_ty.abi.align32).err2anyhow()? != 0 { + let ptr = usize::try_from(src.next().unwrap().get_u32())?; + if ptr % usize::try_from(results_ty.abi.align32)? != 0 { bail!("return pointer not aligned"); } diff --git a/crates/wasmtime/src/runtime/component/func/host.rs b/crates/wasmtime/src/runtime/component/func/host.rs index f53df1b6b6f6..d55ac2ce5237 100644 --- a/crates/wasmtime/src/runtime/component/func/host.rs +++ b/crates/wasmtime/src/runtime/component/func/host.rs @@ -275,8 +275,8 @@ where fn validate_inbounds(memory: &[u8], ptr: &ValRaw) -> Result { // FIXME: needs memory64 support - let ptr = usize::try_from(ptr.get_u32()).err2anyhow()?; - if ptr % usize::try_from(T::ALIGN32).err2anyhow()? != 0 { + let ptr = usize::try_from(ptr.get_u32())?; + if ptr % usize::try_from(T::ALIGN32)? != 0 { bail!("pointer not aligned"); } let end = match ptr.checked_add(T::SIZE32) { @@ -407,8 +407,8 @@ where fn validate_inbounds_dynamic(abi: &CanonicalAbiInfo, memory: &[u8], ptr: &ValRaw) -> Result { // FIXME: needs memory64 support - let ptr = usize::try_from(ptr.get_u32()).err2anyhow()?; - if ptr % usize::try_from(abi.align32).err2anyhow()? != 0 { + let ptr = usize::try_from(ptr.get_u32())?; + if ptr % usize::try_from(abi.align32)? != 0 { bail!("pointer not aligned"); } let end = match ptr.checked_add(usize::try_from(abi.size32).unwrap()) { diff --git a/crates/wasmtime/src/runtime/component/func/options.rs b/crates/wasmtime/src/runtime/component/func/options.rs index 83accf3dee97..cd0482965e21 100644 --- a/crates/wasmtime/src/runtime/component/func/options.rs +++ b/crates/wasmtime/src/runtime/component/func/options.rs @@ -89,10 +89,10 @@ impl Options { let realloc = self.realloc.unwrap(); let params = ( - u32::try_from(old).err2anyhow()?, - u32::try_from(old_size).err2anyhow()?, + u32::try_from(old)?, + u32::try_from(old_size)?, old_align, - u32::try_from(new_size).err2anyhow()?, + u32::try_from(new_size)?, ); type ReallocFunc = crate::TypedFunc<(u32, u32, u32, u32), u32>; @@ -108,7 +108,7 @@ impl Options { if result % old_align != 0 { bail!("realloc return: result not aligned"); } - let result = usize::try_from(result).err2anyhow()?; + let result = usize::try_from(result)?; let memory = self.memory_mut(store.0); diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rs index a2ab99c55ba8..4dd5050e000d 100644 --- a/crates/wasmtime/src/runtime/component/func/typed.rs +++ b/crates/wasmtime/src/runtime/component/func/typed.rs @@ -315,8 +315,8 @@ where ) -> Result { assert!(Return::flatten_count() > MAX_FLAT_RESULTS); // FIXME: needs to read an i64 for memory64 - let ptr = usize::try_from(dst.get_u32()).err2anyhow()?; - if ptr % usize::try_from(Return::ALIGN32).err2anyhow()? != 0 { + let ptr = usize::try_from(dst.get_u32())?; + if ptr % usize::try_from(Return::ALIGN32)? != 0 { bail!("return pointer not aligned"); } @@ -1053,7 +1053,7 @@ unsafe impl Lift for char { #[inline] fn lift(_cx: &mut LiftContext<'_>, ty: InterfaceType, src: &Self::Lower) -> Result { debug_assert!(matches!(ty, InterfaceType::Char)); - Ok(char::try_from(src.get_u32()).err2anyhow()?) + Ok(char::try_from(src.get_u32())?) } #[inline] @@ -1061,7 +1061,7 @@ unsafe impl Lift for char { debug_assert!(matches!(ty, InterfaceType::Char)); debug_assert!((bytes.as_ptr() as usize) % Self::SIZE32 == 0); let bits = u32::from_le_bytes(bytes.try_into().unwrap()); - Ok(char::try_from(bits).err2anyhow()?) + Ok(char::try_from(bits)?) } } @@ -1337,9 +1337,7 @@ impl WasmStr { // Note that bounds-checking already happen in construction of `WasmStr` // so this is never expected to panic. This could theoretically be // unchecked indexing if we're feeling wild enough. - Ok(str::from_utf8(&memory[self.ptr..][..self.len]) - .err2anyhow()? - .into()) + Ok(str::from_utf8(&memory[self.ptr..][..self.len])?.into()) } fn decode_utf16<'a>(&self, memory: &'a [u8], len: usize) -> Result> { @@ -1350,8 +1348,7 @@ impl WasmStr { .chunks(2) .map(|chunk| u16::from_le_bytes(chunk.try_into().unwrap())), ) - .collect::>() - .err2anyhow()? + .collect::>()? .into()) } @@ -1385,10 +1382,7 @@ unsafe impl Lift for WasmStr { // FIXME: needs memory64 treatment let ptr = src[0].get_u32(); let len = src[1].get_u32(); - let (ptr, len) = ( - usize::try_from(ptr).err2anyhow()?, - usize::try_from(len).err2anyhow()?, - ); + let (ptr, len) = (usize::try_from(ptr)?, usize::try_from(len)?); WasmStr::new(ptr, len, cx) } @@ -1399,10 +1393,7 @@ unsafe impl Lift for WasmStr { // FIXME: needs memory64 treatment let ptr = u32::from_le_bytes(bytes[..4].try_into().unwrap()); let len = u32::from_le_bytes(bytes[4..].try_into().unwrap()); - let (ptr, len) = ( - usize::try_from(ptr).err2anyhow()?, - usize::try_from(len).err2anyhow()?, - ); + let (ptr, len) = (usize::try_from(ptr)?, usize::try_from(len)?); WasmStr::new(ptr, len, cx) } } @@ -1539,7 +1530,7 @@ impl WasmList { Some(n) if n <= cx.memory().len() => {} _ => bail!("list pointer/length out of bounds of memory"), } - if ptr % usize::try_from(T::ALIGN32).err2anyhow()? != 0 { + if ptr % usize::try_from(T::ALIGN32)? != 0 { bail!("list pointer is not aligned") } Ok(WasmList { @@ -1695,10 +1686,7 @@ unsafe impl Lift for WasmList { // FIXME: needs memory64 treatment let ptr = src[0].get_u32(); let len = src[1].get_u32(); - let (ptr, len) = ( - usize::try_from(ptr).err2anyhow()?, - usize::try_from(len).err2anyhow()?, - ); + let (ptr, len) = (usize::try_from(ptr)?, usize::try_from(len)?); WasmList::new(ptr, len, cx, elem) } @@ -1711,10 +1699,7 @@ unsafe impl Lift for WasmList { // FIXME: needs memory64 treatment let ptr = u32::from_le_bytes(bytes[..4].try_into().unwrap()); let len = u32::from_le_bytes(bytes[4..].try_into().unwrap()); - let (ptr, len) = ( - usize::try_from(ptr).err2anyhow()?, - usize::try_from(len).err2anyhow()?, - ); + let (ptr, len) = (usize::try_from(ptr)?, usize::try_from(len)?); WasmList::new(ptr, len, cx, elem) } } diff --git a/crates/wasmtime/src/runtime/component/values.rs b/crates/wasmtime/src/runtime/component/values.rs index 423158c0047d..15d99847897d 100644 --- a/crates/wasmtime/src/runtime/component/values.rs +++ b/crates/wasmtime/src/runtime/component/values.rs @@ -439,9 +439,7 @@ impl Val { ty: InterfaceType, offset: usize, ) -> Result<()> { - debug_assert!( - offset % usize::try_from(cx.types.canonical_abi(&ty).align32).err2anyhow()? == 0 - ); + debug_assert!(offset % usize::try_from(cx.types.canonical_abi(&ty).align32)? == 0); match (ty, self) { (InterfaceType::Bool, Val::Bool(value)) => value.store(cx, ty, offset), @@ -832,7 +830,7 @@ fn load_list(cx: &mut LiftContext<'_>, ty: TypeListIndex, ptr: usize, len: usize Some(n) if n <= cx.memory().len() => {} _ => bail!("list pointer/length out of bounds of memory"), } - if ptr % usize::try_from(element_alignment).err2anyhow()? != 0 { + if ptr % usize::try_from(element_alignment)? != 0 { bail!("list pointer is not aligned") } @@ -914,7 +912,7 @@ fn lower_list( items: &[Val], ) -> Result<(usize, usize)> { let abi = cx.types.canonical_abi(&element_type); - let elt_size = usize::try_from(abi.size32).err2anyhow()?; + let elt_size = usize::try_from(abi.size32)?; let elt_align = abi.align32; let size = items .len() diff --git a/crates/wasmtime/src/runtime/debug.rs b/crates/wasmtime/src/runtime/debug.rs index 6636e19b56e0..1fa4d430b88d 100644 --- a/crates/wasmtime/src/runtime/debug.rs +++ b/crates/wasmtime/src/runtime/debug.rs @@ -7,6 +7,7 @@ use object::{ File, NativeEndian as NE, Object, ObjectSection, ObjectSymbol, RelocationEncoding, RelocationKind, RelocationTarget, U64Bytes, }; +use wasmtime_environ::obj; pub(crate) fn create_gdbjit_image( mut bytes: Vec, @@ -32,7 +33,7 @@ pub(crate) fn create_gdbjit_image( fn relocate_dwarf_sections(bytes: &mut [u8], code_region: (*const u8, usize)) -> Result<(), Error> { let mut relocations = Vec::new(); - let obj = File::parse(&bytes[..]).err2anyhow()?; + let obj = File::parse(&bytes[..]).map_err(obj::ObjectCrateErrorWrapper)?; for section in obj.sections() { let section_start = match section.file_range() { Some((start, _)) => start, diff --git a/crates/wasmtime/src/runtime/externals/table.rs b/crates/wasmtime/src/runtime/externals/table.rs index ea765f12bab5..24f611a4c005 100644 --- a/crates/wasmtime/src/runtime/externals/table.rs +++ b/crates/wasmtime/src/runtime/externals/table.rs @@ -111,9 +111,7 @@ impl Table { unsafe { let table = Table::from_wasmtime_table(wasmtime_export, store); let wasmtime_table = table.wasmtime_table(store, iter::empty()); - (*wasmtime_table) - .fill(store.optional_gc_store_mut()?, 0, init, ty.minimum()) - .err2anyhow()?; + (*wasmtime_table).fill(store.optional_gc_store_mut()?, 0, init, ty.minimum())?; Ok(table) } } @@ -344,8 +342,7 @@ impl Table { dst_index, src_index, len, - ) - .err2anyhow()?; + )?; } Ok(()) } @@ -373,9 +370,7 @@ impl Table { let table = self.wasmtime_table(store, iter::empty()); unsafe { - (*table) - .fill(store.optional_gc_store_mut()?, dst, val, len) - .err2anyhow()?; + (*table).fill(store.optional_gc_store_mut()?, dst, val, len)?; } Ok(()) diff --git a/crates/wasmtime/src/runtime/gc.rs b/crates/wasmtime/src/runtime/gc.rs index bcce10e76f62..6c972e287c8d 100644 --- a/crates/wasmtime/src/runtime/gc.rs +++ b/crates/wasmtime/src/runtime/gc.rs @@ -80,8 +80,7 @@ impl fmt::Display for GcHeapOutOfMemory { } } -#[cfg(feature = "std")] -impl std::error::Error for GcHeapOutOfMemory {} +impl core::error::Error for GcHeapOutOfMemory {} impl GcHeapOutOfMemory { pub(crate) fn new(inner: T) -> Self { diff --git a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs index 22661caea007..14ee5b783856 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs @@ -321,10 +321,8 @@ impl ArrayRef { let arrayref = store .gc_store_mut()? .alloc_uninit_array(allocator.type_index(), len, allocator.layout()) - .err2anyhow() .context("unrecoverable error when allocating new `arrayref`")? - .ok_or_else(|| GcHeapOutOfMemory::new(())) - .err2anyhow()?; + .ok_or_else(|| GcHeapOutOfMemory::new(()))?; // From this point on, if we get any errors, then the array is not // fully initialized, so we need to eagerly deallocate it before the diff --git a/crates/wasmtime/src/runtime/gc/enabled/externref.rs b/crates/wasmtime/src/runtime/gc/enabled/externref.rs index 3db2fc5dbdd4..995477f2fa73 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/externref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/externref.rs @@ -209,10 +209,8 @@ impl ExternRef { let gc_ref = ctx .gc_store_mut()? .alloc_externref(value) - .err2anyhow() .context("unrecoverable error when allocating new `externref`")? .map_err(|x| GcHeapOutOfMemory::::new(*x.downcast().unwrap())) - .err2anyhow() .context("failed to allocate `externref`")?; let mut ctx = AutoAssertNoGc::new(ctx); @@ -320,10 +318,8 @@ impl ExternRef { let gc_ref = ctx .gc_store_mut()? .alloc_externref(value) - .err2anyhow() .context("unrecoverable error when allocating new `externref`")? .map_err(|x| GcHeapOutOfMemory::::new(*x.downcast().unwrap())) - .err2anyhow() .context("failed to allocate `externref`")?; let mut ctx = AutoAssertNoGc::new(ctx); diff --git a/crates/wasmtime/src/runtime/gc/enabled/structref.rs b/crates/wasmtime/src/runtime/gc/enabled/structref.rs index c3171008a152..e111c2f2e633 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/structref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/structref.rs @@ -269,10 +269,8 @@ impl StructRef { let structref = store .gc_store_mut()? .alloc_uninit_struct(allocator.type_index(), &allocator.layout()) - .err2anyhow() .context("unrecoverable error when allocating new `structref`")? - .ok_or_else(|| GcHeapOutOfMemory::new(())) - .err2anyhow()?; + .ok_or_else(|| GcHeapOutOfMemory::new(()))?; // From this point on, if we get any errors, then the struct is not // fully initialized, so we need to eagerly deallocate it before the diff --git a/crates/wasmtime/src/runtime/linker.rs b/crates/wasmtime/src/runtime/linker.rs index 1bb0d83565ab..95cbb548447b 100644 --- a/crates/wasmtime/src/runtime/linker.rs +++ b/crates/wasmtime/src/runtime/linker.rs @@ -1199,8 +1199,7 @@ impl Linker { let mut imports = module .imports() .map(|import| self._get_by_import(&import)) - .collect::, _>>() - .err2anyhow()?; + .collect::, _>>()?; if let Some(store) = store { for import in imports.iter_mut() { import.update_size(store); @@ -1494,5 +1493,4 @@ impl fmt::Display for UnknownImportError { } } -#[cfg(feature = "std")] -impl std::error::Error for UnknownImportError {} +impl core::error::Error for UnknownImportError {} diff --git a/crates/wasmtime/src/runtime/module.rs b/crates/wasmtime/src/runtime/module.rs index 92450efd5944..9f2c99a540b9 100644 --- a/crates/wasmtime/src/runtime/module.rs +++ b/crates/wasmtime/src/runtime/module.rs @@ -476,7 +476,7 @@ impl Module { // already. let (info, types) = match info_and_types { Some((info, types)) => (info, types), - None => postcard::from_bytes(code_memory.wasmtime_info()).err2anyhow()?, + None => postcard::from_bytes(code_memory.wasmtime_info())?, }; // Register function type signatures into the engine for the lifetime @@ -546,8 +546,8 @@ impl Module { let mut functions = Vec::new(); for payload in Parser::new(0).parse_all(binary) { - let payload = payload.err2anyhow()?; - if let ValidPayload::Func(a, b) = validator.payload(&payload).err2anyhow()? { + let payload = payload?; + if let ValidPayload::Func(a, b) = validator.payload(&payload)? { functions.push((a, b)); } if let wasmparser::Payload::Version { encoding, .. } = &payload { @@ -557,15 +557,13 @@ impl Module { } } - engine - .run_maybe_parallel(functions, |(validator, body)| { - // FIXME: it would be best here to use a rayon-specific parallel - // iterator that maintains state-per-thread to share the function - // validator allocations (`Default::default` here) across multiple - // functions. - validator.into_validator(Default::default()).validate(&body) - }) - .err2anyhow()?; + engine.run_maybe_parallel(functions, |(validator, body)| { + // FIXME: it would be best here to use a rayon-specific parallel + // iterator that maintains state-per-thread to share the function + // validator allocations (`Default::default` here) across multiple + // functions. + validator.into_validator(Default::default()).validate(&body) + })?; Ok(()) } diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rs index 810283bd29c4..7651c7900a88 100644 --- a/crates/wasmtime/src/runtime/store.rs +++ b/crates/wasmtime/src/runtime/store.rs @@ -2626,7 +2626,7 @@ unsafe impl crate::runtime::vm::VMStore for StoreInner { fn out_of_gas(&mut self) -> Result<()> { if !self.refuel() { - return Err(Trap::OutOfFuel).err2anyhow(); + return Err(Trap::OutOfFuel.into()); } #[cfg(feature = "async")] if self.fuel_yield_interval.is_some() { @@ -2640,7 +2640,7 @@ unsafe impl crate::runtime::vm::VMStore for StoreInner { // multiple times. let mut behavior = self.epoch_deadline_behavior.take(); let delta_result = match &mut behavior { - None => Err(Trap::Interrupt).err2anyhow(), + None => Err(Trap::Interrupt.into()), Some(callback) => callback((&mut *self).as_context_mut()).and_then(|update| { let delta = match update { UpdateDeadline::Continue(delta) => delta, diff --git a/crates/wasmtime/src/runtime/trap.rs b/crates/wasmtime/src/runtime/trap.rs index 608f055756f6..358a96519abb 100644 --- a/crates/wasmtime/src/runtime/trap.rs +++ b/crates/wasmtime/src/runtime/trap.rs @@ -99,7 +99,7 @@ pub(crate) fn from_runtime_box( faulting_addr, trap, } => { - let mut err: Error = trap.into_anyhow(); + let mut err: Error = trap.into(); // If a fault address was present, for example with segfaults, // then simultaneously assert that it's within a known linear memory @@ -110,7 +110,7 @@ pub(crate) fn from_runtime_box( } (err, Some(pc)) } - crate::runtime::vm::TrapReason::Wasm(trap_code) => (trap_code.into_anyhow(), None), + crate::runtime::vm::TrapReason::Wasm(trap_code) => (trap_code.into(), None), }; if let Some(bt) = backtrace { diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rs index 1fa7743061c3..65a17d6510a4 100644 --- a/crates/wasmtime/src/runtime/types.rs +++ b/crates/wasmtime/src/runtime/types.rs @@ -2629,7 +2629,6 @@ impl MemoryTypeBuilder { let min = self .ty .minimum_byte_size() - .err2anyhow() .context("memory's minimum byte size must fit in a u64")?; if min > absolute_max { bail!("minimum size is too large for this memory type's index type"); diff --git a/crates/wasmtime/src/runtime/vm/byte_count.rs b/crates/wasmtime/src/runtime/vm/byte_count.rs index 4fff11a51ca3..5c963b2faad5 100644 --- a/crates/wasmtime/src/runtime/vm/byte_count.rs +++ b/crates/wasmtime/src/runtime/vm/byte_count.rs @@ -233,8 +233,7 @@ impl fmt::Display for ByteCountNotAligned { } } -#[cfg(feature = "std")] -impl std::error::Error for ByteCountNotAligned {} +impl core::error::Error for ByteCountNotAligned {} #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct ByteCountOutOfBounds(ByteCountOutOfBoundsKind); @@ -245,8 +244,7 @@ impl fmt::Display for ByteCountOutOfBounds { } } -#[cfg(feature = "std")] -impl std::error::Error for ByteCountOutOfBounds {} +impl core::error::Error for ByteCountOutOfBounds {} #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum ByteCountOutOfBoundsKind { diff --git a/crates/wasmtime/src/runtime/vm/component/libcalls.rs b/crates/wasmtime/src/runtime/vm/component/libcalls.rs index 7135524bf0bf..31671f5fe6a6 100644 --- a/crates/wasmtime/src/runtime/vm/component/libcalls.rs +++ b/crates/wasmtime/src/runtime/vm/component/libcalls.rs @@ -566,5 +566,5 @@ unsafe fn resource_exit_call(vmctx: *mut VMComponentContext) -> Result<()> { } unsafe fn trap(_vmctx: *mut VMComponentContext, code: u8) -> Result<()> { - Err(wasmtime_environ::Trap::from_u8(code).unwrap()).err2anyhow() + Err(wasmtime_environ::Trap::from_u8(code).unwrap().into()) } diff --git a/crates/wasmtime/src/runtime/vm/cow.rs b/crates/wasmtime/src/runtime/vm/cow.rs index d2ff38aa8134..37ba1864c140 100644 --- a/crates/wasmtime/src/runtime/vm/cow.rs +++ b/crates/wasmtime/src/runtime/vm/cow.rs @@ -119,7 +119,7 @@ impl MemoryImage { // If `mmap` doesn't come from a file then platform-specific mechanisms // may be used to place the data in a form that's amenable to an mmap. - if let Some(source) = MemoryImageSource::from_data(data).err2anyhow()? { + if let Some(source) = MemoryImageSource::from_data(data)? { return Ok(Some(MemoryImage { source, source_offset: 0, @@ -132,23 +132,19 @@ impl MemoryImage { } unsafe fn map_at(&self, base: *mut u8) -> Result<()> { - self.source - .map_at( - base.add(self.linear_memory_offset.byte_count()), - self.len.byte_count(), - self.source_offset, - ) - .err2anyhow()?; + self.source.map_at( + base.add(self.linear_memory_offset.byte_count()), + self.len.byte_count(), + self.source_offset, + )?; Ok(()) } unsafe fn remap_as_zeros_at(&self, base: *mut u8) -> Result<()> { - self.source - .remap_as_zeros_at( - base.add(self.linear_memory_offset.byte_count()), - self.len.byte_count(), - ) - .err2anyhow()?; + self.source.remap_as_zeros_at( + base.add(self.linear_memory_offset.byte_count()), + self.len.byte_count(), + )?; Ok(()) } } @@ -364,7 +360,7 @@ impl MemoryImageSlot { } pub(crate) fn set_heap_limit(&mut self, size_bytes: usize) -> Result<()> { - let size_bytes_aligned = HostAlignedByteCount::new_rounded_up(size_bytes).err2anyhow()?; + let size_bytes_aligned = HostAlignedByteCount::new_rounded_up(size_bytes)?; assert!(size_bytes <= self.static_size); assert!(size_bytes_aligned.byte_count() <= self.static_size); @@ -414,7 +410,7 @@ impl MemoryImageSlot { assert!(!self.dirty); assert!(initial_size_bytes <= self.static_size); let initial_size_bytes_page_aligned = - HostAlignedByteCount::new_rounded_up(initial_size_bytes).err2anyhow()?; + HostAlignedByteCount::new_rounded_up(initial_size_bytes)?; // First order of business is to blow away the previous linear memory // image if it doesn't match the image specified here. If one is @@ -707,9 +703,9 @@ impl MemoryImageSlot { unsafe { let start = self.base.as_ptr().add(range.start.byte_count()); if readwrite { - vm::expose_existing_mapping(start, len.byte_count()).err2anyhow()?; + vm::expose_existing_mapping(start, len.byte_count())?; } else { - vm::hide_existing_mapping(start, len.byte_count()).err2anyhow()?; + vm::hide_existing_mapping(start, len.byte_count())?; } } @@ -735,7 +731,7 @@ impl MemoryImageSlot { } unsafe { - vm::erase_existing_mapping(self.base.as_ptr(), self.static_size).err2anyhow()?; + vm::erase_existing_mapping(self.base.as_ptr(), self.static_size)?; } self.image = None; diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs index fb6f81c71adf..9ac172a52bf9 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs @@ -550,7 +550,7 @@ unsafe impl GcHeap for DrcHeap { let size = u32::try_from(layout.size()).unwrap(); if !VMGcKind::value_fits_in_unused_bits(size) { - return Err(crate::Trap::AllocationTooLarge.into_anyhow()); + return Err(crate::Trap::AllocationTooLarge.into()); } let gc_ref = match self.free_list.alloc(layout)? { diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/free_list.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/free_list.rs index bc79d1c15b83..e1d2a3f923e6 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled/free_list.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled/free_list.rs @@ -60,7 +60,6 @@ impl FreeList { ); let alloc_size = u32::try_from(layout.size()) - .err2anyhow() .context("requested allocation's size does not fit in a u32")?; alloc_size .checked_next_multiple_of(ALIGN_U32) diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs index a423bccb1537..776b3aabd1fb 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs @@ -111,7 +111,7 @@ impl VMNullExternRef { } fn oom() -> Error { - GcHeapOutOfMemory::new(()).into_anyhow() + GcHeapOutOfMemory::new(()).into() } impl NullHeap { @@ -144,7 +144,7 @@ impl NullHeap { } }) { Some(size) => size, - None => return Err(crate::Trap::AllocationTooLarge.into_anyhow()), + None => return Err(crate::Trap::AllocationTooLarge.into()), }; let next = *self.next.get_mut(); diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator.rs b/crates/wasmtime/src/runtime/vm/instance/allocator.rs index 7e32791f515e..1f3ee06ccfab 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator.rs @@ -583,7 +583,7 @@ fn initialize_tables( let gc_store = store.gc_store_mut()?; let items = (0..table.size()) .map(|_| gc_ref.as_ref().map(|r| gc_store.clone_gc_ref(r))); - table.init_gc_refs(0, items).err2anyhow()?; + table.init_gc_refs(0, items)?; } WasmHeapTopType::Any => { @@ -591,13 +591,13 @@ fn initialize_tables( let gc_store = store.gc_store_mut()?; let items = (0..table.size()) .map(|_| gc_ref.as_ref().map(|r| gc_store.clone_gc_ref(r))); - table.init_gc_refs(0, items).err2anyhow()?; + table.init_gc_refs(0, items)?; } WasmHeapTopType::Func => { let funcref = NonNull::new(raw.get_funcref().cast::()); let items = (0..table.size()).map(|_| funcref); - table.init_func(0, items).err2anyhow()?; + table.init_func(0, items)?; } } } @@ -617,18 +617,15 @@ fn initialize_tables( .eval(store, context, &segment.offset) .expect("const expression should be valid") }; - context - .instance - .table_init_segment( - store, - const_evaluator, - segment.table_index, - &segment.elements, - start.get_u64(), - 0, - segment.elements.len(), - ) - .err2anyhow()?; + context.instance.table_init_segment( + store, + const_evaluator, + segment.table_index, + &segment.elements, + start.get_u64(), + 0, + segment.elements.len(), + )?; } Ok(()) @@ -762,7 +759,7 @@ fn initialize_memories( const_evaluator, }); if !ok { - return Err(Trap::MemoryOutOfBounds).err2anyhow(); + return Err(Trap::MemoryOutOfBounds.into()); } Ok(()) diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs index 5c60deeea744..7510d56b17bb 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs @@ -34,15 +34,13 @@ impl TablePool { mem::size_of::<*mut u8>() .checked_mul(config.limits.table_elements) .ok_or_else(|| anyhow!("table size exceeds addressable memory"))?, - ) - .err2anyhow()?; + )?; let max_total_tables = usize::try_from(config.limits.total_tables).unwrap(); let tables_per_instance = usize::try_from(config.limits.max_tables_per_module).unwrap(); let allocation_size = table_size .checked_mul(max_total_tables) - .err2anyhow() .context("total size of tables exceeds addressable memory")?; let mapping = Mmap::accessible_reserved(allocation_size, allocation_size) diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs index c443adb228a9..c4ef3fd91bd1 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs @@ -40,7 +40,6 @@ impl StackPool { } else { HostAlignedByteCount::new_rounded_up(config.stack_size) .and_then(|size| size.checked_add(HostAlignedByteCount::host_page_size())) - .err2anyhow() .context("stack size exceeds addressable memory")? }; @@ -48,7 +47,6 @@ impl StackPool { let allocation_size = stack_size .checked_mul(max_stacks) - .err2anyhow() .context("total size of execution stacks exceeds addressable memory")?; let mapping = Mmap::accessible_reserved(allocation_size, allocation_size) diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rs index f7f3728d9239..e048c24387a8 100644 --- a/crates/wasmtime/src/runtime/vm/libcalls.rs +++ b/crates/wasmtime/src/runtime/vm/libcalls.rs @@ -281,9 +281,7 @@ unsafe fn table_fill_func_ref( match table.element_type() { TableElementType::Func => { let val = NonNull::new(val.cast::()); - table - .fill(store.optional_gc_store_mut()?, dst, val.into(), len) - .err2anyhow()?; + table.fill(store.optional_gc_store_mut()?, dst, val.into(), len)?; Ok(()) } TableElementType::GcRef => unreachable!(), @@ -307,9 +305,7 @@ unsafe fn table_fill_gc_ref( let gc_store = store.store_opaque_mut().unwrap_gc_store_mut(); let gc_ref = VMGcRef::from_raw_u32(val); let gc_ref = gc_ref.map(|r| gc_store.clone_gc_ref(&r)); - table - .fill(Some(gc_store), dst, gc_ref.into(), len) - .err2anyhow()?; + table.fill(Some(gc_store), dst, gc_ref.into(), len)?; Ok(()) } } @@ -333,7 +329,7 @@ unsafe fn table_copy( let src_range = src..(src.checked_add(len).unwrap_or(u64::MAX)); let src_table = instance.get_table_with_lazy_init(src_table_index, src_range); let gc_store = store.optional_gc_store_mut()?; - Table::copy(gc_store, dst_table, src_table, dst, src, len).err2anyhow()?; + Table::copy(gc_store, dst_table, src_table, dst, src, len)?; Ok(()) } @@ -540,8 +536,7 @@ unsafe fn gc_alloc_raw( store .unwrap_gc_store_mut() .alloc_raw(header, layout)? - .ok_or_else(|| GcHeapOutOfMemory::new(())) - .err2anyhow()? + .ok_or_else(|| GcHeapOutOfMemory::new(()))? } }; @@ -634,15 +629,15 @@ unsafe fn array_new_data( let byte_len = len .checked_mul(one_elem_size) .and_then(|x| usize::try_from(x).ok()) - .ok_or_else(|| Trap::MemoryOutOfBounds.into_anyhow())?; + .ok_or_else(|| Trap::MemoryOutOfBounds)?; // Get the data from the segment, checking bounds. - let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds.into_anyhow())?; + let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds)?; let data = instance .wasm_data(data_range) .get(src..) .and_then(|d| d.get(..byte_len)) - .ok_or_else(|| Trap::MemoryOutOfBounds.into_anyhow())?; + .ok_or_else(|| Trap::MemoryOutOfBounds)?; // Allocate the (uninitialized) array. let gc_layout = store @@ -666,7 +661,7 @@ unsafe fn array_new_data( .store_opaque_mut() .unwrap_gc_store_mut() .alloc_uninit_array(shared_ty, u32::try_from(byte_len).unwrap(), &array_layout)? - .ok_or_else(|| GcHeapOutOfMemory::new(()).into_anyhow())? + .ok_or_else(|| GcHeapOutOfMemory::new(()))? } }; @@ -709,24 +704,20 @@ unsafe fn array_init_data( ); // Null check the array. - let gc_ref = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference.into_anyhow())?; + let gc_ref = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference)?; let array = gc_ref .into_arrayref(&*store.unwrap_gc_store().gc_heap) .expect("gc ref should be an array"); - let dst = usize::try_from(dst).map_err(|_| Trap::MemoryOutOfBounds.into_anyhow())?; - let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds.into_anyhow())?; - let len = usize::try_from(len).map_err(|_| Trap::MemoryOutOfBounds.into_anyhow())?; + let dst = usize::try_from(dst).map_err(|_| Trap::MemoryOutOfBounds)?; + let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds)?; + let len = usize::try_from(len).map_err(|_| Trap::MemoryOutOfBounds)?; // Bounds check the array. let array_len = array.len(store.store_opaque()); - let array_len = usize::try_from(array_len).map_err(|_| Trap::ArrayOutOfBounds.into_anyhow())?; - if dst - .checked_add(len) - .ok_or_else(|| Trap::ArrayOutOfBounds.into_anyhow())? - > array_len - { - return Err(Trap::ArrayOutOfBounds.into_anyhow()); + let array_len = usize::try_from(array_len).map_err(|_| Trap::ArrayOutOfBounds)?; + if dst.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > array_len { + return Err(Trap::ArrayOutOfBounds.into()); } // Calculate the byte length from the array length. @@ -738,7 +729,7 @@ unsafe fn array_init_data( .expect("Wasm validation ensures that this type have a defined byte size"); let data_len = len .checked_mul(usize::try_from(one_elem_size).unwrap()) - .ok_or_else(|| Trap::MemoryOutOfBounds.into_anyhow())?; + .ok_or_else(|| Trap::MemoryOutOfBounds)?; // Get the data from the segment, checking its bounds. let data_range = instance.wasm_data_range(data_index); @@ -746,7 +737,7 @@ unsafe fn array_init_data( .wasm_data(data_range) .get(src..) .and_then(|d| d.get(..data_len)) - .ok_or_else(|| Trap::MemoryOutOfBounds.into_anyhow())?; + .ok_or_else(|| Trap::MemoryOutOfBounds)?; // Copy the data into the array. @@ -795,8 +786,8 @@ unsafe fn array_new_elem( let mut storage = None; let elements = instance.passive_element_segment(&mut storage, elem_index); - let src = usize::try_from(src).map_err(|_| Trap::TableOutOfBounds.into_anyhow())?; - let len = usize::try_from(len).map_err(|_| Trap::TableOutOfBounds.into_anyhow())?; + let src = usize::try_from(src).map_err(|_| Trap::TableOutOfBounds)?; + let len = usize::try_from(len).map_err(|_| Trap::TableOutOfBounds)?; let shared_ty = instance.engine_type_index(array_type_index); let array_ty = ArrayType::from_shared_type_index(store.engine(), shared_ty); @@ -811,7 +802,7 @@ unsafe fn array_new_elem( vals.extend( fs.get(src..) .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds.into_anyhow())? + .ok_or_else(|| Trap::TableOutOfBounds)? .iter() .map(|f| { let raw_func_ref = instance.get_func_ref(*f); @@ -824,7 +815,7 @@ unsafe fn array_new_elem( let xs = xs .get(src..) .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds.into_anyhow())?; + .ok_or_else(|| Trap::TableOutOfBounds)?; let mut const_context = ConstEvalContext::new(instance); let mut const_evaluator = ConstExprEvaluator::default(); @@ -887,7 +878,7 @@ unsafe fn array_init_elem( ); // Convert the raw GC ref into a `Rooted`. - let array = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference.into_anyhow())?; + let array = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference)?; let array = store.unwrap_gc_store_mut().clone_gc_ref(&array); let array = { let mut no_gc = AutoAssertNoGc::new(&mut store); @@ -897,12 +888,8 @@ unsafe fn array_init_elem( // Bounds check the destination within the array. let array_len = array._len(&store)?; log::trace!("array_len = {array_len}"); - if dst - .checked_add(len) - .ok_or_else(|| Trap::ArrayOutOfBounds.into_anyhow())? - > array_len - { - return Err(Trap::ArrayOutOfBounds.into_anyhow()); + if dst.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > array_len { + return Err(Trap::ArrayOutOfBounds.into()); } // Get the passive element segment. @@ -910,15 +897,15 @@ unsafe fn array_init_elem( let elements = instance.passive_element_segment(&mut storage, elem_index); // Convert array offsets into `usize`s. - let src = usize::try_from(src).map_err(|_| Trap::TableOutOfBounds.into_anyhow())?; - let len = usize::try_from(len).map_err(|_| Trap::TableOutOfBounds.into_anyhow())?; + let src = usize::try_from(src).map_err(|_| Trap::TableOutOfBounds)?; + let len = usize::try_from(len).map_err(|_| Trap::TableOutOfBounds)?; // Turn the elements into `Val`s. let vals = match elements { TableSegmentElements::Functions(fs) => fs .get(src..) .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds.into_anyhow())? + .ok_or_else(|| Trap::TableOutOfBounds)? .iter() .map(|f| { let raw_func_ref = instance.get_func_ref(*f); @@ -935,7 +922,7 @@ unsafe fn array_init_elem( xs.get(src..) .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds.into_anyhow())? + .ok_or_else(|| Trap::TableOutOfBounds)? .iter() .map(|x| unsafe { let raw = const_evaluator @@ -982,33 +969,23 @@ unsafe fn array_copy( let mut store = AutoAssertNoGc::new(&mut store); // Convert the raw GC refs into `Rooted`s. - let dst_array = - VMGcRef::from_raw_u32(dst_array).ok_or_else(|| Trap::NullReference.into_anyhow())?; + let dst_array = VMGcRef::from_raw_u32(dst_array).ok_or_else(|| Trap::NullReference)?; let dst_array = store.unwrap_gc_store_mut().clone_gc_ref(&dst_array); let dst_array = ArrayRef::from_cloned_gc_ref(&mut store, dst_array); - let src_array = - VMGcRef::from_raw_u32(src_array).ok_or_else(|| Trap::NullReference.into_anyhow())?; + let src_array = VMGcRef::from_raw_u32(src_array).ok_or_else(|| Trap::NullReference)?; let src_array = store.unwrap_gc_store_mut().clone_gc_ref(&src_array); let src_array = ArrayRef::from_cloned_gc_ref(&mut store, src_array); // Bounds check the destination array's elements. let dst_array_len = dst_array._len(&store)?; - if dst - .checked_add(len) - .ok_or_else(|| Trap::ArrayOutOfBounds.into_anyhow())? - > dst_array_len - { - return Err(Trap::ArrayOutOfBounds.into_anyhow()); + if dst.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > dst_array_len { + return Err(Trap::ArrayOutOfBounds.into()); } // Bounds check the source array's elements. let src_array_len = src_array._len(&store)?; - if src - .checked_add(len) - .ok_or_else(|| Trap::ArrayOutOfBounds.into_anyhow())? - > src_array_len - { - return Err(Trap::ArrayOutOfBounds.into_anyhow()); + if src.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > src_array_len { + return Err(Trap::ArrayOutOfBounds.into()); } let mut store = AutoAssertNoGc::new(&mut store); diff --git a/crates/wasmtime/src/runtime/vm/memory/malloc.rs b/crates/wasmtime/src/runtime/vm/memory/malloc.rs index 95378ee3c604..b822a376acc3 100644 --- a/crates/wasmtime/src/runtime/vm/memory/malloc.rs +++ b/crates/wasmtime/src/runtime/vm/memory/malloc.rs @@ -39,17 +39,12 @@ impl MallocMemory { } let initial_allocation_byte_size = minimum - .checked_add( - tunables - .memory_reservation_for_growth - .try_into() - .err2anyhow()?, - ) + .checked_add(tunables.memory_reservation_for_growth.try_into()?) .context("memory allocation size too large")?; let initial_allocation_len = byte_size_to_element_len(initial_allocation_byte_size); let mut storage = Vec::new(); - storage.try_reserve(initial_allocation_len).err2anyhow()?; + storage.try_reserve(initial_allocation_len)?; let initial_len = byte_size_to_element_len(minimum); if initial_len > 0 { @@ -76,8 +71,7 @@ impl RuntimeLinearMemory for MallocMemory { let new_element_len = byte_size_to_element_len(new_size); if new_element_len > self.storage.len() { self.storage - .try_reserve(new_element_len - self.storage.len()) - .err2anyhow()?; + .try_reserve(new_element_len - self.storage.len())?; grow_storage_to(&mut self.storage, new_element_len); self.base_ptr = SendSyncPtr::new(NonNull::new(self.storage.as_mut_ptr()).unwrap()).cast(); diff --git a/crates/wasmtime/src/runtime/vm/memory/mmap.rs b/crates/wasmtime/src/runtime/vm/memory/mmap.rs index de95793032ad..0d536d1d2737 100644 --- a/crates/wasmtime/src/runtime/vm/memory/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/memory/mmap.rs @@ -59,7 +59,6 @@ impl MmapMemory { // Also be sure to round up to the host page size for this value. let offset_guard_bytes = HostAlignedByteCount::new_rounded_up_u64(tunables.memory_guard_size) - .err2anyhow() .context("tunable.memory_guard_size overflows")?; let pre_guard_bytes = if tunables.guard_before_linear_memory { offset_guard_bytes @@ -93,23 +92,20 @@ impl MmapMemory { // Convert `alloc_bytes` and `extra_to_reserve_on_growth` to // page-aligned `usize` values. let alloc_bytes = HostAlignedByteCount::new_rounded_up_u64(alloc_bytes) - .err2anyhow() .context("tunables.memory_reservation overflows")?; let extra_to_reserve_on_growth = HostAlignedByteCount::new_rounded_up_u64(extra_to_reserve_on_growth) - .err2anyhow() .context("tunables.memory_reservation_for_growth overflows")?; let request_bytes = pre_guard_bytes .checked_add(alloc_bytes) .and_then(|i| i.checked_add(offset_guard_bytes)) - .err2anyhow() .with_context(|| format!("cannot allocate {minimum} with guard regions"))?; let mmap = Mmap::accessible_reserved(HostAlignedByteCount::ZERO, request_bytes)?; if minimum > 0 { - let accessible = HostAlignedByteCount::new_rounded_up(minimum).err2anyhow()?; + let accessible = HostAlignedByteCount::new_rounded_up(minimum)?; // SAFETY: mmap is not in use right now so it's safe to make it accessible. unsafe { mmap.make_accessible(pre_guard_bytes, accessible)?; @@ -156,7 +152,7 @@ impl RuntimeLinearMemory for MmapMemory { } fn grow_to(&mut self, new_size: usize) -> Result<()> { - let new_accessible = HostAlignedByteCount::new_rounded_up(new_size).err2anyhow()?; + let new_accessible = HostAlignedByteCount::new_rounded_up(new_size)?; let current_capacity = self.current_capacity(); if new_accessible > current_capacity { // If the new size of this heap exceeds the current size of the @@ -168,7 +164,6 @@ impl RuntimeLinearMemory for MmapMemory { .checked_add(new_accessible) .and_then(|s| s.checked_add(self.extra_to_reserve_on_growth)) .and_then(|s| s.checked_add(self.offset_guard_size)) - .err2anyhow() .context("overflow calculating size of memory allocation")?; let mut new_mmap = @@ -212,7 +207,6 @@ impl RuntimeLinearMemory for MmapMemory { self.mmap.make_accessible( self.pre_guard_size .checked_add(self.accessible()) - .err2anyhow() .context("overflow calculating new accessible region")?, difference, )?; diff --git a/crates/wasmtime/src/runtime/vm/mmap.rs b/crates/wasmtime/src/runtime/vm/mmap.rs index a6b76c67db35..c16ec11e812f 100644 --- a/crates/wasmtime/src/runtime/vm/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/mmap.rs @@ -63,7 +63,7 @@ impl Mmap { /// Create a new `Mmap` pointing to at least `size` bytes of page-aligned /// accessible memory. pub fn with_at_least(size: usize) -> Result { - let rounded_size = HostAlignedByteCount::new_rounded_up(size).err2anyhow()?; + let rounded_size = HostAlignedByteCount::new_rounded_up(size)?; Self::accessible_reserved(rounded_size, rounded_size) } diff --git a/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs index a711089510eb..50512070d7b5 100644 --- a/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs @@ -9,7 +9,7 @@ use std::{fs::File, path::Path}; /// Open a file so that it can be mmap'd for executing. #[cfg(feature = "std")] pub fn open_file_for_mmap(path: &Path) -> Result { - File::open(path).err2anyhow().context("failed to open file") + File::open(path).context("failed to open file") } #[derive(Debug)] @@ -48,8 +48,7 @@ impl Mmap { size.byte_count(), rustix::mm::ProtFlags::READ | rustix::mm::ProtFlags::WRITE, rustix::mm::MapFlags::PRIVATE | MMAP_NORESERVE_FLAG, - ) - .err2anyhow()? + )? }; let memory = std::ptr::slice_from_raw_parts_mut(ptr.cast(), size.byte_count()); let memory = SendSyncPtr::new(NonNull::new(memory).unwrap()); @@ -74,8 +73,7 @@ impl Mmap { // Virtual memory that cannot be accessed should not have a backing store reserved // for it. Hence, passing in NORESERVE is correct here. rustix::mm::MapFlags::PRIVATE | MMAP_NORESERVE_FLAG, - ) - .err2anyhow()? + )? }; let memory = std::ptr::slice_from_raw_parts_mut(ptr.cast(), size.byte_count()); @@ -87,7 +85,6 @@ impl Mmap { pub fn from_file(file: &File) -> Result { let len = file .metadata() - .err2anyhow() .context("failed to get file metadata")? .len(); let len = usize::try_from(len).map_err(|_| anyhow::anyhow!("file too large to map"))?; @@ -100,7 +97,6 @@ impl Mmap { &file, 0, ) - .err2anyhow() .context(format!("mmap failed to allocate {len:#x} bytes"))? }; let memory = std::ptr::slice_from_raw_parts_mut(ptr.cast(), len); @@ -120,8 +116,7 @@ impl Mmap { ptr.byte_add(start.byte_count()).cast(), len.byte_count(), MprotectFlags::READ | MprotectFlags::WRITE, - ) - .err2anyhow()?; + )?; } Ok(()) @@ -168,7 +163,7 @@ impl Mmap { flags }; - mprotect(base, len, flags).err2anyhow()?; + mprotect(base, len, flags)?; Ok(()) } @@ -177,7 +172,7 @@ impl Mmap { let base = self.memory.as_ptr().byte_add(range.start).cast(); let len = range.end - range.start; - mprotect(base, len, MprotectFlags::READ).err2anyhow()?; + mprotect(base, len, MprotectFlags::READ)?; Ok(()) } diff --git a/crates/wasmtime/src/runtime/vm/sys/unix/vm.rs b/crates/wasmtime/src/runtime/vm/sys/unix/vm.rs index 0f3114bfdf78..6d457ba5f191 100644 --- a/crates/wasmtime/src/runtime/vm/sys/unix/vm.rs +++ b/crates/wasmtime/src/runtime/vm/sys/unix/vm.rs @@ -102,7 +102,6 @@ impl MemoryImageSource { // in-memory file to represent the heap image. This anonymous // file is then used as the basis for further mmaps. - use crate::prelude::*; use std::io::{ErrorKind, Write}; // Create the memfd. It needs a name, but the documentation for @@ -118,9 +117,9 @@ impl MemoryImageSource { Err(memfd::Error::Create(err)) if err.kind() == ErrorKind::Unsupported => { return Ok(None) } - Err(e) => return Err(e.into_anyhow()), + Err(e) => return Err(e.into()), }; - memfd.as_file().write_all(data).err2anyhow()?; + memfd.as_file().write_all(data)?; // Seal the memfd's data and length. // @@ -137,14 +136,12 @@ impl MemoryImageSource { // extra-super-sure that it never changes, and because // this costs very little, we use the kernel's "seal" API // to make the memfd image permanently read-only. - memfd - .add_seals(&[ - memfd::FileSeal::SealGrow, - memfd::FileSeal::SealShrink, - memfd::FileSeal::SealWrite, - memfd::FileSeal::SealSeal, - ]) - .err2anyhow()?; + memfd.add_seals(&[ + memfd::FileSeal::SealGrow, + memfd::FileSeal::SealShrink, + memfd::FileSeal::SealWrite, + memfd::FileSeal::SealSeal, + ])?; Ok(Some(MemoryImageSource::Memfd(memfd))) } diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs index 91e58fbbabe5..9f23e0f2066d 100644 --- a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs @@ -22,7 +22,6 @@ pub fn open_file_for_mmap(path: &Path) -> Result { .access_mode(FILE_GENERIC_READ | FILE_GENERIC_EXECUTE) .share_mode(FILE_SHARE_READ) .open(path) - .err2anyhow() .context("failed to open file") } @@ -85,7 +84,6 @@ impl Mmap { unsafe { let len = file .metadata() - .err2anyhow() .context("failed to get file metadata")? .len(); let len = usize::try_from(len).map_err(|_| anyhow!("file too large to map"))?; @@ -105,8 +103,7 @@ impl Mmap { ptr::null(), ); if mapping == INVALID_HANDLE_VALUE { - return Err(io::Error::last_os_error().into_anyhow()) - .context("failed to create file mapping"); + return Err(io::Error::last_os_error()).context("failed to create file mapping"); } // Create a view for the entire file using all our requisite @@ -123,8 +120,7 @@ impl Mmap { let err = io::Error::last_os_error(); CloseHandle(mapping); if ptr.is_null() { - return Err(err.into_anyhow()) - .context(format!("failed to create map view of {:#x} bytes", len)); + return Err(err).context(format!("failed to create map view of {:#x} bytes", len)); } let memory = std::ptr::slice_from_raw_parts_mut(ptr.cast(), len); @@ -138,7 +134,7 @@ impl Mmap { // remove the execute bit) let mut old = 0; if VirtualProtect(ret.as_mut_ptr().cast(), ret.len(), PAGE_WRITECOPY, &mut old) == 0 { - return Err(io::Error::last_os_error().into_anyhow()) + return Err(io::Error::last_os_error()) .context("failed change pages to `PAGE_READONLY`"); } diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index b0c24e598424..79834b4e7642 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -3939,7 +3939,7 @@ end = "2025-09-20" criteria = "safe-to-deploy" user-id = 3618 # David Tolnay (dtolnay) start = "2019-10-05" -end = "2024-09-01" +end = "2025-12-02" [[trusted.async-trait]] criteria = "safe-to-deploy" diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index cb0cbaa3cd7a..11334ceb0671 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -236,8 +236,8 @@ user-login = "epage" user-name = "Ed Page" [[publisher.anyhow]] -version = "1.0.75" -when = "2023-08-17" +version = "1.0.93" +when = "2024-11-06" user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" From 569c1dd53a98b57b69e4132a02a1e02f3cf4271b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 2 Dec 2024 15:24:41 -0800 Subject: [PATCH 2/4] Add some trusted vets --- supply-chain/audits.toml | 6 +++--- supply-chain/imports.lock | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 79834b4e7642..c5a9b0ba57ba 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -4281,13 +4281,13 @@ end = "2024-07-06" criteria = "safe-to-deploy" user-id = 3618 # David Tolnay (dtolnay) start = "2019-03-01" -end = "2024-07-06" +end = "2025-12-02" [[trusted.serde_derive]] criteria = "safe-to-deploy" user-id = 3618 # David Tolnay (dtolnay) start = "2019-03-01" -end = "2024-07-06" +end = "2025-12-02" [[trusted.serde_json]] criteria = "safe-to-deploy" @@ -4305,7 +4305,7 @@ end = "2025-02-12" criteria = "safe-to-deploy" user-id = 3618 # David Tolnay (dtolnay) start = "2019-03-01" -end = "2024-07-06" +end = "2025-12-02" [[trusted.system-interface]] criteria = "safe-to-deploy" diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index 11334ceb0671..df1c28beda17 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -660,8 +660,8 @@ user-login = "dtolnay" user-name = "David Tolnay" [[publisher.proc-macro2]] -version = "1.0.81" -when = "2024-04-17" +version = "1.0.92" +when = "2024-11-21" user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" @@ -750,15 +750,15 @@ user-login = "BurntSushi" user-name = "Andrew Gallant" [[publisher.serde]] -version = "1.0.188" -when = "2023-08-26" +version = "1.0.215" +when = "2024-11-11" user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" [[publisher.serde_derive]] -version = "1.0.188" -when = "2023-08-26" +version = "1.0.215" +when = "2024-11-11" user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" @@ -791,8 +791,8 @@ user-login = "dtolnay" user-name = "David Tolnay" [[publisher.syn]] -version = "2.0.60" -when = "2024-04-17" +version = "2.0.90" +when = "2024-11-29" user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" From 4d4bf8489031858301ee7a0e2bcd79d3e8aaa96b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 2 Dec 2024 15:28:08 -0800 Subject: [PATCH 3/4] Audit object crate update --- supply-chain/audits.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index c5a9b0ba57ba..0235a67f4f16 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -2354,6 +2354,12 @@ No `unsafe` code in this update. Lots of changes but all object-file-format-related, everything looks good. """ +[[audits.object]] +who = "Alex Crichton " +criteria = "safe-to-deploy" +delta = "0.36.0 -> 0.36.5" +notes = "No new unsafe code, lots of new relocations/objects support, everything looks nominal" + [[audits.once_cell]] who = "Chris Fallin " criteria = "safe-to-deploy" From 0cb480b9e71735f6a149a3513d8ededdc1c3deb1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 3 Dec 2024 10:10:23 -0800 Subject: [PATCH 4/4] Disable backtraces on CI --- .github/workflows/main.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0705df14dc4a..dfab1f43af94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -641,12 +641,8 @@ jobs: - run: cmake -Sexamples -Bexamples/build -DBUILD_SHARED_LIBS=OFF - run: cmake --build examples/build --config Debug - run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target RUN_TESTS - env: - RUST_BACKTRACE: 1 if: matrix.os == 'windows-latest' - run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target test - env: - RUST_BACKTRACE: 1 if: matrix.os != 'windows-latest' # Perform all tests (debug mode) for `wasmtime`. @@ -771,8 +767,6 @@ jobs: # Build and test all features - run: ./ci/run-tests.sh --locked ${{ matrix.bucket }} - env: - RUST_BACKTRACE: 1 # NB: the test job here is explicitly lacking in cancellation of this run if # something goes wrong. These take the longest anyway and otherwise if @@ -817,8 +811,6 @@ jobs: # Run the tests! - run: cargo test -p wasmtime-wasi-nn --features ${{ matrix.feature }} - env: - RUST_BACKTRACE: 1 # common logic to cancel the entire run if this job fails - run: gh run cancel ${{ github.run_id }} @@ -843,8 +835,6 @@ jobs: # Run the tests - run: | cargo test -p wasmtime-fuzzing -p wasm-spec-interpreter - env: - RUST_BACKTRACE: 1 # common logic to cancel the entire run if this job fails - run: gh run cancel ${{ github.run_id }} @@ -871,7 +861,6 @@ jobs: sudo ln -s /usr/lib/llvm-15/lib/python3.10/dist-packages/lldb/* /usr/lib/python3/dist-packages/lldb/ cargo test --test all -- --ignored --test-threads 1 debug:: env: - RUST_BACKTRACE: 1 LLDB: lldb-15 # override default version, 14 # common logic to cancel the entire run if this job fails