DOC PREVIEW
Princeton COS 318 - OS Structures and System Calls

This preview shows page 1-2-3-24-25-26 out of 26 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COS 318: Operating SystemsOS Structures and System CallsJaswinder Pal SinghComputer Science DepartmentPrinceton University(http://www.cs.princeton.edu/courses/cos318/)2Outline!Protection mechanisms!OS structures!System and library calls3Protection Issues!CPU"Kernel has the ability to take CPU away from users to prevent a user from using the CPU forever"Users should not have such an ability!Memory"Prevent a user from accessing others’ data"Prevent users from modifying kernel code and data structures!I/O"Prevent users from performing “illegal” I/Os4Architecture Support: Privileged ModeAn interrupt or exception (INT)A special instruction (IRET)Kernel (privileged) mode• Regular instructions• Privileged instructions• Access user memory• Access kernel memoryUser mode• Regular instructions• Access user memory5Privileged Instruction Examples!Memory address mapping!Flush or invalidate data cache!Invalidate TLB entries!Load and read system registers!Change processor modes from kernel to user!Change the voltage and frequency of processor!Halt a processor!Reset a processor!Perform I/O operations6x86 Protection RingsLevel 0Level 1Level 2Level 3Operating systemkernelOperating systemservicesApplicationsPrivileged instructionsCan be executed onlyWhen current privilegedLevel (CPR) is 07Outline!Protection mechanisms!OS structures!System and library calls8Monolithic!All kernel routines are together, any can call any!A system call interface (main program, sys calls, utility funcs)!Examples: "Linux, BSD Unix, Windows!Pros"Shared kernel space"Good performance!Cons"No information hiding"Inflexible"Chaotic"Difficult to understand"How many bugs in 5 million lines of code?Kernel(many things)UserprogramUserprogramsyscallsyscall9Layered Structure!Level N constructed on top of N-1!Hiding information at each layer!E.g. level 1 is processor allocation, level 1 memory management, level 2 comm, level 3 I/O, etc.!Examples"THE System (6 layers)"MS-DOS (4 layers)!Pros"Layered abstraction"Separation of concerns, elegance!Cons"Protection, boundary crossings"PerformanceHardwareLevel 1Level 2Level N...10Microkernel!Put less in kernel mode: only small part of OS; reduce kernel bugs !Services are regular processes; one file system crashing doesn’t crash full system; can’t corrupt kernel memory!!-kernel gets svcs on behalf of users by messaging with service processes!Examples: "Mach, Taos, L4, OS-X!Pros?"Flexibility"Fault isolation and reliability (used in avionics and military apps)!Cons?"Inefficient (boundary crossings)"Insufficient protection"Inconvenient to share data between kernel and servicesentryUserprogramOSServices!-kernelsyscall11Virtual Machine MonitorVM1OS1Virtual Machine!Separate out multiprogramming from abstraction; VMM provides former!Virtual machine monitor"Virtualize hardware, but expose it as multiple instances of ‘raw’ hw"Run several OSes, one on each set"Examples• IBM VM/370• Java VM• VMWare, Xen!What would you use virtual machine for?AppsVMkOSkApps. . .Raw Hardware12Two Popular Ways to Implement VMMHardwareLinuxLinux AppsVMMWin VistaWin AppsHardwareLinuxLinux AppsVMMWin VistaWin AppsVMM as an applicationVMM runs on hardware(A special lecture later in the semester)13Outline!Protection mechanisms!OS structures!System and library calls14System Call Mechanism!Assumptions"User code can be arbitrary"User code cannot modify kernel memory!Design Issues"User code makes a system call with parameters"The call mechanism switches code to kernel mode"Execute system call"Return with results"(Like a procedure call, just crosses kernel boundary)Kernel inprotected memoryUserprogramUserprogramsyscallsyscall15System Calls!Operating system API"Interface between an application and the operating system kernel!Categories"Process management"Memory management"File management"Device management"Communication16OS Kernel: Trap HandlerHW Device InterruptHW exceptionsSW exceptionsSystem CallVirtual address exceptionsHW implementation of the boundarySystem service dispatcherSystem servicesInterrupt service routinesException dispatcherException handlersVM manager’s pagerSyscall tableSystemServicedispatcher17Passing Parameters!Pass by registers"# of registers"# of usable registers"# of parameters in system call"Spill/fill code in compiler!Pass by a memory vector (list)"Single register for starting address"Vector in user’s memory!Pass by stack"Similar to the memory vector"Procedure call convention18Library Stubs for System Calls!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}Linux: 80NT: 2EKernel inprotected memoryUserprogramInt $0x80iret19System Call Entry PointUserstackRegistersUsermemoryKernelstackRegistersKernelmemoryEntryPoint: switch to kernel stack save context check R0 call the real code pointed by R0 place result in Rresult restore context switch to user stack iret (change to user mode and return)(Assume passing parameters in registers)20Design Issues!System calls"There is one result register; what about more results?"How do we pass errors back to the caller?"Can user code lie?"How would you perform QA on system calls?!System calls vs. library calls"What should be system calls?"What should be library calls?21Division of Labor (or Separation Of Concerns)Memory management example!Kernel"Allocates “pages” with hardware protection"Allocates a big chunk (many pages) to library"Does not care about small allocs!Library"Provides malloc/free for allocation and deallocation"Application use these calls to manage memory at fine granularity"When reaching the end, library asks the kernel for more22Feedback To The Program!Applications view system calls and library calls as procedure calls!What about OS to apps?"Various exceptional conditions"General information, like screen resize!What mechanism would OS use for this?ApplicationOperatingSystem23Interrupt and Exceptions!Interrupt Sources"Hardware (by external devices)"Software: INT n!Exceptions"Program error: faults, traps, and aborts"Software generated: INT 3"Machine-check exceptions!See Intel document volume 3 for details24Interrupt and Exceptions (1)Vector #MnemonicDescriptionType0#DEDivide error (by zero)Fault1#DBDebugFault/trap2NMI interruptInterrupt3#BPBreakpointTrap4#OFOverflowTrap5#BRBOUND range exceededTrap6#UDInvalid opcodeFault7#NMDevice not availableFault8#DFDouble faultAbort9Coprocessor segment overrunFault10#TSInvalid TSS25Interrupt and


View Full Document

Princeton COS 318 - OS Structures and System Calls

Documents in this Course
Overview

Overview

25 pages

Deadlocks

Deadlocks

25 pages

lectute 2

lectute 2

28 pages

Lecturel

Lecturel

24 pages

Real mode

Real mode

49 pages

Lecture 2

Lecture 2

54 pages

lecture 5

lecture 5

27 pages

Load more
Download OS Structures and System Calls
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view OS Structures and System Calls and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view OS Structures and System Calls 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?