A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Fix: pull request #15202 (#15255)
Markus Götzb1274d77d07d
diff --git a/Cargo.lock b/Cargo.lockindex 6e300a1361..a1629d04d1 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4567,6 +4567,7 @@ dependencies = ["cranelift-native","encoding_rs","env_logger 0.11.5",+ "foldhash 0.2.0","futures","fxprof-processed-profile","gimli 0.33.0",diff --git a/Cargo.toml b/Cargo.tomlindex 22cad7e06a..10207f8d22 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -406,6 +406,7 @@ log = { version = "0.4.28", default-features = false }clap = { version = "4.5.48", default-features = false, features = ["std", "derive"] }clap_complete = "4.5.58"hashbrown = { version = "0.17", default-features = false }+foldhash = { version = "0.2.0", default-features = false }capstone = { version = "0.14.0", default-features = false, features = ['full', 'arch_x86', 'arch_riscv', 'arch_arm64', 'arch_sysz'] }xed-sys = { version = "0.6" }smallvec = { version = "1.15.1", features = ["union"] }diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.tomlindex f1172866ef..9bd256f2f5 100644--- a/crates/wasmtime/Cargo.toml+++ b/crates/wasmtime/Cargo.toml@@ -56,6 +56,7 @@ indexmap = { workspace = true, optional = true }semver = { workspace = true, optional = true }smallvec = { workspace = true, optional = true }bitflags = { workspace = true }+foldhash = { workspace = true, optional = true }futures = { workspace = true, features = ["alloc"], optional = true }bytes = { workspace = true, optional = true }@@ -294,7 +295,7 @@ runtime = [## You can additionally configure which GC implementations are enabled via the# `gc-drc`, `gc-null`, and `gc-copying` features.-gc = ["wasmtime-environ/gc"]+gc = ["wasmtime-environ/gc", "dep:foldhash"]# Enable the deferred reference counting garbage collector.gc-drc = ["gc", "wasmtime-environ/gc-drc"]diff --git a/crates/wasmtime/src/runtime/store/gc.rs b/crates/wasmtime/src/runtime/store/gc.rsindex 76e637fdfb..e7044e0ac1 100644--- a/crates/wasmtime/src/runtime/store/gc.rs+++ b/crates/wasmtime/src/runtime/store/gc.rs@@ -9,8 +9,8 @@ use crate::store::{};use crate::type_registry::RegisteredType;use crate::vm::{- self, Backtrace, Frame, GcRootsList, GcStore, InstanceAllocationRequest, NopHasher,- SendSyncPtr, StoreGcHostAllocTypes, TraceInfo, VMGcRef,+ self, Backtrace, Frame, GcRootsList, GcStore, InstanceAllocationRequest, SendSyncPtr,+ StoreGcHostAllocTypes, TraceInfo, VMGcRef,};use crate::{Engine, ExnRef, GcHeapOutOfMemory, Result, Rooted, Store, StoreContextMut, Tag,@@ -21,8 +21,8 @@ use core::mem::ManuallyDrop;use core::num::NonZeroU32;use core::ops::{Deref, DerefMut};use core::ptr::NonNull;-use wasmtime_environ::DefinedTagIndex;use wasmtime_environ::packed_option::ReservedValue;+use wasmtime_environ::{DefinedTagIndex, VMSharedTypeIndex};#[derive(Default)]pub(crate) struct StoreGcData {@@ -64,7 +64,8 @@ pub(crate) struct StoreGcData {/// solution" where supertypes are stored inline in a compiled-code-visible/// location which means that a libcall isn't needed at all (nor/// synchronization) to determine subtype/supertype relationships.- subtype_check_cache: HashMap<u64, bool, NopHasher>,+ subtype_check_cache:+ HashMap<(VMSharedTypeIndex, VMSharedTypeIndex), bool, foldhash::fast::FixedState>,}impl<T> Store<T> {@@ -1087,12 +1088,12 @@ impl StoreOpaque {/// for details.pub(crate) fn is_subtype_cached(&mut self,- sub: wasmtime_environ::VMSharedTypeIndex,- sup: wasmtime_environ::VMSharedTypeIndex,+ sub: VMSharedTypeIndex,+ sup: VMSharedTypeIndex,) -> bool {const MAX_SIZE: usize = 1 << 16; // 64k entries- let key = (u64::from(sub.as_u32()) << 32) | u64::from(sup.as_u32());+ let key = (sub, sup);let engine_answer = || self.engine.signatures().is_subtype(sub, sup);if self.gc_data.subtype_check_cache.len() < MAX_SIZE {*selfdiff --git a/crates/wasmtime/src/runtime/vm/gc/enabled.rs b/crates/wasmtime/src/runtime/vm/gc/enabled.rsindex 9d228521be..0090e1f100 100644--- a/crates/wasmtime/src/runtime/vm/gc/enabled.rs+++ b/crates/wasmtime/src/runtime/vm/gc/enabled.rs@@ -40,57 +40,3 @@ fn is_poisoned(bytes: &[u8]) -> bool {.chunks(CHUNK).all(|chunk| chunk == &POISONED[..chunk.len()])}--/// A hasher that doesn't hash, for use in the trace-info hash map, where we are-/// just using scalar keys and aren't overly concerned with collision-based DoS.-#[derive(Default)]-pub struct NopHasher(u64);--impl core::hash::BuildHasher for NopHasher {- type Hasher = Self;-- #[inline]- fn build_hasher(&self) -> Self::Hasher {- NopHasher::default()- }-}--impl core::hash::Hasher for NopHasher {- #[inline]- fn finish(&self) -> u64 {- self.0- }-- #[inline]- fn write(&mut self, bytes: &[u8]) {- let mut hash = self.0.to_ne_bytes();- let n = hash.len().min(bytes.len());- hash[..n].copy_from_slice(bytes);- self.0 = u64::from_ne_bytes(hash);- }-- #[inline]- fn write_u8(&mut self, i: u8) {- self.write_u64(i.into());- }-- #[inline]- fn write_u16(&mut self, i: u16) {- self.write_u64(i.into())- }-- #[inline]- fn write_u32(&mut self, i: u32) {- self.write_u64(i.into())- }-- #[inline]- fn write_u64(&mut self, i: u64) {- self.0 = i;- }-- #[inline]- fn write_usize(&mut self, i: usize) {- self.write_u64(i.try_into().unwrap());- }-}diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/trace_infos.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/trace_infos.rsindex c0d429353b..9cfd3d5011 100644--- a/crates/wasmtime/src/runtime/vm/gc/enabled/trace_infos.rs+++ b/crates/wasmtime/src/runtime/vm/gc/enabled/trace_infos.rs@@ -6,7 +6,7 @@use crate::hash_map::{Entry, HashMap};use crate::module::RegisteredModuleId;-use crate::vm::{GcStoreTraceState, NopHasher, TraceInfo};+use crate::vm::{GcStoreTraceState, TraceInfo};use crate::{bail_bug, prelude::*};use wasmtime_environ::{ModuleInternedTypeIndex, VMSharedTypeIndex};@@ -19,7 +19,7 @@ enum TraceInfoLoc {/// A map from GC type indices to where their tracing information can be found.#[derive(Default)]pub(super) struct TraceInfos {- map: HashMap<VMSharedTypeIndex, TraceInfoLoc, NopHasher>,+ map: HashMap<VMSharedTypeIndex, TraceInfoLoc, foldhash::fast::FixedState>,}impl TraceInfos {