☠️
smadi0x86 Playground
  • 💀Welcome to smadi0x86 Playground
    • 🍷Resources
    • 🚬Projects
    • 🎓Certifications
    • 📌Pinned
    • ❓Questions
    • 📞Contact
  • 🏞️Cloud Native
    • Docker
      • Quick Reference
      • Introduction
      • Containers
      • Images
      • Storage & Volumes
      • Security
      • Cheatsheet
    • Git
    • Serverless Framework
    • YAML
  • 🔨Software Engineering
    • System Design
    • Environment Variables
    • JSON Web Tokens
  • 👾Architecture
    • C Language
      • Introduction
      • Calling Conventions
      • GCC Compilation
      • Libraries & Linking
      • I/O
      • Files
      • Pointers
      • Dynamic Memory Allocation
      • Data Types
      • Strings Manipulation
      • Bit Manipulation
      • Pre-processors
      • Macros
      • Type Qualifiers
    • C/C++ Build Systems
      • Fundamentals for Linking
      • Symbolic Linking
      • Cross-Platform Compilation
      • CMake for Building and Linking
      • Shared Libraries
      • Dynamic Linking and Dependency Management
    • Operating Systems
      • OS & Architecture
      • Processes
      • CPU Scheduling
      • Memory Management
  • 🛩️Cyber Warfare
    • Flight Physics
    • Communication
      • PWM & PPM
      • MAVLink
  • 🏴‍☠️Offensive Security
    • Active Directory
      • Introduction
    • Web Attacks
      • Server Side
        • OS Command Injection
        • Information Disclosure
        • Directory Traversal
        • Business Logic
        • Authentication
        • File Upload
        • SSRF
      • Client Side
        • CSRF
        • XSS
    • Recon
      • Active
        • Host discovery
        • Nmap
        • Mass Scan
      • Passive
        • Metadata
      • Web Applications
        • Discovery
        • Subdomains & Directories
        • SSL Certs
        • CMS
        • WAF Detection
      • Firewall Evasion
  • Binary Exploitation
    • Stack Smashing
      • x86
      • x86_64
    • pwntools
      • Processes and Communication
      • Logging and Context
      • Cyclic
      • Packing
      • ELF
      • ROP
  • 😈Advanced Persistent Threat
    • C2
      • Sliver
    • Malware
      • Windows Internals
        • PEB
      • Academy
        • Basics
      • Sektor7
        • Essentials
  • 💌Certifications
    • AWS Certified Cloud Practitioner (CLF-C01)
      • Cloud Foundations
      • Domain 1: Cloud Concepts
      • Domain 2: Security and Compliance
      • Domain 3: Technology
      • Domain 4: Billing and Pricing
    • AWS Certified Solutions Architect - Associate (SAA-C03)
      • Foundation
    • Certified Kubernetes Administrator (CKA)
      • Core Concepts
      • Scheduling
      • Logging & Monitoring
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Design Kubernetes Cluster
      • Kubernetes The Kubeadm Way
      • Troubleshooting
      • JSONPATH
      • Lightning Lab
      • Mock Exams
      • Killer Shell
    • Certified Kubernetes Security (CKS)
      • Foundation
      • Cluster Setup
      • Cluster Hardening
      • Supply Chain Security
      • Runtime Security
      • System Hardening
      • Killer Shell
    • (KGAC-101) Kong Gateway Foundations
      • Introduction to APIs and API Management
      • Introduction to Kong Gateway
      • Getting Started with Kong Enterprise
      • Getting Started with Kong Konnect
      • Introduction to Kong Plugins
  • 📜Blog Posts
    • Modern Solutions For Preventing Ransomware Attacks
Powered by GitBook
On this page
  • Modern Operating System Functionality
  • Generic Computer Architecture
  • Protection
  • Kernel mode vs User mode
  • Memory Protection
  • Process layout in memory
  • Registers
  • Memory Hierarchy
  • Caches
  • Traps
  • I/O Control
  • Three I/O Methods
  • Virtual Memory
  1. Architecture
  2. Operating Systems

OS & Architecture

Modern Operating System Functionality

Process and Thread Management

Concurrency: Doing many things simultaneously (I/0, processing, multiple programs, etc...)

  • Several users work at the same time as if each has a private machine.

  • Threads (unit of OS control), one thread on the CPU at a time, but many threads active concurrently.

I/O devices: Let the CPU work while a slow I/O device is working.

