Host modules¶
WasmVM ships with a built-in sysenv host that exposes a small POSIX-style
interface to wasm modules. It is split into two sub-modules — sys_fs for
filesystem operations and sys_proc for process / environment access — both
registered automatically by wasmvm unless --no-system is supplied.
Each function below is registered with both an i32 (wasm32) and an i64
(wasm64) variant for every pointer / length parameter. The matching variant is
selected at link time from the importing module’s declared parameter types, so
the same host can serve both wasm32 and wasm64 callers.
Pointer / length convention¶
For functions that take buffers, parameter pairs named ptr and len
refer to a contiguous range in memory 0 of the calling module. Negative i32
return values are POSIX-style errors: the magnitude equals the host’s
errno after the failed syscall.
sys_fs¶
Filesystem operations.
Function |
Signature (wasm32 form) |
Description |
|---|---|---|
|
|
Open a path; returns a wasm fd ( |
|
|
Close a wasm fd. |
|
|
Read up to |
|
|
Write up to |
|
|
Seek; returns the new offset or a negative error. |
|
|
Stat a path into |
|
|
Stat by file descriptor. |
|
|
Remove a file. |
|
|
Rename or move a path. |
|
|
Create a directory. |
|
|
Remove an empty directory. |
|
|
Write the current working directory into |
|
|
Open a directory iterator; returns a directory fd. |
|
|
Read the next entry; returns |
|
|
Close a directory iterator. |
The i64 variants accept i64 for every ptr and len argument
(mode, flags, whence and fd remain i32); for example
open is also registered as (i64, i64, i32, i32) -> i32 for wasm64
callers.
sys_proc¶
Process and environment access.
Function |
Signature (wasm32 form) |
Description |
|---|---|---|
|
|
Terminate the wasm program with the given exit code. |
|
|
Number of command-line arguments. Argument 0 is the main module
path; subsequent arguments come from |
|
|
Length in bytes of argument |
|
|
Copy argument |
|
|
Look up an environment variable and copy it into |
|
|
Read a monotonic / realtime clock into a |
Disabling the host¶
Pass --no-system (-ns) to wasmvm to disable automatic
instantiation of sys_fs and sys_proc. This is useful when running
modules that should not be granted filesystem or process access.