ReactOS  0.4.13-dev-39-g8b6696f
view.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for view.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI CcRosTraceCacheMap (PROS_SHARED_CACHE_MAP SharedCacheMap, BOOLEAN Trace)
 
NTSTATUS NTAPI CcRosFlushVacb (PROS_VACB Vacb)
 
NTSTATUS NTAPI CcRosFlushDirtyPages (ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
 
NTSTATUS CcRosTrimCache (ULONG Target, ULONG Priority, PULONG NrFreed)
 
NTSTATUS NTAPI CcRosReleaseVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
 
PROS_VACB NTAPI CcRosLookupVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
 
VOID NTAPI CcRosMarkDirtyVacb (PROS_VACB Vacb)
 
VOID NTAPI CcRosUnmarkDirtyVacb (PROS_VACB Vacb, BOOLEAN LockViews)
 
NTSTATUS NTAPI CcRosMarkDirtyFile (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
 
NTSTATUS NTAPI CcRosUnmapVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, BOOLEAN NowDirty)
 
static NTSTATUS CcRosMapVacbInKernelSpace (PROS_VACB Vacb)
 
static BOOLEAN CcRosFreeUnusedVacb (PULONG Count)
 
static NTSTATUS CcRosCreateVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
 
NTSTATUS NTAPI CcRosGetVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PLONGLONG BaseOffset, PVOID *BaseAddress, PBOOLEAN UptoDate, PROS_VACB *Vacb)
 
NTSTATUS NTAPI CcRosRequestVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PVOID *BaseAddress, PBOOLEAN UptoDate, PROS_VACB *Vacb)
 
static VOID CcFreeCachePage (PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 
NTSTATUS CcRosInternalFreeVacb (PROS_VACB Vacb)
 
VOID NTAPI CcFlushCache (IN PSECTION_OBJECT_POINTERS SectionObjectPointers, IN PLARGE_INTEGER FileOffset OPTIONAL, IN ULONG Length, OUT PIO_STATUS_BLOCK IoStatus)
 
NTSTATUS NTAPI CcRosDeleteFileCache (PFILE_OBJECT FileObject, PROS_SHARED_CACHE_MAP SharedCacheMap, PKIRQL OldIrql)
 
VOID NTAPI CcRosReferenceCache (PFILE_OBJECT FileObject)
 
VOID NTAPI CcRosRemoveIfClosed (PSECTION_OBJECT_POINTERS SectionObjectPointer)
 
VOID NTAPI CcRosDereferenceCache (PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI CcRosReleaseFileCache (PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI CcRosInitializeFileCache (PFILE_OBJECT FileObject, PCC_FILE_SIZES FileSizes, BOOLEAN PinAccess, PCACHE_MANAGER_CALLBACKS CallBacks, PVOID LazyWriterContext)
 
PFILE_OBJECT NTAPI CcGetFileObjectFromSectionPtrs (IN PSECTION_OBJECT_POINTERS SectionObjectPointers)
 
VOID INIT_FUNCTION NTAPI CcInitView (VOID)
 

Variables

LIST_ENTRY DirtyVacbListHead
 
static LIST_ENTRY VacbLruListHead
 
NPAGED_LOOKASIDE_LIST iBcbLookasideList
 
static NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
 
static NPAGED_LOOKASIDE_LIST VacbLookasideList
 
ULONG CcDirtyPageThreshold = 0
 
ULONG CcTotalDirtyPages = 0
 
LIST_ENTRY CcDeferredWrites
 
KSPIN_LOCK CcDeferredWriteSpinLock
 
LIST_ENTRY CcCleanSharedCacheMapList
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 36 of file view.c.

Function Documentation

◆ CcFlushCache()

VOID NTAPI CcFlushCache ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointers,
IN PLARGE_INTEGER FileOffset  OPTIONAL,
IN ULONG  Length,
OUT PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 1088 of file view.c.

1093 {
1094  PROS_SHARED_CACHE_MAP SharedCacheMap;
1096  LONGLONG RemainingLength;
1098  NTSTATUS Status;
1099 
1100  CCTRACE(CC_API_DEBUG, "SectionObjectPointers=%p FileOffset=%p Length=%lu\n",
1101  SectionObjectPointers, FileOffset, Length);
1102 
1103  DPRINT("CcFlushCache(SectionObjectPointers 0x%p, FileOffset 0x%p, Length %lu, IoStatus 0x%p)\n",
1104  SectionObjectPointers, FileOffset, Length, IoStatus);
1105 
1106  if (SectionObjectPointers && SectionObjectPointers->SharedCacheMap)
1107  {
1108  SharedCacheMap = SectionObjectPointers->SharedCacheMap;
1109  ASSERT(SharedCacheMap);
1110  if (FileOffset)
1111  {
1112  Offset = *FileOffset;
1113  RemainingLength = Length;
1114  }
1115  else
1116  {
1117  Offset.QuadPart = 0;
1118  RemainingLength = SharedCacheMap->FileSize.QuadPart;
1119  }
1120 
1121  if (IoStatus)
1122  {
1123  IoStatus->Status = STATUS_SUCCESS;
1124  IoStatus->Information = 0;
1125  }
1126 
1127  while (RemainingLength > 0)
1128  {
1129  current = CcRosLookupVacb(SharedCacheMap, Offset.QuadPart);
1130  if (current != NULL)
1131  {
1132  if (current->Dirty)
1133  {
1135  if (!NT_SUCCESS(Status) && IoStatus != NULL)
1136  {
1137  IoStatus->Status = Status;
1138  }
1139  }
1140 
1141  CcRosReleaseVacb(SharedCacheMap, current, current->Valid, current->Dirty, FALSE);
1142  }
1143 
1144  Offset.QuadPart += VACB_MAPPING_GRANULARITY;
1145  RemainingLength -= min(RemainingLength, VACB_MAPPING_GRANULARITY);
1146  }
1147  }
1148  else
1149  {
1150  if (IoStatus)
1151  {
1153  }
1154  }
1155 }
Definition: cc.h:202
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
int64_t LONGLONG
Definition: typedefs.h:66
#define CC_API_DEBUG
Definition: cc.h:11
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:421
#define CCTRACE(x, fmt,...)
Definition: cc.h:36
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
PROS_VACB NTAPI CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:458
#define min(a, b)
Definition: monoChain.cc:55
#define VACB_MAPPING_GRANULARITY
LARGE_INTEGER FileSize
Definition: cc.h:175
NTSTATUS NTAPI CcRosFlushVacb(PROS_VACB Vacb)
Definition: view.c:165
return STATUS_SUCCESS
Definition: btrfs.c:2725
struct task_struct * current
Definition: linux.c:32
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by CcRosDeleteFileCache().

◆ CcFreeCachePage()

static VOID CcFreeCachePage ( PVOID  Context,
MEMORY_AREA MemoryArea,
PVOID  Address,
PFN_NUMBER  Page,
SWAPENTRY  SwapEntry,
BOOLEAN  Dirty 
)
static

Definition at line 1027 of file view.c.

1034 {
1035  ASSERT(SwapEntry == 0);
1036  if (Page != 0)
1037  {
1038  ASSERT(MmGetReferenceCountPage(Page) == 1);
1040  }
1041 }
NTSTATUS NTAPI MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
Definition: balance.c:97
ULONG NTAPI MmGetReferenceCountPage(PFN_NUMBER Page)
Definition: freelist.c:509
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define MC_CACHE
Definition: mm.h:93

Referenced by CcRosInternalFreeVacb().

◆ CcGetFileObjectFromSectionPtrs()

PFILE_OBJECT NTAPI CcGetFileObjectFromSectionPtrs ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointers)

Definition at line 1516 of file view.c.

1518 {
1519  PROS_SHARED_CACHE_MAP SharedCacheMap;
1520 
1521  CCTRACE(CC_API_DEBUG, "SectionObjectPointers=%p\n", SectionObjectPointers);
1522 
1523  if (SectionObjectPointers && SectionObjectPointers->SharedCacheMap)
1524  {
1525  SharedCacheMap = SectionObjectPointers->SharedCacheMap;
1526  ASSERT(SharedCacheMap);
1527  return SharedCacheMap->FileObject;
1528  }
1529  return NULL;
1530 }
smooth NULL
Definition: ftsmooth.c:416
#define CC_API_DEBUG
Definition: cc.h:11
#define CCTRACE(x, fmt,...)
Definition: cc.h:36
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PFILE_OBJECT FileObject
Definition: cc.h:178

◆ CcInitView()

VOID INIT_FUNCTION NTAPI CcInitView ( VOID  )

Definition at line 1535 of file view.c.

1537 {
1538  DPRINT("CcInitView()\n");
1539 
1546  NULL,
1547  NULL,
1548  0,
1549  sizeof(INTERNAL_BCB),
1550  TAG_BCB,
1551  20);
1553  NULL,
1554  NULL,
1555  0,
1556  sizeof(ROS_SHARED_CACHE_MAP),
1558  20);
1560  NULL,
1561  NULL,
1562  0,
1563  sizeof(ROS_VACB),
1564  TAG_VACB,
1565  20);
1566 
1568 
1570 }
Definition: cc.h:202
#define TAG_VACB
Definition: tag.h:5
static NPAGED_LOOKASIDE_LIST VacbLookasideList
Definition: view.c:50
#define TAG_BCB
Definition: nodetype.h:157
static LIST_ENTRY VacbLruListHead
Definition: view.c:46
#define TAG_SHARED_CACHE_MAP
Definition: tag.h:6
NTSTATUS CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: view.c:290
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
LIST_ENTRY CcCleanSharedCacheMapList
Definition: view.c:63
VOID NTAPI CcInitCacheZeroPage(VOID)
Definition: copy.c:63
INIT_FUNCTION VOID NTAPI MmInitializeMemoryConsumer(ULONG Consumer, NTSTATUS(*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed))
Definition: balance.c:82
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:222
static NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
Definition: view.c:49
LIST_ENTRY CcDeferredWrites
Definition: view.c:61
KSPIN_LOCK CcDeferredWriteSpinLock
Definition: view.c:62
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NPAGED_LOOKASIDE_LIST iBcbLookasideList
Definition: view.c:48
#define MC_CACHE
Definition: mm.h:93
LIST_ENTRY DirtyVacbListHead
Definition: view.c:45

