Skip to main content

Module os

Module os 

Source
Expand description

The OS boundary: anonymous mapping, unmapping, and returning pages.

Three hand-declared extern "C" symbols, no libc crate — the house rule for OS boundaries. Linux and macOS only; elsewhere every entry point reports failure and the allocator is simply unavailable.

§Why not kevy-madvise

That crate already binds mmap/munmap/madvise, so reusing it was the first choice. It does not fit: it is Linux-only by construction and its contract is huge-page advice — every mapping it hands out has MADV_HUGEPAGE applied. An allocator needs mappings on macOS too (that is where this is developed), and it must be able to return pages, which is the property the whole experiment rests on. Widening a crate whose name is its contract costs more than three extern declarations, so the boundary lives here — which is also why kevy-alloc is in the recorded unsafe set (allocgate M8).

Constants§

PAGE
The system page size this module assumes for rounding.

Functions§

available
Whether this target can map memory at all. Used by tests and by the heap’s construction path to fail fast rather than mysteriously.
discard
Return the physical pages backing len bytes at ptr to the OS while keeping the range mapped and addressable.
map_aligned
Map len bytes anonymously with the returned address aligned to align bytes.
round_up
Round n up to a multiple of align, which must be a power of two.
unmap
Unmap len bytes at ptr.