Docsity

Syscalls, exceptions, and interrupts, …oh my!, Lecture notes of Operating Systems

Partial preview of the text

Download Syscalls, exceptions, and interrupts, …oh my! and more Lecture notes Operating Systems in PDF only on Docsity!

Syscalls, exceptions, and

interrupts, …oh my!

Hakim Weatherspoon CS 3410 Computer Science Cornell University

[Altinbuken, Weatherspoon, Bala, Bracy, McKee, and Sirer]

Announcements

  • P4-Buffer Overflow is due tomorrow
    • Due Tuesday, April 16th
  • C practice assignment
    • Due Friday, April 19th
    • Due Friday, April 27th
  • How do we protect processes from one

another?

  • Skype should not crash Chrome.
  • How do we protect the operating system

(OS) from other processes?

  • Chrome should not crash the computer!
  • How does the CPU and OS (software)

handle exceptional conditions?

  • Division by 0, Page Fault, Syscall, etc.

Outline for Today

  • Operating System
  • Privileged Mode
  • Traps, System calls, Exceptions, Interrupts

Operating

System

Operating System

  • Operating System (OS) is a trusted mediator:
    • Safe control transfer between processes
    • Isolation (memory, registers) of processes

P1 P2 P3 P

VM filesystem net driver driver

untrusted

disk netw card

MMU CPU

trusted

software

hardware

OS

8

Outline for Today

  • How do we protect processes from one

another?

  • Skype should not crash Chrome.
  • How do we protect the operating system

(OS) from other processes?

  • Chrome should not crash the computer!
  • How does the CPU and OS (software)

handle exceptional conditions?

  • Division by 0, Page Fault, Syscall, etc.
  • Operating System
  • Privileged Mode
  • Traps, System calls, Exceptions, Interrupts

One Brain, Many Personalities

You are what you execute.

Personalities:

hailstone_recursive

Microsoft Word

Minecraft

Linux  yes, this is just

software like

every other program

that runs on the CPU

Are they all equal?

Brain

Trusted vs. Untrusted

  • Only trusted processes should access & change important things - Editing TLB, Page Tables, OS code, OS

sp, OS fp…

  • If an untrusted process could change the OS’ sp/fp/gp/ etc ., OS would crash!

Privileged Mode at Startup

1. Boot sequence

  • load first sector of disk (containing OS code) to predetermined address in memory
  • Mode  1; PC  predetermined address

2. OS takes over

  • initializes devices, MMU, timers, etc.
  • loads programs from disk, sets up page tables, etc.
  • Mode  0; PC  program entry point
    • User programs regularly yield control back to OS

Users need access to resources

  • If an untrusted process does not have

privileges to use system resources, how can it

  • Use the screen to print?
  • Send message on the network?
  • Allocate pages?
  • Schedule processes?

System Calls

System calls called executive calls ( ecall ) in RISC-

System call: Not just a function call

  • Don’t let process jump just anywhere in OS code
  • OS can’t trust process’ registers (sp, fp, gp, etc.)

ECALL instruction: safe transfer of control to OS

RISC-V system call convention:

  • Exception handler saves temp regs, saves ra, …
  • but: a7 = system call number, which specifies the operation the application is requesting

User Application

0xfffffffc

0x

top

bottom

0x7ffffffc 0x

0x

0x

system reserved

stack

system reserved

code (text)

static data

dynamic data (heap) .data .text

User Mode System Call Interface Privileged (Kernel) Mode

printf()

printf.c Implementation of printf() syscall!

SYSCALL!

Invoking System Calls

char *gets(char *buf) {

while (...) {

buf[i] = getc();

int getc() {

asm("addi a7, 0, 4");

asm(“ecall");

Anatomy of a Process, v

20

0xfffffffc

0x

0x7ffffffc

0x

0x

0x

system reserved

stack

system reserved

code (text)

static data

dynamic data (heap)

(user) gets (library) getc

??