#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;
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;
(*Count) = 0;
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
WriteCount[0] = WriteCount[1];
WriteCount[1] = WriteCount[2];
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
DirtySegmentListEntry);
current_entry = current_entry->Flink;
- Locked = ExTryToAcquireFastMutex(¤t->Lock);
+ Locked = CcTryToAcquireBrokenMutex(¤t->Lock);
if (!Locked)
{
continue;
ASSERT(current->Dirty);
if (current->ReferenceCount > 1)
{
- ExReleaseFastMutex(¤t->Lock);
+ CcReleaseBrokenMutex(¤t->Lock);
continue;
}
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
PagesPerSegment = current->Bcb->CacheSegmentSize / PAGE_SIZE;
Status = CcRosFlushCacheSegment(current);
- ExReleaseFastMutex(¤t->Lock);
+ CcReleaseBrokenMutex(¤t->Lock);
if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE))
{
DPRINT1("CC: Failed to flush cache segment.\n");
(*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);
InitializeListHead(&FreeList);
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
current_entry = CacheSegmentLRUListHead.Flink;
while (current_entry != &CacheSegmentLRUListHead && Target > 0)
{
ULONG i;
NTSTATUS Status;
- current->ReferenceCount++;
+ CcRosCacheSegmentIncRefCount(current);
last = current;
current->PageOut = TRUE;
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
for (i = 0; i < current->Bcb->CacheSegmentSize / PAGE_SIZE; i++)
{
PFN_TYPE Page;
break;
}
}
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
KeAcquireSpinLock(¤t->Bcb->BcbLock, &oldIrql);
- current->ReferenceCount--;
- current->PageOut = FALSE;
+ CcRosCacheSegmentDecRefCount(current);
+ current->PageOut = FALSE;
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
current_entry = ¤t->CacheSegmentLRUListEntry;
continue;
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
}
}
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
while (!IsListEmpty(&FreeList))
{
}
NTSTATUS
+NTAPI
CcRosReleaseCacheSegment(PBCB Bcb,
PCACHE_SEGMENT CacheSeg,
BOOLEAN Valid,
CacheSeg->Valid = Valid;
CacheSeg->Dirty = CacheSeg->Dirty || Dirty;
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
if (!WasDirty && CacheSeg->Dirty)
{
InsertTailList(&DirtySegmentListHead, &CacheSeg->DirtySegmentListEntry);
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;
if (current->FileOffset <= FileOffset &&
(current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
{
- current->ReferenceCount++;
+ CcRosCacheSegmentIncRefCount(current);
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
- ExAcquireFastMutex(¤t->Lock);
+ CcAcquireBrokenMutex(¤t->Lock);
return(current);
}
current_entry = current_entry->Flink;
}
NTSTATUS
+NTAPI
CcRosMarkDirtyCacheSegment(PBCB Bcb, ULONG FileOffset)
{
PCACHE_SEGMENT CacheSeg;
}
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;
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);
}
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(¤t->Lock);
- ExAcquireFastMutex(¤t->Lock);
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(¤t->Lock);
+ CcAcquireBrokenMutex(&ViewLock);
*CacheSeg = current;
/* There is window between the call to CcRosLookupCacheSegment
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(¤t->Lock);
+ CcAcquireBrokenMutex(¤t->Lock);
return STATUS_SUCCESS;
}
if (current->FileOffset < FileOffset)
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
InsertTailList(&CacheSegmentListHead, ¤t->CacheSegmentListEntry);
InsertTailList(&CacheSegmentLRUListHead, ¤t->CacheSegmentLRUListEntry);
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
#ifdef CACHE_BITMAP
KeAcquireSpinLock(&CiCacheSegMappingRegionLock, &oldIrql);
#else
MmLockAddressSpace(MmGetKernelAddressSpace());
current->BaseAddress = NULL;
- Status = MmCreateMemoryArea(NULL,
- MmGetKernelAddressSpace(),
+ Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_CACHE_SEGMENT,
¤t->BaseAddress,
Bcb->CacheSegmentSize,
PAGE_READWRITE,
(PMEMORY_AREA*)¤t->MemoryArea,
FALSE,
- FALSE,
+ 0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
}
NTSTATUS
+NTAPI
CcRosGetCacheSegmentChain(PBCB Bcb,
ULONG FileOffset,
ULONG Length,
}
NTSTATUS
+NTAPI
CcRosGetCacheSegment(PBCB Bcb,
ULONG FileOffset,
PULONG BaseOffset,
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;
}
NTSTATUS
+NTAPI
CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg)
{
NTSTATUS Status;
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);
}
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
Status = CcRosInternalFreeCacheSegment(CacheSeg);
return(Status);
}
}
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
- ExReleaseFastMutex(¤t->Lock);
- current->ReferenceCount--;
+ CcReleaseBrokenMutex(¤t->Lock);
+ CcRosCacheSegmentDecRefCount(current);
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
}
}
NTSTATUS
+NTAPI
CcRosDeleteFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
/*
* FUNCTION: Releases the BCB associated with a file object
ASSERT(Bcb);
Bcb->RefCount++;
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
Bcb->RefCount--;
if (Bcb->RefCount == 0)
{
}
InsertHeadList(&FreeList, ¤t->BcbSegmentListEntry);
}
+#if defined(DBG) || defined(KDBG)
+ Bcb->Trace = FALSE;
+#endif
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
ObDereferenceObject (Bcb->FileObject);
while (!IsListEmpty(&FreeList))
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)
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)
{
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)
}
}
}
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
}
NTSTATUS STDCALL
{
PBCB Bcb;
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
if (FileObject->SectionObjectPointer->SharedCacheMap != NULL)
{
}
}
}
- 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)
}
Status = STATUS_SUCCESS;
}
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
return Status;
}
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));
RemoveEntryList(&Bcb->BcbRemoveListEntry);
Bcb->BcbRemoveListEntry.Flink = NULL;
}
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
return(STATUS_SUCCESS);
}
break;
}
- ExAcquireFastMutex(&ViewLock);
+ CcAcquireBrokenMutex(&ViewLock);
CcTimeStamp++;
if (CcTimeStamp >= 30)
{
CcRosDeleteFileCache(current->FileObject, current);
}
}
- ExReleaseFastMutex(&ViewLock);
+ CcReleaseBrokenMutex(&ViewLock);
}
}
-VOID INIT_FUNCTION
+VOID
+INIT_FUNCTION
+NTAPI
CcInitView(VOID)
{
#ifdef CACHE_BITMAP
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))