// rt — runtime primitives exposed to ww programs. // Mirrors Hare's rt:: module placement (ref/hare/rt/). package rt; // malloc — mmap-backed page allocator. Untyped: `malloc(n)` returns a // `*void`; callers cast to the target type. Diverges from Hare: Hare // exposes `alloc` / `free` as typed language builtins that the // compiler lowers to rt::malloc/rt::free; ww has no such builtins, // so the rt-symbol surface is exposed directly. Stdlib callers that // need a typed allocation pattern wrap this with a cast plus a stored // capacity (see [[strings.dup]], [[memio.dynamic]]). // // OOM: rt_malloc is a bare mmap(MAP_ANON|MAP_PRIVATE) wrapper with no // error path. The raw Linux mmap syscall returns a negative errno cast // to `*void` on failure (e.g. `(void*)-12` for ENOMEM); the // `MAP_FAILED` (`(void*)-1`) value is a libc-wrapper convention that // rt_malloc doesn't apply. Neither `== nil` nor `== (void*)-1` catches // it; any deref of such a return faults. Today the stdlib does not // check; OOM faults on first dereference. A typed fallible variant is // a future task (task #39). ref/hare/rt/malloc.ha:27. @symbol("rt_malloc") export fn malloc(n: u64) *void;