Bsd Package v0.1.0
The package is under active development and its API is not yet stable. Names, signatures, and behavior may change between releases, and this documentation will be updated to match.
Direct syscall bindings for FreeBSD, OpenBSD, NetBSD, and DragonFly BSD.
Package: Bsd
Source: github.com/rux-lang/Rux/tree/main/Packages/Bsd
The package provides raw zero-to-six-argument syscall entry points, typed wrappers for common I/O, process, memory, and time operations, and the constants and structures those wrappers require. It calls the kernel without libc and uses compiler-provided thunks where the supported BSD variants differ.
Requirements
- FreeBSD, OpenBSD, NetBSD, or DragonFly BSD on x86-64
- A Rux compiler with the BSD syscall thunks
The syscall ABI is platform- and architecture-specific. Prefer the cross-platform packages — Io, Memory — when they provide the operation you need.
Installation
rux add Bsd
rux install
Then import the symbols you need:
import Bsd::{ StdOut, Write };
Platform Compatibility
The package is x86-64 only — the raw syscall entry points are hand-written x86-64 assembly, and there is no AArch64 path yet. On any other architecture the package does not apply.
Syscall numbers and clock IDs differ between the four supported BSDs, so the package selects the right value for the active target at compile time; Mmap, Munmap, Nanosleep, and ClockGetTime route through dedicated per-target paths. ClockMonotonic is 4 on FreeBSD and DragonFly BSD and 3 on NetBSD and OpenBSD. The mapping and protection flags are the same on all four.
Result Convention
The wrappers return the kernel result directly: a non-negative value on success — a byte count, a process ID, a mapped address, or 0 — and a negative errno (-1 through -4095) on failure. IsError tests for that negative range and Errno turns it back into a positive errno number, so a legitimate positive result is never mistaken for an error.
Functions
I/O
| Function | Description |
|---|---|
Read | Read bytes from a file descriptor. |
Write | Write bytes to a file descriptor. |
Close | Close a file descriptor. |
Memory
| Function | Description |
|---|---|
Mmap | Create a virtual-memory mapping. |
Munmap | Remove a virtual-memory mapping. |
Brk | Change the process program break. |
Process
Time
| Function | Description |
|---|---|
ClockGetTime | Read a BSD clock. |
Nanosleep | Suspend for a relative interval. |
Raw syscalls
| Function | Description |
|---|---|
Syscall0–Syscall6 | Invoke an arbitrary syscall by number. |
IsError | Test whether a result is a negative errno. |
Errno | Extract the positive errno from a result. |
Types and constants
The standard descriptors, syscall numbers, mapping and protection flags, clock IDs, and the Timespec structure are listed on the types and constants page.
Example
import Bsd::{ StdOut, Write };
func Main() -> int {
let message = "hello from BSD\n";
let result = Write(StdOut, message.data, message.length);
return result == message.length as int64 ? 0 : 1;
}
Introduction
This reference documents the packages that ship with Rux: what each function does, what it returns, and where its behavior differs from the platform underneath. It is a lookup reference rather than a tutorial — if you are new to the language, start with the Get Started guide or the Rux Language Reference.
Brk
Changes the process program break.