Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

System calls

Access to kernel resources and IPC primitives is accomplished primarily through system calls (syscalls). There are a small number of syscalls that are used primarily to interact with capabilities. Note that the syscall API differs from the capability API, which is largely built on top of of SYS_call.

Common ABI types

Type declarations for Hare code are provided by the uapi module in the kernel source tree.

TypeDescription
u88-bit unsinged integer
u1616-bit unsinged integer
u3232-bit unsinged integer
u6464-bit unsinged integer
uaddr64-bit memory address
caddr32-bit capability address
ctype8-bit capability type

Capability types

IDTypeDescription
0NULLEmpty capability slot
1MEMORYGeneral-purpose memory
2CSPACECapability space
3VSPACEVirtual address space
4TASKSchedulable task
5PAGEPage of memory
6NOTIFICATIONIPC notification
7ENDPOINTIPC endpoint
8REPLYIPC reply

x86_64 specific

IDTypeDescription
9PDPTPage-directory pointer table
10PDPage directory
11PTPage table
12IOCONTROLI/O control
13IOPORTI/O port
14IRQCONTROLIRQ control
15IRQIRQ

x86_64 ABI

The x86_64 syscall ABI is based on the System-V ABI. All arguments are passed in registers. Note that floating point registers are not used by the ABI (and are preserved by the kernel).

Input registers

RegisterPurpose
%raxSyscall number (8 bits) & flags
%rdi(a1) 1st argument register
%rsi(a2) 2nd argument register
%rdx(a3) 3rd argument register
%r10(a4) 4th argument register1
%r8(a5) 5th argument register
%r9(a6) 6th argument register

Output registers

RegisterPurpose
%raxSyscall outcome (8 bits) + 56 syscall-specific bits
%rsi(r1) 1st return register
%rdx(r1) 2nd return register

The syscall outcome is 0 on success or an error code on failure.

Other registers

RegisterPurpose
%r12-%r15Kernel-saved
%rbpKernel-saved
%rbxKernel-saved
%fs, %gsKernel-saved

Note

Certain syscalls, notably SYS_call and SYS_recv, differ from the standard register allocation.

Error codes

The following error codes are defined:

CodeNameDescription
0n/aIndicates a successful outcome.
1EWRONGTYPEAn incorrect resource type was used in an operation.
2ENOMEMInsufficient memory available for requested operation.
3EINVALIDAn invalid parameter was supplied for an operation.
4EINVALCADDRAn invalid capability address was used.
5ERANGEA parameter exceeds the permissible range.
6EEXISTA resource already exists at the given address.
7ENOENTA required resource does not exist.
8EBUSYA required resource is currently in use.
9ENOTSUPThe requested operation is not supported.
10ENOSYSInvalid syscall or function.
11EFAULTUse of invalid address.
12EL1PTVSpace mapping is missing a required level 1 page table.
13EL2PTVSpace mapping is missing a required level 2 page table.
14EL3PTVSpace mapping is missing a required level 3 page table.
15EL4PTVSpace mapping is missing a required level 4 page table.
16EDESTROYEDA resource was destroyed during the operation.

  1. Note that the System-V ABI assigns the 4th argument to %rcx.