mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2024-11-21 16:46:54 -08:00
84 lines
3.3 KiB
Diff
84 lines
3.3 KiB
Diff
From 4785271b7201cd43778befdf15029f858d2d25e9 Mon Sep 17 00:00:00 2001
|
|
From: Andrew Wesie <awesie@gmail.com>
|
|
Date: Fri, 24 Apr 2020 14:55:14 -0500
|
|
Subject: [PATCH] ntdll: Track if a WRITECOPY page has been modified.
|
|
|
|
Once a WRITECOPY page is modified, it should be mapped as if it is a normal
|
|
read-write page.
|
|
|
|
Signed-off-by: Andrew Wesie <awesie@gmail.com>
|
|
---
|
|
dlls/ntdll/unix/virtual.c | 24 +++++++++++++++++++-----
|
|
1 file changed, 19 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
|
|
index bf77d534049..c3c8f2d1d5b 100644
|
|
--- a/dlls/ntdll/unix/virtual.c
|
|
+++ b/dlls/ntdll/unix/virtual.c
|
|
@@ -125,6 +125,7 @@ struct file_view
|
|
#define VPROT_GUARD 0x10
|
|
#define VPROT_COMMITTED 0x20
|
|
#define VPROT_WRITEWATCH 0x40
|
|
+#define VPROT_WRITTEN 0x80
|
|
/* per-mapping protection flags */
|
|
#define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */
|
|
|
|
@@ -1115,7 +1116,7 @@ static int get_unix_prot( BYTE vprot )
|
|
#if defined(__i386__)
|
|
if (vprot & VPROT_WRITECOPY)
|
|
{
|
|
- if (experimental_WRITECOPY())
|
|
+ if (experimental_WRITECOPY() && !(vprot & VPROT_WRITTEN))
|
|
prot = (prot & ~PROT_WRITE) | PROT_READ;
|
|
else
|
|
prot |= PROT_WRITE | PROT_READ;
|
|
@@ -1677,7 +1678,11 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
|
|
*/
|
|
static DWORD get_win32_prot( BYTE vprot, unsigned int map_prot )
|
|
{
|
|
- DWORD ret = VIRTUAL_Win32Flags[vprot & 0x0f];
|
|
+ DWORD ret;
|
|
+
|
|
+ if ((vprot & VPROT_WRITECOPY) && (vprot & VPROT_WRITTEN))
|
|
+ vprot = (vprot & ~VPROT_WRITECOPY) | VPROT_WRITE;
|
|
+ ret = VIRTUAL_Win32Flags[vprot & 0x0f];
|
|
if (vprot & VPROT_GUARD) ret |= PAGE_GUARD;
|
|
if (map_prot & SEC_NOCACHE) ret |= PAGE_NOCACHE;
|
|
return ret;
|
|
@@ -1788,12 +1793,21 @@ static BOOL set_vprot( struct file_view *view, void *base, size_t size, BYTE vpr
|
|
if (view->protect & VPROT_WRITEWATCH)
|
|
{
|
|
/* each page may need different protections depending on write watch flag */
|
|
- set_page_vprot_bits( base, size, vprot & ~VPROT_WRITEWATCH, ~vprot & ~VPROT_WRITEWATCH );
|
|
+ set_page_vprot_bits( base, size, vprot & ~VPROT_WRITEWATCH, ~vprot & ~(VPROT_WRITEWATCH|VPROT_WRITTEN) );
|
|
mprotect_range( base, size, 0, 0 );
|
|
return TRUE;
|
|
}
|
|
+
|
|
+ /* check that we can map this memory with PROT_WRITE since we cannot fail later */
|
|
+ if (vprot & VPROT_WRITECOPY)
|
|
+ unix_prot |= PROT_WRITE;
|
|
+
|
|
if (mprotect_exec( base, size, unix_prot )) return FALSE;
|
|
- set_page_vprot( base, size, vprot );
|
|
+ /* each page may need different protections depending on writecopy */
|
|
+ set_page_vprot_bits( base, size, vprot, ~vprot & ~VPROT_WRITTEN );
|
|
+ if (vprot & VPROT_WRITECOPY)
|
|
+ mprotect_range( base, size, 0, 0 );
|
|
+
|
|
return TRUE;
|
|
}
|
|
|
|
@@ -3365,7 +3379,7 @@ NTSTATUS virtual_handle_fault( void *addr, DWORD err, void *stack )
|
|
}
|
|
if (vprot & VPROT_WRITECOPY)
|
|
{
|
|
- set_page_vprot_bits( page, page_size, VPROT_WRITE, VPROT_WRITECOPY );
|
|
+ set_page_vprot_bits( page, page_size, VPROT_WRITE | VPROT_WRITTEN, VPROT_WRITECOPY );
|
|
mprotect_range( page, page_size, 0, 0 );
|
|
}
|
|
/* ignore fault if page is writable now */
|
|
--
|
|
2.33.0
|
|
|