Referenced by CcInitializeCacheManager().

◆ CcRosCreateVacb()

static NTSTATUS CcRosCreateVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset,
PROS_VACB Vacb 
)
static

Definition at line 780 of file view.c.

784 {
786  PROS_VACB previous;
787  PLIST_ENTRY current_entry;
789  KIRQL oldIrql;
790  ULONG Refs;
791  BOOLEAN Retried;
792 
793  ASSERT(SharedCacheMap);
794 
795  DPRINT("CcRosCreateVacb()\n");
796 
797  if (FileOffset >= SharedCacheMap->SectionSize.QuadPart)
798  {
799  *Vacb = NULL;
801  }
802 
803  current = ExAllocateFromNPagedLookasideList(&VacbLookasideList);
804  current->BaseAddress = NULL;
805  current->Valid = FALSE;
806  current->Dirty = FALSE;
807  current->PageOut = FALSE;
808  current->FileOffset.QuadPart = ROUND_DOWN(FileOffset, VACB_MAPPING_GRANULARITY);
809  current->SharedCacheMap = SharedCacheMap;
810 #if DBG
811  if (SharedCacheMap->Trace)
812  {
813  DPRINT1("CacheMap 0x%p: new VACB: 0x%p\n", SharedCacheMap, current);
814  }
815 #endif
816  current->MappedCount = 0;
817  current->ReferenceCount = 0;
818  InitializeListHead(&current->CacheMapVacbListEntry);
819  InitializeListHead(&current->DirtyVacbListEntry);
820  InitializeListHead(&current->VacbLruListEntry);
821 
823 
824  Retried = FALSE;
825 Retry:
826  /* Map VACB in kernel space */
828  if (!NT_SUCCESS(Status))
829  {
830  ULONG Freed;
831  /* If no space left, try to prune unused VACB
832  * to recover space to map our VACB
833  * If it succeed, retry to map, otherwise
834  * just fail.
835  */
836  if (!Retried && CcRosFreeUnusedVacb(&Freed))
837  {
838  DPRINT("Prunned %d VACB, trying again\n", Freed);
839  Retried = TRUE;
840  goto Retry;
841  }
842 
843  ExFreeToNPagedLookasideList(&VacbLookasideList, current);
844  return Status;
845  }
846 
848 
849  *Vacb = current;
850  /* There is window between the call to CcRosLookupVacb
851  * and CcRosCreateVacb. We must check if a VACB for the
852  * file offset exist. If there is a VACB, we release
853  * our newly created VACB and return the existing one.
854  */
855  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
856  current_entry = SharedCacheMap->CacheMapVacbListHead.Flink;
857  previous = NULL;
858  while (current_entry != &SharedCacheMap->CacheMapVacbListHead)
859  {
860  current = CONTAINING_RECORD(current_entry,
861  ROS_VACB,
862  CacheMapVacbListEntry);
863  if (IsPointInRange(current->FileOffset.QuadPart,
865  FileOffset))
866  {
869 #if DBG
870  if (SharedCacheMap->Trace)
871  {
872  DPRINT1("CacheMap 0x%p: deleting newly created VACB 0x%p ( found existing one 0x%p )\n",
873  SharedCacheMap,
874  (*Vacb),
875  current);
876  }
877 #endif
879 
880  Refs = CcRosVacbDecRefCount(*Vacb);
881  ASSERT(Refs == 0);
882 
883  *Vacb = current;
884  return STATUS_SUCCESS;
885  }
886  if (current->FileOffset.QuadPart < FileOffset)
887  {
888  ASSERT(previous == NULL ||
889  previous->FileOffset.QuadPart < current->FileOffset.QuadPart);
890  previous = current;
891  }
892  if (current->FileOffset.QuadPart > FileOffset)
893  break;
894  current_entry = current_entry->Flink;
895  }
896  /* There was no existing VACB. */
897  current = *Vacb;
898  if (previous)
899  {
900  InsertHeadList(&previous->CacheMapVacbListEntry, &current->CacheMapVacbListEntry);
901  }
902  else
903  {
904  InsertHeadList(&SharedCacheMap->CacheMapVacbListHead, &current->CacheMapVacbListEntry);
905  }
907  InsertTailList(&VacbLruListHead, &current->VacbLruListEntry);
909 
911 #if MI_TRACE_PFNS
912  if ((SharedCacheMap->FileObject) && (SharedCacheMap->FileObject->FileName.Buffer))
913  {
914  PWCHAR pos;
915  ULONG len = 0;
916  pos = wcsrchr(SharedCacheMap->FileObject->FileName.Buffer, '\\');
917  if (pos)
918  {
919  len = wcslen(pos) * sizeof(WCHAR);
921  }
922  else
923  {
924  snprintf(MI_PFN_CURRENT_PROCESS_NAME, min(16, len), "%wZ", &SharedCacheMap->FileObject->FileName);
925  }
926  }
927 #endif
928 
929  /* Reference it to allow release */
931 
932  return Status;
933 }
#define TRUE
Definition: types.h:120
Definition: cc.h:202
LARGE_INTEGER SectionSize
Definition: cc.h:177
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LONG NTSTATUS
Definition: precomp.h:26
#define snprintf
Definition: wintirpc.h:48
static NPAGED_LOOKASIDE_LIST VacbLookasideList
Definition: view.c:50
static LIST_ENTRY VacbLruListHead
Definition: view.c:46
uint16_t * PWCHAR
Definition: typedefs.h:54
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
static BOOLEAN CcRosFreeUnusedVacb(PULONG Count)
Definition: view.c:698
LIST_ENTRY CacheMapVacbListEntry
Definition: cc.h:216
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
void DPRINT(...)
Definition: polytest.cpp:61
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
#define MI_SET_USAGE(x)
Definition: mm.h:253
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:190
FORCEINLINE BOOLEAN IsPointInRange(_In_ LONGLONG Offset1, _In_ LONGLONG Length1, _In_ LONGLONG Point)
Definition: cc.h:496
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:530
GLenum GLsizei len
Definition: glext.h:6722
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
Status
Definition: gdiplustypes.h:24
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
LARGE_INTEGER FileOffset
Definition: cc.h:222
#define VACB_MAPPING_GRANULARITY
unsigned int ULONG
Definition: retypes.h:1
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
PFILE_OBJECT FileObject
Definition: cc.h:178
return STATUS_SUCCESS
Definition: btrfs.c:2725
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
CHAR MI_PFN_CURRENT_PROCESS_NAME[16]
Definition: pfnlist.c:64
struct task_struct * current
Definition: linux.c:32
LONGLONG QuadPart
Definition: typedefs.h:112
static NTSTATUS CcRosMapVacbInKernelSpace(PROS_VACB Vacb)
Definition: view.c:631

