Operating Systems. Part 8. Operating Systems. What is an operating system? Interact with Applications. Vector Tables. The master software

Similar documents
Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Soumava Ghosh The University of Texas at Austin

Mechanisms for entering the system

System Calls. A contract between processes and the operating system. Michael E. Locasto. Department of Computer Science UofC CPSC 457

Function Call Convention

CSC369 Lecture 2. Larry Zhang

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Operating Systems. System calls. Guillaume Salagnac. Fall Insa-Lyon IST Semester

Lecture 4 CIS 341: COMPILERS

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

IA32 Intel 32-bit Architecture

3 Lecture: The Process Model

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

How Software Executes

Computer Architecture and System Programming Laboratory. TA Session 5

Buffer Overflow Attack (AskCypert CLaaS)

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

Machine Program: Procedure. Zhaoguo Wang

Protection and System Calls. Otto J. Anshus

SOEN228, Winter Revision 1.2 Date: October 25,

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

Part 7. Stacks. Stack. Stack. Examples of Stacks. Stack Operation: Push. Piles of Data. The Stack

CSE 153 Design of Operating Systems Fall 18

Credits and Disclaimers

Intel Architecture. Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona

CS Basics 5) Programming in Assembly Language

Hardware OS & OS- Application interface

CS 16: Assembly Language Programming for the IBM PC and Compatibles

Assembly Language Programming 64-bit environments

Processes (Intro) Yannis Smaragdakis, U. Athens

143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017

ECE 341. Lecture # 19

CS 550 Operating Systems Spring System Call

Assembly Language for x86 Processors 7 th Edition. Chapter 2: x86 Processor Architecture

Assembly Language Each statement in an assembly language program consists of four parts or fields.

This is an example C code used to try out our codes, there several ways to write this but they works out all the same.

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

W4118: PC Hardware and x86. Junfeng Yang

Operating systems offer processes running in User Mode a set of interfaces to interact with hardware devices such as

Introduction to Machine/Assembler Language

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Instruction Set Architectures

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

%r8 %r8d. %r9 %r9d. %r10 %r10d. %r11 %r11d. %r12 %r12d. %r13 %r13d. %r14 %r14d %rbp. %r15 %r15d. Sean Barker

0. The first step of this tutorial is to read the following documents (either in the tutorial or at home):

Section 4: Threads and Context Switching

143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

mith College Computer Science CSC231 - Assembly Week #3 Dominique Thiébaut

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing

seccomp-nurse Nicolas Bareil ekoparty 2010 EADS CSC Innovation Works France seccomp-nurse: sandboxing environment

Exceptions. user mode. software should run in supervisor mode Certain features/privileges il are only allowed to code running in supervisor mode

RISC I from Berkeley. 44k Transistors 1Mhz 77mm^2

CS429: Computer Organization and Architecture

OpenBSD Remote Exploit

Lecture Notes for 04/04/06: UNTRUSTED CODE Fatima Zarinni.

Sistemi in Tempo Reale

CSC 405 Computer Security Shellcode

Exceptions and Processes

University of Washington

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software.

W4118: interrupt and system call. Junfeng Yang

Return Oriented Programming

Process Scheduling Queues

Operating Systems. V. Input / Output

The von Neumann Machine

Process Control. Philipp Koehn. 23 April 2018

an infinite loop Processes and Exceptions doing nothing on a busy system timing nothing

COP4610: Operating Systems Project 1

CS Basics 8) Strings. Emmanuel Benoist. Fall Term Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1

Instruction Set Architecture (ISA) Data Types

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

The von Neumann Machine

Machine Language CS 3330 Samira Khan

Machine-Level Programming III: Procedures

Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee

Handling of Interrupts & Exceptions

Computer Architecture and OS. EECS678 Lecture 2

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

Lecture 13: I/O I/O. Interrupts. How?

The Geometry of Innocent Flesh on the Bone

Is stack overflow still a problem?

X86-NASM STANDARD COMMANDS. Comment your code with a semicolon (;)! The assembler won t read anything after it.

Machine-level Programs Procedure

Chapter 1. Hardware. Introduction to Computers and Programming. Chapter 1.2

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames

CS Bootcamp x86-64 Autumn 2015

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.

Tutorial 10 Protection Cont.

Machine- Level Programming III: Switch Statements and IA32 Procedures

SYSTEMS PROGRAMMING AND COMPUTER ARCHITECTURE Assignment 5: Assembly and C

mith College Computer Science CSC231-Assembly Fall 2017 Week #2 Dominique Thiébaut

Assembly Language. Assembly language for x86 compatible processors using GNU/Linux operating system

Credits and Disclaimers

Shell Code For Beginners

Transcription:

