Module wasm::wasm_rt
freestanding wasm32 runtime.
A wasm32-unknown-unknown build is linked with -nostdlib (see std/wasm/dom.h's header comment for the full toolchain invocation) — there is no libc, so the libc functions std's own sources call (malloc & co., the mem*/str* family, strtod/strtoll, qsort) and the compiler-rt builtins LLVM emits calls to (__multi3 & co. for 128-bit arithmetic) have no definition unless something in the module provides one. This file is that something, so a module needs no host imports beyond the ones its own code (and std/wasm/dom) declares.
The heap is a size-class allocator over the module's linear memory: blocks are powers of two (header included), freed blocks are reused by later allocations of the same class, and the memory grows (memory.grow) on demand from the linker's __heap_base — a long-running page can allocate and free indefinitely. Memory is never returned to the host.
Only meaningful for wasm32 freestanding targets — a hosted build (Cocoa/Win32/X11/bare-metal GUI, the RPC server, etc.) must keep using the real libc via std/mem.sc, not this file; including both in the same link would duplicate-symbol on malloc/free/etc.
Functions
| malloc | |
| free | |
| calloc | |
| realloc | |
| memmove | |
| memset | |
| memcmp | |
| memchr | |
| malloc_usable_size | Payload bytes usable in a malloc'd block (0 for any other pointer). |
| posix_memalign | Alignments above 8 over-allocate; such a block is never freed. |
| strlen | |
| strcmp | |
| strncmp | |
| strchr | |
| strrchr | |
| strstr | |
| strspn | |
| strcspn | |
| strpbrk | |
| strncpy | |
| strcat | |
| strncat | |
| strtok_r | |
| strtoull | |
| strtoll | |
| atoi | |
| atoll | |
| strtod | Decimal only ('1.5e-3'), good to ~15 significant digits; no inf/nan/hex. |
| qsort | |
| abort | abort() is wasm's native trap — the host sees a RuntimeError ("unreachable") — and the printf family drops its output (SafeC has no va_arg to decode a varargs list with). snprintf isn't provided: std's float formatting (fmt_float / String::push_float) needs a host on wasm. |
| fprintf | |
| printf |