From af11491f7c97d28d0227dac16df5cffbb99337ca Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 18 Dec 2011 04:55:11 +0000 Subject: [PATCH] [NTOSKRNL] - Fix COW file mappings (modifications to the mappings no longer change the file on disk) - Fixes bug #4308 svn path=/trunk/; revision=54682 --- reactos/ntoskrnl/mm/section.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index 60e4918b20d..860569a1c1e 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -3165,7 +3165,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject, Segment->Protection = SectionPageProtection; Segment->Flags = MM_DATAFILE_SEGMENT; Segment->Characteristics = 0; - Segment->WriteCopy = FALSE; + Segment->WriteCopy = (SectionPageProtection & (PAGE_WRITECOPY | PAGE_EXECUTE_WRITECOPY)); if (AllocationAttributes & SEC_RESERVE) { Segment->Length = Segment->RawLength = 0; @@ -4059,6 +4059,23 @@ MmMapViewOfSegment(PMMSUPPORT AddressSpace, NTSTATUS Status; PHYSICAL_ADDRESS BoundaryAddressMultiple; + if (Segment->WriteCopy) + { + /* We have to do this because the not present fault + * and access fault handlers depend on the protection + * that should be granted AFTER the COW fault takes + * place to be in Region->Protect. The not present fault + * handler changes this to the correct protection for COW when + * mapping the pages into the process's address space. If a COW + * fault takes place, the access fault handler sets the page protection + * to these values for the newly copied pages + */ + if (Protect == PAGE_WRITECOPY) + Protect = PAGE_READWRITE; + else if (Protect == PAGE_EXECUTE_WRITECOPY) + Protect = PAGE_EXECUTE_READWRITE; + } + BoundaryAddressMultiple.QuadPart = 0; Status = MmCreateMemoryArea(AddressSpace,