Syscalls reference (curated)

Source of truth for numbers and semantics: src/kernel/syscalls.rs (syscall_dispatcher).
libc / app stubs: SDK/lib/cstd/src/sys.rs, p1ui.rs.

This table is not every arm in the dispatcher (there are duplicates and legacy stubs). It lists what normal apps and daemons rely on.


POSIX-shaped I/O and files

#

Name

Notes

0

read

Resolves process-local FD; stdin reads the PTY / pipe path only — no direct PS/2 drain in read(0) (compositor + apps use poll_ui_events and/or ps2d → IPC). P1SCode: io.read_line() in p1sc.py lowers to repeated read(0, …) until a newline or EOF, then String::from_utf8_lossy (strips a trailing CR before LF when present).

1

write

Resolve FD; fd 1/2 also push trimmed UTF-8 to system log; int 0x81 yield after stdout/stderr.

2

open

NUL path; cwd-relative; returns process-local FD.

3

close

4

stat

Two implementations exist in match — first full path-based wins for early arms; later stub may be unreachable (debt).

5

fstat

8

lseek

Duplicate arms — same semantics.

21

access

78

getdents

83

mkdir

FAT backend.

87

unlink

FAT delete.


Memory

#

Name

Notes

9

mmap

First 9 => arm: per-task mmap_current growth, anon, invlpg. Later duplicate arm in file is unreachable (Rust match) — dead second implementation using pages_allocated + 0x4000_0000 base; do not rely on it.

227

iomem_map

rdi = physical base (bytes; kernel page-aligns down), rsi = span length, rdx = flags: bit1 set = user executable (clears NX); bit2 set = write-back cacheable (low RAM / DMA window); clear = uncached (MMIO). Maps into the caller’s mmap arena; returns user VA for rdi (same offset within first page) or !0.

230

dma_alloc

rdi = byte size (page-rounded up), rsi = *mut u64 physical base out. Allocates physically contiguous frames, maps RW + NX into mmap arena, returns user VA or !0. 228 is already clock_gettime-style uptime — do not use 228 for DMA.

231

net_io

Delegated RTL8139 port I/O only in legacy userspace NIC mode (network/legacy_kernel_driver == 1). rdi = port (u16), rsi = op (0 inb … 5 outl), rdx = value for out ops. Port must lie in [io_base, io_base+0x100). Returns the read value or 0 after a write; !0 on fault. In kernel-owned mode (legacy == 0), returns !0.

234

iomem_map_user

NIC IRQ subscriber only (netd). Maps another task’s user pages into the caller’s mmap arena: rdi = remote PID, rsi = remote user VA, rdx = byte length (≤1514), r10 = flags (same as 227). Returns page-aligned mapping base VA or !0. Caller **munmap**s the mapped span after use.

12

brk

Query with 0; extend only; no shrink.


Process / thread

#

Name

Notes

39

getpid

56

clone

rdi = flags, rsi = child RSP (stack top), rdx = entry, r10 = arg → RDI at entry. Returns child tid.

59

execve

Path NUL; argv/envp optional; ramdisk fast path via ramdisk_bytes_if_cached. Spawns a new task (fresh PML4); rax = child PID; caller continues (not Linux exec replace). Stray TERMINATED tasks are reaped before load; teardown_sender runs only after SCHEDULER is dropped (process-lifecycle.md §2.2, ipc_present_maps.rs).

60

exit

Shared cleanup with kill — see process-lifecycle.md.

61

waitpid stub

Sets BLOCKED + wait_pid.

62

kill

Phased: kill_recursively → quiesce → cleanup_process_memory → reap_task_fields → purge_target_dead.

63

set_foreground_pid

64

get_foreground_pid

158

arch_prctl

ARCH_SET_FS (0x1002) for TLS.


Scheduling / time

#

Name

Notes

24

yield

int 0x81.

25

sleep

Milliseconds; BLOCKED + yield. (Duplicate arms — same idea.)

228

clock_gettime-style

