Skip to main content

Crate wasi_virt_layer

Crate wasi_virt_layer 

Source
Expand description

wasi_virt_layer provides a virtualization layer for WebAssembly System Interface (WASI).

This crate facilitates merging a Virtual File System (VFS) and threading mechanisms into standard WASI modules without modifying their source code in complex ways. It allows a host environment (like browsers via JavaScript bindings) to seamlessly interact with in-memory Wasm modules.

§Core Concepts

  • Virtual File System (VFS): Overrides filesystem-related WASI calls to a custom virtualized implementation.
  • Threading: Provides components that patch how Wasm spawns and manages threads using shared memory.
  • Memory Bridge: Manages memory boundaries and host-guest interaction.

Modules§

clock
Clock and time operations.
file
Virtual File System operations and definitions.
memory
Memory operations to bridge host and WebAssembly memory models.
poll
I/O polling and event waiting mechanisms.
prelude
Common traits, structs, and macros representing the core functionality.
process
Process execution and lifecycle virtualization.
random
Random number generation and virtualization.
wasi
wasip1
Definitions and bindings for the original WASIP1 API.
wasip1_derive
Procedural macros for generating WASIP1 boilerplate.

Macros§

__as_t
Internal helper macro for handle self and other identifiers.
__memory_director_import_etc
Internal macro used to generate memory trap and director imports for WASM access.
__memory_director_wasm_access
Internal macro used to generate the memory_director_raw method for WASM access.
import_wasm
By entering the names of the files to be combined, a bridge for the combination is created. You need to prepare as many Wasip1 instances on the virtual file system as the number of files to be combined.
non_recursive_wasi_snapshot_preview1
Typically, WASI ABI calls are made using plug!. However, there may be cases where you want to call the ABI directly from within plug!. Doing so would result in recursion. To address this, call the function through this macro. When calling a function through this macro, it becomes a proper WASI ABI call after plug is connected. This allows you to call the ABI without causing recursion.
plug_args
@embedded or @dynamic Whether to import JavaScript runtime args from vfs, args is automatically imported even if you are not using it, so that you can block it
plug_clock
Plugs the clock ecosystem by defining necessary handlers for clock operations.
plug_env
@embedded or @dynamic Whether to import JavaScript runtime env from vfs, env is automatically imported even if you are not using it, so that you can block it
plug_fs
Plugs the file system ecosystem by defining necessary handlers.
plug_poll
Plugs the poll ecosystem by defining necessary handlers.
plug_process
Plugs the process exit ecosystem by defining necessary handlers.
plug_random
Plugs the random ecosystem by defining necessary handlers.
wrap_unreachable
A macro to explicitly wrap WebAssembly’s unreachable instructions for a given Target module. This generates internal markers interpreted by wasi_virt_layer-cli during generation.