Memory management: OS coordinates allocation of memory and moving data between disk and main memory.

Files: OS coordinates how disk space is used for files, in order to find files and to store multiple files.

Distributed systems & networks: Allow a group of machines to work together on distributed hardware.

Generic Computer Architecture

CPU: The processor that performs the actual computation.

  • Multiple “cores” common in today’s processors.

I/O devices: Terminal, disks, video board, printer, etc...

  • Network card is a key component, but also an I/O device.

Memory: RAM containing data and programs used by the CPU.

System bus: Communication medium between CPU, memory, and peripherals.

Protection

CPU supports a set of assembly instructions:

  • MOV [address], ax

  • ADD ax, bx

  • MOV CRn (move control register)

  • IN, INS (input string)

  • HLT (halt)

  • LTR (load task register)

  • INT n (software interrupt)

Some instructions are sensitive or privileged.

Kernel mode vs User mode

To protect the system from aberrant users and processors, some instructions are restricted to use only by the OS.

Users may not:

  • Address I/O directly

  • Use instructions that manipulate the state of memory (page table pointers, TLB load, etc...)

  • Set the mode bits that determine user or kernel mode

  • Disable and enable interrupts

  • Halt the machine

In kernel mode, the OS can do all these things.

The hardware must support at least kernel and user mode.

  • A status bit in a protected processor register indicates the mode.

  • Protected instructions can only be executed in kernel mode.

System call: OS procedure that executes privileged instructions (e.g., I/O), also API exported by the kernel.

Examples of system calls:

Memory Protection

Architecture must provide support so that the OS can:

  • Protect user programs from each other.

  • Protect the OS from user programs.

The simplest technique is to use base and limit registers.

  • Base and limit registers are loaded by the OS before starting a program.

  • The CPU checks each user reference (instruction and data addresses), ensuring it falls between the base and limit register values.

Process layout in memory

Processes have three segments:

  • text

  • data

  • stack

Registers

Register is a dedicated name for one word of memory managed by CPU.

General-purpose on x86:

  • EAX

  • EBX

  • ECX

Special-purpose:

  • “SP” = stack pointer

  • “FP” = Frame pointer

  • “PC” = Program counter

Change processes: Save current registers & load saved registers is called a context switch.

Memory Hierarchy

Caches

Access to main memory is expensive:

  • 100 cycles (slow, but relatively cheap)

Caches are small, fast, expensive memory:

  • Hold recently-accessed data (D$) or instructions (I$)

  • Different sizes & locations

    • Level 1 (L1): On-chip, smallish (tens of KB)

    • Level 2 (L2): On or next to chip, larger (few MB)

    • Level 3 (L3): Pretty large, on bus (several MB)

  • Manages lines of memory (32-128 bytes)

Caches are managed by hardware (no explicit OS management)

Traps

Traps: special conditions detected by the architecture

Examples:

  • Page fault

  • Write to a read-only page

  • Overflow

  • Systems call

On detecting a trap, the hardware:

  • Saves the state of the process (PC, stack, etc...)

  • Transfers control to appropriate trap handler (OS routine)

    • The CPU indexes the memory-mapped trap vector with the trap number.

    • Then jumps to the address given in the vector.

    • Starts to execute at that address.

    • On completion, the OS resumes execution of the process.

Modern OS use Virtual Memory traps for many functions:

  • Debugging

  • Distributed VM

  • Garbage collection

  • Copy-on-write, etc...

Traps are a performance optimization. A less efficient solution is to insert extra instructions into the code everywhere a special condition could arise.

I/O Control

  • Each I/O device has a little processor inside it that enables it to run autonomously.

  • CPU issues commands to I/O devices, and continues.

  • When the I/O device completes the command, it issues an interrupt.

  • CPU stops whatever it was doing and the OS processes the I/O device's interrupt.

Three I/O Methods

  1. Synchronous

  2. Asynchronous

  3. Memory-mapped

Virtual Memory

  • Virtual memory allows users to run programs without loading the entire program in memory at once.

  • Instead, pieces of the program are loaded as they are needed.

  • The OS must keep track of which pieces are in which parts of physical memory and which pieces are on disk.

  • In order for pieces of the program to be located and loaded without causing a major disruption to the program, the hardware provides a translation lookaside buffer to speed the lookup.

PreviousOperating SystemsNextProcesses

Last updated 10 months ago

👾