The Operating-System Interface

privilege levels (rings)

Picture a castle with a set of concentric walls. The throne room is at the dead center, ringed by walls; the further out you stand, the less you are trusted and the fewer doors will open for you. A CPU's privilege levels work the same way: code running closer to the center is trusted with more power, and code on the outer ring is fenced in.

On the common x86 CPU, the hardware defines four numbered privilege levels, ring 0 through ring 3, where a lower number means more privilege. The kernel runs in ring 0 (the throne room) and may run any instruction; ordinary user programs run in ring 3 (the outermost wall) and are blocked from privileged instructions and from each other's memory. Rings 1 and 2 sit in between but are rarely used by mainstream systems. The CPU tags every instruction and memory access with the current ring and refuses anything the ring is not allowed to do. In practice most operating systems use only two of these levels - ring 0 for the kernel and ring 3 for everything else - which is exactly the user-mode / kernel-mode split seen from the hardware's numbering scheme.

Why it matters: rings are the concrete hardware mechanism behind the 'user versus kernel' wall. They are also why some software (virtual-machine hypervisors, for instance) needed extra tricks or new CPU features to insert themselves 'below' ring 0. As a beginner you mostly need to remember the shape: a few numbered levels, lower is more powerful, kernel at the center, your programs on the outside.

On x86, the kernel sits at ring 0 and your shell, browser, and editor all sit at ring 3. A system call is the controlled hop from ring 3 to ring 0 and back, performed at a fixed entry point the kernel set up in advance.

Four rings exist on x86, but most systems really use only ring 0 and ring 3.

Ring numbers are x86-specific. Other CPUs (ARM, RISC-V) have privilege levels too but name and count them differently. The portable idea is 'a few ordered privilege levels, kernel most-privileged' - not the specific numbers 0 to 3.

Also called
protection ringsring 0ring 3保護環權限環