System Calls & Libraries Vivek Pai Lecture 4, COS318 Sep 25, 2001.

Slides:



Advertisements
Similar presentations
Threads Chapter 4 Threads are a subdivision of processes
Advertisements

Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Process Description and Control
Processes and Operating Systems
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
OPERATING SYSTEMS Lecturer: Szabolcs Mikulas Office: B38B
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Chapter 1 Introduction Copyright © Operating Systems, by Dhananjay Dhamdhere Copyright © Introduction Abstract Views of an Operating System.
Chapter 5 : Memory Management
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc
Debugging operating systems with time-traveling virtual machines Sam King George Dunlap Peter Chen CoVirt Project, University of Michigan.
Chapter 4 Memory Management Basic memory management Swapping
Project 5: Virtual Memory
Hardware-assisted Virtualization
Module 10: Virtual Memory
Chapter 3 Memory Management
Chapter 10: Virtual Memory
Memory Management.
Slide 19-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 19.
© 2010 VMware Inc. All rights reserved Application-level mobile virtualization Harvey Tuch, Staff Engineer, Mobile Virtualization Platform January 25 th.
Threads, SMP, and Microkernels
Operating Systems Operating Systems - Winter 2011 Dr. Melanie Rieback Design and Implementation.
Operating Systems Operating Systems - Winter 2012 Dr. Melanie Rieback Design and Implementation.
Global Analysis and Distributed Systems Software Architecture Lecture # 5-6.
KAIST Computer Architecture Lab. The Effect of Multi-core on HPC Applications in Virtualized Systems Jaeung Han¹, Jeongseob Ahn¹, Changdae Kim¹, Youngjin.
SE-292 High Performance Computing
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
Datorteknik OperatingSystem bild 1 the Operating System (OS)
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Chapter 3 Process Description and Control
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Operating System Structure. Announcements Make sure you are registered for CS 415 First CS 415 project is up –Initial design documents due next Friday,
Disco Running Commodity Operating Systems on Scalable Multiprocessors.
OS Spring’03 Introduction Operating Systems Spring 2003.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Microkernels, virtualization, exokernels Tutorial 1 – CSC469.
Protection and the Kernel: Mode, Space, and Context.
CS533 Concepts of Operating Systems Jonathan Walpole.
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
Architecture Support for OS CSCI 444/544 Operating Systems Fall 2008.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
Lecture Topics: 10/29 Architectural support for operating systems –timers –kernel mode –system calls –protected instructions.
A. Frank - P. Weisberg Operating Systems Structure of Operating Systems.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Processes and Virtual Memory
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Introduction to Operating Systems Concepts
Computer System Structures
Virtual Machine Monitors
Introduction to Operating Systems
Operating System Structures
Kernel Design & Implementation
Operating System Structure
Anton Burtsev February, 2017
OS Virtualization.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Architectural Support for OS
Operating Systems Lecture 3.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Operating Systems: A Modern Perspective, Chapter 3
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Operating Systems Structure
Presentation transcript:

System Calls & Libraries Vivek Pai Lecture 4, COS318 Sep 25, 2001

System Calls & Libraries 2 Gedankundmathematics Recall the pointer verification case for fread( ) Can you speed up the checking process? What’s the best you could achieve? O(n)? O(logn)? O(1)? What happens if you have >32 bits? Aside: # atoms in universe = 10 80, or Does this provide any other benefits?

System Calls & Libraries 3 Mechanics Is the project workable? Has everyone started? Barring major problems, due Tuesday midnight Readings updated

System Calls & Libraries 4 Protection Issues I/O protection Prevent users from performing illegal I/Os Memory protection Prevent users from modifying kernel code and data structures CPU protection Prevent a user from using the CPU for too long

System Calls & Libraries 5 Protection Is Not Safety/Security Protection is a prerequisite Safety can be separation of concerns Security related to overall design Examples? Bad pointer access causing seg fault Sniffing cleartext passwords on the wire

System Calls & Libraries 6 Support in Modern Processors: User  Kernel User mode  Regular instructions  Access user-mode memory Kernel ( privileged ) mode  Regular instructions  Access user-mode memory An interrupt or exception ( INT ) A special instruction ( IRET )

System Calls & Libraries 7 Why a Privileged Mode? Special Instructions Mapping, TLB, etc Device registers I/O channels, etc. Mode Bits Processor features Device access

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

System Calls & Libraries 9 Other Design Approaches “Capabilities” Fine-grained access control Crypto-like tokens Microkernels OS services in user space Small core “hypervisor”

System Calls & Libraries 10 Monolithic All kernel routines are together A system call interface Examples: Linux Most Unix OS NT Kernel many many things entry User program User program call return

