Linux Package v0.1.0

Source
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 system-call bindings for Rux programs.

Package: Linux

Source: github.com/rux-lang/Rux/tree/main/Packages/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 or AArch64
  • A Rux compiler with the Linux syscall support

On x86-64 the wrappers issue the syscall instruction directly; on AArch64 the native backend lowers them through libc's syscall function. The syscall numbers are architecture-specific and the package selects the right set for the active target at compile time.

Installation

rux add Linux
rux install

Then import the symbols you need:

import Linux::{ StdOut, Write };

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.

The package does not set a thread-local errno, retry interrupted calls, or convert failures into exceptions.

Functions

I/O

FunctionDescription
ReadRead bytes from a file descriptor.
WriteWrite bytes to a file descriptor.
CloseClose a file descriptor.

Memory

FunctionDescription
MmapCreate a virtual-memory mapping.
MunmapRemove a virtual-memory mapping.
BrkInvoke the kernel's raw program-break operation.

Process

FunctionDescription
ExitTerminate the process immediately.
GetPidReturn the calling process ID.

Time

FunctionDescription
ClockGetTimeRead a Linux clock.
NanosleepSuspend for a relative interval.

Raw syscalls

FunctionDescription
Syscall0Syscall6Invoke an arbitrary syscall by number.
IsErrorTest whether a result is a negative errno.
ErrnoExtract 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 Linux::{ IsError, StdOut, Write };

func Main() -> int {
    let message = "hello from Linux\n";
    let result = Write(StdOut, message.data, message.length);
    if IsError(result) {
        return 1;
    }
    return result == message.length as int64 ? 0 : 2;
}