Rebase against eb5c1872540a71ebef4703387c11c414516233f4.

This commit is contained in:
Sebastian Lackner
2017-09-07 17:45:21 +02:00
parent 578128d012
commit 34f5330124
7 changed files with 90 additions and 86 deletions

View File

@@ -1,4 +1,4 @@
From 87487f38ad629bd54983bcef11a8a205e9da985a Mon Sep 17 00:00:00 2001
From a50d535e6d20143d4a8346e8377ee401d9b5ca9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sat, 4 Oct 2014 03:22:09 +0200
Subject: ntdll: Properly handle PAGE_WRITECOPY protection. (try 5)
@@ -9,10 +9,10 @@ For now, only enable it when a special environment variable is set.
1 file changed, 40 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 5c43d26..bf5bc22 100644
index 2d12a125a3e..84a7fecb5da 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -165,6 +165,21 @@ static const char *VIRTUAL_GetProtStr( BYTE prot )
@@ -206,6 +206,21 @@ static const char *VIRTUAL_GetProtStr( BYTE prot )
return buffer;
}
@@ -34,7 +34,7 @@ index 5c43d26..bf5bc22 100644
/***********************************************************************
* VIRTUAL_GetUnixProt
@@ -178,8 +193,19 @@ static int VIRTUAL_GetUnixProt( BYTE vprot )
@@ -219,8 +234,19 @@ static int VIRTUAL_GetUnixProt( BYTE vprot )
{
if (vprot & VPROT_READ) prot |= PROT_READ;
if (vprot & VPROT_WRITE) prot |= PROT_WRITE | PROT_READ;
@@ -55,48 +55,48 @@ index 5c43d26..bf5bc22 100644
if (vprot & VPROT_WRITEWATCH) prot &= ~PROT_WRITE;
}
if (!prot) prot = PROT_NONE;
@@ -1488,13 +1514,18 @@ NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err, BOOL on_signal_stack )
@@ -1625,13 +1651,18 @@ NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err, BOOL on_signal_stack )
{
void *page = ROUND_ADDR( addr, page_mask );
BYTE *vprot = &view->prot[((const char *)page - (const char *)view->base) >> page_shift];
BYTE vprot = get_page_vprot( view, page );
- if ((err & EXCEPTION_WRITE_FAULT) && (view->protect & VPROT_WRITEWATCH))
+ if (err & EXCEPTION_WRITE_FAULT)
{
- if (*vprot & VPROT_WRITEWATCH)
+ if ((view->protect & VPROT_WRITEWATCH) && (*vprot & VPROT_WRITEWATCH))
- if (vprot & VPROT_WRITEWATCH)
+ if ((view->protect & VPROT_WRITEWATCH) && (vprot & VPROT_WRITEWATCH))
{
*vprot &= ~VPROT_WRITEWATCH;
VIRTUAL_SetProt( view, page, page_size, *vprot );
set_page_vprot_bits( view, page, page_size, 0, VPROT_WRITEWATCH );
mprotect_range( view, page, page_size, 0, 0 );
}
+ if (*vprot & VPROT_WRITECOPY)
+ if (vprot & VPROT_WRITECOPY)
+ {
+ *vprot = (*vprot & ~VPROT_WRITECOPY) | VPROT_WRITE;
+ VIRTUAL_SetProt( view, page, page_size, *vprot );
+ set_page_vprot_bits( view, page, page_size, VPROT_WRITE, VPROT_WRITECOPY );
+ mprotect_range( view, page, page_size, 0, 0 );
+ }
/* ignore fault if page is writable now */
if (VIRTUAL_GetUnixProt( *vprot ) & PROT_WRITE) ret = STATUS_SUCCESS;
if (VIRTUAL_GetUnixProt( get_page_vprot( view, page )) & PROT_WRITE) ret = STATUS_SUCCESS;
}
@@ -1697,14 +1728,16 @@ SIZE_T virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_
@@ -1841,14 +1872,16 @@ SIZE_T CDECL wine_uninterrupted_write_memory( void *addr, const void *buffer, SI
* exception. Similar to virtual_handle_fault. */
if (!(VIRTUAL_GetUnixProt( *p ) & PROT_WRITE))
if (!(VIRTUAL_GetUnixProt( vprot ) & PROT_WRITE))
{
- if (!(view->protect & VPROT_WRITEWATCH))
- break;
-
- if (*p & VPROT_WRITEWATCH)
+ if ((view->protect & VPROT_WRITEWATCH) && (*p & VPROT_WRITEWATCH))
- if (vprot & VPROT_WRITEWATCH)
+ if ((view->protect & VPROT_WRITEWATCH) && (vprot & VPROT_WRITEWATCH))
{
*p &= ~VPROT_WRITEWATCH;
VIRTUAL_SetProt( view, page, page_size, *p );
set_page_vprot_bits( view, page, page_size, 0, VPROT_WRITEWATCH );
mprotect_range( view, page, page_size, 0, 0 );
}
+ if (*p & VPROT_WRITECOPY)
+ if (vprot & VPROT_WRITECOPY)
+ {
+ *p = (*p & ~VPROT_WRITECOPY) | VPROT_WRITE;
+ VIRTUAL_SetProt( view, page, page_size, *p );
+ set_page_vprot_bits( view, page, page_size, VPROT_WRITE, VPROT_WRITECOPY );
+ mprotect_range( view, page, page_size, 0, 0 );
+ }
/* ignore fault if page is writable now */
if (!(VIRTUAL_GetUnixProt( *p ) & PROT_WRITE))
if (!(VIRTUAL_GetUnixProt( get_page_vprot( view, page )) & PROT_WRITE))
break;
--
2.8.0
2.14.1