KERNEL0 KBkernel16 KBB32 KBfree48 KBfreePCB APCB B16384CPUBASEBOUNDS1x = mem[1000]2x = mem[20000]PROCESS APROCESS B1000337681738420000A 32768B 16384
Back: the kernel and physical memory, four 16 KB slotsMiddle: the PCBs, the CPU and its MMU (BASE, BOUNDS); front: the program and processes A and BTokens: an address in, a checked and moved address outAt the back, the kernel and physical memory: four 16 KB slots. In the middle, the kernel's PCBs and the CPU with its MMU, holding the BASE and BOUNDS registers. In front, the program card and the two processes that run it. The same address 1000 becomes 33768 for A and 17384 for B. Address 20000 fails the bounds check, and the kernel ends B and frees its slot. The card is pseudo-code: mem[a] means read the bytes at virtual address a. In C it would be a pointer read.

Setting up

  1. Two processes, A and B, run the same program. Each sees its own private memory, its address space: 16 KB of addresses from 0 up, holding its code, heap and stack. Both can use address 1000 without clashing.

Translating

Protection

What happens

;; step 1/10 · illusion
address space (what each process sees)
  0 KB ......... code     the program itself
  just above ... heap     grows up
  ...  free ...
  up to 16 KB .. stack    grows down toward the heap

every address the program uses is a virtual address:
the kernel and the CPU decide where it really goes.
A and B both say "address 1000"; they mean different bytes.

The machine is the tiny one from OSTEP chapter 15: 64 KB of physical memory and 16 KB address spaces. Real address spaces are far bigger; on x86-64 Linux each process has about 128 TB of user addresses. Linux, Windows and macOS do not use base and bounds: they use paging, covered later in this module. The idea is the same: every address is checked and translated by the MMU, and the kernel switches the translation on every process switch.