CSCE 313 Lecture 3

From Notes
Jump to navigation Jump to search

« previous | Tuesday, January 24, 2012 | next »

Lecture Notes


Pthreads Tutorial (will be important for Machine Problem 1)


Architecture Support for Interrupts

Traditional CPU uses an interrupt vector table (interrupt includes a location), which then points to the location to continue execution.

MIPS handles interrupts just like exceptions: all exceptions are handled by a single exception handler (interrupt reason stored in CAUSE register), which then decides what service routine to run.

Hardware Protection

Processes are not allowed to affect other processes or their access to machine resources.

  1. Dual-mode operation: user vs. subervisor/kernel mode (halt instruction is privileged)
  2. I/O Protection: all I/O operations are privileged (prevents programs from hogging storage devices)
  3. Memory Protection

Timers

Ensures that OS will have control over CPU by switching between user mode and kernel mode

OS decrements counter and generates an interrupt when it reaches 0.

System Calls

Outside view of the OS:

Programs use API to call system-level operations (fopen(), printf(), etc.)

Parameter Passing

  • Simplest: put parameters in registers.
  • Put parameters in block/table in memory and pass pointers (Linux and Solaris)
  • Parameters pushed onto stack by program and then popped by OS.

Why use Interrupts?

  1. load user program into memory without knowing exact address of system procedures
  2. Separate address space (e.g. user stack and kernel stack)
  3. Automatic change to supervisor mode
  4. control access to kernel by masking interrupts (if system receives 2 identical interrupts at the same time, it wil work on one while the other waits)

Buffer Overrun Attacks

#include <stdio.h>
#define BUFFER SIZE 256
int main(int argc, char *argv[])
{
    // allocate BUFFER SIZE bytes in stack
    char buffer[BUFFER SIZE];
    if (argc < 2) {
        return -1
    } else {
        // copy input string into buffer (!!)
        strcpy(buffer, argv[1])
        return 0;
    }
}

After copying BUFFER_SIZE - 1 bytes from argv[1], if there is still more data in argv[1], then it may overwrite the saved frame pointer and return address stored in the stack.

A hacker could use this method to execute malicious code by setting the return address to point to the malicious code.

Organization of Operating System

Outsider's view of the OS

Kernel

layered (I assume "monolithic")
components of kernel (file system, IPC, I/O, virtual memory, process management) interact hierarchically, and only between layers
microkernels
components are actually in user space and have access to hardware through a core OS interface.
client-server architecture within a single computer: message-based communication between users and services.
extensible (modular), flexible, portable (well-defined interface)
SLOW Two interrupts context switch for request and response (4 total)

Most modern kernels implement a mixture between both of these concepts.