CreateFileMapping() SEC_* Flags

Last reviewed: November 2, 1995
Article ID: Q108231
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1, 3.5, and 3.51
        - Microsoft Windows 95 version 4.0
    

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.


Additional reference words: 3.10 3.50 4.00
KBCategory: kbprg
KBSubcategory: BseMm


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.