From 961363c939e566a74b9343ad2e328b1f6fce7361 Mon Sep 17 00:00:00 2001
From: Andrew Wesie <awesie@gmail.com>
Date: Fri, 24 Apr 2020 14:55:17 -0500
Subject: [PATCH] ntdll: Report unmodified WRITECOPY pages as shared.

We also need to clear the modified bit after we clear memory in map_image to
match the behavior of Windows.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48665
Signed-off-by: Andrew Wesie <awesie@gmail.com>
---
 dlls/ntdll/unix/virtual.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 16cfa8bda2d7..8b3f93b70d41 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -2174,6 +2174,8 @@ static NTSTATUS map_image_into_view( struct file_view *view, int fd, void *orig_
                            ptr + sec->VirtualAddress + file_size,
                            ptr + sec->VirtualAddress + end );
             memset( ptr + sec->VirtualAddress + file_size, 0, end - file_size );
+            /* clear WRITTEN mark so QueryVirtualMemory returns correct values */
+            set_page_vprot_bits( ptr + sec->VirtualAddress + file_size, 1, 0, VPROT_WRITTEN );
         }
     }
 
@@ -3937,7 +3939,7 @@ static NTSTATUS get_working_set_ex( HANDLE process, LPCVOID addr,
                 (vprot & VPROT_COMMITTED))
         {
             p->VirtualAttributes.Valid = !(vprot & VPROT_GUARD) && (vprot & 0x0f) && (pagemap >> 63);
-            p->VirtualAttributes.Shared = !is_view_valloc( view ) && ((pagemap >> 61) & 1);
+            p->VirtualAttributes.Shared = (!is_view_valloc( view ) && ((pagemap >> 61) & 1)) || ((view->protect & VPROT_WRITECOPY) && !(vprot & VPROT_WRITTEN));
             if (p->VirtualAttributes.Shared && p->VirtualAttributes.Valid)
                 p->VirtualAttributes.ShareCount = 1; /* FIXME */
             if (p->VirtualAttributes.Valid)
-- 
2.20.1

