Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.

Slides:



Advertisements
Similar presentations
Main Memory.
Advertisements

Part IV: Memory Management
CSS430 Memory Management Textbook Ch8
Operating Systems Lecture Notes Memory Management Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
OS Spring’03 Introduction Operating Systems Spring 2003.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
Operating System Concepts
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
OS Spring’04 Introduction Operating Systems Spring 2004.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Lecture 13 L.Mohammad R.Alkafagee1.  The concept of a logical address space that is bound to a separate physical address space is central to proper memory.
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
CS333 Intro to Operating Systems Jonathan Walpole.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Memory Protection: Kernel and User Address Spaces Andy Wang Operating Systems COP 4610 / CGS 5765.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
W4118 Operating Systems Instructor: Junfeng Yang.
Chapter 9: Memory Management
SLC/VER1.0/OS CONCEPTS/OCT'99
Memory Protection: Kernel and User Address Spaces
Chapter 8: Main Memory Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 8: Memory Management
Chapter 8 Main Memory.
Main Memory Management
Lecture 28: Virtual Memory-Address Translation
Memory Protection: Kernel and User Address Spaces
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Memory Protection: Kernel and User Address Spaces
Memory Protection: Kernel and User Address Spaces
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Multistep Processing of a User Program
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Memory Management Tasks
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
Memory Protection: Kernel and User Address Spaces
CSE 542: Operating Systems
Presentation transcript:

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.

Background and concepts  Raw memory  A large array of words or bytes  Each word/byte has its own address.  Program counter stores the address of the instruction to be executed. Executing an instruction may cause operands to be fetched from memory.  The memory unit sees a stream of memory addresses.  It does not know how or why the addresses are generated.

 Address binding:  Let us assume that a process can reside in any part of the physical memory.  How do we specify the memory addresses that the program uses?  When the compiler generates executable, it must specify the addresses.  E.g ‘load R1, mem[100]’  Addresses used in the executables are logical addresses.  Logical addresses may or may not be physical addresses, that addresses for raw memory.

 Address binding:  Mapping from logical address (used in user programs) to physical addresses (on raw memory)  This can affect how addresses in an executable are generated (or how the executables are generated by the compiler).  What kind of address does the CPU see, logical or physical?

 When is address binding done?  Steps to get our source program to run?  Compile .o files  Link  a.out  Load (after you type ‘a.out’).  Depending on how memory is managed, address binding can be done in any of the steps:  Compile time (compile/link). When the compiler knows the address where the program will be loaded, it can produce the absolute code.  MS-DOS, or some embedded systems.  Logical address = physical address  Load time. When the process can be placed anywhere in the memory. The compiler can only generate relocatable code.  Physical address = base address + logical address  Execution time. The process can be moved during execution. Binding can only be done at run time. Need hardware support.

 When is address binding done?  Compile time, load time, and execution time, which one is the most common one on the current machines?  Execution time through hardware support for virtual memory.  In a typical virtual memory system:  Logical (virtual) memory for a process is a continuous block (e.g. 0 – 2^32 bytes)  Physically, different pages can be mapping to different locations of the physical memory.

 Dynamic loading  So far, we have assumed that the whole program and data for the program must be in memory in order for a process to execute.  Problem? Even if you code is small, the memory needed will be large. Why?  Each program must be linked with the whole standard library.  The whole library must be in memory even though most functions in that library are not used.

 Dynamic loading  Don’t load the whole program into memory before we run a program  Just load the main routine at the beginning. When a new routine is called, it is loaded into the memory.  The executable will still be large, but the memory used will be smaller.  Routines that are not used will not be in the memory.  Dynamic loading can introduce significant time penalty.  Space/time trade-off

 Dynamic linking and shared libraries  With dynamic loading, the actual memory used may not be large, but the executable size is large. A program must be statically linked with all libraries.  Dynamic linking is conceptually similar to dynamic loading (except apply to linking)  Postpone the linking until execution.  How it works:  Use a stub to replace the whole library routine  Enough information to locate the library routine.  When the stub is executed, it replaces itself with the address of the routine and executes the routine.  Only one copy of library code is needed for all programs.  Such library is also known as a shared library.  The executable is much smaller with such libraries.  Windows DLL files (.dll) and UNIX shared object (.so) library

 Dynamic linking and shared libraries  Try ‘gcc a.c’ and ‘gcc –static a.c’ and check the size of the executable.  One problem with dynamically linked executable is that it is less portable: assume the shared library is available and the same  Statically linked executables are more self-contained.

 Swapping  The OS may choose to swap a process out of memory temporarily to swap space.  Swap space is on disk (see ‘top’)

