diff --git a/crates/wasmi/src/memory/buffer.rs b/crates/wasmi/src/memory/buffer.rs index f6a0a47fbe..9ffce2770a 100644 --- a/crates/wasmi/src/memory/buffer.rs +++ b/crates/wasmi/src/memory/buffer.rs @@ -1,15 +1,4 @@ use alloc::{vec, vec::Vec}; -use core::{fmt, fmt::Display}; - -/// Dummy error for fallible `Vec`-based virtual memory operations. -#[derive(Debug)] -pub struct VirtualMemoryError {} - -impl Display for VirtualMemoryError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "encountered failure while operating with virtual memory") - } -} /// A `Vec`-based byte buffer implementation. /// @@ -30,10 +19,10 @@ impl ByteBuffer { /// /// - If the initial length is 0. /// - If the initial length exceeds the maximum supported limit. - pub fn new(initial_len: usize) -> Result { - Ok(Self { + pub fn new(initial_len: usize) -> Self { + Self { bytes: vec![0x00_u8; initial_len], - }) + } } /// Grows the byte buffer to the given `new_size`. diff --git a/crates/wasmi/src/memory/buffer_vmem.rs b/crates/wasmi/src/memory/buffer_vmem.rs index 1c39525611..bbfd3c2a75 100644 --- a/crates/wasmi/src/memory/buffer_vmem.rs +++ b/crates/wasmi/src/memory/buffer_vmem.rs @@ -1,9 +1,6 @@ -use super::MemoryError; use core::fmt::Debug; use wasmi_core::VirtualMemory; -pub use wasmi_core::VirtualMemoryError; - /// A virtual memory based byte buffer implementation. /// /// # Note @@ -37,12 +34,13 @@ impl ByteBuffer { /// /// - If the initial length is 0. /// - If the initial length exceeds the maximum supported limit. - pub fn new(initial_len: usize) -> Result { - let bytes = VirtualMemory::new(Self::ALLOCATION_SIZE)?; - Ok(Self { + pub fn new(initial_len: usize) -> Self { + let bytes = VirtualMemory::new(Self::ALLOCATION_SIZE) + .unwrap_or_else(|err| unreachable!("Failed to allocate memory: {err}")); + Self { bytes, len: initial_len, - }) + } } /// Grows the byte buffer by the given delta. diff --git a/crates/wasmi/src/memory/error.rs b/crates/wasmi/src/memory/error.rs index 807f49f0ed..9ed4379a88 100644 --- a/crates/wasmi/src/memory/error.rs +++ b/crates/wasmi/src/memory/error.rs @@ -1,5 +1,4 @@ use super::MemoryType; -use crate::memory::VirtualMemoryError; use core::{fmt, fmt::Display}; /// An error that may occur upon operating with virtual or linear memory. @@ -14,8 +13,6 @@ pub enum MemoryError { OutOfBoundsAccess, /// Tried to create an invalid linear memory type. InvalidMemoryType, - /// A generic virtual memory error. - Vmem(VirtualMemoryError), /// Occurs when `ty` is not a subtype of `other`. InvalidSubtype { /// The [`MemoryType`] which is not a subtype of `other`. @@ -40,16 +37,9 @@ impl Display for MemoryError { Self::InvalidMemoryType => { write!(f, "tried to create an invalid virtual memory type") } - Self::Vmem(error) => Display::fmt(error, f), Self::InvalidSubtype { ty, other } => { write!(f, "memory type {ty:?} is not a subtype of {other:?}",) } } } } - -impl From for MemoryError { - fn from(error: VirtualMemoryError) -> Self { - Self::Vmem(error) - } -} diff --git a/crates/wasmi/src/memory/mod.rs b/crates/wasmi/src/memory/mod.rs index d6e659e71d..dc8a17bdab 100644 --- a/crates/wasmi/src/memory/mod.rs +++ b/crates/wasmi/src/memory/mod.rs @@ -21,8 +21,6 @@ use super::{AsContext, AsContextMut, StoreContext, StoreContextMut, Stored}; use wasmi_arena::ArenaIndex; use wasmi_core::Pages; -pub use byte_buffer::VirtualMemoryError; - /// A raw index to a linear memory entity. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct MemoryIdx(u32); @@ -142,7 +140,7 @@ impl MemoryEntity { .to_bytes() .ok_or(MemoryError::OutOfBoundsAllocation)?; let memory = Self { - bytes: ByteBuffer::new(initial_len)?, + bytes: ByteBuffer::new(initial_len), memory_type, current_pages: initial_pages, };