#[repr(C, align(16))]
pub struct VMContext { pub _marker: PhantomPinned, }
Expand description

The VM “context”, which is pointed to by the vmctx arg in Cranelift. This has information about globals, memories, tables, and other runtime state associated with the current instance.

The struct here is empty, as the sizes of these fields are dynamic, and we can’t describe them in Rust’s type system. Sufficient memory is allocated at runtime.

Fields§

§_marker: PhantomPinned

There’s some more discussion about this within wasmtime/src/lib.rs but the idea is that we want to tell the compiler that this contains pointers which transitively refers to itself, to suppress some optimizations that might otherwise assume this doesn’t exist.

The self-referential pointer we care about is the *mut Store pointer early on in this context, which if you follow through enough levels of nesting, eventually can refer back to this VMContext

Implementations§

source§

impl VMContext

source

pub unsafe fn from_opaque(opaque: *mut VMOpaqueContext) -> *mut VMContext

Helper function to cast between context types using a debug assertion to protect against some mistakes.

source

pub unsafe fn host_state(&self) -> &dyn Any

Return a reference to the host state associated with this Instance.

Safety

This is unsafe because it doesn’t work on just any VMContext, it must be a VMContext allocated as part of an Instance.

Trait Implementations§

source§

impl Debug for VMContext

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.