The Use of PAGE_WRITECOPY

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

        - Microsoft Windows NT versions 3.1 and 3.5
    

The documentation to CreateFileMapping(), VirtualAlloc(), and VirtualProtect() indicates that the PAGE_WRITECOPY protection gives copy-on-write access to the committed region of pages. As it is, PAGE_WRITECOPY makes sense only in the context of file mapping, where you want to map something from the disk into your view and then modify the view without causing the data to go on the disk.

The only case where VirtualAlloc() should succeed with PAGE_WRITECOPY is the case where CreateFileMapping() is called with -1 and allocates memory with the SEC_RESERVE flag and later on, VirtualAlloc() is used to change this into MEM_COMMIT with a PAGE_WRITECOPY protection.

There is a bug in Windows NT 3.1 such that the following call to VirtualAlloc() will succeed:

   lpCommit = VirtualAlloc(lpvAddr, cbSize, MEM_COMMIT, PAGE_WRITECOPY);

This call will fail under Windows NT 3.5.

NOTE: lpvAddr is a pointer to memory that was allocated with MEM_RESERVE and PAGE_NOACCESS.

One case where this might be useful is when emulating the UNIX fork command. Emulating fork behavior would involve creating instance data and using threads or multiple processes.


Additional reference words: 3.10 3.50
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.