Skip to content

Commit

Permalink
Merge branch 'context_api-refactor' of github.com:wasmerio/wasmer int…
Browse files Browse the repository at this point in the history
…o context_api-refactor
  • Loading branch information
syrusakbary committed Jul 14, 2022
2 parents d703e0a + 7366910 commit 24210ab
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/api/src/sys/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ impl Memory {
self.buffer(ctx).len.try_into().unwrap()
}

/// Retrieve a slice of the memory contents.
///
/// # Safety
///
/// Until the returned slice is dropped, it is undefined behaviour to
/// modify the memory contents in any way including by calling a wasm
/// function that writes to the memory or by resizing the memory.
#[doc(hidden)]
pub unsafe fn data_unchecked(&self, ctx: &impl AsStoreRef) -> &[u8] {
self.data_unchecked_mut(ctx)
}

/// Retrieve a mutable slice of the memory contents.
///
/// # Safety
///
/// This method provides interior mutability without an UnsafeCell. Until
/// the returned value is dropped, it is undefined behaviour to read or
/// write to the pointed-to memory in any way except through this slice,
/// including by calling a wasm function that reads the memory contents or
/// by resizing this Memory.
#[allow(clippy::mut_from_ref)]
#[doc(hidden)]
pub unsafe fn data_unchecked_mut(&self, ctx: &impl AsStoreRef) -> &mut [u8] {
slice::from_raw_parts_mut(
self.buffer(ctx).base,
self.buffer(ctx).len.try_into().unwrap(),
)
}

/// Returns the size (in [`Pages`]) of the `Memory`.
///
/// # Example
Expand Down

0 comments on commit 24210ab

Please sign in to comment.