COS 318: Operating Systems



Similar documents
Operating System Structure

CSC 2405: Computer Systems II

CS161: Operating Systems

COS 318: Operating Systems. Virtual Machine Monitors

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

Operating Systems. Lecture 03. February 11, 2013

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

System Structures. Services Interface Structure

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

OS Concepts and structure

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

ELEC 377. Operating Systems. Week 1 Class 3

Example of Standard API


Chapter 3 Operating-System Structures

Introduction to Virtual Machines

x86 ISA Modifications to support Virtual Machines

Chapter 2 System Structures

COS 318: Operating Systems. Virtual Machine Monitors

Virtual Machine Security

Virtualization. Pradipta De

Operating System Structures

Virtualization. Jia Rao Assistant Professor in CS

Virtualization Technology. Zhiming Shen

Virtualization. Explain how today s virtualization movement is actually a reinvention

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Operating System Overview. Otto J. Anshus

Overview of Operating Systems Instructor: Dr. Tongping Liu

A Unified View of Virtual Machines

Intel s Virtualization Extensions (VT-x) So you want to build a hypervisor?

Operating System Components

How do Users and Processes interact with the Operating System? Services for Processes. OS Structure with Services. Services for the OS Itself

CS 695 Topics in Virtualization and Cloud Computing. More Introduction + Processor Virtualization

Virtual Machine Monitors. Dr. Marc E. Fiuczynski Research Scholar Princeton University

Uses for Virtual Machines. Virtual Machines. There are several uses for virtual machines:

Cloud Computing. Up until now

Xen and the Art of. Virtualization. Ian Pratt

KVM: A Hypervisor for All Seasons. Avi Kivity avi@qumranet.com

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Virtual machines and operating systems

OPERATING SYSTEM SERVICES

Full and Para Virtualization

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

CHAPTER 6 TASK MANAGEMENT

Operating System Organization. Purpose of an OS

VMware and CPU Virtualization Technology. Jack Lo Sr. Director, R&D

Linux Kernel Architecture

Virtualization. Types of Interfaces

W4118 Operating Systems. Junfeng Yang

Cloud Computing #6 - Virtualization

Operating System Structures

Chapter 16: Virtual Machines. Operating System Concepts 9 th Edition

System Virtual Machines

Outline. Outline. Why virtualization? Why not virtualize? Today s data center. Cloud computing. Virtual resource pool

Windows Server Virtualization & The Windows Hypervisor

Networks and Operating Systems ( ) Chapter 1: Introduction to Operating Systems

Introduction. What is an Operating System?

Components of a Computer System

Virtual Hosting & Virtual Machines

Hypervisors. Introduction. Introduction. Introduction. Introduction. Introduction. Credits:

CPS221 Lecture: Operating System Structure; Virtual Machines

Chapter 5 Cloud Resource Virtualization

Virtualization. Dr. Yingwu Zhu

The Plan Today... System Calls and API's Basics of OS design Virtual Machines

An Implementation Of Multiprocessor Linux

Intel 64 and IA-32 Architectures Software Developer s Manual

Virtual Machines. COMP 3361: Operating Systems I Winter

Chapter 6, The Operating System Machine Level

Operating Systems 4 th Class

Virtual Machines.

Presentation of Diagnosing performance overheads in the Xen virtual machine environment

FRONT FLYLEAF PAGE. This page has been intentionally left blank

kvm: Kernel-based Virtual Machine for Linux

Data Centers and Cloud Computing

Operating Systems OS Architecture Models

Distributed Systems. Virtualization. Paul Krzyzanowski

Virtualization. Clothing the Wolf in Wool. Wednesday, April 17, 13

5.14. EXCEPTION AND INTERRUPT REFERENCE

Virtualization. Jukka K. Nurminen

Brian Walters VMware Virtual Platform. Linux J. 1999, 63es, Article 6 (July 1999).

Advanced Computer Networks. Network I/O Virtualization

Project Adding a System Call to the Linux Kernel

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Lecture 2 Cloud Computing & Virtualization. Cloud Application Development (SE808, School of Software, Sun Yat-Sen University) Yabo (Arber) Xu

Sierraware Overview. Simply Secure

The Lagopus SDN Software Switch. 3.1 SDN and OpenFlow. 3. Cloud Computing Technology

12. Introduction to Virtual Machines

Virtualization for Cloud Computing

Arwed Tschoeke, Systems Architect IBM Systems and Technology Group

Operating System Components and Services

Hardware Based Virtualization Technologies. Elsie Wahlig Platform Software Architect

Virtual Machines. Virtualization

Virtual Computing and VMWare. Module 4

A Choices Hypervisor on the ARM architecture

Virtualization in the ARMv7 Architecture Lecture for the Embedded Systems Course CSD, University of Crete (May 20, 2014)

Advanced Operating Systems ( L)

Transcription:

COS 318: Operating Systems OS Structures and System Calls Andy Bavier Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall10/cos318/

Outline Protection mechanisms OS structures System and library calls 2

Protection Issues CPU Kernel has the ability to take CPU away from users to prevent a user from using the CPU forever Users should not have such an ability Memory Prevent a user from accessing others data Prevent users from modifying kernel code and data structures I/O Prevent users from performing illegal I/Os Question What s the difference between protection and security? 3

Architecture Support: Privileged Mode An interrupt or exception (INT) User mode Regular instructions Access user memory Kernel (privileged) mode Regular instructions Privileged instructions Access user memory Access kernel memory A special instruction (IRET) 4

Privileged Instruction Examples Memory address mapping Flush or invalidate data cache Invalidate TLB entries Load and read system registers Change processor modes from kernel to user Change the voltage and frequency of processor Halt a processor Reset a processor Perform I/O operations 5

