Skip to content

4.3 System Call Interface

Glen edited this page Nov 14, 2026 · 2 revisions

System Call Interface

Relevant source files

Purpose and Scope

This section details the CadenzaOS system call interface, which establishes a controlled privilege boundary between ring-3 user tasks and ring-0 kernel services. The architecture relies on the x86 software interrupt gateway (int 0x80), low-level register preservation via assembly context stubs (isr80_stub), a Zig-based dispatch multiplexer (src/kernel/syscall.zig), behavioral telemetry integration with the Conductor (src/kernel/conductor.zig), and traffic validation via src/kernel/security.zig.

Sources: src/kernel/interrupts/irq_stubs.asm1-348, src/kernel/syscall.zig1-127, src/kernel/security.zig1-36


1. The int 0x80 Gateway and Context Stubs

User tasks invoke system services by triggering software interrupt vector 0x80. The Interrupt Descriptor Table (IDT) routes this vector to the assembly stub isr80_stub defined in src/kernel/interrupts/irq_stubs.asm.

When isr80_stub executes, it preserves the general-purpose registers onto the task stack, matching the layout defined by TaskContextsrc/kernel/scheduler.zig56-62. It then passes a pointer to this register frame in rdi to the kernel dispatch handler (syscall_handler), switches stacks according to the returned execution context, and resumes execution via iretqsrc/kernel/interrupts/irq_stubs.asm161-204.

Diagram: Trap Gate to Code Entity Mapping

diagram

Sources: src/kernel/interrupts/irq_stubs.asm161-204, [src/kernel/scheduler.zig:56-62], src/kernel/syscall.zig25-127


2. System Call Numbers and Dispatch Logic

The kernel dispatch logic is implemented within src/kernel/syscall.zig. The SyscallID enumeration defines the supported numeric service identifiers: WRITE_TEXT, GET_TEMPO, and RECORD_HABITsrc/kernel/syscall.zig18-23.

Supported System Call Operations

  • WRITE_TEXT (0): Interprets arg1 as a pointer to a UTF-8 character buffer and arg2 as the length, writing strings via vga.writeStringsrc/kernel/syscall.zig42-49.
  • GET_TEMPO (1): Queries and returns the active Conductor state enumeration from conductor.current_statesrc/kernel/syscall.zig57-59.
  • RECORD_HABIT (2): Receives previous and current command identifiers in arg1 and arg2, evaluates transition scores against the Conductor transition matrix, updates learning weights, and returns anomaly detection indicators src/kernel/syscall.zig76-125.

Additionally, the kernel provisions a physical scratch page (SCRATCH_PAGE_PHYS at address 0x7000) to support binary loading and temporary staging operations during task initialization src/kernel/scheduler.zig21-23.

Diagram: Syscall Dispatch Data Flow

diagram

Sources: src/kernel/syscall.zig18-127, src/kernel/scheduler.zig21-23, src/kernel/conductor.zig24-33


3. Security and Traffic Inspection

Before processing sensitive input or inter-task communication payloads, CadenzaOS invokes lightweight pattern-matching routines via src/kernel/security.zig. The inspectTraffic function inspects byte buffers against a static array of MaliciousPatterns—such as NOP-sled signatures (\x90\x90\x90) and directory traversal sequences (../../) src/kernel/security.zig10-36.

If a signature matches, the inspection fails and the kernel rejects the operation, protecting system integrity against malformed inputs and injection attempts.

Sources: src/kernel/security.zig10-36

Clone this wiki locally