clock_id=0 => realtime Unix epoch from software RTC (tv_nsec=0 today). Other IDs => monotonic uptime from kernel ticks.

300

get_time

Packed RTC fields (moved off 200 collision with raw net).


IPC

#

Name

Notes

30

legacy ipc_send

Registers: target, type, p1–p3; no syscall-50 present remap.

31

legacy ipc_recv

50

ipc_send (P1-DBUS)

Pointer to IpcMessage; message_type == 260: netd RX injection (handled in-kernel, no compositor broker). 261: TX to netd — see 261 paragraph below (p1 / p2 / p3 / sender_pid). Otherwise target_pid == 0 → resolve deskgui.elf; types 2/5/18 cross-map framebuffer; then broker send.

51

ipc_recv

rdi==0 → current PID; returns 1 if message, 0 if empty.

224

ipc_unmap_present_slot

Compositor: drop (current_pid, sender_pid) present map + unmap PTEs.

225

cpu_core_load

Writes two u32 LE: online cores, busy mask.

226

irq_subscribe

rdi = IRQ number (1 keyboard, 12 PS/2 mouse, NIC: PCI interrupt line, often 11 on QEMU pc + RTL8139), rsi = subscriber PID (must equal caller getpid), rdx = syscall-50 message_type. PS/2: raw inb(0x60) in p1. NIC: p1 = RTL8139 ISR bits after ACK (see kernel nic_interrupt_handler). One subscriber per IRQ. Delivery uses bounded spill queues when the IPC broker is contended (src/kernel/irq_subscribe.rs).

235

irq_unsubscribe

rdi = IRQ number. Drops the subscription if the caller is the current subscriber. 0 or !0. Used by netd when RegCube network/legacy_kernel_driver becomes 1 (release IRQ before any future kernel or alternate owner).

IPC message_type 250 / 251 (not syscall numbers)

On syscall 50, message_type == 250 is WIRE_PS2D_KEY_EVENT: ps2d → compositor decoded keyboard. p1 = legacy WM scancode byte; p2 = (modifiers << 32) | key; p3 = 1 if down (make), 0 if up (break). target_pid == 0 resolves to the compositor. Unrelated to syscall 250 (write_file) in the dispatcher table below.

message_type == 251 is WIRE_PS2D_MOUSE_EVENT: ps2d → compositor — p1 packs dx and dy as two i16 in the low 32 bits, p2 carries button bits and optional wheel dz. target_pid == 0 → compositor.

message_type == 260 (WIRE_NETD_RX_RAW): netd → kernel Ethernet payload. p1 = user VA of frame, p2 = length (14…1600, clamped). Kernel copies from sender address space into the normal RX path; this message is part of the legacy userspace-NIC mode.

message_type == 261 (WIRE_KERNEL_NETD_TX): TX to netd. p2 = Ethernet length (14…1514). p3 & 1 (phys mode): p1 = physical address of the first frame byte (kernel / staging); sender_pid usually 0 — netd uses sys_iomem_map (227) then munmap. Otherwise p1 = user VA in sender_pid (e.g. sys_net_send_raw) — netd uses sys_iomem_map_user (234). netd still copies into its DMA TX scratch for RTL8139 descriptors. No kernel bounce and no syscall 233.

message_type == 271 (WIRE_TIME_SVC): time-service control channel used by p1-timesvc. p1=1 requests sync-now; response uses p1=2 success or p1=3 failure.


Signals / PTY / job control

#

Name

Notes

13

sigaction

Stub success.

16

ioctl

VFS ioctl — PTY winsize, etc.

220

openpty

Writes process-local master/slave fds.

221

pty_rebind_std

Maps local 0,1,2 to slave global fd.

223

signal_foreground

SIGINT/SIGKILL bits in sigmask; SIGKILL clears FOREGROUND_PID.


Graphics / introspection (selected)

#

Name

Notes

72

ptrace_peek

Identity-map assumption — security-sensitive.

73

poll

TCP-centric pollfd scan.

79