Referenced by CcRosGetVacb().

◆ CcRosDeleteFileCache()

NTSTATUS NTAPI CcRosDeleteFileCache ( PFILE_OBJECT  FileObject,
PROS_SHARED_CACHE_MAP  SharedCacheMap,
PKIRQL  OldIrql 
)

Definition at line 1159 of file view.c.

1166 {
1167  PLIST_ENTRY current_entry;
1170 
1171  ASSERT(SharedCacheMap);
1172 
1173  SharedCacheMap->OpenCount++;
1175 
1176  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
1177 
1179  SharedCacheMap->OpenCount--;
1180  if (SharedCacheMap->OpenCount == 0)
1181  {
1182  FileObject->SectionObjectPointer->SharedCacheMap = NULL;
1183 
1184  /*
1185  * Release all VACBs
1186  */
1188  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1189  while (!IsListEmpty(&SharedCacheMap->CacheMapVacbListHead))
1190  {
1191  current_entry = RemoveTailList(&SharedCacheMap->CacheMapVacbListHead);
1192  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1193 
1194  current = CONTAINING_RECORD(current_entry, ROS_VACB, CacheMapVacbListEntry);
1195  RemoveEntryList(&current->VacbLruListEntry);
1196  InitializeListHead(&current->VacbLruListEntry);
1197  if (current->Dirty)
1198  {
1199  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1201  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1202  DPRINT1("Freeing dirty VACB\n");
1203  }
1204  if (current->MappedCount != 0)
1205  {
1206  current->MappedCount = 0;
1208  DPRINT1("Freeing mapped VACB\n");
1209  }
1210  InsertHeadList(&FreeList, &current->CacheMapVacbListEntry);
1211 
1212  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1213  }
1214 #if DBG
1215  SharedCacheMap->Trace = FALSE;
1216 #endif
1217  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1218 
1220  ObDereferenceObject(SharedCacheMap->FileObject);
1221 
1222  while (!IsListEmpty(&FreeList))
1223  {
1224  ULONG Refs;
1225 
1226  current_entry = RemoveTailList(&FreeList);
1227  current = CONTAINING_RECORD(current_entry, ROS_VACB, CacheMapVacbListEntry);
1228  InitializeListHead(&current->CacheMapVacbListEntry);
1229  Refs = CcRosVacbDecRefCount(current);
1230 #if DBG // CORE-14578
1231  if (Refs != 0)
1232  {
1233  DPRINT1("Leaking VACB %p attached to %p (%I64d)\n", current, FileObject, current->FileOffset.QuadPart);
1234  DPRINT1("There are: %d references left\n", Refs);
1235  DPRINT1("Map: %d\n", current->MappedCount);
1236  DPRINT1("Dirty: %d\n", current->Dirty);
1237  if (FileObject->FileName.Length != 0)
1238  {
1239  DPRINT1("File was: %wZ\n", &FileObject->FileName);
1240  }
1241  else if (FileObject->FsContext != NULL &&
1242  ((PFSRTL_COMMON_FCB_HEADER)(FileObject->FsContext))->NodeTypeCode == 0x0502 &&
1243  ((PFSRTL_COMMON_FCB_HEADER)(FileObject->FsContext))->NodeByteSize == 0x1F8 &&
1244  ((PUNICODE_STRING)(((PUCHAR)FileObject->FsContext) + 0x100))->Length != 0)
1245  {
1246  DPRINT1("File was: %wZ (FastFAT)\n", (PUNICODE_STRING)(((PUCHAR)FileObject->FsContext) + 0x100));
1247  }
1248  else
1249  {
1250  DPRINT1("No name for the file\n");
1251  }
1252  }
1253 #else
1254  ASSERT(Refs == 0);
1255 #endif
1256  }
1257 
1259  RemoveEntryList(&SharedCacheMap->SharedCacheMapLinks);
1261 
1262  ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
1264  }
1265  return STATUS_SUCCESS;
1266 }
Definition: cc.h:202
ULONG OpenCount
Definition: cc.h:174
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LIST_ENTRY SharedCacheMapLinks
Definition: cc.h:180
unsigned char * PUCHAR
Definition: retypes.h:3
FORCEINLINE PLIST_ENTRY RemoveTailList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:154
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3289
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointers, IN PLARGE_INTEGER FileOffset OPTIONAL, IN ULONG Length, OUT PIO_STATUS_BLOCK IoStatus)
Definition: view.c:1088
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:190
static NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
Definition: view.c:49
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
MmuFreePage * FreeList
Definition: mmuobject.c:60
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI CcRosUnmarkDirtyVacb(PROS_VACB Vacb, BOOLEAN LockViews)
Definition: view.c:538
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
PFILE_OBJECT FileObject
Definition: cc.h:178
return STATUS_SUCCESS
Definition: btrfs.c:2725
struct task_struct * current
Definition: linux.c:32

Referenced by CcRosDereferenceCache(), CcRosReleaseFileCache(), and CcRosRemoveIfClosed().

◆ CcRosDereferenceCache()

VOID NTAPI CcRosDereferenceCache ( PFILE_OBJECT  FileObject)

Definition at line 1305 of file view.c.

1307 {
1308  PROS_SHARED_CACHE_MAP SharedCacheMap;
1309  KIRQL OldIrql;
1310 
1312  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1313  ASSERT(SharedCacheMap);
1314  if (SharedCacheMap->OpenCount > 0)
1315  {
1316  SharedCacheMap->OpenCount--;
1317  if (SharedCacheMap->OpenCount == 0)
1318  {
1320  MmFreeSectionSegments(SharedCacheMap->FileObject);
1321 
1323  CcRosDeleteFileCache(FileObject, SharedCacheMap, &OldIrql);
1325 
1326  return;
1327  }
1328  }
1330 }
ULONG OpenCount
Definition: cc.h:174
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
VOID NTAPI MmFreeSectionSegments(PFILE_OBJECT FileObject)
Definition: section.c:804
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
NTSTATUS NTAPI CcRosDeleteFileCache(PFILE_OBJECT FileObject, PROS_SHARED_CACHE_MAP SharedCacheMap, PKIRQL OldIrql)
Definition: view.c:1159
PFILE_OBJECT FileObject
Definition: cc.h:178

Referenced by MmpDeleteSection().

◆ CcRosFlushDirtyPages()

NTSTATUS NTAPI CcRosFlushDirtyPages ( ULONG  Target,
PULONG  Count,
BOOLEAN  Wait,
BOOLEAN  CalledFromLazy 
)

Definition at line 183 of file view.c.

188 {
189  PLIST_ENTRY current_entry;
191  BOOLEAN Locked;
193  KIRQL OldIrql;
194 
195  DPRINT("CcRosFlushDirtyPages(Target %lu)\n", Target);
196 
197  (*Count) = 0;
198 
201 
202  current_entry = DirtyVacbListHead.Flink;
203  if (current_entry == &DirtyVacbListHead)
204  {
205  DPRINT("No Dirty pages\n");
206  }
207 
208  while ((current_entry != &DirtyVacbListHead) && (Target > 0))
209  {
210  current = CONTAINING_RECORD(current_entry,
211  ROS_VACB,
212  DirtyVacbListEntry);
213  current_entry = current_entry->Flink;
214 
216 
217  /* When performing lazy write, don't handle temporary files */
218  if (CalledFromLazy &&
219  BooleanFlagOn(current->SharedCacheMap->FileObject->Flags, FO_TEMPORARY_FILE))
220  {
222  continue;
223  }
224 
225  /* Don't attempt to lazy write the files that asked not to */
226  if (CalledFromLazy &&
227  BooleanFlagOn(current->SharedCacheMap->Flags, WRITEBEHIND_DISABLED))
228  {
230  continue;
231  }
232 
233  ASSERT(current->Dirty);
234 
236 
237  Locked = current->SharedCacheMap->Callbacks->AcquireForLazyWrite(
238  current->SharedCacheMap->LazyWriteContext, Wait);
239  if (!Locked)
240  {
243  continue;
244  }
245 
247 
248  current->SharedCacheMap->Callbacks->ReleaseFromLazyWrite(
249  current->SharedCacheMap->LazyWriteContext);
250 
253 
254  if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE) &&
256  {
257  DPRINT1("CC: Failed to flush VACB.\n");
258  }
259  else
260  {
261  ULONG PagesFreed;
262 
263  /* How many pages did we free? */
264  PagesFreed = VACB_MAPPING_GRANULARITY / PAGE_SIZE;
265  (*Count) += PagesFreed;
266 
267  /* Make sure we don't overflow target! */
268  if (Target < PagesFreed)
269  {
270  /* If we would have, jump to zero directly */
271  Target = 0;
272  }
273  else
274  {
275  Target -= PagesFreed;
276  }
277  }
278 
279  current_entry = DirtyVacbListHead.Flink;
280  }
281 
284 
285  DPRINT("CcRosFlushDirtyPages() finished\n");
286  return STATUS_SUCCESS;
287 }
Definition: cc.h:202
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_END_OF_FILE
Definition: shellext.h:62
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:260
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define WRITEBEHIND_DISABLED
Definition: cc.h:200
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1067
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:530
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
Status
Definition: gdiplustypes.h:24
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define FO_TEMPORARY_FILE
Definition: iotypes.h:1747
#define DPRINT1
Definition: precomp.h:8
#define VACB_MAPPING_GRANULARITY
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI CcRosFlushVacb(PROS_VACB Vacb)
Definition: view.c:165
return STATUS_SUCCESS
Definition: btrfs.c:2725
LIST_ENTRY DirtyVacbListHead
Definition: view.c:45
struct task_struct * current
Definition: linux.c:32
IN BOOLEAN Wait
Definition: fatprocs.h:1529

