This document defines the required host ABI for ZASM-generated modules (zABI 2.x). All conforming modules and hosts MUST follow this contract.
zABI 2.x replaces the retired legacy “stream ABI” (req_read/res_write/_ctl).
main(req: i32, res: i32) -> ()(WASM runner entrypoint)- Required by
zrun. - Must close
resviazi_end(res)before returning. - Note: legacy entrypoints are not supported; use
main.
- Required by
memory(WASM linear memory)- Required for any ABI calls that read/write guest memory.
All zABI imports live under module name "env".
Core syscalls (required):
zi_abi_version() -> i32- Must return
0x00020005for zABI 2.5.
- Must return
zi_ctl(req_ptr: i64, req_len: i32, resp_ptr: i64, resp_cap: i32) -> i32- Control-plane request/response used for discovery and structured host queries.
zi_alloc(size: i32) -> i64- Allocates
sizebytes in guest memory; returns guest pointer/offset or negative error.
- Allocates
zi_free(ptr: i64) -> i32- Frees a prior
zi_allocresult; returns0or negative error.
- Frees a prior
zi_read(h: i32, dst_ptr: i64, cap: i32) -> i32- Reads up to
capbytes into guest memory atdst_ptr; returns bytes read or negative error.
- Reads up to
zi_write(h: i32, src_ptr: i64, len: i32) -> i32- Writes
lenbytes from guest memory atsrc_ptr; returns bytes written or negative error.
- Writes
zi_end(h: i32) -> i32- Closes a handle/stream; returns
0or negative error.
- Closes a handle/stream; returns
zi_telemetry(topic_ptr: i64, topic_len: i32, msg_ptr: i64, msg_len: i32) -> i32- Best-effort debug/telemetry channel; returns
0or negative error.
- Best-effort debug/telemetry channel; returns
Notes:
- In wasm32,
*_ptrvalues are passed asi64but represent a u32 linear-memory offset. - Optional subsystems (caps/fs/async/etc.) extend the
env.zi_*surface and are discovered viazi_ctl(e.g. CAPS_LIST).
__heap_base: i32- Exported by modules.
- Marks the first free byte after static data.
- Hosts may use it to seed allocators for deterministic bump allocation.
- Linear memory minimum: 1 page (64KiB).
- Static data base offset: 8.
- Static data alignment: 4 bytes.
- Offsets
0..7are reserved for future ABI use. - Dynamic growth may be performed by the guest via
memory.grow(subject to host caps). - All ABI calls that read/write guest memory MUST bounds-check pointers and lengths against the guest memory cap.
- On out-of-bounds pointer/length, calls with return values MUST return a negative error.
- Hosts MUST provide at least the core syscalls above.
- Optional subsystems MUST fail closed when not supported.
Discovery:
- Capability discovery/negotiation is performed via
zi_ctl(ZCL1 frames), not a feature bitset.
zi_writeto a closed/invalid handle MUST return a negative error. Hosts may trap in strict mode.- When a handle is closed, hosts SHOULD NOT perform partial writes.
zi_readMAY return fewer bytes thancap(short read).- If
cap == 0,zi_readMUST return0and MUST NOT write any bytes. zi_writeMAY return fewer bytes thanlen(short write).- If
len == 0,zi_writeMUST return0and MUST NOT write any bytes. zi_endMUST be idempotent: calling it on a closed handle MUST be a no-op.zi_telemetryis best-effort; hosts may drop messages but MUST NOT crash on bad pointers.
- 0 = stdin (
zi_read) - 1 = stdout (
zi_write/zi_end) - 2 = stderr/log (
zi_write/zi_end) - Handles MUST be stable within a run and MUST NOT alias active handles.
- Hosts and guests MUST reject unknown or mismatched ABI versions.
- Capability discovery/negotiation is via
zi_ctl(structured control-plane).
- zABI version is 2.0 (
0x00020000). - Backward-compatible additions MAY be introduced in later minor versions gated by
zi_ctldiscovery.