packages / sys
package

sys

import "sys"

Package sys is the typed Boson surface over the raw Linux syscall stubs in _sys. Adding a syscall here is ordinary Boson: name the number, name the arguments, call the right syscallN. Nothing new has to be written in assembly.

The wrappers are deliberately thin. They convert between Boson types and the kernel's flat i64 arguments and do nothing else -- no retry, no errno translation into an error value, no hidden allocation. A caller that wants richer handling builds it on top; a caller that needs the raw result (the allocator, which runs below any error machinery) still has it.

Index

Functions 15

pub fn is_error(r i64) bool

is_error reports whether a raw syscall return is a failure.

sys.bos:58 #is_error
pub fn errno(r i64) i64

errno extracts the positive errno from a failed syscall return, or 0 if the call succeeded.

sys.bos:64 #errno
pub fn mmap(addr uintptr, length i64, prot i64, flags i64, fd i64, offset i64) i64

mmap maps memory. Returns the mapping address, or a negated errno.

This is the six-argument syscall that motivated the generic floor: with the syscall number it needs seven argument slots, one past the six argument registers, so the last travels on the stack.

sys.bos:76 #mmap
pub fn munmap(addr uintptr, length i64) i64

munmap unmaps a region. Returns 0, or a negated errno.

sys.bos:81 #munmap
pub fn mprotect(addr uintptr, length i64, prot i64) i64

mprotect changes the protection on a region. Returns 0, or a negated errno.

sys.bos:86 #mprotect
pub fn madvise(addr uintptr, length i64, advice i64) i64

madvise advises the kernel about a region's expected use. Returns 0, or a negated errno. MADV_DONTNEED is how an allocator returns pages to the system without giving up the address range.

sys.bos:93 #madvise
pub fn brk(addr uintptr) i64

brk sets the program break. Returns the new break, which equals the old one if the request could not be satisfied -- brk reports failure by refusing to move rather than by returning an errno.

sys.bos:100 #brk
pub fn getpid() i64

getpid returns the calling process's ID. It cannot fail, which makes it the cheapest way to check that the syscall path itself works.

sys.bos:106 #getpid
pub fn exit(status i64)

exit terminates the process with the given status and does not return.

sys.bos:111 #exit
pub fn reserve_anon(length i64) uintptr

reserve_anon maps a large private anonymous region without reserving commit for it, for callers that want address space now and memory later. Returns 0 on failure.

sys.bos:118 #reserve_anon
pub fn read(fd i64, buf []mut byte) i64

read reads up to len(buf) bytes from fd into buf. Returns the byte count, or a negated errno.

sys.bos:142 #read
pub fn write(fd i64, buf []byte) i64

write writes len(buf) bytes from buf to fd. Returns the byte count, or a negated errno.

sys.bos:148 #write
pub fn open(path []byte, flags i64, mode i64) i64

open opens path (which must be null-terminated) with the given flags and mode. Returns the new fd, or a negated errno.

sys.bos:154 #open
pub fn close(fd i64) i64

close closes fd. Returns 0, or a negated errno.

sys.bos:159 #close
pub fn map_anon(length i64) uintptr

map_anon is the common case: private, anonymous, read-write pages backed by nothing, at an address of the kernel's choosing. Returns 0 on failure rather than a negated errno, so the result is directly usable as a pointer.

The pages are zero-filled, which callers may rely on -- it is a property of MAP_ANONYMOUS, not an accident.

sys.bos:169 #map_anon