Operating Systems. Week 2 Recitation: The system call. Paul Krzyzanowski. Rutgers University. Spring 2015

Similar documents
Operating Systems. Lecture 03. February 11, 2013

COS 318: Operating Systems

CS161: Operating Systems

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

CSC 2405: Computer Systems II

OS Virtualization Frank Hofmann

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Automatic Logging of Operating System Effects to Guide Application-Level Architecture Simulation

W4118 Operating Systems. Junfeng Yang

CHAPTER 6 TASK MANAGEMENT

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

Operating System Overview. Otto J. Anshus

64-Bit NASM Notes. Invoking 64-Bit NASM

Jorix kernel: real-time scheduling

Exception and Interrupt Handling in ARM

Virtual machines and operating systems

ELEC 377. Operating Systems. Week 1 Class 3

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

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

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

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Lecture 5. User-Mode Linux. Jeff Dike. November 7, Operating Systems Practical. OSP Lecture 5, UML 1/33

Introduction. What is an Operating System?

An Implementation Of Multiprocessor Linux

An Introduction to the ARM 7 Architecture

1. Computer System Structure and Components

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

Chapter 2: OS Overview

Under The Hood: The System Call

OPERATING SYSTEM SERVICES

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

x86 ISA Modifications to support Virtual Machines

Computer-System Architecture

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

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

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

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

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

System Calls and Standard I/O

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Performance Comparison of RTOS

Operating System Organization. Purpose of an OS

Keil C51 Cross Compiler

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

Lecture 6: Interrupts. CSC 469H1F Fall 2006 Angela Demke Brown

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

Full and Para Virtualization

KVM: Kernel-based Virtualization Driver

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

Virtualization. Pradipta De

FRONT FLYLEAF PAGE. This page has been intentionally left blank

CPS221 Lecture: Operating System Structure; Virtual Machines

Project Adding a System Call to the Linux Kernel

CS222: Systems Programming

sys socketcall: Network systems calls on Linux

RTEMS Porting Guide. On-Line Applications Research Corporation. Edition , for RTEMS July 2015

5. Calling conventions for different C++ compilers and operating systems

The Microsoft Windows Hypervisor High Level Architecture

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Instruction Set Architecture

Systems Design & Programming Data Movement Instructions. Intel Assembly

Distributed Systems. Virtualization. Paul Krzyzanowski

MICROPROCESSOR AND MICROCOMPUTER BASICS


Operating Systems and Networks

Hardware Assisted Virtualization

Multi-core Programming System Overview

Outline: Operating Systems

Virtual Machines. COMP 3361: Operating Systems I Winter

Microprocessor & Assembly Language

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

A Study of Performance Monitoring Unit, perf and perf_events subsystem

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

VxWorks Guest OS Programmer's Guide for Hypervisor 1.1, 6.8. VxWorks GUEST OS PROGRAMMER'S GUIDE FOR HYPERVISOR

Phoenix Technologies Ltd.

Intel 8086 architecture

Faculty of Engineering Student Number:

Kernel Virtual Machine

kvm: Kernel-based Virtual Machine for Linux

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Performance monitoring with Intel Architecture

Overview of Operating Systems Instructor: Dr. Tongping Liu

UNIT 4 Software Development Flow

picojava TM : A Hardware Implementation of the Java Virtual Machine

Virtualization for Cloud Computing

I/O Device and Drivers

Traditional IBM Mainframe Operating Principles

Interrupts. 1.Maskable interrupt request can be ignored or delayed by the microprocessor and used in telephone

Operating Systems: Basic Concepts and History

Andreas Herrmann. AMD Operating System Research Center

Toasterkit - A NetBSD Rootkit. Anthony Martinez Thomas Bowen

Microtronics technologies Mobile:

6.828 Operating System Engineering: Fall Quiz II Solutions THIS IS AN OPEN BOOK, OPEN NOTES QUIZ.

Understanding a Simple Operating System

Buffer Overflows. Security 2011

Introduction to Virtual Machines

Computer Architectures

Transcription:

Operating Systems Week 2 Recitation: The system call Paul Krzyzanowski Rutgers University Spring 2015 February 14, 2015 2014-2015 Paul Krzyzanowski 1

System calls System calls are an operating system s API The set of functions that the operating system exposes to processes If you want to the OS to do something, you tell it via a system call Examples Windows NtOpenFile NtReadFile NtCreateProcess NtGetCurrentProcessorNumber Linux open read fork getpid See http://j00ru.vexillium.org/ntapi/ for a list of Windows system calls See http://linux-documentation.com/en/man/man2/ for a list of Linux system calls February 14, 2015 2014-2015 Paul Krzyzanowski 2