Part 8 Operating Systems Operating Systems The master software Operating Systems What is an operating system? Master controller for all of the activities that take place within a computer Basic Duties: manage the physical resources of the system load and execute programs controlling I/O devices The operating system is simply another program executing on the processor But, it runs in privileged (or supervisor) mode knows about all the hardware in the computer has it the ability to run special instructions Other programs run in user mode 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 3 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 4 Interact with Applications Vector Tables The operating reserves many activities for itself for stability and reliability These include: input/output keyboard, screen ports memory special registers etc Programs (and hardware) often need to talk to the operating system Examples: software needs talk to the OS USB port notifies the OS that a device was plugged in 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 5 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 6 1

Vector Tables Vector Table But how does this happen? The processor can be interrupted alerted that something must be handled It then runs a special program that handles the event When interrupted, the device sends the processor an interrupt number The processor looks up the number in the "vector table" Table contains the address of Interrupt Service Routine (ISR) to execute 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 7 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 8 How It Works The Processor Then Device Interrupt number Vector Table 0 1 2 Address 3 4 5 6 Memory Routine 1. Backup the register file 2. Execute Interrupt Service Routine (ISR) 3. Once completed: restore the original executing program & register file 12/3/2018 Sacramento State - Cook - CSc 35 - Spring 2018 9 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 10 The Kernal All these Interrupt Service Routines belong to the kernal the core of the operating system Vast majority of the operating system is hidden from the end user Interact with Applications How do WE talk to the OS 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 11 2

Interact with Applications Interact with Applications Software also needs to talk to the operating system For example: draw a button print a document close this program etc Software can interrupt itself with a specific number This interrupt is designated specifically for software The operating system then handles the software's request 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 13 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 14 Application Program Interface The Changing Interrupts Programs "talk" to the OS using Application Program Interface (API) Benefits: makes applications faster and smaller also makes the system more secure since apps do not directly talk to IO Application Operating System IO In the 32-bit Intel x86 the program can invoke any interrupt number which turned out not to be particularly safe So, the Intel x64 hardcoded the interrupt number 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 15 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 16 Instruction: Interrupt (32-bit) Instruction: syscall (64-bit) INT number 0x80 for UNIX 0x13 for DOS SYSCALL Calls vector reserved for OS 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 17 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 18 3

Returning from an Interrupt Subroutine vs. Interrupt Subroutine Interrupt Executes code Executes code IRET Interrupt Return (You will never use this unless you write an operating system) Returns when complete Called by the application Returns when complete Executed by the processor Part of the application Handles events for the OS 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 19 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 20 Interrupts on the Linux Linux System Calls How software and hardware "talk" Linux, like other operating systems communicate with applications using interrupts Applications do not know where (in memory) to contact the kernal so they ask the processor to do it 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 22 How It Works Kernals are Simple! 1. Fill the registers 2. Interrupt using 0x80 (or the special software interrupt instruction in 64-bit) 3. Any results will be stored in the registers Linux only has 1 write and 1 read system call The location, number of bytes, and device only change It basically states "write x many bytes from y to device z" So, writing to the screen, a file, a port, etc use the same call! 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 23 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 24 4

How to 32 bit How to 32 bit In the 32-bit version of Linux, the kernal uses eax to identify the system call Each call has a unique constant Interrupt 0x80 activates the kernal Often a system call needs additional information to work Registers ebx, ecx, edx, etc will contain this information 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 25 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 26 Linux 32 Sys Write Linux 32: Sys Read mov $4, %eax mov $1, %ebx mov $address, %ecx mov $length, %edx int $0x80 Linux 32 call for WRITE 1 = Screen How many bytes mov $3, %eax mov $0, %ebx mov $address, %ecx mov $maxbytes, %edx int $0x80 Linux 32 call for READ 0 = Keyboard Maximum number of bytes to read 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 27 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 28 How to 64 bit How to 64 bit The 64-bit version of Linux changed the system calls The rax register still holds the system call number However, the "kernal call" numbers are different now There are 329 total calls Different registers are used to hold data The order is also quite different: rdi, rsi, rdx, r10, r8 The new instruction syscall talks to the OS 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 29 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 30 5

Some Linux 64 Calls Linux 64: Sys Write System Call rax rdi rsi rdx read 0 fd (device) address max bytes write 1 fd (device) address count open 2 address flags mode close 3 fd (device) get pid 39 exit 60 error code mov $1, %rax mov $1, %rdi mov $address, %rsi mov $length, %rdx syscall Linux command for WRITE 1 = Screen 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 31 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 32 Linux 64: Sys Read Null-Terminated Strings mov $0, %rax mov $0, %rdi mov $address, %rsi mov $maxbytes, %rdx syscall Linux command for READ 0 = Keyboard Maximum number of bytes to read Notice that UNIX requires that you specify the number of bytes before you write So, you need to count the bytes every time 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 33 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 34 Null-Terminated Strings That's why nullterminated strings are used The programming language (or library) counts the bytes for you! 12/3/2018 Sacramento State - Cook - CSc 35 - Fall 2018 35 6