Referenced by CcRosTrimCache(), CcWriteBehind(), and NtSetSystemPowerState().

◆ CcRosFlushVacb()

NTSTATUS NTAPI CcRosFlushVacb ( PROS_VACB  Vacb)

Definition at line 165 of file view.c.

167 {
169 
170  CcRosUnmarkDirtyVacb(Vacb, TRUE);
171 
173  if (!NT_SUCCESS(Status))
174  {
175  CcRosMarkDirtyVacb(Vacb);
176  }
177 
178  return Status;
179 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CcWriteVirtualAddress(PROS_VACB Vacb)
Definition: copy.c:153
Status
Definition: gdiplustypes.h:24
VOID NTAPI CcRosMarkDirtyVacb(PROS_VACB Vacb)
Definition: view.c:502
VOID NTAPI CcRosUnmarkDirtyVacb(PROS_VACB Vacb, BOOLEAN LockViews)
Definition: view.c:538

Referenced by CcFlushCache(), CcRosFlushDirtyPages(), and CcUnpinRepinnedBcb().

◆ CcRosFreeUnusedVacb()

static BOOLEAN CcRosFreeUnusedVacb ( PULONG  Count)
static

Definition at line 698 of file view.c.

700 {
701  ULONG cFreed;
702  BOOLEAN Freed;
703  KIRQL oldIrql;
706  PLIST_ENTRY current_entry;
707 
708  cFreed = 0;
709  Freed = FALSE;
711 
713 
714  /* Browse all the available VACB */
715  current_entry = VacbLruListHead.Flink;
716  while (current_entry != &VacbLruListHead)
717  {
718  ULONG Refs;
719 
720  current = CONTAINING_RECORD(current_entry,
721  ROS_VACB,
722  VacbLruListEntry);
723  current_entry = current_entry->Flink;
724 
725  KeAcquireSpinLockAtDpcLevel(&current->SharedCacheMap->CacheMapLock);
726 
727  /* Only deal with unused VACB, we will free them */
729  if (Refs < 2)
730  {
731  ASSERT(!current->Dirty);
732  ASSERT(!current->MappedCount);
733  ASSERT(Refs == 1);
734 
735  /* Reset and move to free list */
736  RemoveEntryList(&current->CacheMapVacbListEntry);
737  RemoveEntryList(&current->VacbLruListEntry);
738  InitializeListHead(&current->VacbLruListEntry);
739  InsertHeadList(&FreeList, &current->CacheMapVacbListEntry);
740  }
741 
742  KeReleaseSpinLockFromDpcLevel(&current->SharedCacheMap->CacheMapLock);
743 
744  }
745 
747 
748  /* And now, free any of the found VACB, that'll free memory! */
749  while (!IsListEmpty(&FreeList))
750  {
751  ULONG Refs;
752 
753  current_entry = RemoveHeadList(&FreeList);
754  current = CONTAINING_RECORD(current_entry,
755  ROS_VACB,
756  CacheMapVacbListEntry);
757  InitializeListHead(&current->CacheMapVacbListEntry);
759  ASSERT(Refs == 0);
760  ++cFreed;
761  }
762 
763  /* If we freed at least one VACB, return success */
764  if (cFreed != 0)
765  {
766  Freed = TRUE;
767  }
768 
769  /* If caller asked for free count, return it */
770  if (Count != NULL)
771  {
772  *Count = cFreed;
773  }
774 
775  return Freed;
776 }
#define TRUE
Definition: types.h:120
Definition: cc.h:202
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
static LIST_ENTRY VacbLruListHead
Definition: view.c:46
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
#define CcRosVacbGetRefCount(vacb)
Definition: cc.h:545
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
MmuFreePage * FreeList
Definition: mmuobject.c:60
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int ULONG
Definition: retypes.h:1
struct task_struct * current
Definition: linux.c:32

Referenced by CcRosCreateVacb().

◆ CcRosGetVacb()

NTSTATUS NTAPI CcRosGetVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset,
PLONGLONG  BaseOffset,
PVOID BaseAddress,
PBOOLEAN  UptoDate,
PROS_VACB Vacb 
)

Definition at line 937 of file view.c.

944 {
947  ULONG Refs;
948  KIRQL OldIrql;
949 
950  ASSERT(SharedCacheMap);
951 
952  DPRINT("CcRosGetVacb()\n");
953 
954  /*
955  * Look for a VACB already mapping the same data.
956  */
957  current = CcRosLookupVacb(SharedCacheMap, FileOffset);
958  if (current == NULL)
959  {
960  /*
961  * Otherwise create a new VACB.
962  */
963  Status = CcRosCreateVacb(SharedCacheMap, FileOffset, &current);
964  if (!NT_SUCCESS(Status))
965  {
966  return Status;
967  }
968  }
969 
971 
973 
974  /* Move to the tail of the LRU list */
975  RemoveEntryList(&current->VacbLruListEntry);
976  InsertTailList(&VacbLruListHead, &current->VacbLruListEntry);
977 
979 
980  /*
981  * Return information about the VACB to the caller.
982  */
983  *UptoDate = current->Valid;
984  *BaseAddress = current->BaseAddress;
985  DPRINT("*BaseAddress %p\n", *BaseAddress);
986  *Vacb = current;
987  *BaseOffset = current->FileOffset.QuadPart;
988 
989  ASSERT(Refs > 1);
990 
991  return STATUS_SUCCESS;
992 }
Definition: cc.h:202
LONG NTSTATUS
Definition: precomp.h:26
static LIST_ENTRY VacbLruListHead
Definition: view.c:46
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define CcRosVacbGetRefCount(vacb)
Definition: cc.h:545
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
Status
Definition: gdiplustypes.h:24
static NTSTATUS CcRosCreateVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
Definition: view.c:780
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
PROS_VACB NTAPI CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:458
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
struct task_struct * current
Definition: linux.c:32

Referenced by CcpMapData(), CcRosRequestVacb(), and MiReadPage().

◆ CcRosInitializeFileCache()

NTSTATUS NTAPI CcRosInitializeFileCache ( PFILE_OBJECT  FileObject,
PCC_FILE_SIZES  FileSizes,
BOOLEAN  PinAccess,
PCACHE_MANAGER_CALLBACKS  CallBacks,
PVOID  LazyWriterContext 
)

Definition at line 1399 of file view.c.

