Operating System

User-level Applications

Operating System

Hardware Resources

Sean Barker 2

Processes

Memory Memory Memory Stack Stack Stack Heap Heap Heap Data Data … Data Code Code Code

CPU CPU CPU Registers Registers Registers

Sean Barker 3 Control Flow Abstraction

Process A B Process

Time

Sean Barker 4

Control Flow Time-Sharing

Process A Process B Process C

Time

Sean Barker 5 Context Switching

Process A Process B

user code

kernel code

Time user code

kernel code context switch

user code

Sean Barker 6

Physical Control Flow

Physical control flow inst1 inst Time 2 inst3 …

instn

Sean Barker 7 11/12/15

Exceptions:'hardware/support/for/OS/ 'Vector stored/in/memory Exceptions special/register/holds/base/address transfer' control' to'OS'in'response' to'event What'code'should'the'OS'run'to'handle'the'event? code/for// Unique'ID'per'type'of'event exception/handler/ 0 Exception Ta bl e code/for/ ID'='index'into'exception'table' User-Process OS exception/handler/ 1 0 (a.k.a./interrupt/vector) 1 code/for exception 2 event' ... exception/handler/ 2 Handler'i is'called'each'time' exception'processing n&1 exception'i occurs by/exception'handler ... return'or'abort code/for/ exception/handler/ n<1

Exception/ numbers a/ jump/table/ for/exceptions… 9 10

Sean Barker 8

Open'a'file (/system/ call) Segmentation'Fault Exception Table User/process/calls:/open(filename, options) int a[1000]; open executes/system/call/instruction/int void bad () { Write/to/invalid/memory/location. Excep&on a[5000] = 13; 0804d070 <__li b c _o p e n>: } . . . numbers 804d082: cd 80 int $0x80 80483b7: c7 05 60 e3 04 08 0d movl $0xd,0x804e360 804d084: 5b Code for pop %eb x . . . excep&on handler 0 User-Process OS Excep&on Code for Table User-Process excep&on handler 1 OS exception:'page'fault 0 movl 1 detect'invalid'address int exceptionCode for 2 pop excep&on handler 2 'process ... open-file returns n-1 ... aborts/process/with/SIGSEGV/ signal

Code for excep&on handler n-1 12 13

Sean Barker 9 3 11/12/15

Exceptions:'hardware/support/for/OS/ Interrupt'Vector stored/in/memory Exceptions special/register/holds/base/address transfer' control' to'OS'in'response' to'event What'code'should'the'OS'run'to'handle'the'event? code/for// Unique'ID'per'type'of'event exception/handler/ 0 Exception Ta bl e code/for/ ID'='index'into'exception'table' User-Process OS exception/handler/ 1 0 (a.k.a./interrupt/vector) 1 code/for exception 2 event' ... exception/handler/ 2 Handler'i is'called'each'time' exception'processing n&1 exception'i occurs by/exception'handler ... return'or'abort code/for/ exception/handler/ n<1

Exception/ numbers a/ jump/table/ for/exceptions… 9 10

Sean Barker 10

Open'a'file (trap/system/ call) Segmentation'Fault Example: Segmentation Fault User/process/calls:/open(filename, options) int a[1000]; open executes/system/call/instruction/int void bad () { Write/to/invalid/memory/location. a[5000] = 13; int0804d070 a[1000]; <__li b c _o p e n>: } . . . main () 804d082: cd 80 int $0x80 80483b7: c7 05 60 e3 04 08 0d movl $0xd,0x804e360 {804d084: 5b pop %eb x . . a[5000]. = 13; } User-Process OS 80483b7: User-Process c7 05 60 e3 04 08 0dOS movl $0xd,0x804e360 movl exception:'page'fault detect'invalid'address User code int exceptionKernel code pop signal'process open-file Excep&on: returns movl aborts/process/with/SIGSEGV/ signal Detect invalid address Signal process 12 13

Sean Barker 11 3