Index: trunk/src/kernel32/mmap.cpp
===================================================================
--- trunk/src/kernel32/mmap.cpp	(revision 21470)
+++ trunk/src/kernel32/mmap.cpp	(revision 21472)
@@ -35,5 +35,5 @@
 #include "oslibmem.h"
 #include <winimagepeldr.h>
-#include <custombuild.h> 
+#include <custombuild.h>
 #include "asmutil.h"
 
@@ -54,5 +54,5 @@
 //******************************************************************************
 //******************************************************************************
-void WIN32API SetCustomMMapSemName(LPSTR pszSemName) 
+void WIN32API SetCustomMMapSemName(LPSTR pszSemName)
 {
     pszMMapSemName = pszSemName;
@@ -79,5 +79,5 @@
 //******************************************************************************
 Win32MemMap::Win32MemMap(HANDLE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName)
-               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), 
+               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0),
                  image(0), pWriteBitmap(NULL), lpszFileName(NULL)
 {
@@ -105,5 +105,5 @@
 //******************************************************************************
 Win32MemMap::Win32MemMap(Win32PeLdrImage *pImage, ULONG baseAddress, ULONG size)
-               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), 
+               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0),
                  image(0), pWriteBitmap(NULL), lpszFileName(NULL)
 {
@@ -273,7 +273,7 @@
     dprintf(("Win32MemMap::commitRange %x (faultaddr %x)", pageAddr, lpPageFaultAddr));
 
-    if(fWriteAccess) 
+    if(fWriteAccess)
     {//writes are handled on a per-page basis
-        for(int i=0;i<nrpages;i++) 
+        for(int i=0;i<nrpages;i++)
         {
             if(commitPage(ulFaultAddr, offset, TRUE, 1) == FALSE) {
@@ -305,5 +305,5 @@
 //   FALSE                      - failure
 //
-// NOTE: 
+// NOTE:
 //   We handle only one pages for write access!
 //
@@ -327,5 +327,5 @@
   }
 
-  if(fWriteAccess && (mProtFlags & PAGE_WRITECOPY)) 
+  if(fWriteAccess && (mProtFlags & PAGE_WRITECOPY))
   {//this is a COW map, call commitGuardPage to handle write faults
       return commitGuardPage(ulFaultAddr, offset, fWriteAccess);
@@ -340,5 +340,5 @@
   if(fWriteAccess) {
       Win32MemMapView *view = Win32MemMapView::findView(ulFaultAddr);
-      if(view) { 
+      if(view) {
           if(!(view->getAccessFlags() & MEMMAP_ACCESS_WRITE)) {
               dprintf(("Write access for a readonly view!!"));
@@ -354,5 +354,5 @@
   int faultsize = nrpages*PAGE_SIZE;
 
-  if(fWriteAccess) 
+  if(fWriteAccess)
   {//write access needs special care, so do that on a per page basis
       dprintf(("Write access -> handle only one page"));
@@ -365,5 +365,5 @@
   }
 
-  while(faultsize) 
+  while(faultsize)
   {
         if(VirtualQuery((LPSTR)pageAddr, &memInfo, sizeof(MEMORY_BASIC_INFORMATION)) == 0) {
@@ -386,5 +386,5 @@
             updateViewPages(offset, memInfo.RegionSize, (fWriteAccess) ? PAGEVIEW_VIEW : PAGEVIEW_READONLY);
 
-            if(hMemFile != -1) 
+            if(hMemFile != -1)
             {//now read the page(s) from disk
                 DWORD size;
@@ -408,10 +408,10 @@
                     goto fail;
                 }
-            }            
-            //We set the protection flags to PAGE_READONLY, unless this pagefault 
+            }
+            //We set the protection flags to PAGE_READONLY, unless this pagefault
             //was due to a write access
             //This way we can track dirty pages which need to be flushed to
             //disk when FlushViewOfFile is called or the map is closed.
-            if(!fWriteAccess) 
+            if(!fWriteAccess)
             {
                 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, PAGE_READONLY, &oldProt) == FALSE) {
@@ -420,5 +420,5 @@
                 }
             }
-            else 
+            else
             {//make these pages as dirty
                 ULONG startPage  = (pageAddr - (ULONG)pMapping) >> PAGE_SHIFT;
@@ -431,11 +431,11 @@
                 markDirtyPages(startPage, nrPages);
 
-                //Write access means that the next time the corresponding COW page 
+                //Write access means that the next time the corresponding COW page
                 //is touched, we need to reload it. So set the GUARD flags.
                 updateViewPages(offset, memInfo.RegionSize, PAGEVIEW_GUARD);
             }
         }
-        else 
-        if(fWriteAccess) 
+        else
+        if(fWriteAccess)
         {
             //mark these pages as dirty
@@ -457,5 +457,5 @@
             updateViewPages(offset, memInfo.RegionSize, PAGEVIEW_VIEW);
 
-            //Write access means that the next time the corresponding COW page 
+            //Write access means that the next time the corresponding COW page
             //is touched, we need to reload it. So set the GUARD flags.
             updateViewPages(offset, memInfo.RegionSize, PAGEVIEW_GUARD);
@@ -519,5 +519,5 @@
    memcpy((LPVOID)pageAddr, (char *)pMapping+ulOffset, PAGE_SIZE);
 
-   if(fWriteAccess) 
+   if(fWriteAccess)
    {//copy on write; mark pages as private
         DWORD startpage = (ulOffset) >> PAGE_SHIFT;
@@ -526,5 +526,5 @@
 
         Win32MemMapView *view = Win32MemMapView::findView(ulFaultAddr);
-        if(view) 
+        if(view)
         {
             view->markCOWPages(startpage, 1);
@@ -532,5 +532,5 @@
         else DebugInt3(); //oh, oh
    }
-   else 
+   else
    {//read access; must set the map + all views to READONLY to track write access
 
@@ -574,13 +574,13 @@
     int localmaps;
 
-    if(views) 
+    if(views)
     {
         localmaps = Win32MemMapView::findViews(this, nrMappings, views);
-        if(localmaps <= nrMappings) 
+        if(localmaps <= nrMappings)
         {
-            for(int i=0;i<localmaps;i++) 
+            for(int i=0;i<localmaps;i++)
             {
                 views[i]->changePageFlags(offset, size, flags);
-            }           
+            }
         }
         else {
@@ -619,5 +619,5 @@
         dprintf(("ERROR: Win32MemMap::invalidatePages: VirtualFree failed!!"));
     }
-    //invalidate all shared COW pages too by setting the GUARD flag 
+    //invalidate all shared COW pages too by setting the GUARD flag
     //(which forces a resync the next time the app touches them)
     return updateViewPages(offset, size, PAGEVIEW_GUARD);
@@ -640,5 +640,5 @@
 
     //Memory has already been allocated for executable image maps (only used internally)
-    if(!pMapping && nrMappings == 0) 
+    if(!pMapping && nrMappings == 0)
     {//if not mapped, reserve/commit entire view
         //SvL: Always read/write access or else ReadFile will crash once we
@@ -648,5 +648,5 @@
         //     flag it will also crash)
         //NOTE: If this is ever changed, then we must update setProtFlags!!!!
-        
+
         //All named file mappings are shared (files & memory only)
         if(lpszMapName) {
@@ -687,5 +687,5 @@
     return TRUE;
 
-fail: 
+fail:
     return FALSE;
 }
@@ -702,5 +702,5 @@
 //                                FILE_MAP_WRITE, FILE_MAP_READ, FILE_MAP_COPY
 //                                FILE_MAP_ALL_ACCESS
-//                                
+//
 //
 // Returns:
@@ -723,7 +723,9 @@
     if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
         goto parmfail;
-    if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
+    // CreateFileMapping docs say that PAGE_WRITECOPY is equivalent to PAGE_READONLY and thus
+    // is okay for FILE_MAP_READ too
+    if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY|PAGE_WRITECOPY)))
         goto parmfail;
-    
+
     if (fdwAccess != FILE_MAP_ALL_ACCESS)
         if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
@@ -786,5 +788,5 @@
 
     view = Win32MemMapView::findView((ULONG)addr);
-    if(view == NULL) 
+    if(view == NULL)
         goto fail;
 
@@ -825,5 +827,5 @@
       goto parmfail;
 
-  if(viewaddr != MMAP_FLUSHVIEW_ALL) 
+  if(viewaddr != MMAP_FLUSHVIEW_ALL)
   {
       view = Win32MemMapView::findView(viewaddr);
@@ -854,5 +856,5 @@
 
   //Check the write page bitmap for dirty pages and write them to disk
-  while(cbFlush) 
+  while(cbFlush)
   {
       int startPage = offset >> PAGE_SHIFT;
@@ -944,9 +946,9 @@
   Win32MemMap *map = memmaps;
 
-  if(map != NULL) 
+  if(map != NULL)
   {
     while(map) {
         //TODO: we currently don't support sharing file maps between processes
-        if(map->mProcessId == processId && map->lpszFileName) 
+        if(map->mProcessId == processId && map->lpszFileName)
         {
             if(!strcmp(map->lpszFileName, szFileName))
@@ -1020,5 +1022,5 @@
   while(map) {
       nextmap = map->next;
-      if(map->getProcessId() == processId) 
+      if(map->getProcessId() == processId)
       {
           //delete map can delete multiple objects (duplicate memory map), so make
