[NTOSKRNL] Allow filtering !poolused output using a tag

This commit is contained in:
Pierre Schweitzer 2017-12-29 17:00:53 +01:00
parent 879d8f2104
commit 454e8738f2
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
2 changed files with 27 additions and 7 deletions

View file

@ -185,7 +185,7 @@ static const struct
{ "kmsg", "kmsg", "Kernel dmesg. Alias for dmesg.", KdbpCmdDmesg }, { "kmsg", "kmsg", "Kernel dmesg. Alias for dmesg.", KdbpCmdDmesg },
{ "help", "help", "Display help screen.", KdbpCmdHelp }, { "help", "help", "Display help screen.", KdbpCmdHelp },
{ "!pool", "!pool [Address [Flags]]", "Display information about pool allocations.", ExpKdbgExtPool }, { "!pool", "!pool [Address [Flags]]", "Display information about pool allocations.", ExpKdbgExtPool },
{ "!poolused", "!poolused", "Display pool usage.", ExpKdbgExtPoolUsed }, { "!poolused", "!poolused [Tag]", "Display pool usage.", ExpKdbgExtPoolUsed },
}; };
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/

View file

@ -480,7 +480,7 @@ ExpTagAllowPrint(CHAR Tag)
else DPRINT1(fmt, ##__VA_ARGS__) else DPRINT1(fmt, ##__VA_ARGS__)
VOID VOID
MiDumpPoolConsumers(BOOLEAN CalledFromDbg) MiDumpPoolConsumers(BOOLEAN CalledFromDbg, ULONG Tag)
{ {
SIZE_T i; SIZE_T i;
@ -519,8 +519,10 @@ MiDumpPoolConsumers(BOOLEAN CalledFromDbg)
{ {
// //
// If there's a tag, attempt to do a pretty print // If there's a tag, attempt to do a pretty print
// only if it matches the caller tag, or if
// any tag is allowed
// //
if (TableEntry->Key != 0 && TableEntry->Key != TAG_NONE) if (TableEntry->Key != 0 && TableEntry->Key != TAG_NONE && (Tag == 0 || TableEntry->Key == Tag))
{ {
CHAR Tag[4]; CHAR Tag[4];
@ -548,7 +550,7 @@ MiDumpPoolConsumers(BOOLEAN CalledFromDbg)
TableEntry->PagedAllocs, TableEntry->PagedBytes); TableEntry->PagedAllocs, TableEntry->PagedBytes);
} }
} }
else else if (Tag == 0 || Tag == TAG_NONE)
{ {
MiDumperPrint(CalledFromDbg, "Anon\t\t%ld\t\t%ld\t\t%ld\t\t%ld\n", MiDumperPrint(CalledFromDbg, "Anon\t\t%ld\t\t%ld\t\t%ld\t\t%ld\n",
TableEntry->NonPagedAllocs, TableEntry->NonPagedBytes, TableEntry->NonPagedAllocs, TableEntry->NonPagedBytes,
@ -1749,7 +1751,7 @@ ExAllocatePoolWithTag(IN POOL_TYPE PoolType,
// //
// Out of memory, display current consumption // Out of memory, display current consumption
// //
MiDumpPoolConsumers(FALSE); MiDumpPoolConsumers(FALSE, 0);
#endif #endif
// //
@ -2082,7 +2084,7 @@ ExAllocatePoolWithTag(IN POOL_TYPE PoolType,
// //
// Out of memory, display current consumption // Out of memory, display current consumption
// //
MiDumpPoolConsumers(FALSE); MiDumpPoolConsumers(FALSE, 0);
#endif #endif
// //
@ -2942,7 +2944,25 @@ ExpKdbgExtPoolUsed(
ULONG Argc, ULONG Argc,
PCHAR Argv[]) PCHAR Argv[])
{ {
MiDumpPoolConsumers(TRUE); ULONG Tag = 0;
if (Argc > 1)
{
CHAR Tmp[4];
ULONG Len;
/* Get the tag */
Len = strlen(Argv[1]);
if (Len > 4)
{
Len = 4;
}
RtlCopyMemory(Tmp, Argv[1], Len * sizeof(CHAR));
Tag = *((PULONG)Tmp);
}
MiDumpPoolConsumers(TRUE, Tag);
return TRUE; return TRUE;
} }