1408 {
1409  KIRQL OldIrql;
1411  PROS_SHARED_CACHE_MAP SharedCacheMap;
1412 
1413  DPRINT("CcRosInitializeFileCache(FileObject 0x%p)\n", FileObject);
1414 
1415  Allocated = FALSE;
1416  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1417  if (SharedCacheMap == NULL)
1418  {
1419  Allocated = TRUE;
1420  SharedCacheMap = ExAllocateFromNPagedLookasideList(&SharedCacheMapLookasideList);
1421  if (SharedCacheMap == NULL)
1422  {
1424  }
1425  RtlZeroMemory(SharedCacheMap, sizeof(*SharedCacheMap));
1426  SharedCacheMap->NodeTypeCode = NODE_TYPE_SHARED_MAP;
1427  SharedCacheMap->NodeByteSize = sizeof(*SharedCacheMap);
1428  SharedCacheMap->FileObject = FileObject;
1429  SharedCacheMap->Callbacks = CallBacks;
1430  SharedCacheMap->LazyWriteContext = LazyWriterContext;
1431  SharedCacheMap->SectionSize = FileSizes->AllocationSize;
1432  SharedCacheMap->FileSize = FileSizes->FileSize;
1433  SharedCacheMap->PinAccess = PinAccess;
1434  SharedCacheMap->DirtyPageThreshold = 0;
1435  SharedCacheMap->DirtyPages = 0;
1436  InitializeListHead(&SharedCacheMap->PrivateList);
1437  KeInitializeSpinLock(&SharedCacheMap->CacheMapLock);
1438  InitializeListHead(&SharedCacheMap->CacheMapVacbListHead);
1439  InitializeListHead(&SharedCacheMap->BcbList);
1440  }
1441 
1443  if (Allocated)
1444  {
1445  if (FileObject->SectionObjectPointer->SharedCacheMap == NULL)
1446  {
1449  NULL,
1450  KernelMode);
1451  FileObject->SectionObjectPointer->SharedCacheMap = SharedCacheMap;
1452 
1454  }
1455  else
1456  {
1457  ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
1458  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1459  }
1460  }
1461  if (FileObject->PrivateCacheMap == NULL)
1462  {
1463  PPRIVATE_CACHE_MAP PrivateMap;
1464 
1465  /* Allocate the private cache map for this handle */
1466  if (SharedCacheMap->PrivateCacheMap.NodeTypeCode != 0)
1467  {
1469  }
1470  else
1471  {
1472  PrivateMap = &SharedCacheMap->PrivateCacheMap;
1473  }
1474 
1475  if (PrivateMap == NULL)
1476  {
1477  /* If we also allocated the shared cache map for this file, kill it */
1478  if (Allocated)
1479  {
1480  RemoveEntryList(&SharedCacheMap->SharedCacheMapLinks);
1481 
1482  FileObject->SectionObjectPointer->SharedCacheMap = NULL;
1484  ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
1485  }
1486 
1489  }
1490 
1491  /* Initialize it */
1492  RtlZeroMemory(PrivateMap, sizeof(PRIVATE_CACHE_MAP));
1493  PrivateMap->NodeTypeCode = NODE_TYPE_PRIVATE_MAP;
1494  PrivateMap->ReadAheadMask = PAGE_SIZE - 1;
1495  PrivateMap->FileObject = FileObject;
1497 
1498  /* Link it to the file */
1499  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1500  InsertTailList(&SharedCacheMap->PrivateList, &PrivateMap->PrivateLinks);
1501  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1502 
1503  FileObject->PrivateCacheMap = PrivateMap;
1504  SharedCacheMap->OpenCount++;
1505  }
1507 
1508  return STATUS_SUCCESS;
1509 }
BOOLEAN PinAccess
Definition: cc.h:192
LIST_ENTRY PrivateList
Definition: cc.h:184
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
ULONG OpenCount
Definition: cc.h:174
LARGE_INTEGER SectionSize
Definition: cc.h:177
LIST_ENTRY SharedCacheMapLinks
Definition: cc.h:180
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LIST_ENTRY BcbList
Definition: cc.h:176
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static CC_FILE_SIZES FileSizes
#define InsertTailList(ListHead, Entry)
ULONG ReadAheadMask
Definition: cctypes.h:75
LARGE_INTEGER FileSize
Definition: cctypes.h:16
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
unsigned char BOOLEAN
IN PFCB IN VBO OUT PLBO OUT PULONG OUT PBOOLEAN Allocated
Definition: fatprocs.h:297
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI ObReferenceObjectByPointer(IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode)
Definition: obref.c:383
PCACHE_MANAGER_CALLBACKS Callbacks
Definition: cc.h:182
LIST_ENTRY CcCleanSharedCacheMapList
Definition: view.c:63
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:190
KSPIN_LOCK ReadAheadSpinLock
Definition: cctypes.h:83
static NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
Definition: view.c:49
LIST_ENTRY PrivateLinks
Definition: cctypes.h:84
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
CSHORT NodeTypeCode
Definition: cc.h:172
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define PAGE_SIZE
Definition: env_spec_w32.h:49
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
PFILE_OBJECT FileObject
Definition: cctypes.h:76
CSHORT NodeByteSize
Definition: cc.h:173
#define NODE_TYPE_PRIVATE_MAP
Definition: cc.h:288
PRIVATE_CACHE_MAP PrivateCacheMap
Definition: cc.h:187
LARGE_INTEGER AllocationSize
Definition: cctypes.h:15
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PVOID LazyWriteContext
Definition: cc.h:183
LARGE_INTEGER FileSize
Definition: cc.h:175
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define TAG_PRIVATE_CACHE_MAP
Definition: tag.h:7
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
CSHORT NodeTypeCode
Definition: cctypes.h:71
PFILE_OBJECT FileObject
Definition: cc.h:178
return STATUS_SUCCESS
Definition: btrfs.c:2725
ULONG DirtyPageThreshold
Definition: cc.h:185
#define NODE_TYPE_SHARED_MAP
Definition: cc.h:289
ULONG DirtyPages
Definition: cc.h:179

Referenced by CcInitializeCacheMap().

◆ CcRosInternalFreeVacb()

NTSTATUS CcRosInternalFreeVacb ( PROS_VACB  Vacb)

Definition at line 1044 of file view.c.

1049 {
1050  DPRINT("Freeing VACB 0x%p\n", Vacb);
1051 #if DBG
1052  if (Vacb->SharedCacheMap->Trace)
1053  {
1054  DPRINT1("CacheMap 0x%p: deleting VACB: 0x%p\n", Vacb->SharedCacheMap, Vacb);
1055  }
1056 #endif
1057 
1060  Vacb->MemoryArea,
1062  NULL);
1064 
1065  if (Vacb->ReferenceCount != 0)
1066  {
1067  DPRINT1("Invalid free: %ld\n", Vacb->ReferenceCount);
1068  if (Vacb->SharedCacheMap->FileObject && Vacb->SharedCacheMap->FileObject->FileName.Length)
1069  {
1070  DPRINT1("For file: %wZ\n", &Vacb->SharedCacheMap->FileObject->FileName);
1071  }
1072  }
1073 
1074  ASSERT(Vacb->ReferenceCount == 0);
1078  RtlFillMemory(Vacb, sizeof(*Vacb), 0xfd);
1079  ExFreeToNPagedLookasideList(&VacbLookasideList, Vacb);
1080  return STATUS_SUCCESS;
1081 }
static VOID CcFreeCachePage(PVOID Context, MEMORY_AREA *MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
Definition: view.c:1027
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1423
static NPAGED_LOOKASIDE_LIST VacbLookasideList
Definition: view.c:50
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY CacheMapVacbListEntry
Definition: cc.h:216
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PROS_SHARED_CACHE_MAP SharedCacheMap
Definition: cc.h:226
NTSTATUS NTAPI MmFreeMemoryArea(PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_FREE_PAGE_FUNC FreePage, PVOID FreePageContext)
Definition: marea.c:278
volatile ULONG ReferenceCount
Definition: cc.h:224
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _MEMORY_AREA * MemoryArea
Definition: cc.h:207
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1445
#define DPRINT1
Definition: precomp.h:8
LIST_ENTRY DirtyVacbListEntry
Definition: cc.h:218
PFILE_OBJECT FileObject
Definition: cc.h:178
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1416
LIST_ENTRY VacbLruListEntry
Definition: cc.h:220

◆ CcRosLookupVacb()

PROS_VACB NTAPI CcRosLookupVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset 
)

Definition at line 458 of file view.c.

461 {
462  PLIST_ENTRY current_entry;
464  KIRQL oldIrql;
465 
466  ASSERT(SharedCacheMap);
467 
468  DPRINT("CcRosLookupVacb(SharedCacheMap 0x%p, FileOffset %I64u)\n",
469  SharedCacheMap, FileOffset);
470 
472  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
473 
474  current_entry = SharedCacheMap->CacheMapVacbListHead.Flink;
475  while (current_entry != &SharedCacheMap->CacheMapVacbListHead)
476  {
477  current = CONTAINING_RECORD(current_entry,
478  ROS_VACB,
479  CacheMapVacbListEntry);
480  if (IsPointInRange(current->FileOffset.QuadPart,
482  FileOffset))
483  {
487  return current;
488  }
489  if (current->FileOffset.QuadPart > FileOffset)
490  break;
491  current_entry = current_entry->Flink;
492  }
493 
496 
497  return NULL;
498 }
Definition: cc.h:202
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:190
FORCEINLINE BOOLEAN IsPointInRange(_In_ LONGLONG Offset1, _In_ LONGLONG Length1, _In_ LONGLONG Point)
Definition: cc.h:496
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:530
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define VACB_MAPPING_GRANULARITY
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
struct task_struct * current
Definition: linux.c:32

