From cb52c8212501589681aa8927ede568b73b51e3ea Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Wed, 24 Jan 2018 21:45:37 +0100 Subject: [PATCH] [NTOSKRNL] Implement (it's a bit raw for now!) the !filecache command in KDBG --- ntoskrnl/cc/view.c | 55 +++++++++++++++++++++++++++++++++++++++++ ntoskrnl/kdbg/kdb_cli.c | 2 ++ 2 files changed, 57 insertions(+) diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c index a9e83bb5b1f..adf79eba7d9 100644 --- a/ntoskrnl/cc/view.c +++ b/ntoskrnl/cc/view.c @@ -1493,4 +1493,59 @@ CcInitView ( return TRUE; } +BOOLEAN +ExpKdbgExtFileCache(ULONG Argc, PCHAR Argv[]) +{ + PLIST_ENTRY ListEntry; + UNICODE_STRING NoName = RTL_CONSTANT_STRING(L"No name for File"); + + KdbpPrint("Control\t\tValid\tDirty\tName\n"); + /* No need to lock the spin lock here, we're in DBG */ + for (ListEntry = CcCleanSharedCacheMapList.Flink; + ListEntry != &CcCleanSharedCacheMapList; + ListEntry = ListEntry->Flink) + { + PLIST_ENTRY Vacbs; + ULONG Valid = 0, Dirty = 0; + PROS_SHARED_CACHE_MAP SharedCacheMap; + PUNICODE_STRING FileName; + + SharedCacheMap = CONTAINING_RECORD(ListEntry, ROS_SHARED_CACHE_MAP, SharedCacheMapLinks); + + /* First, count for all the associated VACB */ + for (Vacbs = SharedCacheMap->CacheMapVacbListHead.Flink; + Vacbs != &SharedCacheMap->CacheMapVacbListHead; + Vacbs = Vacbs->Flink) + { + PROS_VACB Vacb; + + Vacb = CONTAINING_RECORD(Vacbs, ROS_VACB, CacheMapVacbListEntry); + if (Vacb->Dirty) + { + Dirty += VACB_MAPPING_GRANULARITY / 1024; + } + if (Vacb->Valid) + { + Valid += VACB_MAPPING_GRANULARITY / 1024; + } + } + + /* Setup name */ + if (SharedCacheMap->FileObject != NULL && + SharedCacheMap->FileObject->FileName.Length != 0) + { + FileName = &SharedCacheMap->FileObject->FileName; + } + else + { + FileName = &NoName; + } + + /* And print */ + KdbpPrint("%p\t%d\t%d\t%wZ\n", SharedCacheMap, Valid, Dirty, FileName); + } + + return TRUE; +} + /* EOF */ diff --git a/ntoskrnl/kdbg/kdb_cli.c b/ntoskrnl/kdbg/kdb_cli.c index fe83d5d4219..dfb01f49604 100644 --- a/ntoskrnl/kdbg/kdb_cli.c +++ b/ntoskrnl/kdbg/kdb_cli.c @@ -93,6 +93,7 @@ static BOOLEAN KdbpCmdDmesg(ULONG Argc, PCHAR Argv[]); BOOLEAN ExpKdbgExtPool(ULONG Argc, PCHAR Argv[]); BOOLEAN ExpKdbgExtPoolUsed(ULONG Argc, PCHAR Argv[]); +BOOLEAN ExpKdbgExtFileCache(ULONG Argc, PCHAR Argv[]); #ifdef __ROS_DWARF__ static BOOLEAN KdbpCmdPrintStruct(ULONG Argc, PCHAR Argv[]); @@ -186,6 +187,7 @@ static const struct { "help", "help", "Display help screen.", KdbpCmdHelp }, { "!pool", "!pool [Address [Flags]]", "Display information about pool allocations.", ExpKdbgExtPool }, { "!poolused", "!poolused [Flags [Tag]]", "Display pool usage.", ExpKdbgExtPoolUsed }, + { "!filecache", "!filecache", "Display cache usage.", ExpKdbgExtFileCache }, }; /* FUNCTIONS *****************************************************************/