Due to CcRos's abusive usage and dependency on our broken Fast Mutex implementation...
[reactos.git] / reactos / ntoskrnl / cc / view.c
index 8614375..8b7fe67 100644 (file)
@@ -81,13 +81,85 @@ void* _alloca(size_t size);
 #error Unknown compiler for alloca intrinsic stack allocation "function"
 #endif
 
+#if defined(DBG) || defined(KDBG)
+static void CcRosCacheSegmentIncRefCount_ ( PCACHE_SEGMENT cs, const char* file, int line )
+{
+       ++cs->ReferenceCount;
+       if ( cs->Bcb->Trace )
+       {
+               DbgPrint("(%s:%i) CacheSegment %p ++RefCount=%d, Dirty %d, PageOut %d\n",
+                       file, line, cs, cs->ReferenceCount, cs->Dirty, cs->PageOut );
+       }
+}
+static void CcRosCacheSegmentDecRefCount_ ( PCACHE_SEGMENT cs, const char* file, int line )
+{
+       --cs->ReferenceCount;
+       if ( cs->Bcb->Trace )
+       {
+               DbgPrint("(%s:%i) CacheSegment %p --RefCount=%d, Dirty %d, PageOut %d\n",
+                       file, line, cs, cs->ReferenceCount, cs->Dirty, cs->PageOut );
+       }
+}
+#define CcRosCacheSegmentIncRefCount(cs) CcRosCacheSegmentIncRefCount_(cs,__FILE__,__LINE__)
+#define CcRosCacheSegmentDecRefCount(cs) CcRosCacheSegmentDecRefCount_(cs,__FILE__,__LINE__)
+#else
+#define CcRosCacheSegmentIncRefCount(cs) (++((cs)->ReferenceCount))
+#define CcRosCacheSegmentDecRefCount(cs) (--((cs)->ReferenceCount))
+#endif
 
 NTSTATUS
 CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg);
 
 /* FUNCTIONS *****************************************************************/
 
+VOID
+STDCALL
+CcRosTraceCacheMap (
+       PBCB Bcb,
+       BOOLEAN Trace )
+{
+#if defined(DBG) || defined(KDBG)
+       KIRQL oldirql;
+       PLIST_ENTRY current_entry;
+       PCACHE_SEGMENT current;
+
+       if ( !Bcb )
+               return;
+
+       Bcb->Trace = Trace;
+
+       if ( Trace )
+       {
+               DPRINT1("Enabling Tracing for CacheMap 0x%p:\n", Bcb );
+
+               CcAcquireBrokenMutex(&ViewLock);
+               KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
+
+               current_entry = Bcb->BcbSegmentListHead.Flink;
+               while (current_entry != &Bcb->BcbSegmentListHead)
+               {
+                       current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
+                       current_entry = current_entry->Flink;
+
+                       DPRINT1("  CacheSegment 0x%p enabled, RefCount %d, Dirty %d, PageOut %d\n",
+                               current, current->ReferenceCount, current->Dirty, current->PageOut );
+               }
+               KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
+               CcReleaseBrokenMutex(&ViewLock);
+       }
+       else
+       {
+               DPRINT1("Disabling Tracing for CacheMap 0x%p:\n", Bcb );
+       }
+
+#else
+       Bcb = Bcb;
+       Trace = Trace;
+#endif
+}
+
 NTSTATUS
+NTAPI
 CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
 {
   NTSTATUS Status;
@@ -95,19 +167,20 @@ CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
   Status = WriteCacheSegment(CacheSegment);
   if (NT_SUCCESS(Status))
     {
-      ExAcquireFastMutex(&ViewLock);
+      CcAcquireBrokenMutex(&ViewLock);
       KeAcquireSpinLock(&CacheSegment->Bcb->BcbLock, &oldIrql);
       CacheSegment->Dirty = FALSE;
       RemoveEntryList(&CacheSegment->DirtySegmentListEntry);
       DirtyPageCount -= CacheSegment->Bcb->CacheSegmentSize / PAGE_SIZE;
-      CacheSegment->ReferenceCount--;
+      CcRosCacheSegmentDecRefCount ( CacheSegment );
       KeReleaseSpinLock(&CacheSegment->Bcb->BcbLock, oldIrql);
-      ExReleaseFastMutex(&ViewLock);
+      CcReleaseBrokenMutex(&ViewLock);
     }
   return(Status);
 }
 
 NTSTATUS
