Put sound into multimedia and rename it to audio because it is "MoreCorrect©"
[reactos.git] / reactos / drivers / lib / ip / network / memtrack.c
1 #define MEMTRACK_NO_POOL
2 #include "precomp.h"
3
4 #ifdef MEMTRACK
5
6 #define TRACK_TAG TAG('T','r','C','K')
7
8 static LIST_ENTRY AllocatedObjectsList;
9 static KSPIN_LOCK AllocatedObjectsLock;
10 static NPAGED_LOOKASIDE_LIST AllocatedObjectsLookasideList;
11 DWORD TagsToShow[MEMTRACK_MAX_TAGS_TO_TRACK] = { 0 };
12
13 VOID TrackTag( DWORD Tag ) {
14 UINT i;
15
16 for( i = 0; TagsToShow[i]; i++ );
17 TagsToShow[i] = Tag;
18 }
19
20 VOID TrackingInit() {
21 TcpipInitializeSpinLock( &AllocatedObjectsLock );
22 InitializeListHead( &AllocatedObjectsList );
23 ExInitializeNPagedLookasideList(&AllocatedObjectsLookasideList,
24 NULL,
25 NULL,
26 0,
27 sizeof(ALLOCATION_TRACKER),
28 TRACK_TAG,
29 0 );
30 }
31
32 VOID ShowTrackedThing( PCHAR What, PALLOCATION_TRACKER Thing,
33 PCHAR File, UINT Line ) {
34 /* if( ShowTag( Thing->Tag ) ) */
35 if( File ) {
36 TI_DbgPrint(MAX_TRACE,
37 ("[%s] Thing %08x %c%c%c%c (%s:%d) (Called from %s:%d)\n",
38 What,
39 Thing->Thing,
40 ((PCHAR)&Thing->Tag)[3],
41 ((PCHAR)&Thing->Tag)[2],
42 ((PCHAR)&Thing->Tag)[1],
43 ((PCHAR)&Thing->Tag)[0],
44 Thing->FileName,
45 Thing->LineNo,
46 File, Line));
47 } else {
48 TI_DbgPrint(MAX_TRACE,
49 ( "[%s] Thing %08x %c%c%c%c (%s:%d)\n",
50 What,
51 Thing->Thing,
52 ((PCHAR)&Thing->Tag)[3],
53 ((PCHAR)&Thing->Tag)[2],
54 ((PCHAR)&Thing->Tag)[1],
55 ((PCHAR)&Thing->Tag)[0],
56 Thing->FileName,
57 Thing->LineNo ));
58 }
59 }
60
61 VOID TrackWithTag( DWORD Tag, PVOID Thing, PCHAR FileName, DWORD LineNo ) {
62 PALLOCATION_TRACKER TrackedThing =
63 ExAllocateFromNPagedLookasideList( &AllocatedObjectsLookasideList );
64
65 KIRQL OldIrql;
66 PLIST_ENTRY Entry;
67 PALLOCATION_TRACKER ThingInList;
68
69 TcpipAcquireSpinLock( &AllocatedObjectsLock, &OldIrql );
70 Entry = AllocatedObjectsList.Flink;
71 while( Entry != &AllocatedObjectsList ) {
72 ThingInList = CONTAINING_RECORD(Entry, ALLOCATION_TRACKER, Entry);
73 if( ThingInList->Thing == Thing ) {
74 RemoveEntryList(Entry);
75
76 TcpipReleaseSpinLock( &AllocatedObjectsLock, OldIrql );
77 ShowTrackedThing( "Alloc", ThingInList, FileName, LineNo );
78 PoolFreeBuffer( ThingInList );
79 TrackDumpFL( FileName, LineNo );
80 DbgPrint("TRACK: SPECIFIED ALREADY ALLOCATED ITEM %x\n", Thing);
81 TcpipBugCheck( 0 );
82 }
83 Entry = Entry->Flink;
84 }
85
86 if( TrackedThing ) {
87 TrackedThing->Tag = Tag;
88 TrackedThing->Thing = Thing;
89 TrackedThing->FileName = FileName;
90 TrackedThing->LineNo = LineNo;
91
92
93 InsertHeadList( &AllocatedObjectsList, &TrackedThing->Entry );
94 ShowTrackedThing( "Alloc", TrackedThing, FileName, LineNo );
95 }
96
97 TcpipReleaseSpinLock( &AllocatedObjectsLock, OldIrql );
98
99 /*TrackDumpFL( FileName, LineNo );*/
100 }
101
102 BOOL ShowTag( DWORD Tag ) {
103 UINT i;
104
105 for( i = 0; TagsToShow[i] && TagsToShow[i] != Tag; i++ );
106
107 return TagsToShow[i] ? TRUE : FALSE;
108 }
109
110 VOID UntrackFL( PCHAR File, DWORD Line, PVOID Thing ) {
111 KIRQL OldIrql;
112 PLIST_ENTRY Entry;
113 PALLOCATION_TRACKER ThingInList;
114
115 TcpipAcquireSpinLock( &AllocatedObjectsLock, &OldIrql );
116 Entry = AllocatedObjectsList.Flink;
117 while( Entry != &AllocatedObjectsList ) {
118 ThingInList = CONTAINING_RECORD(Entry, ALLOCATION_TRACKER, Entry);
119 if( ThingInList->Thing == Thing ) {
120 RemoveEntryList(Entry);
121
122 ShowTrackedThing( "Free ", ThingInList, File, Line );
123
124 ExFreeToNPagedLookasideList( &AllocatedObjectsLookasideList,
125 ThingInList );
126
127 TcpipReleaseSpinLock( &AllocatedObjectsLock, OldIrql );
128 /* TrackDumpFL( File, Line ); */
129 return;
130 }
131 Entry = Entry->Flink;
132 }
133 TcpipReleaseSpinLock( &AllocatedObjectsLock, OldIrql );
134 TrackDumpFL( File, Line );
135 DbgPrint("UNTRACK: SPECIFIED ALREADY FREE ITEM %x\n", Thing);
136 TcpipBugCheck( 0 );
137 }
138
139 VOID TrackDumpFL( PCHAR File, DWORD Line ) {
140 KIRQL OldIrql;
141 PLIST_ENTRY Entry;
142 PALLOCATION_TRACKER Thing;
143
144 TI_DbgPrint(MAX_TRACE,("Dump: %s:%d\n", File, Line));
145
146 TcpipAcquireSpinLock( &AllocatedObjectsLock, &OldIrql );
147 Entry = AllocatedObjectsList.Flink;
148 while( Entry != &AllocatedObjectsList ) {
149 Thing = CONTAINING_RECORD(Entry, ALLOCATION_TRACKER, Entry);
150 ShowTrackedThing( "Dump ", Thing, 0, 0 );
151 Entry = Entry->Flink;
152 }
153 TcpipReleaseSpinLock( &AllocatedObjectsLock, OldIrql );
154 }
155
156 #endif/*MEMTRACK*/