ajhahn.de
← FlashOS
Flash 21 lines
// meminfo — free-page reporter for /bin/meminfo.
//
// The standalone /bin form of the shell's `free` built-in: a print-and-exit
// coreutil that writes one line carrying the kernel's current free-page count
// (via the dump_free syscall) through flibc.printf. Exercises the v0.2
// expression grammar's anonymous struct literal — printf's variadic arguments
// are passed as a `.{ ... }` tuple, exactly as in Zig.
//
// Like the other coreutils it pulls in the flibc _start shim and flibc_mem so a
// later change that introduces a libcall cannot regress the link.

use flibc

link "flibc_start"
link "flibc_mem"

export fn main(_ usize, _ argv) noreturn {
    flibc.printf("free pages: %u\n", .{flibc.sys.dump_free()})
    flibc.exit()
}