+NTAPI
 CcRosFlushDirtyPages(ULONG Target, PULONG Count)
 {
   PLIST_ENTRY current_entry;
@@ -122,7 +195,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
 
   (*Count) = 0;
 
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
 
   WriteCount[0] = WriteCount[1];
   WriteCount[1] = WriteCount[2];
@@ -154,7 +227,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
       current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
                                  DirtySegmentListEntry);
       current_entry = current_entry->Flink;
-      Locked = ExTryToAcquireFastMutex(&current->Lock);
+      Locked = CcTryToAcquireBrokenMutex(&current->Lock);
       if (!Locked)
        {
          continue;
@@ -162,13 +235,13 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
       ASSERT(current->Dirty);
       if (current->ReferenceCount > 1)
        {
-         ExReleaseFastMutex(&current->Lock);
+         CcReleaseBrokenMutex(&current->Lock);
          continue;
        }
-      ExReleaseFastMutex(&ViewLock);
+      CcReleaseBrokenMutex(&ViewLock);
       PagesPerSegment = current->Bcb->CacheSegmentSize / PAGE_SIZE;
       Status = CcRosFlushCacheSegment(current);
-      ExReleaseFastMutex(&current->Lock);
+      CcReleaseBrokenMutex(&current->Lock);
       if (!NT_SUCCESS(Status) &&  (Status != STATUS_END_OF_FILE))
       {
         DPRINT1("CC: Failed to flush cache segment.\n");
@@ -178,14 +251,14 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
          (*Count) += PagesPerSegment;
          Target -= PagesPerSegment;
       }
-      ExAcquireFastMutex(&ViewLock);
+      CcAcquireBrokenMutex(&ViewLock);
       current_entry = DirtySegmentListHead.Flink;
     }
   if (*Count < NewTarget)
   {
      WriteCount[1] += (NewTarget - *Count);
   }
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
   DPRINT("CcRosFlushDirtyPages() finished\n");
 
   return(STATUS_SUCCESS);
@@ -215,7 +288,7 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
 
   InitializeListHead(&FreeList);
 
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
   current_entry = CacheSegmentLRUListHead.Flink;
   while (current_entry != &CacheSegmentLRUListHead && Target > 0)
     {
@@ -243,11 +316,11 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
             ULONG i;
             NTSTATUS Status;
 
-             current->ReferenceCount++;
+         CcRosCacheSegmentIncRefCount(current);
             last = current;
             current->PageOut = TRUE;
              KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql);
-            ExReleaseFastMutex(&ViewLock);
+            CcReleaseBrokenMutex(&ViewLock);
             for (i = 0; i < current->Bcb->CacheSegmentSize / PAGE_SIZE; i++)
               {
                 PFN_TYPE Page;
@@ -258,10 +331,10 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
                     break;
                   }
               }
-             ExAcquireFastMutex(&ViewLock);
+             CcAcquireBrokenMutex(&ViewLock);
              KeAcquireSpinLock(&current->Bcb->BcbLock, &oldIrql);
-            current->ReferenceCount--;
-            current->PageOut = FALSE;
+             CcRosCacheSegmentDecRefCount(current);
+             current->PageOut = FALSE;
              KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql);
              current_entry = &current->CacheSegmentLRUListEntry;
             continue;
@@ -269,7 +342,7 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
         KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql);
       }
   }
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
 
   while (!IsListEmpty(&FreeList))
   {
@@ -284,6 +357,7 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
 }
 
 NTSTATUS
