system calls libraries l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
System Calls & Libraries PowerPoint Presentation
Download Presentation
System Calls & Libraries

Loading in 2 Seconds...

play fullscreen
1 / 34

System Calls & Libraries - PowerPoint PPT Presentation


  • 368 Views
  • Uploaded on

System Calls & Libraries. Vivek Pai Lecture 4, COS318 Sep 25, 2001. 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?

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'System Calls & Libraries' - salena


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
system calls libraries

System Calls & Libraries

Vivek Pai

Lecture 4, COS318

Sep 25, 2001

gedankundmathematics
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 = 1080, or 2256
  • Does this provide any other benefits?

System Calls & Libraries

mechanics
Mechanics
  • Is the project workable?
    • Has everyone started?
    • Barring major problems, due Tuesday midnight
  • Readings updated

System Calls & Libraries

protection issues
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

protection is not safety security
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

support in modern processors user kernel
Support in Modern Processors:User  Kernel

An interrupt or exception (INT)

User mode

  • Regular instructions
  • Access user-mode memory

Kernel (privileged) mode

  • Regular instructions
  • Access user-mode memory

A special instruction (IRET)

System Calls & Libraries

why a privileged mode
Why a Privileged Mode?
  • Special Instructions
    • Mapping, TLB, etc
    • Device registers
    • I/O channels, etc.
  • Mode Bits
    • Processor features
  • Device access

System Calls & Libraries

x86 protection rings
x86 Protection Rings

Privileged instructions

Can be executed only

When current privileged

Level (CPR) is 0

Level 3

Level 2

Level 1

Operating system

kernel

Level 0

Operating system

services

Applications

System Calls & Libraries

other design approaches
Other Design Approaches
  • “Capabilities”
    • Fine-grained access control
    • Crypto-like tokens
  • Microkernels
    • OS services in user space
    • Small core “hypervisor”

System Calls & Libraries

monolithic
Monolithic

User

program

User

program

  • All kernel routines are together
  • A system call interface
  • Examples:
    • Linux
    • Most Unix OS
    • NT

return

call

entry

Kernel

many many things

System Calls & Libraries

monolithic pros and cons
Monolithic Pros and Cons

Pros

  • Relatively few crossings
  • Shared kernel address space
  • Performance

Cons

  • Flexibility
  • Stability
  • Experimentation

System Calls & Libraries

layered structure
Layered Structure
  • Hiding information at each layer
  • Develop a layer at a time
  • Examples
    • THE (6 layers)
    • MS-DOS (4 layers)

Level N

.

.

.

Level 2

Level 1

Hardware

System Calls & Libraries

layering pros and cons
Layering Pros and Cons

Pros

  • Separation of concerns
  • Simplicity / elegance

Cons

  • Boundary crossings
  • Performance?

System Calls & Libraries

microkernel
Microkernel

User

program

Services

  • 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

return

call

entry

m-kernel

System Calls & Libraries

microkernel pros and cons
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

virtual machine
Virtual Machine
  • Virtual machine monitor
    • provide multiple virtual “real” hardware
    • run different OS codes
  • Example
    • IBM VM/370
    • virtual 8086 mode
    • Java
    • VMWare

user

user

OS1

OSn

. . .

VM1

VMn

Small kernel

Bare hardware

System Calls & Libraries

hardware support
Hardware Support
  • What is the minimal support?
  • Can virtual machine be protected without such support?
  • Hint: what is a Turing machine?

System Calls & Libraries

system call mechanism
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

System Call Mechanism

User

program

User

program

return

call

entry

Kernel in

protected memory

System Calls & Libraries

interrupt and exceptions
Interrupt and Exceptions
  • Interrupt Sources
    • Hardware (by external devices)
    • Software: INTn
  • 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

interrupt and exceptions 1
Interrupt and Exceptions (1)

System Calls & Libraries

interrupt and exceptions 2
Interrupt and Exceptions (2)

System Calls & Libraries

system calls
System Calls
  • Interface between a process and the operating system kernel
  • Categories
    • Process management
    • Memory management
    • File management
    • Device management
    • Communication

System Calls & Libraries

os kernel trap handler

Interrupt service routines

System services

Exception handlers

Exception dispatcher

VM manager’s pager

OS Kernel: Trap Handler

HW Device Interrupt

Sys_call_table

System service dispatcher

System Service Call

HW exceptions

SW exceptions

Virtual address exceptions

HW implementation of the boundary

System Calls & Libraries

passing parameters
Passing Parameters
  • Affects and depends on
    • Architecture
    • Compiler
    • OS
  • Different choices for different purposes

System Calls & Libraries

passing parameters registers
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

passing parameters vector
Passing Parameters - Vector

Register holds vector address

  • Single register
  • Vector in user’s memory
  • Nothing horrible, just not common

System Calls & Libraries

passing parameters stack
Passing Parameters - Stack

Place parameters on stack

  • Similar to vector approach
  • Stack already exists
  • Gets copied anyway

Top

frame

frame

System Calls & Libraries

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 R1, R2, R3

move READ to R0

int $0x80

move result to Rresult

}

Library Stubs for System Calls

User

stack

User

memory

Registers

Kernel

stack

Registers

Linux: 80

NT: 2E

Kernel

memory

System Calls & Libraries

system call entry point
Assume passing parameters in registers

EntryPoint:

switch to kernel stack

save context

check R0

call the real code pointed by R0

restore context

switch to user stack

iret (change to user mode and return)

System Call Entry Point

User

stack

User

memory

Registers

Kernel

stack

Registers

Kernel

memory

System Calls & Libraries

design performance issues
Design & Performance Issues
  • Can user code lie?
  • One result register – large results?
  • Parameters in user memory
  • Multiprocessors

System Calls & Libraries

general design aesthetics
General Design Aesthetics
  • Simplicity, obviousness
  • Generality – same call handles many cases
  • Composition / decomposition

But:

  • Expressiveness
  • Performance

System Calls & Libraries

separation of concerns
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

library benefits
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

feedback to the program
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

System Calls & Libraries