// rt/alloc.s — raw page primitive via the mmap syscall. // // rt_segmalloc(n: u64) returns a *void aligned at a page boundary, sized // to the next page multiple. It is the primitive under rt/malloc.ww's // bump allocator (renamed from rt_malloc, task #8) — callers use the // bump rt_malloc, not this directly. // // We pin to PROT_READ|PROT_WRITE and MAP_PRIVATE|MAP_ANONYMOUS so // callers never have to plumb file descriptors through. // // On mmap failure the raw syscall returns -errno (negative); we map // that to 0 so the bump allocator's null-check (and the alloc builtin's // `!`/`?` lowering, task #30) sees a clean nil. TEXT rt_segmalloc,$0 MOVQ DI, SI // arg 1: length = caller's n MOVQ $0, DI // arg 0: addr = NULL (kernel chooses) MOVQ $3, DX // arg 2: prot = R|W MOVQ $34, R10 // arg 3: flags = MAP_PRIVATE|MAP_ANON MOVQ $-1, R8 // arg 4: fd = -1 MOVQ $0, R9 // arg 5: offset = 0 MOVQ $9, AX // syscall: mmap SYSCALL CMPQ $0, AX JGE rt_segmalloc_ok XORQ AX, AX rt_segmalloc_ok: RET // rt_free is a no-op: ww is a no-free runtime. rt/malloc.ww bumps over // shared 2MiB chunks, so a mid-chunk pointer cannot be unmapped without // corrupting its neighbours; all memory is reclaimed at process exit. // Kept as a symbol because os.free re-exports it (lib/os/os.ww) for the // public API — callers' frees become harmless leaks. (task #8) TEXT rt_free,$0 RET