Linux Package
Unstable API
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 Linux x86-64 system-call bindings for Rux programs.
Module: Linux
Source: github.com/rux-lang/Linux
The package calls the kernel without going through libc. It provides raw zero-to-six-argument syscall entry points, typed wrappers for a focused set of common operations, and the constants and structures those wrappers need.
Requirements
- Linux on x86-64
- A Rux compiler with the
rux-linuxsyscall thunks
The syscall numbers and calling convention are architecture-specific. Do not use this package when targeting another operating system or architecture.
Installation
Add the package and install project dependencies:
rux add Linux
rux installThen import the symbols you need:
import Linux::{ IsError, Stdout, Write };Result Convention
Functions that return int64 expose the kernel result unchanged. A non-negative value indicates success. Values from -4095 through -1 encode an error as negative errno; test them with IsError and extract the positive errno value with Errno.
The package does not set a thread-local errno, retry interrupted calls, or convert failures into exceptions.
I/O and Process
| Function | Description |
|---|---|
Read | Read bytes from a file descriptor. |
Write | Write bytes to a file descriptor. |
Close | Close a file descriptor. |
GetPid | Return the calling process ID. |
Exit | Terminate the calling thread immediately. |
Memory
| Function | Description |
|---|---|
Mmap | Create a virtual-memory mapping. |
Munmap | Remove a virtual-memory mapping. |
Brk | Invoke the kernel's raw program-break operation. |
Time
| Symbol | Description |
|---|---|
Timespec | Seconds-and-nanoseconds time value. |
Nanosleep | Suspend execution for a relative interval. |
ClockGetTime | Read a Linux clock. |
Low-level API
| Topic | Description |
|---|---|
Syscall0–Syscall6 | Invoke an arbitrary syscall with 0–6 arguments. |
Constants | File descriptors, syscall numbers, and flags. |
IsError | Test whether a raw result encodes an error. |
Errno | Decode a raw error result. |
Example
import Linux::{ Errno, IsError, Stdout, Write };
func Main() -> int32 {
let message = "hello from Linux\n";
let result = Write(Stdout, message.data, message.length);
if IsError(result) {
// Errno(result) is the positive Linux errno value.
return 1i32;
}
return result == message.length as int64 ? 0i32 : 2i32;
}Higher-level code
Prefer Std::Io, Std::Memory, and Std::Time for portable application code. Use this package when Linux-specific behavior or direct syscall control is required.