Rebase against 6a7bfbab10d653f6724e2917e0552515520e4fb3.

This commit is contained in:
Elizabeth Figura
2024-08-22 19:07:19 -05:00
parent ae46f56f2c
commit 5fad8dd101
10 changed files with 93 additions and 84 deletions

View File

@@ -1,4 +1,4 @@
From 4a297f731112822e51086826f975bf5db9178e52 Mon Sep 17 00:00:00 2001
From 8ec23a75cf45f9b2841b76504c827d368682c126 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: [PATCH] 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, 39 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index cf0c1598720..ff585c647bc 100644
index b108e49ad4d..70211bbfa3d 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -495,6 +495,21 @@ static void reserve_area( void *addr, void *end )
@@ -506,6 +506,21 @@ static void reserve_area( void *addr, void *end )
#endif /* __APPLE__ */
}
@@ -34,7 +34,7 @@ index cf0c1598720..ff585c647bc 100644
static void mmap_init( const struct preload_info *preload_info )
{
@@ -852,8 +867,19 @@ static int get_unix_prot( BYTE vprot )
@@ -1136,8 +1151,19 @@ static int get_unix_prot( BYTE vprot )
{
if (vprot & VPROT_READ) prot |= PROT_READ;
if (vprot & VPROT_WRITE) prot |= PROT_WRITE | PROT_READ;
@@ -55,7 +55,7 @@ index cf0c1598720..ff585c647bc 100644
if (vprot & VPROT_WRITEWATCH) prot &= ~PROT_WRITE;
}
if (!prot) prot = PROT_NONE;
@@ -1457,7 +1483,7 @@ static void update_write_watches( void *base, size_t size, size_t accessed_size
@@ -1817,7 +1843,7 @@ static void update_write_watches( void *base, size_t size, size_t accessed_size
{
TRACE( "updating watch %p-%p-%p\n", base, (char *)base + accessed_size, (char *)base + size );
/* clear write watch flag on accessed pages */
@@ -64,9 +64,9 @@ index cf0c1598720..ff585c647bc 100644
/* restore page protections on the entire range */
mprotect_range( base, size, 0, 0 );
}
@@ -2985,12 +3011,13 @@ NTSTATUS virtual_handle_fault( void *addr, DWORD err, void *stack )
set_page_vprot_bits( page, page_size, 0, VPROT_WRITEWATCH );
mprotect_range( page, page_size, 0, 0 );
@@ -4065,12 +4091,13 @@ NTSTATUS virtual_handle_fault( EXCEPTION_RECORD *rec, void *stack )
mprotect_range( page, page_size, 0, 0 );
}
}
- /* ignore fault if page is writable now */
- if (get_unix_prot( get_page_vprot( page )) & PROT_WRITE)
@@ -81,8 +81,8 @@ index cf0c1598720..ff585c647bc 100644
+ if (get_unix_prot( get_page_vprot( page ) ) & PROT_WRITE) ret = STATUS_SUCCESS;
}
mutex_unlock( &virtual_mutex );
return ret;
@@ -3067,11 +3094,16 @@ static NTSTATUS check_write_access( void *base, size_t size, BOOL *has_write_wat
rec->ExceptionCode = ret;
@@ -4144,11 +4171,16 @@ static NTSTATUS check_write_access( void *base, size_t size, BOOL *has_write_wat
{
BYTE vprot = get_page_vprot( addr + i );
if (vprot & VPROT_WRITEWATCH) *has_write_watch = TRUE;
@@ -101,5 +101,5 @@ index cf0c1598720..ff585c647bc 100644
}
--
2.28.0
2.45.2

View File

@@ -1,4 +1,4 @@
From e00479d767bf9bbb480be7b5c75dbd55812feb4d Mon Sep 17 00:00:00 2001
From 10f273da9caa0b7c814f46b76279065a956393af 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.
@@ -8,11 +8,11 @@ read-write page.
Signed-off-by: Andrew Wesie <awesie@gmail.com>
---
dlls/ntdll/unix/virtual.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
dlls/ntdll/unix/virtual.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 75d5a3fc966..c91484432c1 100644
index 5eadabf7dca..58fd4d0edfc 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -122,6 +122,7 @@ struct file_view
@@ -23,7 +23,7 @@ index 75d5a3fc966..c91484432c1 100644
/* per-mapping protection flags */
#define VPROT_ARM64EC 0x0100 /* view may contain ARM64EC code */
#define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */
@@ -1127,7 +1128,7 @@ static int get_unix_prot( BYTE vprot )
@@ -1155,7 +1156,7 @@ static int get_unix_prot( BYTE vprot )
#if defined(__i386__)
if (vprot & VPROT_WRITECOPY)
{
@@ -32,7 +32,7 @@ index 75d5a3fc966..c91484432c1 100644
prot = (prot & ~PROT_WRITE) | PROT_READ;
else
prot |= PROT_WRITE | PROT_READ;
@@ -1641,7 +1642,11 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
@@ -1672,7 +1673,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 )
{
@@ -45,7 +45,12 @@ index 75d5a3fc966..c91484432c1 100644
if (vprot & VPROT_GUARD) ret |= PAGE_GUARD;
if (map_prot & SEC_NOCACHE) ret |= PAGE_NOCACHE;
return ret;
@@ -1752,12 +1757,21 @@ static BOOL set_vprot( struct file_view *view, void *base, size_t size, BYTE vpr
@@ -1778,16 +1783,29 @@ static void mprotect_range( void *base, size_t size, BYTE set, BYTE clear )
*/
static BOOL set_vprot( struct file_view *view, void *base, size_t size, BYTE vprot )
{
+ int unix_prot;
+
if (view->protect & VPROT_WRITEWATCH)
{
/* each page may need different protections depending on write watch flag */
@@ -54,13 +59,17 @@ index 75d5a3fc966..c91484432c1 100644
mprotect_range( base, size, 0, 0 );
return TRUE;
}
+
if (enable_write_exceptions && is_vprot_exec_write( vprot )) vprot |= VPROT_WRITEWATCH;
- if (mprotect_exec( base, size, get_unix_prot(vprot) )) return FALSE;
- set_page_vprot( base, size, vprot );
+ unix_prot = get_unix_prot(vprot);
+
+ /* 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 );
+ if (mprotect_exec( base, size, unix_prot )) return FALSE;
+ /* each page may need different protections depending on writecopy */
+ set_page_vprot_bits( base, size, vprot, ~vprot & ~VPROT_WRITTEN );
+ if (vprot & VPROT_WRITECOPY)
@@ -69,7 +78,7 @@ index 75d5a3fc966..c91484432c1 100644
return TRUE;
}
@@ -3739,7 +3753,7 @@ NTSTATUS virtual_handle_fault( void *addr, DWORD err, void *stack )
@@ -4093,7 +4111,7 @@ NTSTATUS virtual_handle_fault( EXCEPTION_RECORD *rec, void *stack )
}
if (vprot & VPROT_WRITECOPY)
{
@@ -79,5 +88,5 @@ index 75d5a3fc966..c91484432c1 100644
}
/* ignore fault if page is writable now */
--
2.40.1
2.45.2

View File

@@ -1,4 +1,4 @@
From f26f4f9338473fee2ad3901fe5b259ac26e66f3c Mon Sep 17 00:00:00 2001
From 1d8b9ce07aaafd3184a118c8d986b54617571c7b Mon Sep 17 00:00:00 2001
From: Andrew Wesie <awesie@gmail.com>
Date: Tue, 28 Apr 2020 03:27:16 -0500
Subject: [PATCH] ntdll: Fallback to copy pages for WRITECOPY.
@@ -16,12 +16,12 @@ Signed-off-by: Andrew Wesie <awesie@gmail.com>
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 8346baf77a9..457468b47d9 100644
index 71fe33cdb0e..ba5701d7bfe 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -1587,8 +1587,9 @@ static BOOL set_vprot( struct file_view *view, void *base, size_t size, BYTE vpr
return TRUE;
}
@@ -1796,8 +1796,9 @@ static BOOL set_vprot( struct file_view *view, void *base, size_t size, BYTE vpr
if (enable_write_exceptions && is_vprot_exec_write( vprot )) vprot |= VPROT_WRITEWATCH;
unix_prot = get_unix_prot(vprot);
- /* check that we can map this memory with PROT_WRITE since we cannot fail later */
- if (vprot & VPROT_WRITECOPY)
@@ -31,9 +31,9 @@ index 8346baf77a9..457468b47d9 100644
unix_prot |= PROT_WRITE;
if (mprotect_exec( base, size, unix_prot )) return FALSE;
@@ -3335,10 +3336,26 @@ NTSTATUS virtual_handle_fault( void *addr, DWORD err, void *stack )
set_page_vprot_bits( page, page_size, 0, VPROT_WRITEWATCH );
mprotect_range( page, page_size, 0, 0 );
@@ -4111,10 +4112,26 @@ NTSTATUS virtual_handle_fault( EXCEPTION_RECORD *rec, void *stack )
mprotect_range( page, page_size, 0, 0 );
}
}
- if (vprot & VPROT_WRITECOPY)
+ if ((vprot & VPROT_WRITECOPY) && (vprot & VPROT_COMMITTED))
@@ -61,5 +61,5 @@ index 8346baf77a9..457468b47d9 100644
/* ignore fault if page is writable now */
if (get_unix_prot( get_page_vprot( page ) ) & PROT_WRITE) ret = STATUS_SUCCESS;
--
2.30.2
2.45.2