https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8b20755040754506f3f12…
commit 8b20755040754506f3f12a30857f8edc5bf83f33
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Thu Mar 8 12:25:19 2018 +0100
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Nov 24 18:26:19 2019 +0100
[NTOS] Add compile time option to trace callers of pool allocations
---
ntoskrnl/mm/ARM3/expool.c | 42 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/ntoskrnl/mm/ARM3/expool.c b/ntoskrnl/mm/ARM3/expool.c
index 647a4d15681..00c68f4ab19 100644
--- a/ntoskrnl/mm/ARM3/expool.c
+++ b/ntoskrnl/mm/ARM3/expool.c
@@ -22,6 +22,10 @@
#define POOL_BIG_TABLE_ENTRY_FREE 0x1
+/* DEBUGGING ******************************************************************/
+
+//#define DBG_NUMBER_OF_FRAMES_TO_CAPTURE 5
+
typedef struct _POOL_DPC_CONTEXT
{
PPOOL_TRACKER_TABLE PoolTrackTable;
@@ -1847,9 +1851,14 @@ ExReturnPoolQuota(IN PVOID P)
*/
PVOID
NTAPI
-ExAllocatePoolWithTag(IN POOL_TYPE PoolType,
- IN SIZE_T NumberOfBytes,
- IN ULONG Tag)
+#ifdef DBG_NUMBER_OF_FRAMES_TO_CAPTURE
+ExAllocatePoolWithTagInternal(
+#else
+ExAllocatePoolWithTag(
+#endif
+ _In_ POOL_TYPE PoolType,
+ _In_ SIZE_T NumberOfBytes,
+ _In_ ULONG Tag)
{
PPOOL_DESCRIPTOR PoolDesc;
PLIST_ENTRY ListHead;
@@ -2417,6 +2426,33 @@ ExAllocatePoolWithTag(IN POOL_TYPE PoolType,
return Allocation;
}
+#ifdef DBG_NUMBER_OF_FRAMES_TO_CAPTURE
+PVOID
+NTAPI
+ExAllocatePoolWithTag(
+ _In_ POOL_TYPE PoolType,
+ _In_ SIZE_T NumberOfBytes,
+ _In_ ULONG Tag)
+{
+ SIZE_T FullSize;
+ PVOID Allocation, *DbgData;
+
+ /* Allocate a larger chunk to add the debug data */
+ FullSize = NumberOfBytes + (DBG_NUMBER_OF_FRAMES_TO_CAPTURE + 2) * sizeof(PVOID);
+ Allocation = ExAllocatePoolWithTagInternal(PoolType, FullSize, Tag);
+ if (Allocation == NULL)
+ {
+ return NULL;
+ }
+
+ /* Append the debug data, separated by a '####' */
+ DbgData = ALIGN_UP_POINTER_BY((PUCHAR)Allocation + NumberOfBytes, sizeof(PVOID));
+ DbgData[0] = (PVOID)(ULONG_PTR)'####';
+ RtlWalkFrameChain(&DbgData[1], DBG_NUMBER_OF_FRAMES_TO_CAPTURE, 0);
+ return Allocation;
+}
+#endif
+
/*
* @implemented
*/