LOGBOOK

HELP

1 / 427
time's up — finish this card
Other keys: show • Space: good • 1-4: rate • 0: skip • 5: flag
Topic Overview of Computer Systems

Question

What is the role of the operating system?

Answer

The OS protects the hardware from misuse and gives programs simple, uniform abstractions for it — processes, virtual memory, and files.

It sits between programs and the machine so that no single buggy or malicious program can monopolize the CPU, corrupt another program's memory, or talk to devices directly — everything risky is funneled through the kernel.

Two main roles:

  1. Protect hardware from misuse by buggy/malicious programs
  2. Provide simple, uniform mechanisms for hardware manipulation

Three fundamental OS abstractions:

Abstraction Abstracts Over Purpose
Processes Processor Illusion of dedicated CPU
Virtual Memory Main memory Illusion of dedicated memory
Files I/O devices Uniform interface for all I/O

Why these abstractions exist:

  • Without processes, one buggy program could crash the whole system
  • Without virtual memory, programs would fight over memory addresses
  • Without file abstraction, every program would need disk/network/device drivers!

Protection Rings (x86):

  • Ring 0 (Kernel): Full hardware access - can execute ANY instruction
  • Ring 1-2 (Device drivers): Limited access (rarely used in modern OSes)
  • Ring 3 (Applications): Most restricted - can only execute "safe" instructions

Why rings matter for security:

  • Malware in Ring 3 can't directly access hardware or other processes
  • Even if your browser is compromised, it can't read kernel memory
  • Kernel bugs (Ring 0) are much more dangerous than userspace bugs

Tip: Ring 0 = "Root/God mode", Ring 3 = "Restricted/User mode". Lower ring number = more power.

Go deeper:

Many operating systems can "trick" programs into using memory scattered around the hard disk and RAM as if it is one continuous chunk of memory, called virtual memory.
Many operating systems can "trick" programs into using memory scattered around the hard disk and RAM as if it is one continuous chunk of memory, called virtual memory.
Ehamberg · CC BY-SA 3.0 · Wikimedia Commons
or press any other key
Topic Assembly Patterns & GDB

Question

What is the xor %eax, %eax idiom?

Answer

It zeroes %eax (anything XORed with itself is 0) — smaller and faster than mov $0, %eax, and it also clears the upper half of %rax.

xor %eax, %eax

Any value XORed with itself is zero. The CPU recognizes this special case and:

  • Executes it with zero latency (register renaming)
  • Clears dependency chains
  • Is only 2 bytes (vs 5 bytes for mov $0, %eax)

Bonus: On x86_64, writing to %eax automatically zeros the upper 32 bits of %rax. So xor %eax, %eax also zeros %rax.

Where you'll see it: Function prologues, before a loop accumulator, before call to set %eax = 0 (indicates no floating-point varargs to printf/sscanf).

Go deeper:

Bitwise AND of 4-bit integers
Bitwise AND of 4-bit integers
WatchduckYou can name the author as "T. Piesk", "Tilman Piesk" or "Watchduck". · CC BY 4.0 · Wikimedia Commons
or press any other key