Referenced by CcFlushCache(), CcRosGetVacb(), CcRosMarkDirtyFile(), CcRosUnmapVacb(), CcSetFileSizes(), and MiIsPageFromCache().

◆ CcRosMapVacbInKernelSpace()

static NTSTATUS CcRosMapVacbInKernelSpace ( PROS_VACB  Vacb)
static

Definition at line 631 of file view.c.

633 {
634  ULONG i;
636  ULONG_PTR NumberOfPages;
638 
639  /* Create a memory area. */
642  0, // nothing checks for VACB mareas, so set to 0
643  &BaseAddress,
646  (PMEMORY_AREA*)&Vacb->MemoryArea,
647  0,
648  PAGE_SIZE);
649  ASSERT(Vacb->BaseAddress == NULL);
650  Vacb->BaseAddress = BaseAddress;
652  if (!NT_SUCCESS(Status))
653  {
654  DPRINT1("MmCreateMemoryArea failed with %lx for VACB %p\n", Status, Vacb);
655  return Status;
656  }
657 
658  ASSERT(((ULONG_PTR)Vacb->BaseAddress % PAGE_SIZE) == 0);
661 
662  /* Create a virtual mapping for this memory area */
663  NumberOfPages = BYTES_TO_PAGES(VACB_MAPPING_GRANULARITY);
664  for (i = 0; i < NumberOfPages; i++)
665  {
666  PFN_NUMBER PageFrameNumber;
667 
669  Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &PageFrameNumber);
670  if (PageFrameNumber == 0)
671  {
672  DPRINT1("Unable to allocate page\n");
673  KeBugCheck(MEMORY_MANAGEMENT);
674  }
675 
676  ASSERT(BaseAddress == Vacb->BaseAddress);
680 
682  (PVOID)((ULONG_PTR)Vacb->BaseAddress + (i * PAGE_SIZE)),
684  &PageFrameNumber,
685  1);
686  if (!NT_SUCCESS(Status))
687  {
688  DPRINT1("Unable to create virtual mapping\n");
689  KeBugCheck(MEMORY_MANAGEMENT);
690  }
691  }
692 
693  return STATUS_SUCCESS;
694 }
#define TRUE
Definition: types.h:120
PVOID BaseAddress
Definition: cc.h:205
NTSTATUS NTAPI MmCreateVirtualMapping(struct _EPROCESS *Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1423
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:229
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG PFN_NUMBER
Definition: ke.h:8
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
#define MI_SET_USAGE(x)
Definition: mm.h:253
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI MmCreateMemoryArea(PMMSUPPORT AddressSpace, ULONG Type, PVOID *BaseAddress, SIZE_T Length, ULONG Protection, PMEMORY_AREA *Result, ULONG AllocationFlags, ULONG AllocationGranularity)
Definition: marea.c:410
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define BYTES_TO_PAGES(Size)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
struct _MEMORY_AREA * MemoryArea
Definition: cc.h:207
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1445
#define DPRINT1
Definition: precomp.h:8
#define VACB_MAPPING_GRANULARITY
#define MC_CACHE
Definition: mm.h:93
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1416
#define MmSystemRangeStart
Definition: mm.h:32
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by CcRosCreateVacb().

◆ CcRosMarkDirtyFile()

NTSTATUS NTAPI CcRosMarkDirtyFile ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset 
)

Definition at line 572 of file view.c.

575 {
576  PROS_VACB Vacb;
577 
578  ASSERT(SharedCacheMap);
579 
580  DPRINT("CcRosMarkDirtyVacb(SharedCacheMap 0x%p, FileOffset %I64u)\n",
581  SharedCacheMap, FileOffset);
582 
583  Vacb = CcRosLookupVacb(SharedCacheMap, FileOffset);
584  if (Vacb == NULL)
585  {
586  KeBugCheck(CACHE_MANAGER);
587  }
588 
589  CcRosReleaseVacb(SharedCacheMap, Vacb, Vacb->Valid, TRUE, FALSE);
590 
591  return STATUS_SUCCESS;
592 }
#define TRUE
Definition: types.h:120
Definition: cc.h:202
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
NTSTATUS NTAPI CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:421
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN Valid
Definition: cc.h:209
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
PROS_VACB NTAPI CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:458
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by MmFreeSectionPage(), and MmWritePageSectionView().

◆ CcRosMarkDirtyVacb()

VOID NTAPI CcRosMarkDirtyVacb ( PROS_VACB  Vacb)

Definition at line 502 of file view.c.

504 {
505  KIRQL oldIrql;
506  PROS_SHARED_CACHE_MAP SharedCacheMap;
507 
508  SharedCacheMap = Vacb->SharedCacheMap;
509 
511  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
512 
513  ASSERT(!Vacb->Dirty);
514 
518  CcRosVacbIncRefCount(Vacb);
519 
520  /* Move to the tail of the LRU list */
523 
524  Vacb->Dirty = TRUE;
525 
527 
528  /* Schedule a lazy writer run to now that we have dirty VACB */
529  if (!LazyWriter.ScanActive)
530  {
532  }
534 }
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
static LIST_ENTRY VacbLruListHead
Definition: view.c:46
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
LAZY_WRITER LazyWriter
Definition: lazywrite.c:37
PROS_SHARED_CACHE_MAP SharedCacheMap
Definition: cc.h:226
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
BOOLEAN ScanActive
Definition: cc.h:247
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
BOOLEAN Dirty
Definition: cc.h:211
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG CcTotalDirtyPages
Definition: view.c:60
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:530
#define PAGE_SIZE
Definition: env_spec_w32.h:49
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
VOID CcScheduleLazyWriteScan(IN BOOLEAN NoDelay)
Definition: lazywrite.c:200
#define VACB_MAPPING_GRANULARITY
LIST_ENTRY DirtyVacbListEntry
Definition: cc.h:218
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
LIST_ENTRY DirtyVacbListHead
Definition: view.c:45
ULONG DirtyPages
Definition: cc.h:179
LIST_ENTRY VacbLruListEntry
Definition: cc.h:220

Referenced by CcRosFlushVacb(), CcRosReleaseVacb(), and CcSetDirtyPinnedData().

◆ CcRosReferenceCache()

VOID NTAPI CcRosReferenceCache ( PFILE_OBJECT  FileObject)

Definition at line 1270 of file view.c.

1272 {
1273  PROS_SHARED_CACHE_MAP SharedCacheMap;
1274  KIRQL OldIrql;
1275 
1277  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1278  ASSERT(SharedCacheMap);
1279  ASSERT(SharedCacheMap->OpenCount != 0);
1280  SharedCacheMap->OpenCount++;
1282 }
ULONG OpenCount
Definition: cc.h:174
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108

Referenced by MmCreateDataFileSection(), and MmCreateImageSection().

◆ CcRosReleaseFileCache()

NTSTATUS NTAPI CcRosReleaseFileCache ( PFILE_OBJECT  FileObject)

Definition at line 1334 of file view.c.

1340 {
1341  KIRQL OldIrql;
1342  PPRIVATE_CACHE_MAP PrivateMap;
1343  PROS_SHARED_CACHE_MAP SharedCacheMap;
1344 
1346 
1347  if (FileObject->SectionObjectPointer->SharedCacheMap != NULL)
1348  {
1349  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1350 
1351  /* Closing the handle, so kill the private cache map
1352  * Before you event try to remove it from FO, always
1353  * lock the master lock, to be sure not to race
1354  * with a potential read ahead ongoing!
1355  */
1356  PrivateMap = FileObject->PrivateCacheMap;
1357  FileObject->PrivateCacheMap = NULL;
1358 
1359  if (PrivateMap != NULL)
1360  {
1361  /* Remove it from the file */
1362  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1363  RemoveEntryList(&PrivateMap->PrivateLinks);
1364  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1365 
1366  /* And free it. */
1367  if (PrivateMap != &SharedCacheMap->PrivateCacheMap)
1368  {
1370  }
1371  else
1372  {
1373  PrivateMap->NodeTypeCode = 0;
1374  }
1375 
1376  if (SharedCacheMap->OpenCount > 0)
1377  {
1378  SharedCacheMap->OpenCount--;
1379  if (SharedCacheMap->OpenCount == 0)
1380  {
1382  MmFreeSectionSegments(SharedCacheMap->FileObject);
1383 
1385  CcRosDeleteFileCache(FileObject, SharedCacheMap, &OldIrql);
1387 
1388  return STATUS_SUCCESS;
1389  }
1390  }
1391  }
1392  }
1394  return STATUS_SUCCESS;
1395 }
ULONG OpenCount
Definition: cc.h:174
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
VOID NTAPI MmFreeSectionSegments(PFILE_OBJECT FileObject)
Definition: section.c:804
LIST_ENTRY PrivateLinks
Definition: cctypes.h:84
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
PRIVATE_CACHE_MAP PrivateCacheMap
Definition: cc.h:187
NTSTATUS NTAPI CcRosDeleteFileCache(PFILE_OBJECT FileObject, PROS_SHARED_CACHE_MAP SharedCacheMap, PKIRQL OldIrql)
Definition: view.c:1159
#define TAG_PRIVATE_CACHE_MAP
Definition: tag.h:7
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
CSHORT NodeTypeCode
Definition: cctypes.h:71
PFILE_OBJECT FileObject
Definition: cc.h:178
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by CcUninitializeCacheMap().

