[NTOS:MM]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Mon, 9 Jun 2014 18:21:03 +0000 (18:21 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Mon, 9 Jun 2014 18:21:03 +0000 (18:21 +0000)
MmUnmapViewOfCacheSegment expects DeleteInProgress to be FALSE and the address space to be unlocked.
Allow unmapping memory areas which belong to the cache.

svn path=/trunk/; revision=63580

reactos/ntoskrnl/mm/section.c

index af87192..e30cc2a 100644 (file)
@@ -4090,15 +4090,22 @@ MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
       return(STATUS_UNSUCCESSFUL);
    }
 
-   MemoryArea->DeleteInProgress = TRUE;
    Section = MemoryArea->Data.SectionData.Section;
    Segment = MemoryArea->Data.SectionData.Segment;
 
 #ifdef NEWCC
-   if (Segment->Flags & MM_DATAFILE_SEGMENT)
-      return MmUnmapViewOfCacheSegment(AddressSpace, BaseAddress);
+    if (Segment->Flags & MM_DATAFILE_SEGMENT)
+    {
+        MmUnlockAddressSpace(AddressSpace);
+        Status = MmUnmapViewOfCacheSegment(AddressSpace, BaseAddress);
+        MmLockAddressSpace(AddressSpace);
+
+        return Status;
+    }
 #endif
 
+   MemoryArea->DeleteInProgress = TRUE;
+
    MmLockSectionSegment(Segment);
 
    RegionListHead = &MemoryArea->Data.SectionData.RegionListHead;
@@ -4151,7 +4158,8 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
    MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
                                             BaseAddress);
    if (MemoryArea == NULL ||
-       MemoryArea->Type != MEMORY_AREA_SECTION_VIEW ||
+       ((MemoryArea->Type != MEMORY_AREA_SECTION_VIEW) &&
+       (MemoryArea->Type != MEMORY_AREA_CACHE)) ||
        MemoryArea->DeleteInProgress)
    {
       if (MemoryArea) NT_ASSERT(MemoryArea->Type != MEMORY_AREA_OWNED_BY_ARM3);
@@ -4159,11 +4167,9 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
       return STATUS_NOT_MAPPED_VIEW;
    }
 
-   MemoryArea->DeleteInProgress = TRUE;
-
    Section = MemoryArea->Data.SectionData.Section;
 
-   if (Section->AllocationAttributes & SEC_IMAGE)
+   if ((Section != NULL) && (Section->AllocationAttributes & SEC_IMAGE))
    {
       ULONG i;
       ULONG NrSegments;
@@ -4176,6 +4182,8 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
       SectionSegments = ImageSectionObject->Segments;
       NrSegments = ImageSectionObject->NrSegments;
 
+      MemoryArea->DeleteInProgress = TRUE;
+
       /* Search for the current segment within the section segments
        * and calculate the image base address */
       for (i = 0; i < NrSegments; i++)