pub struct WapcHost { /* private fields */ }
Expand description
A WebAssembly host runtime for waPC-compliant modules
Use an instance of this struct to provide a means of invoking procedure calls by
specifying an operation name and a set of bytes representing the opaque operation payload.
WapcHost
makes no assumptions about the contents or format of either the payload or the
operation name, other than that the operation name is a UTF-8 encoded string.
Implementations§
source§impl WapcHost
impl WapcHost
sourcepub fn new(
engine: Box<dyn WebAssemblyEngineProvider>,
host_callback: Option<Box<HostCallback>>
) -> Result<Self, Error>
pub fn new( engine: Box<dyn WebAssemblyEngineProvider>, host_callback: Option<Box<HostCallback>> ) -> Result<Self, Error>
Creates a new instance of a waPC-compliant host runtime paired with a given low-level engine provider
sourcepub fn id(&self) -> u64
pub fn id(&self) -> u64
Returns a reference to the unique identifier of this module. If a parent process
has instantiated multiple WapcHost
s, then the single static host callback function
will contain this value to allow disambiguation of modules
sourcepub fn call(&self, op: &str, payload: &[u8]) -> Result<Vec<u8>, Error>
pub fn call(&self, op: &str, payload: &[u8]) -> Result<Vec<u8>, Error>
Invokes the __guest_call
function within the guest module as per the waPC specification.
Provide an operation name and an opaque payload of bytes and the function returns a Result
containing either an error or an opaque reply of bytes.
It is worth noting that the first time call
is invoked, the WebAssembly module
might incur a “cold start” penalty, depending on which underlying engine you’re using. This
might be due to lazy initialization or JIT-compilation.
sourcepub fn replace_module(&self, module: &[u8]) -> Result<(), Error>
pub fn replace_module(&self, module: &[u8]) -> Result<(), Error>
Performs a live “hot swap” of the WebAssembly module. Since all internal waPC execution is assumed to be
single-threaded and non-reentrant, this call is synchronous and so
you should never attempt to invoke call
from another thread while performing this hot swap.
Note: if the underlying engine you’ve chosen is a JITting engine, then performing a swap will re-introduce a “cold start” delay upon the next function call.
If you perform a hot swap of a WASI module, you cannot alter the parameters used to create the WASI module like the environment variables, mapped directories, pre-opened files, etc. Not abiding by this could lead to privilege escalation attacks or non-deterministic behavior after the swap.