From c2cd9abf312b20deb71f87aae05329259c54383f Mon Sep 17 00:00:00 2001
From: Roman Dadkov <romand@etersoft.ru>
Date: Fri, 14 Dec 2012 14:12:26 +0400
Subject: [PATCH] kernel32: Fix access flags to page protection mapping in
 MapViewOfFileEx.

---
 dlls/kernel32/virtual.c | 14 ++++++++++----
 dlls/ntdll/virtual.c    |  2 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel32/virtual.c b/dlls/kernel32/virtual.c
index a15b124..e64f7bf 100644
--- a/dlls/kernel32/virtual.c
+++ b/dlls/kernel32/virtual.c
@@ -557,15 +557,21 @@ LPVOID WINAPI MapViewOfFileEx( HANDLE handle, DWORD access,
     NTSTATUS status;
     LARGE_INTEGER offset;
     ULONG protect;
+    BOOL exec;
 
     offset.u.LowPart  = offset_low;
     offset.u.HighPart = offset_high;
 
-    if (access & FILE_MAP_WRITE) protect = PAGE_READWRITE;
-    else if (access & FILE_MAP_COPY) protect = PAGE_WRITECOPY;
-    else protect = PAGE_READONLY;
+    exec = access & FILE_MAP_EXECUTE;
+    access &= ~FILE_MAP_EXECUTE;
 
-    if (access & FILE_MAP_EXECUTE) protect <<= 4;
+    if (access == FILE_MAP_COPY)
+        protect = exec ? PAGE_EXECUTE_WRITECOPY : PAGE_WRITECOPY;
+    else if (access & FILE_MAP_WRITE)
+        protect = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
+    else if (access & FILE_MAP_READ)
+        protect = exec ? PAGE_EXECUTE_READ : PAGE_READONLY;
+    else protect = PAGE_NOACCESS;
 
     if ((status = NtMapViewOfSection( handle, GetCurrentProcess(), &addr, 0, 0, &offset,
                                       &count, ViewShare, 0, protect )) < 0)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 9a68f20..51de118 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -2512,7 +2512,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
     switch(protect)
     {
     case PAGE_NOACCESS:
-        access = 0;
+        access = SECTION_MAP_READ;
         break;
     case PAGE_READWRITE:
     case PAGE_EXECUTE_READWRITE:
-- 
1.7.12.4
