1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*++ |
6 | |
7 | |
8 | |
9 | Module Name: |
10 | |
11 | include/pal/map.hpp |
12 | |
13 | Abstract: |
14 | |
15 | Header file for file mapping functions. |
16 | |
17 | |
18 | |
19 | --*/ |
20 | |
21 | #ifndef _PAL_MAP_H_ |
22 | #define _PAL_MAP_H_ |
23 | |
24 | #include "corunix.hpp" |
25 | #include <sys/param.h> |
26 | |
27 | extern "C" |
28 | { |
29 | #include "list.h" |
30 | |
31 | #ifndef NO_INO |
32 | #define NO_INO ((ino_t)-1) |
33 | #endif |
34 | |
35 | /*++ |
36 | Function : |
37 | MapInitialize |
38 | |
39 | Initialize the critical sections. |
40 | |
41 | Return value: |
42 | TRUE if initialization succeeded |
43 | FALSE otherwise |
44 | --*/ |
45 | BOOL MAPInitialize( void ); |
46 | |
47 | /*++ |
48 | Function : |
49 | MapCleanup |
50 | |
51 | Deletes the critical sections. |
52 | |
53 | --*/ |
54 | void MAPCleanup( void ); |
55 | |
56 | /*++ |
57 | Function : |
58 | MAPGetRegionInfo |
59 | |
60 | Parameters: |
61 | lpAddress: pointer to the starting memory location, not necessary |
62 | to be rounded to the page location |
63 | |
64 | lpBuffer: if this function finds information about the specified address, |
65 | the information is stored in this struct |
66 | |
67 | Note: This function is to be used in virtual.c |
68 | |
69 | Returns TRUE if this function finds information about the specified address |
70 | --*/ |
71 | |
72 | BOOL MAPGetRegionInfo(LPVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer); |
73 | |
74 | /*++ |
75 | MAPMapPEFile - |
76 | |
77 | Map a PE format file into memory like Windows LoadLibrary() would do. |
78 | Doesn't apply base relocations if the function is relocated. |
79 | |
80 | Parameters: |
81 | IN hFile - file to map |
82 | |
83 | Return value: |
84 | non-NULL - the base address of the mapped image |
85 | NULL - error, with last error set. |
86 | --*/ |
87 | |
88 | void * MAPMapPEFile(HANDLE hFile); |
89 | |
90 | /*++ |
91 | Function : |
92 | MAPUnmapPEFile - unmap a PE file, and remove it from the recorded list of PE files mapped |
93 | |
94 | returns TRUE if successful, FALSE otherwise |
95 | --*/ |
96 | BOOL MAPUnmapPEFile(LPCVOID lpAddress); |
97 | } |
98 | |
99 | namespace CorUnix |
100 | { |
101 | extern CObjectType otFileMapping; |
102 | |
103 | #if ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS |
104 | typedef struct _NativeMapHolder |
105 | { |
106 | Volatile<LONG> ref_count; |
107 | LPVOID address; |
108 | SIZE_T size; |
109 | SIZE_T offset; /* for future use */ |
110 | } NativeMapHolder; |
111 | #endif |
112 | |
113 | /* Process specific information. This |
114 | structure is not stored in shared memory.*/ |
115 | typedef struct _MVL |
116 | { |
117 | LIST_ENTRY Link; |
118 | |
119 | // |
120 | // Each MVL entry holds a reference to its parent file |
121 | // mapping object. |
122 | // |
123 | |
124 | IPalObject *pFileMapping; |
125 | |
126 | #if ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS |
127 | NativeMapHolder * pNMHolder; /* Ref-counted holder for memory mapping */ |
128 | dev_t MappedFileDevNum; /* ID of device containing the file to be mapped */ |
129 | ino_t MappedFileInodeNum; /* Inode number of file to be mapped. |
130 | These two fields are used used to uniquely |
131 | identify files on systems that do not allow |
132 | more than one shared mmapping per region of |
133 | physical file, per process */ |
134 | #endif |
135 | LPVOID lpAddress; /* The pointer to the mapped memory. */ |
136 | SIZE_T NumberOfBytesToMap; /* Number of bytes to map. */ |
137 | DWORD dwDesiredAccess; /* Desired access. */ |
138 | LPVOID lpPEBaseAddress; /* If this mapping is part of a PE file mapping, this is the |
139 | base address pointer of the PE file (used to find all |
140 | parts of the PE file mapping to allow PE file unload). |
141 | Otherwise, it is NULL. */ |
142 | } MAPPED_VIEW_LIST, * PMAPPED_VIEW_LIST; |
143 | |
144 | class CFileMappingImmutableData |
145 | { |
146 | public: |
147 | CHAR *lpFileName; |
148 | UINT MaxSize; // The max size of the file mapping object |
149 | DWORD flProtect; // Protection desired for the file view |
150 | BOOL bPALCreatedTempFile; // TRUE if it's a PAL created file |
151 | DWORD dwDesiredAccessWhenOpened; // FILE_MAP_WRITE etc |
152 | }; |
153 | |
154 | class CFileMappingProcessLocalData |
155 | { |
156 | public: |
157 | INT UnixFd; /* File descriptor. */ |
158 | |
159 | #if ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS |
160 | dev_t MappedFileDevNum; /* ID of device containing the file to be mapped */ |
161 | ino_t MappedFileInodeNum; /* Inode number of file to be mapped. |
162 | These two fields are used used to uniquely |
163 | identify files on systems that do not allow |
164 | more than one shared mmapping per region of |
165 | physical file, per process */ |
166 | #endif |
167 | }; |
168 | |
169 | PAL_ERROR |
170 | InternalCreateFileMapping( |
171 | CPalThread *pThread, |
172 | HANDLE hFile, |
173 | LPSECURITY_ATTRIBUTES lpFileMappingAttributes, |
174 | DWORD flProtect, |
175 | DWORD dwMaximumSizeHigh, |
176 | DWORD dwMaximumSizeLow, |
177 | LPCWSTR lpName, |
178 | HANDLE *phMapping |
179 | ); |
180 | |
181 | PAL_ERROR |
182 | InternalMapViewOfFile( |
183 | CPalThread *pThread, |
184 | HANDLE hFileMappingObject, |
185 | DWORD dwDesiredAccess, |
186 | DWORD dwFileOffsetHigh, |
187 | DWORD dwFileOffsetLow, |
188 | SIZE_T dwNumberOfBytesToMap, |
189 | LPVOID *ppvBaseAddress |
190 | ); |
191 | |
192 | PAL_ERROR |
193 | InternalUnmapViewOfFile( |
194 | CPalThread *pThread, |
195 | LPCVOID lpBaseAddress |
196 | ); |
197 | |
198 | } |
199 | |
200 | #endif /* _PAL_MAP_H_ */ |
201 | |