Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2004-07-15 21:00:44 +0400
committerCorinna Vinschen <corinna@vinschen.de>2004-07-15 21:00:44 +0400
commit0c0ad23a2c21053562f971b133bd1b0fba15a66d (patch)
tree0616616a67e6dde225a170f1d4d2c7d624d0b60e /winsup/cygwin/mmap.cc
parent4243412aa5a9443a696cba6198a0daac3100ef3c (diff)
* mmap.cc (mprotect): When MAP_WRITE protection is requested, use
READWRITE or WRITECOPY protection, whatever has been used when the page has been allocated initially.
Diffstat (limited to 'winsup/cygwin/mmap.cc')
-rw-r--r--winsup/cygwin/mmap.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index e2a25de52..16611480c 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -786,15 +786,31 @@ mprotect (void *addr, size_t len, int prot)
return 0;
}
+ /* If write protection is requested, check if the page was
+ originally protected writecopy. In this case call VirtualProtect
+ requesting PAGE_WRITECOPY, otherwise the VirtualProtect will fail
+ on NT version >= 5.0 */
+ bool writecopy = false;
+ if (prot & PROT_WRITE)
+ {
+ MEMORY_BASIC_INFORMATION mbi;
+ if (VirtualQuery (addr, &mbi, sizeof mbi))
+ {
+ if (mbi.AllocationProtect == PAGE_WRITECOPY
+ || mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY)
+ writecopy = true;
+ }
+ }
+
switch (prot)
{
case PROT_READ | PROT_WRITE | PROT_EXEC:
case PROT_WRITE | PROT_EXEC:
- new_prot = PAGE_EXECUTE_READWRITE;
+ new_prot = writecopy ? PAGE_EXECUTE_WRITECOPY : PAGE_EXECUTE_READWRITE;
break;
case PROT_READ | PROT_WRITE:
case PROT_WRITE:
- new_prot = PAGE_READWRITE;
+ new_prot = writecopy ? PAGE_WRITECOPY : PAGE_READWRITE;
break;
case PROT_READ | PROT_EXEC:
new_prot = PAGE_EXECUTE_READ;