Operating System Abstractions

Table of Contents

The operating system abstracts underlying hardware to help tame complexity. The bottom line of an operating system is to provide the ability to run programs.

1. Threads

A thread is a single unique execution context, which contains things like the program counter, registers, execution flags, stack, and its memory state.

A thread is executing on a processor (core) when it is resident in the processor registers. Resident means that the registers of the processor are currently holding the state for that thread. This includes the instruction pointer and currently executing instruction; the rest is stored in memory.

A thread is said to be suspended (not executing) when its state is not resident in the processor. This happens when the processor is executing some other thread, and the previous state for the suspended thread is usually stored somewhere in memory.

Threads are used to create the illusion that there are more cores than there are processors: threads are virtual cores. To do this, threads multiplex between different “vCPUs” in real time:

os_abstractions1.png

2. Address Spaces

An address space is the set of accessible addresses and the state associated with them. Address spaces may be virtual, in which case it is distinct from the memory space of the actual physical machine.

Threads have to share non-CPU resources such as memory and I/O devices, which means that each thread can possibly read/write memory of other processes or even the OS. This is a problem, which means our OS must implement some kind of protection on what memory programs can access.

3. Processes

A process is an execution environment with restricted rights, which consists of a (protected) address space along with one or more threads. Application programs executes as processes.

Processes are protected by the OS from each other. This is done by creating protected address spaces for each process, such as using translation techniques like those described earlier. However, there is a tradeoff, as communication becomes harder between processes.

4. Dual Mode Operation

The hardware provides at least two modes of operation: the kernel mode (sysmode = 0) and the user mode (sysmode = 1). At least 1 mode bit in the hardware keeps track of which mode the processor is in, and certain operations will be prohibited by the hardware when running in user mode, such as changing the page table pointer, diabling interrupts, etc.

4.1. Separate Kernel Stack

The kernel needs space to work, so it must have a stack. However, the kernel uses its own separate kernel stack for security reasons: we can’t trust the user’s stack pointer. We also can’t trust other threads to not mess with information on user stack. This is called the two-stack model, where each thread has both user stack (located in user memory) and kernel stack (located in kernel memory).

Last modified: 2026-10-13 14:41