Struct polkavm::Instance

source ·
pub struct Instance<T>(/* private fields */);

Implementations§

source§

impl<T> Instance<T>

source

pub fn module(&self) -> &Module

Returns the module from which this instance was created.

source

pub fn call( &self, state_args: StateArgs, call_args: CallArgs<'_, T>, ) -> Result<(), ExecutionError<Error>>

Updates the state of the instance according to the state_args and calls a given function.

source

pub fn call_typed<FnArgs, FnResult>( &self, user_data: &mut T, symbol: impl AsRef<[u8]>, args: FnArgs, ) -> Result<FnResult, ExecutionError<Error>>
where FnArgs: FuncArgs, FnResult: FuncResult,

A conveniance function to call into this particular instance according to the default ABI.

This is equivalent to calling Instance::call with an appropriately set up CallArgs.

source

pub fn update_state( &self, state_args: StateArgs, ) -> Result<(), ExecutionError<Error>>

Updates the state of this particular instance.

source

pub fn reset_memory(&self) -> Result<(), Error>

A conveniance function to reset the instance’s memory to its initial state from when it was first instantiated.

This is equivalent to calling Instance::update_state with an appropriately set up StateArgs.

source

pub fn sbrk(&self, size: u32) -> Result<Option<u32>, Error>

A conveniance function to increase the size of the program’s heap by a given number of bytes, allocating memory if necessary.

If successful returns a pointer to the end of the guest’s heap.

This is equivalent to manually checking that the size bytes can actually be allocated, calling Instance::sbrk with an appropriately set up StateArgs, and calculating the new address of the end of the guest’s heap.

source

pub fn read_memory_into_slice<'slice, B>( &self, address: u32, buffer: &'slice mut B, ) -> Result<&'slice mut [u8], Trap>
where B: ?Sized + AsUninitSliceMut,

source

pub fn read_memory_into_vec( &self, address: u32, length: u32, ) -> Result<Vec<u8>, Trap>

source

pub fn write_memory(&self, address: u32, data: &[u8]) -> Result<(), Trap>

source

pub fn heap_size(&self) -> u32

Returns the current size of the program’s heap.

source

pub fn get_reg(&self, reg: Reg) -> u32

Returns the value of the given register.

source

pub fn get_result_typed<FnResult>(&self) -> FnResult
where FnResult: FuncResult,

Extracts a return value from the argument registers according to the default ABI.

This is equivalent to manually calling Instance::get_reg.

source

pub fn gas_remaining(&self) -> Option<Gas>

Gets the amount of gas remaining, or None if gas metering is not enabled for this instance.

Note that this being zero doesn’t necessarily mean that the execution ran out of gas, if the program ended up consuming exactly the amount of gas that it was provided with!

source

pub fn pid(&self) -> Option<u32>

Returns the PID of the sandbox corresponding to this instance.

Will be None if the instance doesn’t run in a separate process. Mostly only useful for debugging.

Trait Implementations§

source§

impl<T> Clone for Instance<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Instance<T>

§

impl<T> !RefUnwindSafe for Instance<T>

§

impl<T> Send for Instance<T>
where T: Sync + Send,

§

impl<T> Sync for Instance<T>
where T: Sync + Send,

§

impl<T> Unpin for Instance<T>

§

impl<T> !UnwindSafe for Instance<T>

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

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>,

§

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 T
where 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.