Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Management: Overlays and Virtual Memory
Copyright ©: Lawrence Angrave, Vikram Adve, Caccamo 1 Virtual Memory III.
May 7, A Real Problem  What if you wanted to run a program that needs more memory than you have?
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
Memory Management Design & Implementation Segmentation Chapter 4.
Memory Management (II)
Operating System Support Focus on Architecture
Understanding Operating Systems1 Operating Systems Virtual Memory Thrashing Single-User Contiguous Scheme Fixed Partitions Dynamic Partitions.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
Memory Management 2010.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Computer Organization and Architecture
PRASHANTHI NARAYAN NETTEM.
November 1, 2004Introduction to Computer Security ©2004 Matt Bishop Slide #29-1 Chapter 33: Virtual Machines Virtual Machine Structure Virtual Machine.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Windows 2000 Memory Management Computing Department, Lancaster University, UK.
By Matthew Smith, John Allred, Chris Fulton. Requirements Relocation Protection Sharing Logical Organization Physical Organization.
Review of Memory Management, Virtual Memory CS448.
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Windows Memory Architecture 井民全製作. A Process ’ s Virtual Address Space Every Process has its own private virtual address 32-bits processes  4 GB address.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.
Chapter 4 Memory Management Virtual Memory.
Memory Management II CS Spring Overview Logical Addressing and Virtual Memory –Logical to Linear Address Mapping –Linear to Physical Address.
Computer Systems Week 14: Memory Management Amanda Oddie.
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
CS 153 Design of Operating Systems Spring 2015 Final Review 2.
Computer Architecture Lecture 27 Fasih ur Rehman.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Win32 Programming Lesson 17: Memory Mapped Files (Finally, cool stuff again, all this work is getting tedious!)
Memory Management: Overlays and Virtual Memory. Agenda Overview of Virtual Memory –Review material based on Computer Architecture and OS concepts Credits.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Protection of Processes Security and privacy of data is challenging currently. Protecting information – Not limited to hardware. – Depends on innovation.
Win32 Programming Lesson 19: Introduction to DLLs.
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.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
Virtual Memory.
Lecture 24 – Paging implementation
Lesson Objectives Aims Key Words Paging, Segmentation, Virtual Memory
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
Some Real Problem What if a program needs more memory than the machine has? even if individual programs fit in memory, how can we run multiple programs?
Bruhadeshwar Meltdown Bruhadeshwar
OS Virtualization.
O.S Lecture 13 Virtual Memory.
Data Structures and Algorithms
Page Replacement.
Introduction to the Intel x86’s support for “virtual” memory
Operating Systems.
Lecture 3: Main Memory.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Cache writes and examples
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
Dirty COW Race Condition Attack
Presentation transcript:

Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)

Where are we?  We’ve covered threads in glorious detail  But to really take advantage of threads, we need to know a lot more about Windows Memory Architecture Why?

Why Study Memory  “How do I share data between applications?”  “Where is this information stored?”  “Why is my program so sloooooow?”  Understanding how the system uses memory helps us answer these questions and more…

Process Memory  Every 32-bit process has its own virtual address space  4GB (why?)  How much for a 64-bit process?  As the space is virtual, memory by default isn’t shared between processes (but is between threads… why?)

Virtualization  Two different processes can have data stored at 0x … but the values are different  Each Virtual space is partitioned into different areas

Null-Pointer Assignment  If you point to a NULL pointer, you want your code to throw an exception  This is accomplished by the NULL-pointer assignment partition space

User-Mode Partition  Contains the process’ private (unshared) address space  Not accessible from other Processes  However, not all of this is directly useable by the application

Kernel-mode partition  Used by the Kernel for various process- related things  Everything in this partition is shared among processes

Regions in Address Space  When a process is created, most of its virtual memory is free  To use this space, must call VirtualAlloc  Reserving memory happens in blocks called “chunks” (allocation granularity, to use a fancy term)  Memory is reserved in multiples of the systems “page” size

But…  You must free memory if you use it  Call VirtualFree

Physical Storage  If every 32-bit process has 4GB of storage, don’t I run out of memory?  No… because of the paging file  Transparent in operation  Pages blocks of memory to disk from RAM  So, Memory works a lot like this…

Paging

Thrashing  When you’re really short of memory, an application can thrash (demo…)  Happens when the OS spends most of its time fetching memory from disk  Hence, to speed up your machine add RAM (thanks Nate!)

Memory Protection  It is possible to share physical memory…  Thus, you need to know about memory protection attributes

Flags  PAGE_NOACCESS – Any attempt to read, write or execute raises a violation  PAGE_READONLY  PAGE_READWRITE  PAGE_EXECUTE  PAGE_EXECUTE_READ  PAGE_EXECUTE_READWRITE  PAGE_WRITECOPY – Attempts to write to this page causes the application to get its own private copy of this page  PAGE_EXECUTE_WRITECOPY

Copy On Write  Interesting idea  Memory is shared until you write  Exists to conserve RAM and prevent thrashing  When a write is detected: OS finds a free page in RAM Copies the page to the new page and marks it PAGE_READWRITE or PAGE_EXECUTE_READWRITE Updates the process’ page tables

Special Flags  PAGE_NOCACHE – Disable Cacheing on this page (why… Hardware)  PAGE_WRITECOMBINE – Multiple writes are linked together  PAGE_GUARD – alert when a write occurs

Assignment  Create a command line program in Visual Studio  Write an application which allocates memory and tries different protection schemes  Show how the system throws exceptions when you access this memory (for example, try and execute code from the memory location when PAGE_READONLY is set)  Use an exception handler to catch this exception  Reset the PAGE to EXECUTE and show how the exception is no longer thrown…