+NTAPI
 CcRosReleaseCacheSegment(PBCB Bcb,
                         PCACHE_SEGMENT CacheSeg,
                         BOOLEAN Valid,
@@ -301,7 +375,7 @@ CcRosReleaseCacheSegment(PBCB Bcb,
   CacheSeg->Valid = Valid;
   CacheSeg->Dirty = CacheSeg->Dirty || Dirty;
 
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
   if (!WasDirty && CacheSeg->Dirty)
     {
       InsertTailList(&DirtySegmentListHead, &CacheSeg->DirtySegmentListEntry);
@@ -315,23 +389,24 @@ CcRosReleaseCacheSegment(PBCB Bcb,
      CacheSeg->MappedCount++;
   }
   KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
-  CacheSeg->ReferenceCount--;
+  CcRosCacheSegmentDecRefCount(CacheSeg);
   if (Mapped && CacheSeg->MappedCount == 1)
   {
-      CacheSeg->ReferenceCount++;
+      CcRosCacheSegmentIncRefCount(CacheSeg);
   }
   if (!WasDirty && CacheSeg->Dirty)
   {
-      CacheSeg->ReferenceCount++;
+      CcRosCacheSegmentIncRefCount(CacheSeg);
   }
   KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
-  ExReleaseFastMutex(&ViewLock);
-  ExReleaseFastMutex(&CacheSeg->Lock);
+  CcReleaseBrokenMutex(&ViewLock);
+  CcReleaseBrokenMutex(&CacheSeg->Lock);
 
   return(STATUS_SUCCESS);
 }
 
 PCACHE_SEGMENT
+NTAPI
 CcRosLookupCacheSegment(PBCB Bcb, ULONG FileOffset)
 {
   PLIST_ENTRY current_entry;
@@ -351,9 +426,9 @@ CcRosLookupCacheSegment(PBCB Bcb, ULONG FileOffset)
       if (current->FileOffset <= FileOffset &&
          (current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
        {
-         current->ReferenceCount++;
+      CcRosCacheSegmentIncRefCount(current);
          KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
-          ExAcquireFastMutex(&current->Lock);
+          CcAcquireBrokenMutex(&current->Lock);
          return(current);
        }
       current_entry = current_entry->Flink;
@@ -363,6 +438,7 @@ CcRosLookupCacheSegment(PBCB Bcb, ULONG FileOffset)
 }
 
 NTSTATUS
+NTAPI
 CcRosMarkDirtyCacheSegment(PBCB Bcb, ULONG FileOffset)
 {
   PCACHE_SEGMENT CacheSeg;
@@ -379,26 +455,27 @@ CcRosMarkDirtyCacheSegment(PBCB Bcb, ULONG FileOffset)
     }
   if (!CacheSeg->Dirty)
     {
-      ExAcquireFastMutex(&ViewLock);
+      CcAcquireBrokenMutex(&ViewLock);
       InsertTailList(&DirtySegmentListHead, &CacheSeg->DirtySegmentListEntry);
       DirtyPageCount += Bcb->CacheSegmentSize / PAGE_SIZE;
-      ExReleaseFastMutex(&ViewLock);
+      CcReleaseBrokenMutex(&ViewLock);
     }
   else
   {
      KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
-     CacheSeg->ReferenceCount--;
+     CcRosCacheSegmentDecRefCount(CacheSeg);
      KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
   }
 
 
   CacheSeg->Dirty = TRUE;
-  ExReleaseFastMutex(&CacheSeg->Lock);
+  CcReleaseBrokenMutex(&CacheSeg->Lock);
 
   return(STATUS_SUCCESS);
 }
 
 NTSTATUS
+NTAPI
 CcRosUnmapCacheSegment(PBCB Bcb, ULONG FileOffset, BOOLEAN NowDirty)
 {
   PCACHE_SEGMENT CacheSeg;
@@ -423,25 +500,25 @@ CcRosUnmapCacheSegment(PBCB Bcb, ULONG FileOffset, BOOLEAN NowDirty)
 
   if (!WasDirty && NowDirty)
   {
-     ExAcquireFastMutex(&ViewLock);
+     CcAcquireBrokenMutex(&ViewLock);
      InsertTailList(&DirtySegmentListHead, &CacheSeg->DirtySegmentListEntry);
      DirtyPageCount += Bcb->CacheSegmentSize / PAGE_SIZE;
-     ExReleaseFastMutex(&ViewLock);
+     CcReleaseBrokenMutex(&ViewLock);
   }
 
   KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
-  CacheSeg->ReferenceCount--;
+  CcRosCacheSegmentDecRefCount(CacheSeg);
   if (!WasDirty && NowDirty)
   {
-     CacheSeg->ReferenceCount++;
+     CcRosCacheSegmentIncRefCount(CacheSeg);
   }
   if (CacheSeg->MappedCount == 0)
   {
-     CacheSeg->ReferenceCount--;
+     CcRosCacheSegmentDecRefCount(CacheSeg);
   }
   KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
 
-  ExReleaseFastMutex(&CacheSeg->Lock);
+  CcReleaseBrokenMutex(&CacheSeg->Lock);
   return(STATUS_SUCCESS);
 }
 
@@ -480,13 +557,19 @@ CcRosCreateCacheSegment(PBCB Bcb,
   current->PageOut = FALSE;
   current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
   current->Bcb = Bcb;
+#if defined(DBG) || defined(KDBG)
+  if ( Bcb->Trace )
+  {
+    DPRINT1("CacheMap 0x%p: new Cache Segment: 0x%p\n", Bcb, current );
+  }
+#endif
   current->MappedCount = 0;
   current->DirtySegmentListEntry.Flink = NULL;
   current->DirtySegmentListEntry.Blink = NULL;
   current->ReferenceCount = 1;
   ExInitializeFastMutex(&current->Lock);
-  ExAcquireFastMutex(&current->Lock);
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&current->Lock);
+  CcAcquireBrokenMutex(&ViewLock);
 
   *CacheSeg = current;
   /* There is window between the call to CcRosLookupCacheSegment
@@ -504,13 +587,22 @@ CcRosCreateCacheSegment(PBCB Bcb,
      if (current->FileOffset <= FileOffset &&
        (current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
      {
-       current->ReferenceCount++;
+       CcRosCacheSegmentIncRefCount(current);
        KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
-       ExReleaseFastMutex(&(*CacheSeg)->Lock);
-       ExReleaseFastMutex(&ViewLock);
+#if defined(DBG) || defined(KDBG)
+       if ( Bcb->Trace )
+       {
+               DPRINT1("CacheMap 0x%p: deleting newly created Cache Segment 0x%p ( found existing one 0x%p )\n",
+                       Bcb,
+                       (*CacheSeg),
+                       current );
+       }
+#endif
+       CcReleaseBrokenMutex(&(*CacheSeg)->Lock);
+       CcReleaseBrokenMutex(&ViewLock);
        ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
        *CacheSeg = current;
-        ExAcquireFastMutex(&current->Lock);
+        CcAcquireBrokenMutex(&current->Lock);
        return STATUS_SUCCESS;
      }
      if (current->FileOffset < FileOffset)
@@ -542,7 +634,7 @@ CcRosCreateCacheSegment(PBCB Bcb,
   KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
   InsertTailList(&CacheSegmentListHead, &current->CacheSegmentListEntry);
   InsertTailList(&CacheSegmentLRUListHead, &current->CacheSegmentLRUListEntry);
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
 #ifdef CACHE_BITMAP
   KeAcquireSpinLock(&CiCacheSegMappingRegionLock, &oldIrql);
 
@@ -565,15 +657,14 @@ CcRosCreateCacheSegment(PBCB Bcb,
 #else
   MmLockAddressSpace(MmGetKernelAddressSpace());
   current->BaseAddress = NULL;
-  Status = MmCreateMemoryArea(NULL,
-                             MmGetKernelAddressSpace(),
+  Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
                              MEMORY_AREA_CACHE_SEGMENT,
                              &current->BaseAddress,
                              Bcb->CacheSegmentSize,
                              PAGE_READWRITE,
                              (PMEMORY_AREA*)&current->MemoryArea,
                              FALSE,
-                             FALSE,
+                             0,
                              BoundaryAddressMultiple);
   MmUnlockAddressSpace(MmGetKernelAddressSpace());
   if (!NT_SUCCESS(Status))
@@ -603,6 +694,7 @@ CcRosCreateCacheSegment(PBCB Bcb,
 }
 
 NTSTATUS
+NTAPI
 CcRosGetCacheSegmentChain(PBCB Bcb,
                          ULONG FileOffset,
                          ULONG Length,
@@ -666,6 +758,7 @@ CcRosGetCacheSegmentChain(PBCB Bcb,
 }
 
 NTSTATUS
+NTAPI
 CcRosGetCacheSegment(PBCB Bcb,
                     ULONG FileOffset,
                     PULONG BaseOffset,
@@ -761,6 +854,12 @@ CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg)
   KIRQL oldIrql;
 #endif
   DPRINT("Freeing cache segment 0x%p\n", CacheSeg);
+#if defined(DBG) || defined(KDBG)
+       if ( CacheSeg->Bcb->Trace )
+       {
+               DPRINT1("CacheMap 0x%p: deleting Cache Segment: 0x%p\n", CacheSeg->Bcb, CacheSeg );
+       }
+#endif
 #ifdef CACHE_BITMAP
   RegionSize = CacheSeg->Bcb->CacheSegmentSize / PAGE_SIZE;
 
@@ -797,6 +896,7 @@ CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg)
 }
 
 NTSTATUS
+NTAPI
 CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg)
 {
   NTSTATUS Status;
@@ -807,7 +907,7 @@ CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg)
   DPRINT("CcRosFreeCacheSegment(Bcb 0x%p, CacheSeg 0x%p)\n",
          Bcb, CacheSeg);
 
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
   KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
   RemoveEntryList(&CacheSeg->BcbSegmentListEntry);
   RemoveEntryList(&CacheSeg->CacheSegmentListEntry);
@@ -819,7 +919,7 @@ CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg)
 
   }
   KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
 
   Status = CcRosInternalFreeCacheSegment(CacheSeg);
   return(Status);
@@ -877,8 +977,8 @@ CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointers,
               }
            }
             KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
-           ExReleaseFastMutex(&current->Lock);
-           current->ReferenceCount--;
+           CcReleaseBrokenMutex(&current->Lock);
+            CcRosCacheSegmentDecRefCount(current);
            KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
         }
 
@@ -903,6 +1003,7 @@ CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointers,
 }
 
 NTSTATUS
+NTAPI
 CcRosDeleteFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
 /*
  * FUNCTION: Releases the BCB associated with a file object
@@ -917,11 +1018,11 @@ CcRosDeleteFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
    ASSERT(Bcb);
 
    Bcb->RefCount++;
-   ExReleaseFastMutex(&ViewLock);
+   CcReleaseBrokenMutex(&ViewLock);
 
    CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
 
-   ExAcquireFastMutex(&ViewLock);
+   CcAcquireBrokenMutex(&ViewLock);
    Bcb->RefCount--;
    if (Bcb->RefCount == 0)
    {
@@ -953,9 +1054,12 @@ CcRosDeleteFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
         }
          InsertHeadList(&FreeList, &current->BcbSegmentListEntry);
       }
+#if defined(DBG) || defined(KDBG)
+      Bcb->Trace = FALSE;
+#endif
       KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
 
-      ExReleaseFastMutex(&ViewLock);
+      CcReleaseBrokenMutex(&ViewLock);
       ObDereferenceObject (Bcb->FileObject);
 
       while (!IsListEmpty(&FreeList))
@@ -965,15 +1069,17 @@ CcRosDeleteFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
          Status = CcRosInternalFreeCacheSegment(current);
       }
       ExFreeToNPagedLookasideList(&BcbLookasideList, Bcb);
-      ExAcquireFastMutex(&ViewLock);
+      CcAcquireBrokenMutex(&ViewLock);
    }
    return(STATUS_SUCCESS);
 }
 
-VOID CcRosReferenceCache(PFILE_OBJECT FileObject)
+VOID
+NTAPI
+CcRosReferenceCache(PFILE_OBJECT FileObject)
 {
   PBCB Bcb;
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
   Bcb = (PBCB)FileObject->SectionObjectPointer->SharedCacheMap;
   ASSERT(Bcb);
   if (Bcb->RefCount == 0)
@@ -988,14 +1094,16 @@ VOID CcRosReferenceCache(PFILE_OBJECT FileObject)
      ASSERT(Bcb->BcbRemoveListEntry.Flink == NULL);
   }
   Bcb->RefCount++;
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
 }
 
-VOID CcRosSetRemoveOnClose(PSECTION_OBJECT_POINTERS SectionObjectPointer)
+VOID
+NTAPI
+CcRosSetRemoveOnClose(PSECTION_OBJECT_POINTERS SectionObjectPointer)
 {
   PBCB Bcb;
   DPRINT("CcRosSetRemoveOnClose()\n");
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
   Bcb = (PBCB)SectionObjectPointer->SharedCacheMap;
   if (Bcb)
   {
@@ -1005,14 +1113,16 @@ VOID CcRosSetRemoveOnClose(PSECTION_OBJECT_POINTERS SectionObjectPointer)
       CcRosDeleteFileCache(Bcb->FileObject, Bcb);
     }
   }
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
 }
 
 
-VOID CcRosDereferenceCache(PFILE_OBJECT FileObject)
+VOID
+NTAPI
+CcRosDereferenceCache(PFILE_OBJECT FileObject)
 {
   PBCB Bcb;
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
   Bcb = (PBCB)FileObject->SectionObjectPointer->SharedCacheMap;
   ASSERT(Bcb);
   if (Bcb->RefCount > 0)
@@ -1032,7 +1142,7 @@ VOID CcRosDereferenceCache(PFILE_OBJECT FileObject)
        }
     }
   }
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
 }
 
 NTSTATUS STDCALL
@@ -1044,7 +1154,7 @@ CcRosReleaseFileCache(PFILE_OBJECT FileObject)
 {
   PBCB Bcb;
 
-  ExAcquireFastMutex(&ViewLock);
+  CcAcquireBrokenMutex(&ViewLock);
 
   if (FileObject->SectionObjectPointer->SharedCacheMap != NULL)
   {
@@ -1071,17 +1181,18 @@ CcRosReleaseFileCache(PFILE_OBJECT FileObject)
       }
     }
   }
-  ExReleaseFastMutex(&ViewLock);
+  CcReleaseBrokenMutex(&ViewLock);
   return(STATUS_SUCCESS);
 }
 
 NTSTATUS
+NTAPI
 CcTryToInitializeFileCache(PFILE_OBJECT FileObject)
 {
    PBCB Bcb;
    NTSTATUS Status;
 
-   ExAcquireFastMutex(&ViewLock);
+   CcAcquireBrokenMutex(&ViewLock);
 
    Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
    if (Bcb == NULL)
@@ -1102,7 +1213,7 @@ CcTryToInitializeFileCache(PFILE_OBJECT FileObject)
       }
       Status = STATUS_SUCCESS;
    }
-   ExReleaseFastMutex(&ViewLock);
+   CcReleaseBrokenMutex(&ViewLock);
 
    return Status;
 }
@@ -1121,13 +1232,13 @@ CcRosInitializeFileCache(PFILE_OBJECT FileObject,
    DPRINT("CcRosInitializeFileCache(FileObject 0x%p, Bcb 0x%p, CacheSegmentSize %d)\n",
            FileObject, Bcb, CacheSegmentSize);
 
-   ExAcquireFastMutex(&ViewLock);
+   CcAcquireBrokenMutex(&ViewLock);
    if (Bcb == NULL)
    {
       Bcb = ExAllocateFromNPagedLookasideList(&BcbLookasideList);
       if (Bcb == NULL)
       {
-        ExReleaseFastMutex(&ViewLock);
+        CcReleaseBrokenMutex(&ViewLock);
        return(STATUS_UNSUCCESSFUL);
       }
       memset(Bcb, 0, sizeof(BCB));
@@ -1158,7 +1269,7 @@ CcRosInitializeFileCache(PFILE_OBJECT FileObject,
       RemoveEntryList(&Bcb->BcbRemoveListEntry);
       Bcb->BcbRemoveListEntry.Flink = NULL;
    }
-   ExReleaseFastMutex(&ViewLock);
+   CcReleaseBrokenMutex(&ViewLock);
 
    return(STATUS_SUCCESS);
 }
@@ -1213,7 +1324,7 @@ CmLazyCloseThreadMain(PVOID Ignored)
          break;
       }
 
-      ExAcquireFastMutex(&ViewLock);
+      CcAcquireBrokenMutex(&ViewLock);
       CcTimeStamp++;
       if (CcTimeStamp >= 30)
       {
@@ -1229,11 +1340,13 @@ CmLazyCloseThreadMain(PVOID Ignored)
             CcRosDeleteFileCache(current->FileObject, current);
         }
       }
-      ExReleaseFastMutex(&ViewLock);
+      CcReleaseBrokenMutex(&ViewLock);
    }
 }
 
-VOID INIT_FUNCTION
+VOID
+INIT_FUNCTION
+NTAPI
 CcInitView(VOID)
 {
 #ifdef CACHE_BITMAP
@@ -1252,15 +1365,14 @@ CcInitView(VOID)
 
   MmLockAddressSpace(MmGetKernelAddressSpace());
 
-  Status = MmCreateMemoryArea(NULL,
-                             MmGetKernelAddressSpace(),
+  Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
                              MEMORY_AREA_CACHE_SEGMENT,
                              &CiCacheSegMappingRegionBase,
                              CI_CACHESEG_MAPPING_REGION_SIZE,
-                             0,
+                             PAGE_READWRITE,
                              &marea,
                              FALSE,
-                             FALSE,
+                             0,
                              BoundaryAddressMultiple);
   MmUnlockAddressSpace(MmGetKernelAddressSpace());
   if (!NT_SUCCESS(Status))