ptrace_poke

Identity-map assumption — was dead code when it shared number 73 with poll; use 79.

100

init_graphics

Framebuffer info to user; heavy mapping path.

101

poll_ui_events

102

ps

103

get_network_info

rdi = buffer, rsi = max length. 56 bytes: MAC, SLIRP-style IPv4/gateway/DNS, link, mask, TX/RX counters (legacy layout). If rsi ≥ 128, kernel also writes netd tail: u16 LE I/O base @56, PCI IRQ byte @58, last RX len @59 (≤64), preview @60–123, 0x813910EC @124–127 when RTL8139 present. Return value is bytes written (56 or 128) or !0.

104–107

RegCube get/set/flush/load

98

klog

99

get_logs

rdi = buffer, rsi = max length. Writes UTF-8 text, NUL-terminated if room. One line per log entry. P1E2 (preferred): P1E2, code, level, timestamp, category (Kernel / Application / …), component (subsystem: PCI, TCP, netd, …), message (all fields after P1E2 separated by U+001F \x1f; message escaped). Legacy P1E1: same without component (viewers may infer). Plain text may still appear for non-snapshot output.

318

getrandom

RDRAND-backed.

400

get_sys_mem_info

Total / free frames.


RegCube (selected)

Hive

Key

Notes

HIVE_LOCAL_MACHINE

network/legacy_kernel_driver

0 (default) = kernel owns RTL8139 (MMIO/DMA/IRQ in-kernel). 1 = legacy userspace netd owner mode (sys_net_io, IRQ subscribe, IPC 260/261 path). \\boot.cfg: NET=USERSPACE / NETWORK=USERSPACE forces 1. NET=LEGACY / NETWORK=LEGACY forces kernel-owned mode (no userspace NIC delegation).

HIVE_LOCAL_MACHINE

time/ntp_server

Hostname for SNTP sync (p1-timesvc / timectl), default time.cloudflare.com.

HIVE_LOCAL_MACHINE

time/auto_sync

1/0 toggle for daemon periodic sync behavior.

HIVE_LOCAL_MACHINE

time/sync_interval_sec

Periodic sync interval in seconds (daemon clamps minimum to 60).

HIVE_LOCAL_MACHINE

time/last_sync_status, time/last_sync_unix

Last SNTP outcome diagnostics.


Networking

#

Name

Notes

41

socket

TCP unless type 2 (UDP) or 3 (raw-ish TCP ref).

42

connect

44

send

45

recv

len==0 probes TCP state.

49

bind

52

listen

Stub no-op success.

200

net_send_raw

Validates Ethernet frame (14..1514). In kernel-owned mode (legacy_kernel_driver == 0), kernel copies from caller memory and transmits via rtl8139::kernel_tx_packet (or optimized IPv4 path). In legacy userspace mode (legacy_kernel_driver == 1), forwards TX to netd via IPC 261 with caller sender_pid.

201

net_recv_raw

202

dns_resolve

203

net_config_set

Copies 16 bytes from caller (`ip

204

net_event_subscribe

rdi=1 subscribe caller as net-event daemon; rdi=0 unsubscribe caller. Used by p1-netmgr.

210

tcp_state

211

tcp_retransmit_syn


Misc

#

Name

Notes

20

writev

stdout/stderr only → system log.

22

set_time / RTC refresh

250

write_file

Path + bytes → FAT write (legacy name).


int 0x81

Fast reschedule path used from syscall layer and IRQ return plumbing — treat as yield/reschedule, not a Linux syscall number.


Kernel NIC smoke test (default path)

  1. Ensure \\boot.cfg does not contain NET=USERSPACE.

  2. Boot and confirm logs show kernel-owned mode ([NET] boot mode: KERNEL OWNER default ... and init says netd not spawned).

  3. Exercise ping / DNS / sockets and verify get_network_info (103) counters change as traffic flows.

  4. Optional legacy check: run with NET=USERSPACE and confirm netd subscription logs and IPC 260/261 activity.

See also