Memory protection  Isolate processes from one another and from the OS.

uniprogramming without memory protection  Simplest.  Each application runs within a hardwired range of physical memory addresses  One application runs at a time  Application can use the same physical addresses every time, across reboots

Uniprogramming Without Memory Protection  Applications typically use the lower memory addresses  An OS uses the higher memory addresses  An application can address any physical memory location ffffff Physical memory ApplicationOperating system

Multiprogramming Without Memory Protection  When a program is copied into memory, a linker-loader alters the code of the program (e.g., loads, stores, and jumps)  To use the address of where the program lands in memory

Multiprogramming Without Memory Protection  Bugs in any program can cause other programs to crash, even the OS ffffff Physical memory Application 1Operating systemApplication 2

Multiprogrammed OS With Memory Protection  Memory protection keeps user programs from crashing one another and the OS  The big idea: make all memory accesses go through an OS controlled agency  The agency provides services (address translation) while checking all addresses  Two hardware-supported mechanisms  Address translation (the OS controlled agency)  Dual-mode operation

Address Translation  Each process is associated with an address space, or all the addresses a process can touch  Each process believes that it owns the entire memory, starting with the virtual address 0  The missing piece is a translation table to translate every memory reference from virtual to physical addresses

Address Translation Visualized Virtual addresses Physical addresses Translation table Data reads or writes (untranslated)

More on Address Translations  Address translation example:  Translation table maintains  Translation table maintains  If (virtual address > bound) error;  Else Physical address = base + virtual address;  This allows multiple processes to be in memory with protection.  Translation provides protection  Processes cannot talk about other processes’ addresses, nor about the OS addresses  OS uses physical addresses directly  No translations

Dual-Mode Operation Revisited  Translation tables offer protection if they cannot be altered by applications  An application can only touch its address space under the user mode  Hardware requires the CPU to be in the kernel mode to modify the address translation tables

Switching from the Kernel to User Mode  To run a user program, the kernel  Creates a process and initialize the address space  Loads the program into the memory  Initializes translation tables  Sets the hardware pointer to the translation table  Sets the CPU to user mode  Jumps to the entry point of the program

To Run a Program User level Kernel level Translation table Hardware pointer user mode PC

Switching from User Mode to Kernel Mode  Voluntary  System calls: a user process asks the OS to do something on the process’s behalf  Involuntary  Hardware interrupts (e.g., I/O)  Program exceptions (e.g., segmentation fault)

Switching from User Mode to Kernel Mode  For all cases, hardware atomically performs the following steps  Sets the CPU to kernel mode  Saves the current program counter  Jumps to the handler in the kernel  The handler saves old register values

Switching from User Mode to Kernel Mode  Context switching between processes  Need to save and restore pointers to translation tables  To resume process execution  Kernel reloads old register values  Sets CPU to user mode  Jumps to the old program counter

User  Kernel User level Kernel level set kernel mode PC handler trusted code register valuestranslation tables (for processes)

Kernel  User User level Kernel level set kernel mode PC handler trusted code register valuestranslation tables (for processes)

Kernel  User User level Kernel level PC handler trusted code register valuestranslation tables (for processes) user mode