Kernel mode and system call boundary
Quick answer
The Linux kernel mediates access to hardware and shared resources. Applications run in user mode and request kernel services through controlled entry points.
A library function is not necessarily a system call: it may perform all its work in userspace or invoke one or more kernel services. Follow the return value and documented error contract instead of assuming every function enters kernel mode.
Prepare the practice environment
Run python3 lab-fixtures/kernel/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not write kernel attributes, load modules, or change boot settings. Supplied records are fictional; read only the selected non-sensitive live fields. Review the lab guide.
Prerequisites
Review: Performance experiments, Service failures and boot recovery.
How it works
Linux is a modular monolithic kernel: scheduling, virtual memory, VFS, networking and many drivers run in kernel space. CPU privilege modes are different from Unix user IDs; even a root process normally runs its application code in user mode. A library wrapper may prepare architecture-specific syscall arguments, enter the kernel, receive a result and translate errors to errno. Not every library call enters the kernel: some work entirely in userspace or use a vDSO. The userspace ABI defines observable calling conventions and results; internal kernel functions are not a stable module API. In the toy example open resolves a pathname and returns a descriptor, read copies bytes, close releases the reference. A short read or interrupted operation is possible in general. Python is used only as a convenient wrapper, not as a claim about exact syscall sequences.
Try the examples
Open, read and close a private file through Python os wrappers.
Expected stdout:
read: kernel labA deliberate invalid descriptor returns an error; the wrapper raises OSError.
Expected stdout:
EBADF observedIn a disposable VM with strace installed, inspect only this child process. Loader activity also appears; do not assume one library call equals one syscall.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Root is not kernel mode. Do not equate library APIs with exact syscall instructions or infer a stable kernel-internal ABI.
Practice
Read the sample, reproduce EBADF, then explain which parts are application, library and kernel behavior.
Related references
Study: strace. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kernel mode and system call boundary — Knowledge Check
Apply kernel concepts to read-only observations and synthetic models.
Where does ordinary root application code execute?
What does the syscall boundary provide?
Does every library call issue a syscall?
What does EBADF indicate in the example?