source: trunk/src/kernel32/old/mmap.h@ 1036

Last change on this file since 1036 was 955, checked in by sandervl, 26 years ago

Backup copy of old kernel32

File size: 3.2 KB
Line 
1/* $Id: mmap.h,v 1.1 1999-09-15 23:32:58 sandervl Exp $ */
2
3/*
4 * Memory mapped class
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#ifndef __MMAP_H__
13#define __MMAP_H__
14
15#include <vmutex.h>
16
17#ifndef PAGE_SIZE
18#define PAGE_SIZE 4096
19#endif
20
21//commit 4 pages at once when the app accesses it
22#define NRPAGES_TOCOMMIT 200
23
24#define MEMMAP_ACCESS_READ 1
25#define MEMMAP_ACCESS_WRITE 2
26#define MEMMAP_ACCESS_EXECUTE 4
27
28class Win32MemMapView;
29
30//******************************************************************************
31//******************************************************************************
32class Win32MemMap
33{
34public:
35 Win32MemMap(HFILE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName);
36 ~Win32MemMap();
37
38 BOOL Init(HANDLE hMemMap);
39 BOOL flushView(ULONG offset, ULONG cbFlush);
40 LPVOID mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess);
41 BOOL unmapViewOfFile(Win32MemMapView *view);
42
43 HFILE getMapHandle() { return hMemMap; };
44 LPSTR getMemName() { return lpszMapName; };
45 DWORD getProtFlags() { return mProtFlags; };
46 LPVOID getMappingAddr() { return pMapping; };
47
48 void AddRef() { ++referenced; };
49 void Release() { if(--referenced == 0) delete this; };
50
51 BOOL commitPage(ULONG offset, BOOL fWriteAccess);
52
53static Win32MemMap *findMap(LPSTR lpszName);
54static Win32MemMap *findMap(ULONG address);
55
56//Should only be called in ExitProcess
57static void deleteAll();
58
59protected:
60 HFILE hMemMap, hMemFile;
61 ULONG mSize;
62 ULONG mProtFlags;
63 ULONG mMapAccess;
64 LPSTR lpszMapName;
65 void *pMapping;
66
67 ULONG nrMappings;
68
69 ULONG referenced;
70
71 VMutex mapMutex;
72
73private:
74 static Win32MemMap *memmaps;
75 Win32MemMap *next;
76};
77//******************************************************************************
78//Memory mapped file View Class
79//******************************************************************************
80class Win32MemMapView
81{
82public:
83 Win32MemMapView(Win32MemMap *map, ULONG offset, ULONG size, ULONG fdwAccess);
84 ~Win32MemMapView();
85
86 DWORD getAccessFlags() { return mfAccess; };
87 DWORD getSize() { return mSize; };
88 LPVOID getViewAddr() { return pMapView; };
89 ULONG getOffset() { return mOffset; };
90
91 BOOL everythingOk() { return errorState == 0; };
92
93Win32MemMap *getParentMap() { return mParentMap;};
94
95static void deleteView(Win32MemMap *map);
96static Win32MemMap *findMapByView(ULONG address, ULONG *offset, ULONG accessType, Win32MemMapView **pView=NULL);
97static Win32MemMapView *findView(LPVOID address);
98
99protected:
100 ULONG mSize, errorState;
101 ULONG mfAccess, mOffset;
102 void *pMapView;
103
104 Win32MemMap *mParentMap;
105
106private:
107 static Win32MemMapView *mapviews;
108 Win32MemMapView *next;
109
110 friend class Win32MemMap;
111};
112//******************************************************************************
113//******************************************************************************
114
115#endif //__MMAP_H__
Note: See TracBrowser for help on using the repository browser.