代写 C android scala concurrency assembly operating system software security Operating Systems Lecture 1b

Operating Systems Lecture 1b
Dr Ronald Grau School of Engineering and Informatics Spring term 2018

Previous Lecture 1 A brief introduction to operating systems
 A bit of history:
 How operating systems came about and developed over time
 A few basics about operating systems
 They offer a virtual machine abstraction to work with diverse hardware  They make computers easier to program
 They manage resources for programs
 They offer protection for programs (and their users), and themselves

Today 2 Operating system architectures
 Abstractions
 Basic design principles  Basic architectures

Abstractions: Overview
3
Image: Silberschatz, pg. 54

Abstractions: Overview 4 Let’s talk about:
 Processes
 Virtual memory
 Files
 System call interface

Process abstraction 5 A process is a program in execution
 Operating system duties:
 Process creation:
Load the executable file from secondary storage into primary memory (RAM)
 Handle concurrency
 Scheduling
 Coordination of resource requests
 Synchronisation
 Signalling of events (e.g. I/O)
 Inter-process communication (IPC)
Process list in Windows 7 (Task manager)

Virtual memory abstraction 6 Memory can be provided to processes irrespective of the actual
organisation and size of the physical memory available.
Virtual Memory provides each process with its own address space.
 Operating system duties:
 Address translation
 Memory management:
 CPU can only address main memory
 Data is only partially in memory (paging)
 Memory protection
 Process can only access its “own” memory segments
 Provision of shared memory
Virtual address spaces (Source: microsoft.com)

File abstraction 7
Files provide persistent storage of data
Files have names and can be hierarchically organised
The operating system can restrict access to files in various ways
Files are accessed as sequences of bytes (allows consistency checking)
 Operating system duties:
 Provide a uniform interface for different devices
 Manage efficient access (e.g. caching)
 Protect storage device from being damaged/corrupted  In UNIX systems I/O devices are files

System call interface 8
The SCI contains the functions the kernel provides for  Process control
 File management
 System information (date, time, etc.)
 Inter-process communication
E.g.
 Win32 API: windows.h, Unix API (POSIX, IEEE Std 1003): unistd.h
For programming languages, these calls are wrapped by libraries

A few examples: Windows and Unix 9

How can we protect the OS? 10
Kernel Mode vs User Mode
 In principle, system calls execute in kernel mode

How to implement protection? 11 Kernel Mode vs User Mode
 How to implement security for kernel mode?
 Requires hardware support
 Disallows certain instructions in user mode
 trap instruction / exception: software-initiated interrupt

Quick recap: Interrupts 12

System call example 13 UNIX SC read (fd, buffer, size)
 fd: The file to read from (file handle)
 buffer: Memory address to store the
data in
 size: number of bytes to be read
 Returning a number >= 0: bytes read
 Returning -1: there was a problem!

System call example 14 UNIX SC read (fd, buffer, size) – sequence
 1, 2, 3: Push parameters onto system stack
 4: Call the library procedure read
 5, 6: Place this system call in a special register and call trap to switch modes
 7, 8: Run correct system call handler
 9: Pass control back to the user space
procedure
 10: Return to user program
 11: Increment stack pointer
 … next instruction

Operating System Architectures 15 Why the need for an architecture?
 Modern operating systems tend to be complex because  They provide many services and have many functions
 There is a wide range of hardware that must be supported
Architectures help us cope with complexity

Design principles 16 Separation of interface and implementation
 Interfaces should be simple, complete, and stable: A published interface is hard to change
 Encapsulation: keep internals opaque. E.g. indirection via naming

Design principles 17 Separation of policy and mechanism
 Policy: The what
 Mechanism: The how
 Mechanism should be general and efficient
 Orthogonality: concepts can be combined independently

Design principles 18
Portability
 Hardware abstraction layer
 Word sizes, endianness, alignment, time, etc.

Design principles 19
Coherence
 Adherence to coding conventions
 Operating systems are huge software development projects that often stretch over many years

OS Implementation 20
Languages used
 IBM 360: Assembly language
 MULICS: PL/1
 Linux, Windows: Mostly C (plus small parts in Assembly language)
Why not just implement everything in Assembly language?

Architectures 21 Layers
 Each layer provides a service interface
 Higher layers use services of lower layers

Architectures 22 Modules
 Each module provides a service interface
 Modules support encapsulation and can be replaced and changed easily
 Potentially complex dependencies

Monolithic Kernel vs. Microkernel 23 Overview

Monolithic Kernel 24 Entire operating system runs in kernel mode
 All components can talk directly to each other
 Extending the operating system can be difficult
 Good performance but errors can be difficult to trace

Microkernel 25 Kernel provides minimal services
 A lot of message-passing communication
(impact on performance)
 Very general mechanisms that allow a wide range of policies to be implemented
 Modules run in user mode
 Extensible, portable, scalable

What type of architecture is this? 26 Example: Windows NT

What type of architecture is this? 27 Example: UNIX

What type of architecture is this? 28 Example: Android

What type of architecture is this? 29 Example: Linux
 Interactive map of
the Linux kernel
(explore on Study Direct)

Summary 30 Operating system architectures
 Abstractions  Processes
 Virtual memory
 Files
 System call interface
 Basic design principles
 Separation of interface and implementation  Separation of policy and mechanism
 Portability
 Coherence
 Basic architectures  Layers & modules  Monolithic kernels  Microkernels

Read 31  Tanenbaum & Bos., Modern Operating Systems
 Chapter 1
 Silberschatz et al., Operating System Concepts  Chapter 2

Prepare 32  For your labs next week, review the basic content on
Microarchitectures, Instruction set architectures, Machine code and Assembly language
from your Year 1 module “Introduction to Computer Systems“.  Don’t forget to work on your question sheet!

Next Lecture
33
 Introduction
 Operating System Architectures  Processes
 Threads
 Process Scheduling
 Process Synchronisation
 Deadlocks
 Memory Management
 File Systems
 Input / Output
 Security and Virtualisation