What are system calls used for? Anything to do with: Accessing devices Communicating with other processes Accessing files Stopping/starting processes Requesting memory Setting a timer Setting/changing access permissions You need a system call to: Open a file Get data from the network Kill a process You do not need a system call to: Replace data in a string Create an object (instance of a class) Call a function February 14, 2015 2014-2015 Paul Krzyzanowski 3

System calls are made via traps System calls request operating system services Operating system code executes with the processor running in kernel (also known as supervisor or privileged) mode Privileged mode gives the CPU the rights to: Execute special instructions (change interrupt masks, set hardware timers, halt the processor) Access specific registers (e.g., private stack pointer) Change the memory map Access regions of memory that have been restricted for kernel access only Access the processor s I/O ports (if the architecture has them) A trap takes has one parameter: index into an Interrupt Vector Table The table is in memory that only the kernel can access All addresses in the table go to well-defined entry points in the OS February 14, 2015 2014-2015 Paul Krzyzanowski 4

Variations on software interrupts Classic system call mechanism in Intel s x86 architecture Use INT 80h (software interrupt) instruction to invoke a system call On Intel architectures, if the privilege level changed, the processor switches to a different stack For security: don t leave kernel crud on a stack that the user might inspect What happens: Various registers are saved in temporary space in the processor (flags, instruction pointer, stack segment, etc.) The new stack pointer is loaded The saved registers are pushed on the stack Any error code indicating the nature of the trap is pushed on the stack Flags are adjusted Execution continues February 14, 2015 2014-2015 Paul Krzyzanowski 5

Variations on software interrupts Call gate (Intel x86 architecture) Operating system sets up a call gate The user program executes a CALL FAR instruction (essentially just a regular subroutine call instruction) with a specific segment number The CPU checks if the segment number is a valid gate If so, it loads the appropriate instruction pointer and elevates the privilege level Unique to Intel architecture nobody else used memory segments Hence, portable operating systems avoided this February 14, 2015 2014-2015 Paul Krzyzanowski 6

Variations on software interrupts SYSCALL/SYSRET (Intel) or SYSENTER/SYSEXIT (AMD) instructions Faster mechanism than interrupts or call gates Target address is in a CPU register no need to access memory to do a table lookup Linux does a test to check which mechanisms exist before making a system call: Check if syscall exists (Intel architecture) Check if sysenter exists (AMD architecture) Otherwise use INT 80 (works on even the oldest processors) No matter what is used, the effect is the same: Branch to a well-known location & run in privileged mode February 14, 2015 2014-2015 Paul Krzyzanowski 7

System calls have parameters A software interrupt (trap) has one parameter: the trap # There are more system calls than interrupt vectors All system calls share the same trap # (the same entry point) Use one vector & have the system call number be a parameter The operating system can jump to the right place based on sys call # Dispatch table System calls need to pass multiple parameters E.g., read needs to identify the open file, starting byte, number of bytes There are three ways to pass these parameters 1. In the processor s registers 2. On the stack 3. In some memory location whose address is passed to the kernel February 14, 2015 2014-2015 Paul Krzyzanowski 8

Making system calls programmer-friendly System calls are made to look like function calls As a programmer, you do not want to copy parameters into some special place know the system call number invoke a software interrupt figure out how to copy any return data back System call library A user-level library that is linked with your program Provides a functional interface to system calls Handles the work of passing parameters and getting results February 14, 2015 2014-2015 Paul Krzyzanowski 9

System calls Entry Trap to system call handler Save state Verify parameters are in a valid address Copy them to kernel address space Call the function that implements the system call If the function cannot be satisfied immediately then Put process on a blocked list Context switch to let another ready process run Return from system call or interrupt Check for signals to the process Call the appropriate handler if signal is not ignored Check if another process should run Context switch to let the other process run Put our process on a ready list Calculate time spent in the call for profiling/accounting Restore user process state Return from interrupt February 14, 2015 2014-2015 Paul Krzyzanowski 10

System call walk-through 1. User calls a system call library function (e.g., open) Compiler generates code to push parameters on the stack & call the function 2. The library function is run Compiler generates code to save registers System call number for the open system call (5) is placed in register %eax Other parameters go in registers %ebx, %ecx, and %edx Trap to the OS 3. The operating system kernel code is now run Save registers Look up the address of system call #5 Call the system call handler, which processes the request Return the result of the system call in the %eax register Restore other registers Return from interrupt 4. Back to the library function Copy results (if necessary) Restore registers (except for return) Return value to the caller Note: This is an example using Linux and an x86 architecture. x86-64 uses the 64-bit version of the eax register: rax. Other processors will use totally different registers. Other operating systems may use a different entry point. February 14, 2015 2014-2015 Paul Krzyzanowski 11

The End February 14, 2015 2014-2015 Paul Krzyzanowski 12