Article ID: 108231 - View products that this article applies to.
This article was previously published under Q108231
The definition of CreateFileMapping() is as follows:
HANDLE CreateFileMapping(hFile, lpsa, fdwProtect, dwMaximumSizeHigh,
HANDLE hFile; LPSECURITY_ATTRIBUTES lpsa; DWORD fdwProtect; DWORD dwMaximumSizeHigh; DWORD dwMaximumSizeLow; LPCTSTR lpszMapName;
The following flags are four possible values for the parameter fdwProtect:
All pages of a section are to be set to the commit state.
The file specified for a section's file mapping is an executable image file.
All pages of a section are to be set as noncacheable.
All pages of a section are to be set to the reserved state.
If none of these flags are specified, SEC_COMMIT is the default. This behaves the same way as MEM_COMMIT in VirtualAlloc().
The SEC_RESERVE flag is intended for file mappings that are backed by the paging file, and therefore use SEC_RESERVE only when hFile is -1. The pages are reserved just as they are when the MEM_RESERVE flag is used in VirtualAlloc(). The pages can be committed by subsequently using the VirtualAlloc() application programming interface (API), specifying MEM_COMMIT. Once committed, these pages cannot be decommitted.
The SEC_NOCACHE flag is intended for architectures that require various locking structures to be located in memory that is not ever fetched into the CPU cache. On x86 and MIPS machines, use of this flag just slows down the performance because the hardware keeps the cache coherent. Certain device drivers may require noncached data so that programs can write through to the physical memory. SEC_NOCACHE requires that either SEC_RESERVE or SEC_COMMIT be used in addition to SEC_NOCACHE.
The SEC_IMAGE flag indicates that the file handle points to an executable file, and it should be loaded as such. The mapping information and file protection are taken from the image file, and therefore no other options are allowed when SEC_IMAGE is used.
Under Windows NT, the Win32 loader simply sits on top of the memory mapped file subsystem, and so when the loader needs to load a PE executable, it simply calls down into the existing memory mapped file code. Therefore, it is extremely easy for to support SEC_IMAGE in CreateFileMapping() under Windows NT.
In Windows 95, the loader is more complex and the memory mapped files are simple and only support the bare minimum of functionality to make the existing MapViewOfFile() work. Therefore, Windows 95 does not support SEC_IMAGE. There is support for SEC_NOCACHE, SEC_RESERVE and SEC_COMMIT.
Article ID: 108231 - Last Review: November 21, 2006 - Revision: 3.2
Contact us for more help
Connect with Answer Desk for expert help.