Introduction to Operating Systems

Slides:



Advertisements
Similar presentations
The Kernel Abstraction. Debugging as Engineering Much of your time in this course will be spent debugging – In industry, 50% of software dev is debugging.
Advertisements

The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
CMPT 300: Operating Systems I Dr. Mohamed Hefeeda
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Dr. Mohamed Hefeeda.
Cs238 Lecture 3 Operating System Structures Dr. Alan R. Davis.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
System Calls 1.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
CE Operating Systems Lecture 14 Memory management.
Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Lecture 4 Page 1 CS 111 Online Modularity and Memory Clearly, programs must have access to memory We need abstractions that give them the required access.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Introduction to Operating Systems
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
Processes and threads.
Operating Systems CMPSC 473
Protection and OS Structure
Chapter 1: Introduction
Day 08 Processes.
Day 09 Processes.
Overview of today’s lecture
Chapter 8 Main Memory.
Modularity and Memory Clearly, programs must have access to memory
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
The Kernel Abstraction
Introduction to Operating Systems
Introduction to Operating Systems
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Evolution in Memory Management Techniques
Chapter 9: Virtual-Memory Management
More examples How many processes does this piece of code create?
Computer-System Architecture
Module 2: Computer-System Structures
Process Description and Control
What does an Operating System Do?
Lecture Topics: 11/1 General Operating System Concepts Processes
Process Description and Control
Exceptions Control Flow
Architectural Support for OS
CSCE 313 – Introduction to UNIx process
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Process Description and Control
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Lecture 2: The Kernel Abstraction
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
Lecture 7: Flexible Address Translation
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Architectural Support for OS
CSE 471 Autumn 1998 Virtual memory
CSE 153 Design of Operating Systems Winter 2019
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Module 2: Computer-System Structures
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Module 2: Computer-System Structures
Cache writes and examples
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Introduction to Operating Systems Summer 2017 Lecture Notes OSPP Chapter 2 – Part 1 (adapted from Tom Anderson’s slides on OSPP web site)

Kernel Lowest level of software running on the system Purpose is to implement protection Kernel is fully trusted and has access to all the hardware

Untrusted Code We should restrict privileges of untrusted code Should not have access to all the hardware Should not have ability to modify the kernel or other applications

Challenge: Protection How do we execute code with restricted privileges? Either because the code is buggy or if it might be malicious Some examples: A script running in a web browser A program you just downloaded off the Internet A program you just wrote that you haven’t tested yet

Stages of a Program Source file on disk Executable file on disk After compiling and linking Set of machine instructions (with a specified entry point) and initialized data Memory image After loading Stack, heap, and uninitialized data areas added to provide full execution environment

Compiling and Loading a Program

Main Points of Chapter 2 Process concept A process is the OS abstraction for executing a program with limited privileges Dual-mode operation: user vs. kernel Kernel-mode: execute with complete privileges User-mode: execute with fewer privileges Safe control transfer How do we switch from one mode to the other?

Process Abstraction Process: an instance of a program, running with limited rights Thread: a sequence of instructions within a process Potentially many threads per process (for now 1:1) Address space: the range of valid addresses Allocated resources: the physical memory, files, and network connections the process can currently access [in some systems] Capabilities: the permissions the process has (e.g., which system calls it can make, what objects it can access and how)

Thought Experiment How can we implement execution with limited privilege? Execute each program instruction in a simulator If the instruction is permitted, do the instruction Otherwise, stop the process Basic model in Javascript and other interpreted languages How do we go faster? Run the unprivileged code directly on the CPU!

Hardware Support: Dual-Mode Operation Kernel mode Execution with the full privileges of the hardware Read/write to any memory, access any I/O device, read/write any disk sector, send/rcv any packet User mode Limited privileges Only those granted by the operating system kernel Mode bit stored in processor status register (stored in CS register on the x86)

Hardware Support: Dual-Mode Operation Privileged instructions Available to kernel Not available to user code Limits on memory accesses To prevent user code from overwriting the kernel Timer To regain control from a user program in a loop Need safe way to switch from user mode to kernel mode, and vice versa

Privileged instructions Examples Change mode bit in processor status register Change which memory locations a user program can access Send commands to I/O devices Jump into kernel code What should happen if a user program attempts to execute a privileged instruction?

Non-Privileged (“Safe”) Instructions Examples Load, store Add, subtract, … Conditional branch, jump to subroutine, … Allowed to execute in both kernel and user mode OS and applications all need the ability to add numbers! OS and applications all need the ability to use loops and call subroutines!

Valid Instructions User mode: non-privileged (“safe”) instructions only Kernel mode: both privileged and non-privileged instructions

Invalid Instructions Attempt to execute a privileged instruction in user mode? Stop the application and alert the OS! Typically the attempt is an error, but for selected instructions we will use this response to intentionally invoke the OS (Note: could be an inefficient way to implement a virtual machine that is running a guest OS completely in user mode)

Question For a “Hello world” program, the kernel must copy the string from the user program memory into the screen memory. Why not allow the application to write directly to the screen’s buffer memory?

Simple Memory Protection Physical address generated by processor is range-checked against top and bottom limits

A Better Approach Virtual address relative to 0 checked against bottom limit Virtual address added to contents of base register

Even Better Approaches! Problems with the additive base and bounds? Memory sharing between processes? (e.g., how to share one copy of same machine instructions) Memory fragmentation as processes come and go Paging and segmentation in Chapter 8 Translation done in hardware, using a table for each process Table is set up and managed by kernel

Test Program – Determine if OS Runs with Virtual Addresses #include<stdio.h> int staticVar = 0; // a static variable main() { staticVar += 1; // sleep causes the program to wait for x seconds sleep(10); printf ("Address: %p; Value: %d\n", &staticVar, staticVar); }

Script to Run Processes in Parallel % cat test.script ./a.out & wait echo all done % csh < test.script [1] 9453 [2] 9454 [3] 9455 Address: 0x60104c; Value: 1 [2] Exit 28 ./a.out [1] Exit 28 ./a.out [3] Exit 28 ./a.out all done