2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 Header file for file mapping functions.
25 #include "corunix.hpp"
26 #include <sys/param.h>
33 #define NO_INO ((ino_t)-1)
40 Initialize the critical sections.
43 TRUE if initialization succeeded
46 BOOL MAPInitialize( void );
52 Deletes the critical sections.
55 void MAPCleanup( void );
62 lpAddress: pointer to the starting memory location, not necessary
63 to be rounded to the page location
65 lpBuffer: if this function finds information about the specified address,
66 the information is stored in this struct
68 Note: This function is to be used in virtual.c
70 Returns TRUE if this function finds information about the specified address
73 BOOL MAPGetRegionInfo(LPVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer);
78 Map a PE format file into memory like Windows LoadLibrary() would do.
79 Doesn't apply base relocations if the function is relocated.
82 IN hFile - file to map
85 non-NULL - the base address of the mapped image
86 NULL - error, with last error set.
89 void * MAPMapPEFile(HANDLE hFile);
93 MAPUnmapPEFile - unmap a PE file, and remove it from the recorded list of PE files mapped
95 returns TRUE if successful, FALSE otherwise
97 BOOL MAPUnmapPEFile(LPCVOID lpAddress);
102 extern CObjectType otFileMapping;
104 #if ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
105 typedef struct _NativeMapHolder
107 Volatile<LONG> ref_count;
110 SIZE_T offset; /* for future use */
114 /* Process specific information. This
115 structure is not stored in shared memory.*/
121 // Each MVL entry holds a reference to its parent file
125 IPalObject *pFileMapping;
127 #if ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
128 NativeMapHolder * pNMHolder; /* Ref-counted holder for memory mapping */
129 dev_t MappedFileDevNum; /* ID of device containing the file to be mapped */
130 ino_t MappedFileInodeNum; /* Inode number of file to be mapped.
131 These two fields are used used to uniquely
132 identify files on systems that do not allow
133 more than one shared mmapping per region of
134 physical file, per process */
136 LPVOID lpAddress; /* The pointer to the mapped memory. */
137 SIZE_T NumberOfBytesToMap; /* Number of bytes to map. */
138 DWORD dwDesiredAccess; /* Desired access. */
139 LPVOID lpPEBaseAddress; /* If this mapping is part of a PE file mapping, this is the
140 base address pointer of the PE file (used to find all
141 parts of the PE file mapping to allow PE file unload).
142 Otherwise, it is NULL. */
143 } MAPPED_VIEW_LIST, * PMAPPED_VIEW_LIST;
145 class CFileMappingImmutableData
148 CHAR szFileName[MAXPATHLEN];
149 UINT MaxSize; // The max size of the file mapping object
150 DWORD flProtect; // Protection desired for the file view
151 BOOL bPALCreatedTempFile; // TRUE if it's a PAL created file
152 DWORD dwDesiredAccessWhenOpened; // FILE_MAP_WRITE etc
155 class CFileMappingProcessLocalData
158 INT UnixFd; /* File descriptor. */
160 #if ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
161 dev_t MappedFileDevNum; /* ID of device containing the file to be mapped */
162 ino_t MappedFileInodeNum; /* Inode number of file to be mapped.
163 These two fields are used used to uniquely
164 identify files on systems that do not allow
165 more than one shared mmapping per region of
166 physical file, per process */
171 InternalCreateFileMapping(
174 LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
176 DWORD dwMaximumSizeHigh,
177 DWORD dwMaximumSizeLow,
183 InternalOpenFileMapping(
185 DWORD dwDesiredAccess,
192 InternalMapViewOfFile(
194 HANDLE hFileMappingObject,
195 DWORD dwDesiredAccess,
196 DWORD dwFileOffsetHigh,
197 DWORD dwFileOffsetLow,
198 SIZE_T dwNumberOfBytesToMap,
199 LPVOID *ppvBaseAddress
203 InternalUnmapViewOfFile(
205 LPCVOID lpBaseAddress
210 #endif /* _PAL_MAP_H_ */