pub struct MemoryImage { /* private fields */ }runtime only.Expand description
A copy-on-write image of the initial contents of a linear memory.
When Config::memory_init_cow is enabled
Wasmtime prepares, where possible, an image of a module’s data segments for
each of its linear memories that can be mapped into memory copy-on-write
instead of being copied byte-by-byte. Such images are handed to
LinearMemory::init_from_image for the specific memory implementation to map into its
underlying representation.
An image covers len() bytes of the linear memory starting at
linear_memory_offset().
Both values are multiples of the host page size, and the image always lies within
the minimum size of the memory it was created for.
All other bytes are expected to be zero.
Cloning a MemoryImage is cheap and keeps the underlying image alive.
Implementations§
Source§impl MemoryImage
impl MemoryImage
Sourcepub fn linear_memory_offset(&self) -> usize
pub fn linear_memory_offset(&self) -> usize
Returns the offset, in bytes, within linear memory where this image starts.
This is guaranteed to be a multiple of the host page size.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length, in bytes, of this image.
This is guaranteed to be a multiple of the host page size.
Sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
Returns the bytes of this image.
The returned slice is len() bytes long and holds
the initial contents of linear memory starting at
linear_memory_offset(). All
bytes of the memory outside of that range are initially zero.
Sourcepub unsafe fn map_at(&self, base: *mut u8) -> Result<()>
pub unsafe fn map_at(&self, base: *mut u8) -> Result<()>
Maps this image copy-on-write into the linear memory starting at
base.
The bytes base + linear_memory_offset() up to
base + linear_memory_offset() + len() are replaced with a private,
readable and writable copy-on-write mapping of the image. Nothing
outside of that range is modified.
Returns an error if base is not aligned to the host page size or if
the underlying mapping operation fails.
§Safety
The caller must exclusively own the virtual memory range being mapped
over, nothing may hold references into it, and it must be valid for
its pages to be replaced by a new mapping (for example by mmap with
MAP_FIXED on Unix). Any previous contents and memory protections of
that range are lost. The mapping lives until the range is unmapped or
mapped over again by its owner. In particular, the runtime does not unmap the image by itself.
The owner of the virtual memory range must clean it up after usage.
The typical usage is owning a memory-mapped region and requesting the image to be mapped into a subrange of that mapping. Unmapping the entire region at the end of the memory’s lifetime takes care of the cleanup.
Trait Implementations§
Source§impl Clone for MemoryImage
impl Clone for MemoryImage
Source§impl Debug for MemoryImage
impl Debug for MemoryImage
impl Eq for MemoryImage
Source§impl Hash for MemoryImage
impl Hash for MemoryImage
Auto Trait Implementations§
impl !RefUnwindSafe for MemoryImage
impl !UnwindSafe for MemoryImage
impl Freeze for MemoryImage
impl Send for MemoryImage
impl Sync for MemoryImage
impl Unpin for MemoryImage
impl UnsafeUnpin for MemoryImage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more