A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Use `Trap` for more error conditions in GC (#13465)
Alex Crichton17836e91c06b
diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rsindex 2d39177413..38057577f1 100644--- a/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs+++ b/crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs@@ -54,7 +54,7 @@ use crate::runtime::vm::{VMGcObjectData, VMGcRef,};use crate::vm::VMMemoryDefinition;-use crate::{Engine, bail_bug, prelude::*};+use crate::{Engine, Trap, bail_bug, prelude::*};use core::sync::atomic::AtomicUsize;use core::{alloc::Layout,@@ -1070,8 +1070,7 @@ unsafe impl GcHeap for DrcHeap {}let object_size = u32::try_from(layout.size()).unwrap();- let alloc_size = FreeList::aligned_size(object_size)- .ok_or_else(|| format_err!("allocation size too large"))?;+ let alloc_size = FreeList::aligned_size(object_size).ok_or(Trap::AllocationTooLarge)?;let gc_ref = match self.free_list.as_mut().unwrap().alloc_fast(alloc_size) {None => return Ok(Err(u64::try_from(layout.size())?)),@@ -1136,9 +1135,7 @@ unsafe impl GcHeap for DrcHeap {length: u32,layout: &GcArrayLayout,) -> Result<Result<VMArrayRef, u64>> {- let layout = layout- .layout(length)- .ok_or_else(|| format_err!("allocation size too large"))?;+ let layout = layout.layout(length).ok_or(Trap::AllocationTooLarge)?;let gc_ref = match self.alloc_raw(VMGcHeader::from_kind_and_index(VMGcKind::ArrayRef, ty),layout,diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rsindex 8d31030751..9ab201e61b 100644--- a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs+++ b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs@@ -6,7 +6,7 @@use super::*;use crate::{- Engine,+ Engine, Trap,prelude::*,vm::{ExternRefHostDataId, ExternRefHostDataTable, GarbageCollection, GcHeap, GcHeapObject,@@ -311,9 +311,7 @@ unsafe impl GcHeap for NullHeap {length: u32,layout: &GcArrayLayout,) -> Result<Result<VMArrayRef, u64>> {- let layout = layout- .layout(length)- .ok_or_else(|| format_err!("allocation size too large"))?;+ let layout = layout.layout(length).ok_or(Trap::AllocationTooLarge)?;let gc_ref = match self.alloc(VMGcHeader::from_kind_and_index(VMGcKind::ArrayRef, ty),layout,