A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Add context to malloc-based-memory error messages (#12468)
Alex Crichtonc656ed3b967c
diff --git a/crates/wasmtime/src/runtime/vm/memory/malloc.rs b/crates/wasmtime/src/runtime/vm/memory/malloc.rsindex 7143430166..3a25843b05 100644--- a/crates/wasmtime/src/runtime/vm/memory/malloc.rs+++ b/crates/wasmtime/src/runtime/vm/memory/malloc.rs@@ -44,7 +44,15 @@ impl MallocMemory {let initial_allocation_len = byte_size_to_element_len(initial_allocation_byte_size);let mut storage = Vec::new();- storage.try_reserve(initial_allocation_len)?;+ storage+ .try_reserve(initial_allocation_len)+ .with_context(|| {+ format!(+ "failed to allocate {initial_allocation_byte_size:#x} \+ bytes ({minimum:#x} minimum + {:#x} memory_reservation_for_growth)",+ tunables.memory_reservation_for_growth,+ )+ })?;let initial_len = byte_size_to_element_len(minimum);if initial_len > 0 {@@ -71,7 +79,8 @@ 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())?;+ .try_reserve(new_element_len - self.storage.len())+ .with_context(|| format!("failed to grow memory to {new_size:#x} bytes"))?;grow_storage_to(&mut self.storage, new_element_len);self.base_ptr =SendSyncPtr::new(NonNull::new(self.storage.as_mut_ptr()).unwrap()).cast();