Skip to content
BIASED

System calls

Block 1 of 3~3 min

Why not jal into the kernel

The operating-systems topic put the kernel in a privileged mode that user programs cannot enter by jumping, and the C topic wrote programs that need printing, files, processes and memory. Between them stands a narrow door. A system call is a trap that carries a request number and its arguments into the kernel and brings a result back. The exceptions topic followed the trap through the hardware; this topic follows the request from a C call through libc to ecall, through the kernel’s table and back.

Why not call sys_write with jal like any other function? Three reasons. The code is out of reach: kernel pages are mapped in every process with the UU bit clear, so fetching them in U-mode raises an instruction page fault (cause 12) answered with SIGSEGV. The mode would not change: even if fetch worked, the code would still run in U-mode and every privileged instruction would fault. Any entry point would do: a jal can target the middle of a function, past the argument checks. A request into the kernel therefore needs an instruction that changes mode and jumps to an address the program does not choose: RISC-V’s ecall, x86-64’s syscall, Arm’s svc. Which service and which arguments is an agreement between kernel and libc — the system-call ABI.

Answers are saved on the server and tied to this browser until you sign in.