Memory Mapped I/O Gregory Mortensen CSIS 4330, Advanced Windows Programming – UVSC.

Slides:



Advertisements
Similar presentations
Process A process is usually defined as an instance of a running program and consists of two components: A kernel object that the operating system uses.
Advertisements

C Lab 3 C Arraylist Implementation. Goals ●Review ○ Referencing/Dereferencing ○ Free ●realloc and memmove ●ArrayList ●Debugging with GDB.
Spark: Cluster Computing with Working Sets
Win32 Programming Lesson 5: Error Codes. Before We Begin  Much of the time in this class we’ll be calling Win32 Functions  However, sometimes they’re.
1 JMH Associates © 2004, All rights reserved Chapter 5 Memory Management, Memory-Mapped Files, and DLLs.
Read vs. mmap Tan Li. Man mmap #include void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); int munmap(void *start, size_t.
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
Case Study: Distributed OS Distributed Systems, Lecture # 17.
Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address.
File System Implementation: beyond the user’s view A possible file system layout on a disk.
DISTRIBUTED CONSISTENCY MANAGEMENT IN A SINGLE ADDRESS SPACE DISTRIBUTED OPERATING SYSTEM Sombrero.
1 Case Study 2: Windows 2000 Chapter History of windows Programming windows System structure 11.4 Processes and threads in.
Ceng Operating Systems
Memory Management April 28, 2000 Instructor: Gary Kimura.
File System Implementation
1 JMH Associates © 2004, All rights reserved Chapter 1 Getting Started with Win32/64.
计算机系 信息处理实验室 Lecture 14 Cache Manager
Ceng Operating Systems 11-1 Chapter 11 : Case Study - Win 2000 History of windows 2000 Programming windows 2000 System structure Processes and threads.
Win32 Programming Lesson 9: Jobs & Thread Basics.
Windows Memory Management, Memory- Mapped Files, and DLLs.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
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.
Win32 Programming Lesson 20: Advanced DLL Techniques.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Win32 Programming Lesson 22: DLL Magic Part Deux All your base are belong to us…
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
Win32 Programming Lesson 7: Kernel Objects. Abstract  Many of the concepts we’ll look at today won’t make complete sense until you use them  However,
Win32 Programming Lesson 18: More Memory Mapped Files and the HEAP (Finally, cool stuff!)
Win32 Programming Lesson 8a: Jobs. Where are we?  Grouping processes into logical groups: Jobs  However, processes don’t retain a parent- child relationship.
1 Process migration n why migrate processes n main concepts n PM design objectives n design issues n freezing and restarting a process n address space.
G53SEC 1 Reference Monitors Enforcement of Access Control.
© 2004, D. J. Foreman 1 Implementing Processes and Threads.
Memory Management II CS Spring Overview Logical Addressing and Virtual Memory –Logical to Linear Address Mapping –Linear to Physical Address.
Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)
C++ Pointers Review. Overview  What is a pointer  Why do I care?  What can be 'pointed to'?  Example.
Windows XP & Vista Memory Management
Best Practices Steve Maillet Chief Software Architect EmbeddedFusion ECE401 Best Practices For Driver Development.
Win32 Programming Lesson 17: Memory Mapped Files (Finally, cool stuff again, all this work is getting tedious!)
File Systems cs550 Operating Systems David Monismith.
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
Win32 Programming Lesson 15: Practical Windows Memory (If you can read this you have good vision)
4P13 Week 7 Talking Points Memory Mgmt Data Structs 5.
Windows Security Features protect Memory Disk Network.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
Virtual Memory By CS147 Maheshpriya Venkata. Agenda Review Cache Memory Virtual Memory Paging Segmentation Configuration Of Virtual Memory Cache Memory.
File-System Management
Chapter 3: Windows7 Part 5.
CS 140 Lecture Notes: Virtual Memory
Chapter 8: Main Memory.
Protection and OS Structure
Protection of System Resources
Implementing Processes and Threads
CSE451 I/O Systems and the Full I/O Path Autumn 2002
CS 140 Lecture Notes: Virtual Memory
Chapter 3: Windows7 Part 5.
File system(conti..) Lecture November 2018.
Paging Lecture November 2018.
Windows CE Memory Management
Case Study 2: Windows History of windows 2000
Outline Midterm results summary Distributed file systems – continued
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Files in Windows API David Halbig Lopez.
CS 140 Lecture Notes: Virtual Memory
Interprocess Communication
CSC 497/583 Advanced Topics in Computer Security
CS 140 Lecture Notes: Virtual Memory
The File Manager Implementation issues
Memory allocation.
Presentation transcript:

Memory Mapped I/O Gregory Mortensen CSIS 4330, Advanced Windows Programming – UVSC

Implementing Memory Mapped I/O 1.Create or Open the File Object (see lecture 5). 2.Create the Memory Mapped Object 3.Create a view to map the object into your address space

Memory Mapped I/O 2. Create the Memory Mapped Object HANDLE CreateFileMapping (HANDLE hFile, psa, DWORD protect, DWORD maxSizeHigh, DWORD maxSizeLow PCTSTR optionalName) Protect is PAGE_READONLY, PAGE_READWRITE, PAGE_WRITECOPY, SEC_RESERVE or SEC_COMMIT, for 2000 also SEC_NOCACHE, or PAGE_NOCACHE, SEC_IMAGE. If maxSizeLow and msHi are both 0, it opens the file at its current size, but appends fail. optionalName is used if the Memory Mapped object is shared between processes.

Memory Mapped I/O 3. Create a view PVOID MapViewOfFileObject (HANDLE hFMObject, DWORD access, DWORD highOffset, DWORD lowOffset,SIZE_T numBytes) Access= FILE_MAP_WRITE, FILE_MAP_READ, or FILE_MAP_COPY(F_M_C the hFMObject must be created with PAGE_WRITE_COPY – WIN98) All zeros for hOffset, lOffset and numBytes maps the whole file

Coherency If the view is created with access FILE_MAP_COPY, then only the original file is shared between process boundries. Any changes are made to your copy not to the original If the view is create with access FILE_MAP_WRITE then changes made in your process are also made in other processes transparently, by the operating system.

Using Memory Mapped IO without a file Passing INVALID_HANDLE_VALUE (the value returned by a failed CreateFile) creates a memory mapping of the page file and not of a disk file. A simple clipboard could use a memory mapped file of a process’es memory space and not of an actual file.

Preserving Memory By default, when you create a Map Object, the default pageProtection is SEC_COMMIT. To use memory only as you need it: 1. Create with SEC_RESERVE 2. Use PVOID VirtualAlloc(PVOID pvAddress, SIZE_T dwSize, DWORD allocType, DWORD protect) 3. All processes mapped to the object can then access that location successfully!

Relocatability You can use CreateFileMappingEx & CreateMapViewEx to force a Map Object or view to always be forced to an address. This allows you to use pointers freely, (every process would have the Map Object to same the memory address) however if that address is in use, the above creates would fail. To use pointers and guarantee relocatablity you should use relative addressing.

Clean up 1.Close the View: UnmapViewOfFile (PVOID returnedByCreateMapView) 2.Close the File Mapping Object: CloseHandle(MappingObject) 3.Close the File Handle, if using files: CloseHandle(FileObject)