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
impl ProtoWasmSandbox
Sourcepub fn load_runtime(self) -> Result<WasmSandbox>
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.
Sourcepub fn register<Args: ParameterTuple, Output: SupportedReturnType>(
&mut self,
name: impl AsRef<str>,
host_func: impl Into<HostFunction<Output, Args>>,
) -> Result<()>
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.
Sourcepub fn register_print(
&mut self,
print_func: impl Into<HostFunction<i32, (String,)>>,
) -> Result<()>
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
impl Debug for ProtoWasmSandbox
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.
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.