Skip to main content

ProtoWasmSandbox

Struct ProtoWasmSandbox 

Source
pub struct ProtoWasmSandbox { /* private fields */ }
Expand description

A Hyperlight Sandbox with no Wasm run time loaded and no guest module code loaded. This is used to register new host functions that can be called by guest code.

Once all guest functions have been loaded you can call load_runtime to load the Wasm runtime and get a WasmSandbox`.

With that WasmSandbox you can load a Wasm module through the load_module method and get a LoadedWasmSandbox which can then execute functions defined in the Wasm module.

Implementations§

Source§

impl ProtoWasmSandbox

Source

pub fn load_runtime(self) -> Result<WasmSandbox>

Load the Wasm runtime into the sandbox and return a WasmSandbox that can be cached and used to load a Wasm module resulting in a LoadedWasmSandbox

The LoadedWasmSandbox can be reverted to a WasmSandbox by calling the unload_runtime method. The returned WasmSandbox can be then be cached and used to load a different Wasm module.

Source

pub fn register<Args: ParameterTuple, Output: SupportedReturnType>( &mut self, name: impl AsRef<str>, host_func: impl Into<HostFunction<Output, Args>>, ) -> Result<()>

Register the given host function host_func with self under the given name. Return Ok if the registration succeeded, and a descriptive Err otherwise.

Source

pub fn register_print( &mut self, print_func: impl Into<HostFunction<i32, (String,)>>, ) -> Result<()>

Register the given host printing function print_func with self. Return Ok if the registration succeeded, and a descriptive Err otherwise.

Trait Implementations§

Source§

impl Debug for ProtoWasmSandbox

Source§

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

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

impl Default for ProtoWasmSandbox

Create a new sandbox with a default configuration with a Wasm runtime but no end-user code loaded. Since there’s no user code loaded, the returned sandbox cannot execute anything.

It can be used to register new host functions that can be called by guest code.

Once all guest functions have been loaded you can call load_runtime to load the Wasm runtme and get a WasmSandbox.

The default configuration is as follows:

  • The Hyperlight default Host Print implementation is used.
  • The Sandbox will attempt to run in a hypervisor and will fail if no Hypervisor is available.
  • The Sandbox will have a stack size of 8K and a heap size of 64K
  • All other Hyperlight configuration values will be set to their defaults.

This will result in a memory footprint for the VM backing the Sandbox of approximately 434K

Use the load_runtime method to load the Wasm runtime and convert the returned ProtoWasmSandbox into a WasmSandbox that can have a Wasm module loaded returning a LoadedWasmSandbox that can be used to call Wasm functions in the guest.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for ProtoWasmSandbox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Registerable for ProtoWasmSandbox

Source§

fn register_host_function<Args: ParameterTuple, Output: SupportedReturnType>( &mut self, name: &str, hf: impl Into<HostFunction<Output, Args>>, ) -> Result<()>

Register a primitive host function

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more