◆ CcRosReleaseVacb()

NTSTATUS NTAPI CcRosReleaseVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
PROS_VACB  Vacb,
BOOLEAN  Valid,
BOOLEAN  Dirty,
BOOLEAN  Mapped 
)

Definition at line 421 of file view.c.

427 {
428  ULONG Refs;
429  ASSERT(SharedCacheMap);
430 
431  DPRINT("CcRosReleaseVacb(SharedCacheMap 0x%p, Vacb 0x%p, Valid %u)\n",
432  SharedCacheMap, Vacb, Valid);
433 
434  Vacb->Valid = Valid;
435 
436  if (Dirty && !Vacb->Dirty)
437  {
438  CcRosMarkDirtyVacb(Vacb);
439  }
440 
441  if (Mapped)
442  {
443  if (InterlockedIncrement((PLONG)&Vacb->MappedCount) == 1)
444  {
445  CcRosVacbIncRefCount(Vacb);
446  }
447  }
448 
449  Refs = CcRosVacbDecRefCount(Vacb);
450  ASSERT(Refs > 0);
451 
452  return STATUS_SUCCESS;
453 }
ULONG MappedCount
Definition: cc.h:214
void DPRINT(...)
Definition: polytest.cpp:61
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
BOOLEAN Dirty
Definition: cc.h:211
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:530
#define InterlockedIncrement
Definition: armddk.h:53
BOOLEAN Valid
Definition: cc.h:209
VOID NTAPI CcRosMarkDirtyVacb(PROS_VACB Vacb)
Definition: view.c:502
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
signed int * PLONG
Definition: retypes.h:5

Referenced by CcCopyData(), CcFlushCache(), CcMapData(), CcpDereferenceBcb(), CcPerformReadAhead(), CcpGetAppropriateBcb(), CcpMapData(), CcpPinData(), CcRosMarkDirtyFile(), CcRosUnmapVacb(), CcSetFileSizes(), CcUnpinRepinnedBcb(), MiIsPageFromCache(), and MiReadPage().

◆ CcRosRemoveIfClosed()

VOID NTAPI CcRosRemoveIfClosed ( PSECTION_OBJECT_POINTERS  SectionObjectPointer)

Definition at line 1286 of file view.c.

1288 {
1289  PROS_SHARED_CACHE_MAP SharedCacheMap;
1290  KIRQL OldIrql;
1291 
1292  DPRINT("CcRosRemoveIfClosed()\n");
1294  SharedCacheMap = SectionObjectPointer->SharedCacheMap;
1295  if (SharedCacheMap && SharedCacheMap->OpenCount == 0)
1296  {
1297  CcRosDeleteFileCache(SharedCacheMap->FileObject, SharedCacheMap, &OldIrql);
1298  }
1300 }
ULONG OpenCount
Definition: cc.h:174
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1368
UCHAR KIRQL
Definition: env_spec_w32.h:591
void DPRINT(...)
Definition: polytest.cpp:61
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
NTSTATUS NTAPI CcRosDeleteFileCache(PFILE_OBJECT FileObject, PROS_SHARED_CACHE_MAP SharedCacheMap, PKIRQL OldIrql)
Definition: view.c:1159
PFILE_OBJECT FileObject
Definition: cc.h:178

Referenced by MmFlushImageSection().

◆ CcRosRequestVacb()

NTSTATUS NTAPI CcRosRequestVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset,
PVOID BaseAddress,
PBOOLEAN  UptoDate,
PROS_VACB Vacb 
)

Definition at line 996 of file view.c.

1005 {
1006  LONGLONG BaseOffset;
1007 
1008  ASSERT(SharedCacheMap);
1009 
1011  {
1012  DPRINT1("Bad fileoffset %I64x should be multiple of %x",
1014  KeBugCheck(CACHE_MANAGER);
1015  }
1016 
1017  return CcRosGetVacb(SharedCacheMap,
1018  FileOffset,
1019  &BaseOffset,
1020  BaseAddress,
1021  UptoDate,
1022  Vacb);
1023 }
NTSTATUS NTAPI CcRosGetVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PLONGLONG BaseOffset, PVOID *BaseAddress, PBOOLEAN UptoDate, PROS_VACB *Vacb)
Definition: view.c:937
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
int64_t LONGLONG
Definition: typedefs.h:66
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define DPRINT1
Definition: precomp.h:8
#define VACB_MAPPING_GRANULARITY

Referenced by CcCopyData(), and CcPerformReadAhead().

◆ CcRosTraceCacheMap()

VOID NTAPI CcRosTraceCacheMap ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
BOOLEAN  Trace 
)

Definition at line 118 of file view.c.

121 {
122 #if DBG
123  KIRQL oldirql;
124  PLIST_ENTRY current_entry;
126 
127  if (!SharedCacheMap)
128  return;
129 
130  SharedCacheMap->Trace = Trace;
131 
132  if (Trace)
133  {
134  DPRINT1("Enabling Tracing for CacheMap 0x%p:\n", SharedCacheMap);
135 
137  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
138 
139  current_entry = SharedCacheMap->CacheMapVacbListHead.Flink;
140  while (current_entry != &SharedCacheMap->CacheMapVacbListHead)
141  {
142  current = CONTAINING_RECORD(current_entry, ROS_VACB, CacheMapVacbListEntry);
143  current_entry = current_entry->Flink;
144 
145  DPRINT1(" VACB 0x%p enabled, RefCount %lu, Dirty %u, PageOut %lu\n",
146  current, current->ReferenceCount, current->Dirty, current->PageOut );
147  }
148 
151  }
152  else
153  {
154  DPRINT1("Disabling Tracing for CacheMap 0x%p:\n", SharedCacheMap);
155  }
156 
157 #else
158  UNREFERENCED_PARAMETER(SharedCacheMap);
160 #endif
161 }
Definition: cc.h:202
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
UCHAR KIRQL
Definition: env_spec_w32.h:591
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:190
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
#define Trace(x)
Definition: zutil.h:197
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define DPRINT1
Definition: precomp.h:8
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
struct task_struct * current
Definition: linux.c:32

◆ CcRosTrimCache()

NTSTATUS CcRosTrimCache ( ULONG  Target,
ULONG  Priority,
PULONG  NrFreed 
)

Definition at line 290 of file view.c.

