protection of system resources

22
Protection of System Resources I/O Devices Memory CPU Based on different modes of operation: kernel mode and user mode. Privileged instructions can be issued only in kernel mode. Mode bit in PSW, checked on every instruction.

Upload: lilith

Post on 25-Feb-2016

31 views

Category:

Documents


0 download

DESCRIPTION

Protection of System Resources. I/O Devices Memory CPU Based on different modes of operation: kernel mode and user mode. Privileged instructions can be issued only in kernel mode . Mode bit in PSW, checked on every instruction . Protection of I/O Devices. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Protection of System Resources

Protection of System Resources I/O Devices Memory CPU Based on different modes of

operation: kernel mode and user mode. Privileged instructions can be issued only in kernel

mode. Mode bit in PSW, checked on every instruction.

Page 2: Protection of System Resources

Protection of I/O Devices All I/O instructions are privileged instructions. Only accessed through system calls.

Page 3: Protection of System Resources

Memory Protection Must provide memory protection for the

interrupt vector, interrupt service routines, and other applications address space.

Two registers that determine the range of legal addresses a program may access: Base register – holds the smallest legal

physical memory address. Limit register – contains the size of the

range Memory outside the defined range is

protected.

Page 4: Protection of System Resources

Use of A Base and Limit Register

Page 5: Protection of System Resources

Hardware Address Protection

Page 6: Protection of System Resources

CPU (and OS) Protection Keep user from monopolizing CPU. Ensure OS regains control of CPU.

Page 7: Protection of System Resources

CPU Protection Timer – interrupts computer after

specified period to ensure operating system maintains control. Timer is decremented every clock tick. When timer reaches the value 0, an

interrupt occurs. Timer commonly used to

implement time sharing.

Page 8: Protection of System Resources

Privileged Instructions Load base and limit registers?

Page 9: Protection of System Resources

Privileged Instructions Load base and limit registers? Set the system timer?

Page 10: Protection of System Resources

Privileged Instructions Load base and limit registers? Set the system timer? Read the system clock?

Page 11: Protection of System Resources

Privileged Instructions Set the system timer? Read the system clock? Load base and limit registers? Open a file?

Page 12: Protection of System Resources

Privileged Instructions Load base and limit registers? Set the system timer? Read the system clock? Open a file? Compile a program and create executable?

Page 13: Protection of System Resources

Privileged Instructions Load base and limit registers? Set the system timer? Read the system clock? Open a file? Compile a program and create executable? Enable/disable interrupts?

Page 14: Protection of System Resources

System Calls Interface between executing program and OS defined

by set of system calls OS provides. System call causes a TRAP to switch from user to kernel

mode and starts execution at interrupt vector location for TRAP instruction.

Operating system looks at requested operation and any parameters passed by the application.

Dispatches the correct system call handler through a table of pointers to system call handlers.

Handler completes and (may) return to user code at the next instruction. OS may schedule another process to execute.

Page 15: Protection of System Resources

System Call Interface Example: num_bytes = read(file, buffer,

nbytes) ; Note: application level read is a library call,

and the library call invokes the read system call.

Code is inserted by the compiler to perform steps necessary for call to library.

Page 16: Protection of System Resources

System Calls

Steps 1-3: Push parameters onto the stack. Step 4. Calls read library function.Step 5. Library puts system call number in register (or other pre-defined location).Step 6: Executes a TRAP instruction switching to kernel mode. Step 7. OS retrieves system call request and calls handler(generally via a table indexed by system call number).

Page 17: Protection of System Resources

Step 8. System call handler executes system call.Step 9. Call completes, may return to user level-level library call at instruction immediately following TRAP instruction. Count set to –1 if call failed or to number of bytes actually read if successful. Step 10. Library procedure returns to user program.Step 11. User program resets stack pointer to clean up library call.

Page 18: Protection of System Resources

System Calls for Process Management Process Creation:

fork() system call. Creates an exact duplicate of the calling process

including all variables, file descriptors, registers ……..

fork returns the process ID of child to the parent (pid), and returns a zero to child.

After completion, two independent processes executing “concurrently”.

The parent can choose to wait for the child process to complete before resuming its execution.

Page 19: Protection of System Resources

Unix fork()

#include <stdio.h>main(int argc, char *argv[]) { int pid, j,k ; j = 10 ; k = 32 ; pid = fork() ; if (pid == 0) /*I am the child*/

{ Do childish things }

else /* I am the parent */wait(NULL) ; /* Block execution until child terminates */

}

Page 20: Protection of System Resources

j = 10k =32pid = ?

Page 21: Protection of System Resources

j = 10k =32pid =

j = 10k = 32pid = 0

Set to pid of child.

fork()

Page 22: Protection of System Resources

Processes Tree on a UNIX System