x86 Protection Rings Privileged instructions Can be executed only When current privileged Level (CPR) is 0 Operating system kernel Operating system services Applications Level 0 Level 1 Level 2 Level 3 6

Outline Protection mechanisms OS structures System and library calls 7

Monolithic All kernel routines are together, any can call any A system call interface Examples: Pros Cons Linux, BSD Unix, Windows Shared kernel space Good performance No information hiding Chaotic Hard to understand How many bugs in 5M lines of code? User program Kernel (many things) User program 8

Layered Structure Level N constructed on N-1 Hiding information at each layer Examples: THE (6 layers) MULTICS (8 rings) Pros Cons Layered abstraction Separation of concerns Elegance Protection boundary crossings Performance Inflexible Level N. Level 2 Level 1 Hardware 9

Microkernel Put less in kernel mode; only small part of OS Services are implemented as regular process µ-kernel gets svcs on for users by messaging with service processes Examples: Mach, Taos, L4 Pros? Modularity: easier management Fault isolation and reliability Cons? Inefficient (boundary crossings) Insufficient protection Inconvenient to share data between kernel and services User program entry µ-kernel OS Services 10

Virtual Machine Separate multiprogramming from abstraction; VMM provides former Virtual machine monitor Virtualize hardware, but expose as multiple instances of raw HW Run several OSes, one on each instance Examples IBM VM/370 Java VM VMWare, Xen What would you use a virtual machine for? Apps Apps OS 1... OS k VM 1 VM k Virtual Machine Monitor Raw Hardware 11

Two Popular Ways to Implement VMM Win Apps Linux Apps Win Apps Win Vista Linux Win Vista Linux Apps VMM VMM Hardware Linux Hardware VMM runs on hardware VMM as an application (A special lecture later in the semester) 12

Outline Protection mechanisms OS structures System and library calls 13

System Calls Operating system API Interface between an application and the operating system kernel Categories Process management Memory management File management Device management Communication 14

How many system calls? 6th Edition Unix: ~45 POSIX: ~130 FreeBSD: ~130 Linux: ~250 Windows: 400? 1000? 1M? 15

System Call Mechanism Assumptions User code can be arbitrary User code cannot modify kernel memory Design Issues User makes a system call with parameters The call mechanism switches code to kernel mode Execute system call Return with results (Like a procedure call, just crosses kernel boundary) User program User program Kernel in protected memory 16

OS Kernel: Trap Handler HW Device Interrupt System Call HW exceptions SW exceptions Virtual address exceptions Syscall table System Service dispatcher System service dispatcher Interrupt service routines System services Exception dispatcher Exception handlers HW implementation of the boundary VM manager s pager 17

From http://minnie.tuhs.org/unixtree/v6 18

Passing Parameters Pass by registers # of registers # of usable registers # of parameters in system call Spill/fill code in compiler Pass by a memory vector (list) Single register for starting address Vector in user s memory Pass by stack Similar to the memory vector Procedure call convention 19

Library Stubs for System Calls Example: int read( int fd, char * buf, int size) { move fd, buf, size to R 1, R 2, R 3 User program } move READ to R 0 int $0x80 move result from R result Linux: 80 NT: 2E Kernel in protected memory 20

System Call Entry Point EntryPoint: save context switch to kernel stack check R 0 call the real code pointed by R 0 place result in R result switch to user stack restore context iret (change to user mode and return) (Assume passing parameters in registers) User stack Kernel stack User memory Registers Registers Kernel memory 21

Design Issues System calls There is one result register; what about more results? How do we pass errors back to the caller? System calls vs. library calls What should go in system calls? What should go in library calls? 22

Division of Labors Memory management example Kernel Library Allocates pages with hardware protection Allocates a big chunk (many pages) to library Does not care about small allocs Provides malloc/free for allocation and deallocation Application use these calls to manage memory at fine granularity When reaching the end, library asks the kernel for more 23

Feedback To The Program Applications view system calls and library calls as procedure calls What about OS to apps? Various exceptional conditions General information, like screen resize What mechanism would OS use for this? Application Operating System 24

Interrupts and Exceptions Interrupt Sources Hardware (by external devices) Software: INT n Exceptions Program error: faults, traps, and aborts Software generated: INT 3 Machine-check exceptions See Intel document volume 3 for details 25

Interrupts and Exceptions (1) Vector # Mnemonic Description Type 0 #DE Divide error (by zero) Fault 1 #DB Debug Fault/trap 2 NMI interrupt Interrupt 3 #BP Breakpoint Trap 4 #OF Overflow Trap 5 #BR BOUND range exceeded Trap 6 #UD Invalid opcode Fault 7 #NM Device not available Fault 8 #DF Double fault Abort 9 Coprocessor segment overrun Fault 10 #TS Invalid TSS 26

Interrupts and Exceptions (2) Vector # Mnemonic Description Type 11 #NP Segment not present Fault 12 #SS Stack-segment fault Fault 13 #GP General protection Fault 14 #PF Page fault Fault 15 Reserved Fault 16 #MF Floating-point error (math fault) Fault 17 #AC Alignment check Fault 18 #MC Machine check Abort 19-31 Reserved 32-255 User defined Interrupt 27

Example: Divide error What happens when your program divides by zero? Processor exception Defined by x86 architecture as INT 0 Jump to kernel, execute handler 0 in interrupt vector Handler 0 sends SIGFPE to process Kernel returns control to process Process has outstanding signal Did process register SIGFPE handler? Yes: Execute SIGFPE handler When handler returns, resume program and redo divide No: kills process 28

Summary Protection mechanism Architecture support: two modes Software traps (exceptions) OS structures Monolithic, layered, microkernel and virtual machine System calls Implementation Design issues Tradeoffs with library calls 29