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
- pub fn is_error(r i64) bool
- pub fn errno(r i64) i64
- pub fn mmap(addr uintptr, length i64, prot i64, flags i64, fd i64, offset i64) i64
- pub fn munmap(addr uintptr, length i64) i64
- pub fn mprotect(addr uintptr, length i64, prot i64) i64
- pub fn madvise(addr uintptr, length i64, advice i64) i64
- pub fn brk(addr uintptr) i64
- pub fn getpid() i64
- pub fn exit(status i64)
- pub fn reserve_anon(length i64) uintptr
- pub fn read(fd i64, buf []mut byte) i64
- pub fn write(fd i64, buf []byte) i64
- pub fn open(path []byte, flags i64, mode i64) i64
- pub fn close(fd i64) i64
- pub fn map_anon(length i64) uintptr
Functions 15
is_error reports whether a raw syscall return is a failure.
errno extracts the positive errno from a failed syscall return, or 0 if the call succeeded.
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.
munmap unmaps a region. Returns 0, or a negated errno.
mprotect changes the protection on a region. Returns 0, or a negated errno.
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.
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.
getpid returns the calling process's ID. It cannot fail, which makes it the cheapest way to check that the syscall path itself works.
exit terminates the process with the given status and does not return.
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.
read reads up to len(buf) bytes from fd into buf. Returns the byte count, or a negated errno.
write writes len(buf) bytes from buf to fd. Returns the byte count, or a negated errno.
open opens path (which must be null-terminated) with the given flags and mode. Returns the new fd, or a negated errno.
close closes fd. Returns 0, or a negated errno.
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.