Kernel space, user space and system calls
The privilege boundary every Linux program crosses, how system calls work under the C library, why some skip the kernel via the vDSO, and whose bug it is.
Kernel space, user space and system calls
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- The CPU runs the kernel in a privileged mode and every program in an unprivileged one. A program cannot touch hardware or another process's memory, so it asks the kernel through a system call.
- A system call is a numbered request. On x86-64 the number goes in the rax register and the syscall instruction switches to kernel mode; getpid is number 39, write is 1.
- Programs rarely make system calls themselves. The C library's wrapper functions put the arguments in registers, make the call, and turn a negative return into -1 plus errno.
- The vDSO is a small piece of kernel-provided code mapped into every process so frequent, harmless calls like clock_gettime run without entering the kernel at all.
- The system call interface is the stable contract. The kernel's "no regressions" rule protects it, which is why a crash in kernel code is a kernel bug and a wrong result from a program is usually that program's bug.
Why there is a wall
Picture every program on a server able to write any memory address and any hardware register. One buggy program could overwrite another’s data, scribble on the disk outside its files, or hang the network card. Multi-user computing would be impossible.
So the CPU itself enforces a wall. It runs in at least two modes. In kernel mode any instruction is allowed. In user mode, privileged instructions fault and only the memory the kernel has mapped for that process is reachable. Linux runs its own code in kernel mode, in kernel space, and every program, even one running as root, in user mode, in user space. Root has more permission to ask; it does not get to bypass the wall.
The computer science roadmap covers the theory in processes and threads and how a CPU executes instructions. Here we look at how Linux does it.
The door in the wall
A program that needs something only the kernel can do makes a system call. Think of a bank: customers never walk into the vault; they fill in a numbered form at the counter, and staff do the work behind the glass and hand back a result.
On x86-64 the form number goes in the rax register, arguments go in other registers, and the syscall instruction switches the CPU to kernel mode at an entry point the kernel chose. The kernel looks the number up in its table, checks the request, does the work, puts the result in rax, and returns to user mode.
The table is a plain file in the kernel source. I fetched arch/x86/entry/syscalls/syscall_64.tbl from kernel.org’s git on 2026-11-28. It lists 386 entries usable by 64-bit programs, numbered up to 472. A few lines:
0 common read sys_read
1 common write sys_write
39 common getpid sys_getpid
228 common clock_gettime sys_clock_gettime
The C library does the paperwork
Almost no program issues syscall itself. The syscalls(2) man page explains that system calls “are generally not invoked directly, but rather via wrapper functions in glibc”. The wrapper is usually thin: it copies arguments to registers, makes the call, and on failure “negates the returned error number (to make it positive), copies it to errno, and returns -1”.
You can see this in a real C library without a Linux machine. I disassembled libc.so.6 from the Debian 13 container image (glibc 2.41) with the objdump that ships with Apple’s developer tools, which reads Linux ELF files. getpid is as thin as it gets:
e3b20: movl $0x27, %eax # 0x27 = 39, getpid
e3b25: syscall
e3b27: retq
An internal helper behind close() shows the error path the man page describes:
104880: movl $0x3, %eax # 3 = close
104885: syscall
104887: cmpq $-0x1000, %rax # result in the error range?
...
104897: negl %eax # make the error number positive
104899: movl %eax, %fs:(%rdx) # store it in errno (thread-local)
10489c: movl $0xffffffff, %eax # return -1
The comments are mine; the instructions are what objdump printed.
Skipping the kernel: the vDSO
Crossing the wall costs time, and some calls happen constantly. Every log line and every timer asks “what time is it?”. The answer is not secret. The vdso(7) man page explains the trick: the kernel maps a small shared library, the vDSO, into every process, and keeps the time in memory that process can read. A call to clock_gettime “changes from a system call to a normal function call and a few memory accesses”. On x86-64 the vDSO exports clock_gettime, gettimeofday, time and getcpu.
glibc’s clock_gettime in the same library reflects this. It first calls through a function pointer, and only if that pointer is empty does it fall back to movl $0xe4, %eax; syscall, which is number 228. That the pointer holds the vDSO’s address is my reading of the code together with the man page, not something objdump prints.
Whose bug is it?
The boundary is also a contract. The kernel documentation calls “We don’t cause regressions” the first rule of kernel development: if a program that worked with one kernel breaks with a newer one built from a similar configuration, that is a kernel regression and the kernel developers fix it. The rule covers only interfaces the kernel offers to user space, such as system calls, /proc and /sys, not internal ones like the module API.
This gives you a working triage rule. If the machine panics, freezes or a driver misbehaves, the fault is in kernel space: collect dmesg output and look at the kernel package. If one program crashes or gives wrong answers while the rest of the system is fine, the fault is almost always in user space: that program or its libraries. The tools for watching the boundary live, strace and perf, come in the last group of this roadmap.
About the video
The embed is Ben Dicken’s “How Operating Systems ACTUALLY work (kernel mode vs. user mode)”, July 2026, clipped to the “User and kernel modes” and “System calls and OS interfaces” chapters (about 10 minutes). It explains the mode switch and system calls visually and generally. It does not cover the vDSO, glibc wrappers or Linux’s syscall table, which this lesson adds. I judged it from the chapters and description, and English from the original English audio track. Dave Plummer’s video in deeper adds a former Windows kernel developer’s view.
What was run: the objdump and nm reads of Debian’s real glibc, on a Mac, and the count of the syscall table fetched from kernel.org. Nothing executed on Linux. The quotations are from the syscalls(2) and vdso(7) man pages (man-pages 6.19) and the kernel’s regressions document, checked 2026-11-28.
Check yourself
Why can't a normal program just write to the disk controller's registers directly?
It runs in user mode, where the CPU refuses privileged instructions and the kernel has not mapped device memory into its address space. Only the kernel, in kernel mode, can drive the hardware.
A C call to close() fails. Where does the value in errno come from?
The kernel returns a negative error number in rax. The glibc wrapper sees a value in the error range, negates it, stores it in errno, and returns -1.
Why does the vDSO help clock_gettime but would not help write?
The time is not secret and can be read from memory the kernel shares with every process, so no privilege change is needed. Writing to a file needs the kernel to check permissions and drive devices, so it must enter the kernel.
After a kernel upgrade, an unchanged program starts failing in a way it did not before. What does the kernel project call that, and who is expected to fix it?
A regression. The kernel's 'no regressions' rule means the kernel developers who caused it are expected to fix it quickly, as long as the configuration is similar.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.