Skip to main content
Be Bitwise

Systems Programming Companion

Students taking a university systems course built around how programs really run on x86-64 Linux.

Weeks follow the chapter order of Computer Systems: A Programmer's Perspective by Randal E. Bryant and David R. O'Hallaron. Be Bitwise isn't affiliated with the book or its publisher.

Your progress0 of 62 lessons
Week 1Chapters 2.1, 2.2, 2.3

Bits, bytes and integers

Every value in memory is a bit pattern, and the type you read it as decides what it means. Get two's complement and unsigned wraparound straight now and half of next month's bugs stop being mysterious.

Read

  1. What Are Bits?Binary & Number Systems
  2. HexadecimalBinary & Number Systems
  3. Two's ComplementBinary & Number Systems
  4. Integers & OverflowData Representation
  5. Integer Overflow & UnderflowInteger Overflows & Type Confusion
  6. Signed vs. Unsigned ConfusionInteger Overflows & Type Confusion
Week 2Chapter 2.4

Floating point

Floats are scientific notation squeezed into 32 or 64 bits, which is why 0.1 + 0.2 misbehaves. Learn where the sign, exponent and fraction live and the rounding puzzles start to look mechanical.

Read

  1. Binary ArithmeticBinary & Number Systems
  2. Floating-Point NumbersData Representation
  3. Numeric Types: Integers & FloatsVariables & Data Types

Coming soon

  • Worked examples of rounding modes, denormals and float-to-int conversion
Week 3Chapters 3.1, 3.2, 3.3, 3.4, 3.5

Machine code basics

Your C compiles down to a few dozen instructions shuffling values between registers and memory. Once mov, lea and the arithmetic ops read naturally, disassembly stops looking like noise.

Read

  1. Why Assembly?Assembly Language
  2. Assembly SyntaxAssembly Language
  3. Writing Your First ProgramAssembly Language
  4. Assembly and Machine CodeAssembly Language
  5. x86 Registersx86 Architecture Deep Dive
  6. x86 Instruction Setx86 Architecture Deep Dive
  7. From Source to BinaryWhat Your C Code Actually Does

Practise

Week 4Chapters 3.6, 3.7

Control flow and procedures

If statements become compares and jumps; function calls become a careful dance with the stack and six argument registers. This is the week the stack frame finally clicks, so draw it out.

Read

  1. What Are Functions?Functions & Control Flow
  2. The StackThe Stack & The Heap
  3. x86 Calling Conventions & ABIx86 Architecture Deep Dive
  4. Function Calls Under the HoodWhat Your C Code Actually Does
  5. Control Flow in Machine CodeWhat Your C Code Actually Does
Week 5Chapters 3.8, 3.9, 3.10

Arrays, structs and buffer overflows

Arrays and structs are just base addresses plus offsets, and nothing stops a write from running off the end. Overflow a stack buffer yourself and the defences in the second half of the week make sense.

Read

  1. Pointer ArithmeticAddresses & Pointers
  2. Defining StructsStructs & Data Structures
  3. Anatomy of a Stack FrameStack-Based Buffer Overflows
  4. Writing Past the BufferStack-Based Buffer Overflows
  5. Controlling ExecutionStack-Based Buffer Overflows
  6. Real-World Stack OverflowsStack-Based Buffer Overflows
  7. Stack CanariesExploit Mitigations
  8. ASLR & Position-Independent CodeExploit Mitigations

Practise

Week 6Chapter 4

Processor architecture

A CPU fetches, decodes and executes, and a pipelined one does all three at once on different instructions. Hazards are what happens when those instructions trip over each other.

Read

  1. The Instruction CycleCPU Basics
  2. The Instruction PipelineCPU Pipeline & Microarchitecture
  3. Branch PredictionCPU Pipeline & Microarchitecture

Practise

Coming soon

  • Step-by-step pipeline hazard walkthrough for a simple teaching ISA
Week 7Chapters 5, 6

Performance and the memory hierarchy

Memory is a stack of ever-bigger, ever-slower caches, and the fastest code is the code that keeps hitting the small ones. Loop order alone can change runtime by an order of magnitude.

Read

  1. Cache HierarchyMemory Fundamentals
  2. CPU Cache ArchitectureCache & Performance
  3. Cache-Friendly ProgrammingCache & Performance
  4. Memory Performance AnalysisCache & Performance

Coming soon

  • Worked cache simulation examples: sets, tags, hits and misses by hand
Week 8Chapter 7

Linking

The linker stitches object files together by resolving symbols and patching addresses. Learn to read an ELF file and the GOT and PLT, and odd 'undefined reference' errors become easy to fix.

Read

  1. The Compilation-to-Execution PipelineLinking, Loading & Binary Formats
  2. ELF Format Deep DiveLinking, Loading & Binary Formats
  3. Dynamic Linking & the GOT/PLTLinking, Loading & Binary Formats
  4. Shared LibrariesSystems Programming in C
Week 9Chapter 8

Exceptional control flow

Interrupts, system calls, fork, exec and signals all yank control away from the normal flow of your program. Build a small shell and you'll have used every one of them.

Read

  1. User-Kernel Transition MechanicsSyscall Interfaces & the Kernel Boundary
  2. What Is a ProcessProcess Management & Scheduling
  3. Process Lifecycle & StatesProcess Management & Scheduling
  4. Signal HandlingSystems Programming in C
  5. Process ManagementSystems Programming in C

Practise

Coming soon

  • Step-by-step support for a shell project: reaping children, races with SIGCHLD
Week 10Chapters 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8

Virtual memory

Every process thinks it owns the whole address space; page tables and the TLB keep that illusion cheap. Walk a translation by hand once and page faults, copy-on-write and mmap all fall out of it.

Read

  1. Virtual MemoryMemory Fundamentals
  2. Address Spaces & Page TablesVirtual Memory Internals
  3. TLB & Page Fault HandlingVirtual Memory Internals
  4. Demand Paging & Copy-on-WriteVirtual Memory Internals
Week 11Chapters 9.9, 9.10, 9.11

Dynamic memory allocation

malloc is a bookkeeper carving one big region into chunks and keeping lists of the free ones. Write your own allocator and you'll never look at a use-after-free the same way again.

Read

  1. The HeapThe Stack & The Heap
  2. Memory Allocator InternalsAdvanced Memory Management
  3. Custom AllocatorsAdvanced Memory in C
  4. Heap Allocation BasicsHeap Vulnerabilities & Use-After-Free
  5. Use-After-Free & Tcache PoisoningHeap Vulnerabilities & Use-After-Free

Practise

Coming soon

  • Explicit free list and segregated fits walkthrough with diagrams
Week 12Chapters 10, 11, 12

I/O, networking and concurrency

Files and sockets are both just file descriptors, which is why a web server is mostly reads and writes. Add threads and you get speed, plus a whole new family of bugs when two of them share data.

Read

  1. Standard I/O StreamsFile I/O
  2. Introduction to SocketsNetworking in C
  3. Building a TCP ServerNetworking in C
  4. Threads with pthreadsConcurrency in C
  5. Race ConditionsConcurrency & Race Conditions
  6. Synchronisation PrimitivesConcurrency & Race Conditions