# Software Stack 1. [The Software Stack](#software-stack) 1. [Types of Software](#types-of-software) 1. [The Operating System](#operating-systems) 1. [Types of Operating Systems](#types-of-operating-systems) 1. [The Software Stack in Modern Systems](#modern-software-stacks) --- ## Software Stack --- ![What We Have](overview/media/hardware-software/1-hardware.svg) ---- ![What We Want](overview/media/hardware-software/2-features.svg) ---- ![Have to Want](overview/media/hardware-software/3-software.svg) ---- ![Hardware + Software](overview/media/software-use.svg) ---- ### Flexibility of Software * Hardware provides basic actions * Users request rich features * Software bridges the gap between user demands and hardware possibility ---- ### Hardware vs Software | Hardware | Software | | :------------------------------: | :----------------------------------------: | | do one thing, do one thing well | flexible | | efficient | featureful | | unmodifiable | (un)installable, configurable | | physical | virtual, easy to duplicate | | use once at a time | reusable | | monolithic | (de/re)composable | --- ### Properties of Software * Reusability * Portability * Configurability / Flexibility ---- ### Reusability
---- ![Don't Reinvent the Wheel](overview/media/dont-reinvent-the-wheel.jpeg) ---- ### Portability ![Portability](overview/media/portability.svg) ---- ### Configurability Same software, different use cases ![Software Configurability](overview/media/software-configurability.svg) --- ### Interface and Implementation ![Inteface and Implementation](overview/media/interface-implementation.svg) ---- ### Interface and Implementation * different applications / use cases * diverse implementations * same interface * API - _Application Programming Interface_ ---- ### Portability vs Performance ![Portability vs Performance](overview/media/portability-performance.svg) --- ### Software Stack ![Software Stack](overview/media/software-stack.svg) ---- ### Software Stack * Each layer provides an interface to the upper layer * Richer set of features are implemented by the upper layers * Similar to the networking stack ---- ### Android Software Stack
---- ### iOS Software Stack
---- ### Flutter Framework ![iOS Software Stack](overview/media/flutter.png) --- ## Types of Software ---- ### Usable vs Reusable * Software provides features by extending hardware * Features are used by: * users (as interactive applications / processes) * system (as non-interactive services / processes) * other applications (as reusable libraries) * Software components * Applications: usable * Libraries: reusable ---- ### Applications ![Applications](software-types/media/applications.svg) ---- ### Libraries ![Libraries](software-types/media/libraries.svg) ---- ### Application Software and System Software ![Application and System Software](software-types/media/application-system-software.png) ---- ### Libraries and Frameworks ![Libraries and Frameworks](software-types/media/libraries-frameworks.png) ---- ### Applications and Libraries Common features / attributes * machine / binary code (for compiled programs) * data and instructions sections (`rodata`, `data`, `bss`, `text`) * stored as files in the filesystem ---- ### Applications vs Libraries | Applications | Libraries | | :------------------------------: | :----------------------------------------: | | entry point (`main`, `_start`) | exposed interface (API) | | usable | reusable | | load-time | link-time and load-time | | used by system and user | used by other applications or libraries | --- ## Operating Systems --- ### Need for Operating System (OS) * Hardware portability * Use different I/O devices (drivers) * Run on different architectures * Core system features * Memory management * Scheduling for multiple applications / processes * File system implementation * Networking stack ---- ### OS Roles * Hardware abstraction * System services * Isolation between processes * Resource protection (memory, devices) --- ### OS: Library-like Component ![OS Components](operating-system/media/os-components.jpg) ---- ### System Call Interface ![OS Layers](operating-system/media/os-layers.png) ---- ### System Calls * API for the operating system * Also called **system services** * Similar to library calls * Transfer control to the operating system code * Typically standard * System call IDs with system call handlers * Linux: `/usr/include/x86_64-linux-gnu/asm/unistd_64.h` ---- ### OS Perspective * Also called **kernel** * A software component that doesn't do work by itself * It serves applications, by providing an API - system (call) API * When a process invokes a kernel feature we say _the kernel runs on behalf of the process_ --- ### Privilege Domains * typically, there are multiple applications / processes * requirement for isolation * provider of isolation must be protected / privileged * privileged vs unprivileged actions ---- ### OS in Privileged Domain Security role: _Reference Monitor_ ![OS as Reference Monitor](operating-system/media/os-reference-monitor.svg) ---- ### User Mode, Kernel Mode ![User Mode / Kernel Mode](operating-system/media/user-kernel-mode.png) ---- ### User Mode vs Kernel Mode | User Mode | Kernel Mode | | :------------------------------: | :----------------------------------------: | | application code | kernel code | | unprivileged | privileged | | may fault | critical | | applications / processes | kernel, drivers | | flexible, diverse | specific, standard | ---- ### Privileged vs Unprivileged Actions #### Unprivileged * memory access (read, write) * logical and arithmetic operations * function calls #### Privileged * I/O resource access (files, network, terminal, time) * memory allocation * inter-app communication ---- ### TCB: Trusted Computing Base * The critical part of the system (wrt security) * Bugs in TCB jeopardize the whole system * Kernel, drivers, system services, system database, hardware, firmware * Hardware, hypervisor, control domain for virtualized environments --- ### System Calls * Calls from application to kernel * Typically transfer control from user mode to kernel mode * Cause overhead (mode transfer) ---- ### Kernel Code * Runs when system calls are made (application invokation) ... * ... or when interrupts are delivered (device actions) * It is not a process or an entity * It is a library (software component) that runs in privileged mode when invoked * by applications - via system calls * by I/O devices - via interrupts ---- ### Implementing Kernel Mode Also called **supervisor mode** ![Dual Mode](operating-system/media/dual-mode.jpeg) ---- ### Standard C Library ![libc](operating-system/media/libc.svg) ---- ### C APIs * ANSI / ISO * standard API, portable across OSes *
* POSIX * standard for UNIX-based OSes: Linux, \*BSD, macOS * Windows has a POSIX API *
* Windows API * formerly Win32 API *
---- ### Library Calls vs System Calls | Library calls | System calls | | :------------------------------: | :----------------------------------------: | | provided by libraries | provided by operating system | | flexible, diverse | specific, standard | | typical function calls | typically cause mode switch | | use standard C calling convetion | custom OS calling convention | | generally portable | OS-specific | --- ## Types of Operating Systems --- ### Use Cases * Provide thin layer on top of hardware (generally embedded) * Allow multitasking * Allow isolated multitasking * Multiple OSes on the same hardware (hypervisors) * Fast & transient runs (micro VMs, function-as-a-service - FaaS) * Large CPU / I/O / memory loads * High-Performance Computing (HPC) * Time constraints ---- ### Requirements * A system call API is generally provided * Multiprocessing / multithreading / scheduling: yes / no * Resource isolation between applications: yes / no * Domain separation (privileged vs unprivileged) * Hardware mode for hypervisors: yes / no * Real-time features --- ### OS Types * Embedded OSes * Single Address Space OSes * Microkernels * Monolithic Kernels * Hypervisors ---- ### Embedded OSes * Typically run on small devices * low-power, low-memory * Often does not require domain separation * OS closer to a library * Typically provide real-time features ---- ### Single Address Space OSes * The OS and application linked together * Typically run in the same domain: no need for domain transitions * Library OS + application code linked together * Unikernels * Can be run as VMs ---- ### Unikraft ![Unikraft](operating-system-types/media/unikraft.png) ---- ### Microkernels * Small kernel (small TCB) * Components run as user space processes (scheduler, file system, network stack) * Increased security, increased overhead ---- ### The L4 Microkernel ![L4](operating-system-types/media/l4.png) ---- ### Monolithic Kernels * All components run in kernel mode * Typical architecture of modern desktop / server systems * Extensible via loadable kernel-modules * Larger TCB when compared to microkernel * Increased performance (all in one place) ---- ### The Linux Kernel ![Linux](operating-system-types/media/linux-kernel.png) ---- ### Hypervisors * Thin layer on top of hardware * Host OSes inside virtual machines * Typically require hardware features (e.g. Intel VT-x) ---- ### Xen and KVM ![Xen](operating-system-types/media/xen-kvm.jpeg) --- ## Modern Software Stacks ---- ### Android Software Stack
---- ### iOS Software Stack
---- ### Windows Software Stack ![Windows](modern-software-stacks/media/windows.png) ---- ### macOS Software Stack ![macOS](modern-software-stacks/media/macos.svg) ---- ### Linux Software Stack ![Linux](modern-software-stacks/media/linux.svg) ---- ### RIOT (IoT devices) ![Tock](modern-software-stacks/media/riot.png) ---- ### Tock (low-power microcontrollers)