302 {
303  PLIST_ENTRY current_entry;
305  ULONG PagesFreed;
306  KIRQL oldIrql;
308  PFN_NUMBER Page;
309  ULONG i;
310  BOOLEAN FlushedPages = FALSE;
311 
312  DPRINT("CcRosTrimCache(Target %lu)\n", Target);
313 
315 
316  *NrFreed = 0;
317 
318 retry:
320 
321  current_entry = VacbLruListHead.Flink;
322  while (current_entry != &VacbLruListHead)
323  {
324  ULONG Refs;
325 
326  current = CONTAINING_RECORD(current_entry,
327  ROS_VACB,
328  VacbLruListEntry);
329  current_entry = current_entry->Flink;
330 
331  KeAcquireSpinLockAtDpcLevel(&current->SharedCacheMap->CacheMapLock);
332 
333  /* Reference the VACB */
335 
336  /* Check if it's mapped and not dirty */
337  if (InterlockedCompareExchange((PLONG)&current->MappedCount, 0, 0) > 0 && !current->Dirty)
338  {
339  /* We have to break these locks because Cc sucks */
340  KeReleaseSpinLockFromDpcLevel(&current->SharedCacheMap->CacheMapLock);
342 
343  /* Page out the VACB */
344  for (i = 0; i < VACB_MAPPING_GRANULARITY / PAGE_SIZE; i++)
345  {
346  Page = (PFN_NUMBER)(MmGetPhysicalAddress((PUCHAR)current->BaseAddress + (i * PAGE_SIZE)).QuadPart >> PAGE_SHIFT);
347 
349  }
350 
351  /* Reacquire the locks */
353  KeAcquireSpinLockAtDpcLevel(&current->SharedCacheMap->CacheMapLock);
354  }
355 
356  /* Dereference the VACB */
358 
359  /* Check if we can free this entry now */
360  if (Refs < 2)
361  {
362  ASSERT(!current->Dirty);
363  ASSERT(!current->MappedCount);
364  ASSERT(Refs == 1);
365 
366  RemoveEntryList(&current->CacheMapVacbListEntry);
367  RemoveEntryList(&current->VacbLruListEntry);
368  InitializeListHead(&current->VacbLruListEntry);
369  InsertHeadList(&FreeList, &current->CacheMapVacbListEntry);
370 
371  /* Calculate how many pages we freed for Mm */
372  PagesFreed = min(VACB_MAPPING_GRANULARITY / PAGE_SIZE, Target);
373  Target -= PagesFreed;
374  (*NrFreed) += PagesFreed;
375  }
376 
377  KeReleaseSpinLockFromDpcLevel(&current->SharedCacheMap->CacheMapLock);
378  }
379 
381 
382  /* Try flushing pages if we haven't met our target */
383  if ((Target > 0) && !FlushedPages)
384  {
385  /* Flush dirty pages to disk */
386  CcRosFlushDirtyPages(Target, &PagesFreed, FALSE, FALSE);
387  FlushedPages = TRUE;
388 
389  /* We can only swap as many pages as we flushed */
390  if (PagesFreed < Target) Target = PagesFreed;
391 
392  /* Check if we flushed anything */
393  if (PagesFreed != 0)
394  {
395  /* Try again after flushing dirty pages */
396  DPRINT("Flushed %lu dirty cache pages to disk\n", PagesFreed);
397  goto retry;
398  }
399  }
400 
401  while (!IsListEmpty(&FreeList))
402  {
403  ULONG Refs;
404 
405  current_entry = RemoveHeadList(&FreeList);
406  current = CONTAINING_RECORD(current_entry,
407  ROS_VACB,
408  CacheMapVacbListEntry);
409  InitializeListHead(&current->CacheMapVacbListEntry);
411  ASSERT(Refs == 0);
412  }
413 
414  DPRINT("Evicted %lu cache pages\n", (*NrFreed));
415 
416  return STATUS_SUCCESS;
417 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define TRUE
Definition: types.h:120
Definition: cc.h:202
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
unsigned char * PUCHAR
Definition: retypes.h:3
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
#define InterlockedCompareExchange
Definition: interlocked.h:104
static LIST_ENTRY VacbLruListHead
Definition: view.c:46
NTSTATUS NTAPI CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
Definition: view.c:183
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG PFN_NUMBER
Definition: ke.h:8
unsigned char BOOLEAN
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI MmPageOutPhysicalAddress(PFN_NUMBER Page)
Definition: rmap.c:57
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1067
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
MmuFreePage * FreeList
Definition: mmuobject.c:60
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:530
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define min(a, b)
Definition: monoChain.cc:55
#define VACB_MAPPING_GRANULARITY
unsigned int ULONG
Definition: retypes.h:1
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:682
return STATUS_SUCCESS
Definition: btrfs.c:2725
signed int * PLONG
Definition: retypes.h:5
struct task_struct * current
Definition: linux.c:32
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by CcInitView().

◆ CcRosUnmapVacb()

NTSTATUS NTAPI CcRosUnmapVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset,
BOOLEAN  NowDirty 
)

Definition at line 600 of file view.c.

604 {
605  PROS_VACB Vacb;
606 
607  ASSERT(SharedCacheMap);
608 
609  DPRINT("CcRosUnmapVacb(SharedCacheMap 0x%p, FileOffset %I64u, NowDirty %u)\n",
610  SharedCacheMap, FileOffset, NowDirty);
611 
612  Vacb = CcRosLookupVacb(SharedCacheMap, FileOffset);
613  if (Vacb == NULL)
614  {
615  return STATUS_UNSUCCESSFUL;
616  }
617 
618  ASSERT(Vacb->MappedCount != 0);
619  if (InterlockedDecrement((PLONG)&Vacb->MappedCount) == 0)
620  {
621  CcRosVacbDecRefCount(Vacb);
622  }
623 
624  CcRosReleaseVacb(SharedCacheMap, Vacb, Vacb->Valid, NowDirty, FALSE);
625 
626  return STATUS_SUCCESS;
627 }
Definition: cc.h:202
ULONG MappedCount
Definition: cc.h:214
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Valid, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:421
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define InterlockedDecrement
Definition: armddk.h:52
BOOLEAN Valid
Definition: cc.h:209
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
PROS_VACB NTAPI CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:458
return STATUS_SUCCESS
Definition: btrfs.c:2725
signed int * PLONG
Definition: retypes.h:5

Referenced by MmPageOutSectionView(), and MmUnsharePageEntrySectionSegment().

◆ CcRosUnmarkDirtyVacb()

VOID NTAPI CcRosUnmarkDirtyVacb ( PROS_VACB  Vacb,
BOOLEAN  LockViews 
)

Definition at line 538 of file view.c.

541 {
542  KIRQL oldIrql;
543  PROS_SHARED_CACHE_MAP SharedCacheMap;
544 
545  SharedCacheMap = Vacb->SharedCacheMap;
546 
547  if (LockViews)
548  {
550  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
551  }
552 
553  ASSERT(Vacb->Dirty);
554 
555  Vacb->Dirty = FALSE;
556 
561  CcRosVacbDecRefCount(Vacb);
562 
563  if (LockViews)
564  {
567  }
568 }
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PROS_SHARED_CACHE_MAP SharedCacheMap
Definition: cc.h:226
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:533
BOOLEAN Dirty
Definition: cc.h:211
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG CcTotalDirtyPages
Definition: view.c:60
#define PAGE_SIZE
Definition: env_spec_w32.h:49
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define VACB_MAPPING_GRANULARITY
LIST_ENTRY DirtyVacbListEntry
Definition: cc.h:218
KSPIN_LOCK CacheMapLock
Definition: cc.h:193
ULONG DirtyPages
Definition: cc.h:179

Referenced by CcPurgeCacheSection(), CcRosDeleteFileCache(), and CcRosFlushVacb().

Variable Documentation

◆ CcCleanSharedCacheMapList

LIST_ENTRY CcCleanSharedCacheMapList

Definition at line 63 of file view.c.

Referenced by CcInitView(), and CcRosInitializeFileCache().

◆ CcDeferredWrites

LIST_ENTRY CcDeferredWrites

◆ CcDeferredWriteSpinLock

KSPIN_LOCK CcDeferredWriteSpinLock

Definition at line 62 of file view.c.

Referenced by CcCanIWrite(), CcDeferWrite(), CcInitView(), and CcPostDeferredWrites().

◆ CcDirtyPageThreshold

ULONG CcDirtyPageThreshold = 0

Definition at line 59 of file view.c.

Referenced by CcCanIWrite(), and CcInitializeCacheManager().

◆ CcTotalDirtyPages

ULONG CcTotalDirtyPages = 0

◆ DirtyVacbListHead

LIST_ENTRY DirtyVacbListHead

Definition at line 45 of file view.c.

Referenced by CcInitView(), CcIsThereDirtyData(), CcRosFlushDirtyPages(), and CcRosMarkDirtyVacb().

◆ iBcbLookasideList

NPAGED_LOOKASIDE_LIST iBcbLookasideList

Definition at line 48 of file view.c.

Referenced by CcInitView(), CcpDereferenceBcb(), CcpGetAppropriateBcb(), and CcUnpinRepinnedBcb().

◆ SharedCacheMapLookasideList

NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
static

Definition at line 49 of file view.c.

Referenced by CcInitView(), CcRosDeleteFileCache(), and CcRosInitializeFileCache().

◆ VacbLookasideList

NPAGED_LOOKASIDE_LIST VacbLookasideList
static

Definition at line 50 of file view.c.

Referenced by CcInitView(), CcRosCreateVacb(), and CcRosInternalFreeVacb().

◆ VacbLruListHead

LIST_ENTRY VacbLruListHead
static