Skip to main content

MemoryImage

Struct MemoryImage 

Source
pub struct MemoryImage { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns whether this image is empty (length equal to zero).

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryImage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MemoryImage

Source§

impl Hash for MemoryImage

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MemoryImage

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.