INFO: CreateFileMapping() SEC_* Flags

Article translations Article translations
Article ID: 108231 - View products that this article applies to.
This article was previously published under Q108231
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SUMMARY

The definition of CreateFileMapping() is as follows:

   HANDLE CreateFileMapping(hFile, lpsa, fdwProtect, dwMaximumSizeHigh,
				
dwMaximumSizeLow, lpszMapName)


   HANDLE hFile;
   LPSECURITY_ATTRIBUTES lpsa;
   DWORD fdwProtect;
   DWORD dwMaximumSizeHigh;
   DWORD dwMaximumSizeLow;
   LPCTSTR lpszMapName;
				


The following flags are four possible values for the parameter fdwProtect:

   SEC_COMMIT
				
All pages of a section are to be set to the commit state.
   SEC_IMAGE
				
The file specified for a section's file mapping is an executable image file.
   SEC_NOCACHE
				
All pages of a section are to be set as noncacheable.
   SEC_RESERVE
				
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().

MORE INFORMATION

Windows NT



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.

Windows 95



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.

Properties

Article ID: 108231 - Last Review: February 24, 2014 - Revision: 3.2
APPLIES TO
  • Microsoft Win32 Application Programming Interface, when used with:
    • Microsoft Windows NT Server 3.5
    • Microsoft Windows NT Server 3.51
    • Microsoft Windows NT Workstation 3.5
    • Microsoft Windows NT Workstation 3.51
    • Microsoft Windows 95
Keywords: 
kbnosurvey kbarchive kbinfo KB108231

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com