Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions crates/interpreter/src/interpreter/shared_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ impl MemoryTr for SharedMemory {

/// Returns a byte slice of the memory region at the given offset.
///
/// # Panics
///
/// Panics on out of bounds access in debug builds only.
///
/// # Safety
///
/// In debug this will panic on out of bounds. In release it will silently fail.
/// In release builds, calling this method with an out-of-bounds range triggers undefined
/// behavior. Callers must ensure that the range is within the bounds of the buffer.
#[inline]
#[cfg_attr(debug_assertions, track_caller)]
fn global_slice(&self, range: Range<usize>) -> Ref<'_, [u8]> {
Expand Down Expand Up @@ -261,7 +266,12 @@ impl SharedMemory {
///
/// # Panics
///
/// Panics on out of bounds.
/// Panics on out of bounds access in debug builds only.
///
/// # Safety
///
/// In release builds, calling this method with an out-of-bounds range triggers undefined
/// behavior. Callers must ensure that the range is within the bounds of the buffer.
#[inline]
#[cfg_attr(debug_assertions, track_caller)]
pub fn global_slice_range(&self, range: Range<usize>) -> Ref<'_, [u8]> {
Expand Down Expand Up @@ -416,6 +426,15 @@ impl SharedMemory {
}

/// Returns a reference to the memory of the current context, the active memory.
///
/// # Panics
///
/// Panics if the checkpoint is invalid in debug builds only.
///
/// # Safety
///
/// In release builds, calling this method with an invalid checkpoint triggers undefined
/// behavior. The checkpoint must be within the bounds of the buffer.
#[inline]
pub fn context_memory(&self) -> Ref<'_, [u8]> {
let buffer = self.buffer().borrow();
Expand All @@ -426,6 +445,15 @@ impl SharedMemory {
}

/// Returns a mutable reference to the memory of the current context.
///
/// # Panics
///
/// Panics if the checkpoint is invalid in debug builds only.
///
/// # Safety
///
/// In release builds, calling this method with an invalid checkpoint triggers undefined
/// behavior. The checkpoint must be within the bounds of the buffer.
#[inline]
pub fn context_memory_mut(&mut self) -> RefMut<'_, [u8]> {
let buffer = self.buffer().borrow_mut(); // Borrow the inner Vec<u8> mutably
Expand Down
Loading