## INFO: The Use of PAGE_WRITECOPY

Q105532

The information in this article applies to:

- Microsoft Win32 Application Programming Interface (API), used with:
  - the operating system: Microsoft Windows NT, versions 3.1, 3.5, 4.0
  - the operating system: Microsoft Windows 2000

## SUMMARY

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 INVALID_HANDLE_VALUE 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 any other versions of Windows NT.
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 query words: 3.10 3.50

Keywords : kbAPI kbKernBase kbMemory kbOSWin2000 kbDSupport kbGrpDSKernBase
Issue type : kbinfo
Technology : kbAudDeveloper kbWin32sSearch kbWin32API

Last Reviewed: October 27, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use.