| 1 | /* $Id: mmf.cpp,v 1.1 2000-10-31 17:35:00 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * Memory Mapped Files.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
|---|
| 6 | *
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /** @design Memory Mapped Files - Ring 0
|
|---|
| 12 |
|
|---|
| 13 | Support for Memory Mapped Files (MMF) is an excellent feature missing in OS/2.
|
|---|
| 14 | Several Ring-3 implementations exists. Most of them have problems when calling
|
|---|
| 15 | OS/2 APIs. APIs like DosRead, DosWrite will at Ring-0 check if the buffer
|
|---|
| 16 | passed in is valid (all pages commited), and will fail if the pages aren't
|
|---|
| 17 | commited. And AFAIK the Ring-3 MMF implementations exploits the commit/decommit
|
|---|
| 18 | feature of DosSetMem.<p>
|
|---|
| 19 |
|
|---|
| 20 | So, the only way to get this right and fast is to implement it at Ring-0 level.
|
|---|
| 21 | This is what I (knut) aim to do some day. These are my current thoughts on
|
|---|
| 22 | the subject. (Oct 31 2000 5:39pm)<p>
|
|---|
| 23 |
|
|---|
| 24 | What I am think about is to create a Ring-0 class for MMF which maintains all
|
|---|
| 25 | of the MMF handling. There will be a Ring-3 DLL which provides APIs which
|
|---|
| 26 | uses IOCtls to communicate with the Ring-0 class. These APIs will be presented
|
|---|
| 27 | in these forms:
|
|---|
| 28 | <ul>
|
|---|
| 29 | <li>My own "native" APIs.
|
|---|
| 30 | <li>UNIX mmap, munmap, msync APIs
|
|---|
| 31 | <li>Win32 styled APIs. (if needed)
|
|---|
| 32 | </ul><p>
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | @subsection Loader Exploits (Overloads)
|
|---|
| 36 |
|
|---|
| 37 | The Ring-0 part will overload the handling of the Ring-3 DLL, that's the
|
|---|
| 38 | reason why I will insist on having a separate MMF DLL. When the first call to
|
|---|
| 39 | the MMF is issued we'll find the MMF DLL and "hook" it's handle. This
|
|---|
| 40 | "hooking" will enable us to make speciall processing in LDRGetPage,
|
|---|
| 41 | LDRFreeTask and maybe ldrAllocateObjects. All of these LDR functions will have
|
|---|
| 42 | to be overloaded with my own functions - LDRGetPage will be written in
|
|---|
| 43 | assembly to minimize latency.<p>
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | @subsubsection LDRGetPage
|
|---|
| 47 |
|
|---|
| 48 | As you will see somewhere else (when this text is completed) we'll allocate
|
|---|
| 49 | objects my self and give the hMTE of the MMF DLL. The block number will be
|
|---|
| 50 | relative to the start of each mapping if there is a filebacking of the
|
|---|
| 51 | object.<p>
|
|---|
| 52 |
|
|---|
| 53 | So, what we'll actually do is 1st to check that the call isn't for the real
|
|---|
| 54 | LX objects of the MMF DLL. Since we're overloading the processing of the
|
|---|
| 55 | MMF DLL we will have to distiguish between calls related to the processing
|
|---|
| 56 | of the DLL and the processing of our memorymapped objects. Then, if this
|
|---|
| 57 | is a request for a page in the one of the objects of the MMF DLL we'll simply
|
|---|
| 58 | call(/jump) to the original LDRGetPage.<p>
|
|---|
| 59 |
|
|---|
| 60 | If this is a request for a page in one of the memory mapped objects, we'll
|
|---|
| 61 | have to get that page. Starts out by finding the mapping this is for. If it's
|
|---|
| 62 | a mapping without filebacking we'll simply return a zero'ed page. Else, we'll
|
|---|
| 63 | have to read it from the disk. And that's about all we'll have to do.
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | @subsubsection LDRFreeTask
|
|---|
| 67 |
|
|---|
| 68 | Here we'll clean up all our resources associated with this process. I am not
|
|---|
| 69 | quite sure what this will be; flushing mappings, decreasing usage counts,
|
|---|
| 70 | eventually releasing objects, closing files.
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | @subsubsection ldrAllocObjects
|
|---|
| 74 |
|
|---|
| 75 | Here we could attach inherited mappings. Not really needed.
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | @subsection Interface Ring-0 to Ring-3
|
|---|
| 80 |
|
|---|
| 81 | An interface between Ring-0 and Ring-3 will have to be as simple as possible,
|
|---|
| 82 | and yet the Ring-0 would not trust the Ring-3 very much since someone may
|
|---|
| 83 | call the DosIOCtls them selves. These are the proposed interfaces:
|
|---|
| 84 | <ul>
|
|---|
| 85 | <li>MMFCreating - Create a mapping handle.
|
|---|
| 86 | <li>MMFDuplicate - Duplicates an mapping handle.
|
|---|
| 87 | <li>MMFOpen - Open an existing mapping.
|
|---|
| 88 | <li>MMFViewMap - Creates a view for a part of the file.
|
|---|
| 89 | <li>MMFViewUnmap - Flushes and destroys a view.
|
|---|
| 90 | <li>MMFViewSync - Flush a view.
|
|---|
| 91 | </ul>
|
|---|
| 92 | This will roughly be the exported "native" APIs too.
|
|---|
| 93 |
|
|---|
| 94 | @subsubsection MMFCreating
|
|---|
| 95 | @subsubsection MMFDuplicate
|
|---|
| 96 | @subsubsection MMFOpen
|
|---|
| 97 | @subsubsection MMFViewMap
|
|---|
| 98 | @subsubsection MMFViewUnmap
|
|---|
| 99 | @subsubsection MMFViewSync
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | @subsection Innerworkings of the Ring-0 MMF class(es)
|
|---|
| 103 |
|
|---|
| 104 | To be written some other day.
|
|---|
| 105 |
|
|---|
| 106 | */
|
|---|