pub struct WasiConfig { /* private fields */ }Expand description
WASI (WebAssembly System Interface) configuration for zwasm modules.
Supports WASI Preview 1 and 2, full syscalls, stdio overrides, preopened directories, and environment/argv configuration. Used to provide system interface capabilities to Wasm modules running in the zwasm runtime.
Implementations§
Source§impl WasiConfig
impl WasiConfig
Sourcepub fn new() -> Result<Self, ZwasmError>
pub fn new() -> Result<Self, ZwasmError>
Creates a new WASI configuration for zwasm modules.
Supports both WASI Preview 1 and 2. Use this to provide system interface capabilities to Wasm code.
Sourcepub fn set_argv(&mut self, argv: &[&str]) -> Result<(), ZwasmError>
pub fn set_argv(&mut self, argv: &[&str]) -> Result<(), ZwasmError>
Sets the argv (command-line arguments) for the guest process.
These will be visible to the Wasm module via WASI syscalls.
Sourcepub fn set_env(&mut self, env: &[(&str, &str)]) -> Result<(), ZwasmError>
pub fn set_env(&mut self, env: &[(&str, &str)]) -> Result<(), ZwasmError>
Sets environment variables for the guest process.
These will be visible to the Wasm module via WASI syscalls.
Sourcepub fn preopen_dir(
&mut self,
host_path: &str,
guest_path: &str,
) -> Result<(), ZwasmError>
pub fn preopen_dir( &mut self, host_path: &str, guest_path: &str, ) -> Result<(), ZwasmError>
Preopens a host directory at a guest-visible path for the Wasm module.
Grants the guest access to the specified host directory under the given guest path.
§Safety
This method grants the guest access to host filesystem resources. Callers must ensure the mapped host path is intended to be exposed to untrusted Wasm code.
Sourcepub fn preopen_fd(
&mut self,
host_fd: isize,
guest_path: &str,
kind: u8,
ownership: u8,
) -> Result<(), ZwasmError>
pub fn preopen_fd( &mut self, host_fd: isize, guest_path: &str, kind: u8, ownership: u8, ) -> Result<(), ZwasmError>
Preopens an existing host file descriptor at a guest-visible path for the Wasm module.
Useful for passing already-opened files or sockets into the guest.
§Safety
This method transfers or borrows host FD capabilities into the guest, depending on
ownership. Callers must ensure FD lifetime/ownership policy matches the supplied flag
and that exposing the FD to guest code is acceptable.
Sourcepub fn set_stdio_fd(
&mut self,
wasi_fd: u32,
host_fd: isize,
ownership: u8,
) -> Result<(), ZwasmError>
pub fn set_stdio_fd( &mut self, wasi_fd: u32, host_fd: isize, ownership: u8, ) -> Result<(), ZwasmError>
Overrides WASI stdio file descriptor mapping (stdin, stdout, stderr).
Allows redirecting guest stdio to custom host file descriptors.
§Safety
The runtime may close or retain the supplied host_fd based on ownership. Callers
must ensure ownership mode is correct to avoid double-close or leaked descriptors.