System Calls & Libraries 11 Monolithic Pros and Cons Pros Relatively few crossings Shared kernel address space Performance Cons Flexibility Stability Experimentation

System Calls & Libraries 12 Layered Structure Hiding information at each layer Develop a layer at a time Examples THE (6 layers) MS-DOS (4 layers) Hardware Level 1 Level 2 Level N......

System Calls & Libraries 13 Layering Pros and Cons Pros Separation of concerns Simplicity / elegance Cons Boundary crossings Performance?

System Calls & Libraries 14 Microkernel Micro-kernel is “micro” Services are implemented as regular process Micro-kernel get services on behalf of users by messaging with the service processes Examples: Taos, Mach, L4  kernel entry User program Services call return

System Calls & Libraries 15 Microkernel Pros and Cons Pros Easier to develop services Fault isolation Customization Smaller kernel => easier to optimize Cons Lots of boundary crossings Really poor performance

System Calls & Libraries 16 Virtual Machine Virtual machine monitor provide multiple virtual “real” hardware run different OS codes Example IBM VM/370 virtual 8086 mode Java VMWare Bare hardware Small kernel VM1VMn... OS1OSn user

System Calls & Libraries 17 Hardware Support What is the minimal support? Can virtual machine be protected without such support? Hint: what is a Turing machine?

System Calls & Libraries 18 System Call Mechanism Kernel in protected memory entry User code can be arbitrary User code cannot modify kernel memory Makes a system call with parameters The call mechanism switches code to kernel mode Execute system call Return with results User program User program call return

System Calls & Libraries 19 Interrupt 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 chapter 5, volume 3 for details

System Calls & Libraries 20 Interrupt and Exceptions (1) Vector #MnemonicDescriptionType 0#DEDivide error (by zero)Fault 1#DBDebugFault/trap 2NMI interruptInterrupt 3#BPBreakpointTrap 4#OFOverflowTrap 5#BRBOUND range exceededTrap 6#UDInvalid opcodeFault 7#NMDevice not availableFault 8#DFDouble faultAbort 9Coprocessor segment overrunFault 10#TSInvalid TSS

System Calls & Libraries 21 Interrupt and Exceptions (2) Vector #MnemonicDescriptionType 11#NPSegment not presentFault 12#SSStack-segment faultFault 13#GPGeneral protectionFault 14#PFPage faultFault 15ReservedFault 16#MFFloating-point error (math fault)Fault 17#ACAlignment checkFault 18#MCMachine checkAbort 19-31Reserved User definedInterrupt

System Calls & Libraries 22 System Calls Interface between a process and the operating system kernel Categories Process management Memory management File management Device management Communication

System Calls & Libraries 23 OS Kernel: Trap Handler HW Device Interrupt HW exceptions SW exceptions System Service Call Virtual address exceptions HW implementation of the boundary System service dispatcher System services Interrupt service routines Exception dispatcher Exception handlers VM manager’s pager Sys_call_table

System Calls & Libraries 24 Passing Parameters Affects and depends on Architecture Compiler OS Different choices for different purposes

System Calls & Libraries 25 Passing Parameters - Registers Place parameters in registers # of registers # of usable registers # of parameters in system call Spill/fill code in compiler Really fast

System Calls & Libraries 26 Passing Parameters - Vector Register holds vector address Single register Vector in user’s memory Nothing horrible, just not common

System Calls & Libraries 27 Passing Parameters - Stack Place parameters on stack Similar to vector approach Stack already exists Gets copied anyway frame Top

System Calls & Libraries 28 Library Stubs for System Calls Use read( fd, buf, size) as an example: int read( int fd, char * buf, int size) { move fd, buf, size to R 1, R 2, R 3 move READ to R 0 int $0x80 move result to R result } User stack Registers User memory Kernel stack Registers Kernel memory Linux: 80 NT: 2E

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

System Calls & Libraries 30 Design & Performance Issues Can user code lie? One result register – large results? Parameters in user memory Multiprocessors

System Calls & Libraries 31 General Design Aesthetics Simplicity, obviousness Generality – same call handles many cases Composition / decomposition But: Expressiveness Performance

System Calls & Libraries 32 Separation Of Concerns Memory management Kernel allocates “pages” – hw protection Programs use malloc( ) – fine grained Kernel doesn’t care about small allocs Allocates pages to library Library handles malloc/free

System Calls & Libraries 33 Library Benefits Call overhead Chains of alloc/free don’t go to kernel Flexibility – easy to change policy Fragmentation Coalescing, free list management Easier to program

System Calls & Libraries 34 Feedback To The Program System calls, libraries are program to OS What about other direction? Various exceptional conditions General information, like screen resize When would this occur? Answer: signals