- Forgot to commit these for MSVC build...
[reactos.git] / reactos / drivers / net / tcpip / include / memtrack.h
1 #ifndef MEMTRACK_H
2 #define MEMTRACK_H
3
4 #include <pool.h>
5
6 #ifndef FOURCC
7 #define FOURCC(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
8 #endif
9
10 #define FBSD_MALLOC FOURCC('d','s','b','f')
11 #define EXALLOC_TAG FOURCC('E','x','A','l')
12 #define IRP_TAG FOURCC('P','I','R','P')
13
14 #define AllocatePacketWithBuffer(x,y,z) AllocatePacketWithBufferX(x,y,z,__FILE__,__LINE__)
15 #define FreeNdisPacket(x) FreeNdisPacketX(x,__FILE__,__LINE__)
16
17 #ifdef MEMTRACK
18 #define MTMARK() TrackDumpFL(__FILE__, __LINE__)
19 #define exAllocatePool(x,y) ExAllocatePoolX(x,y,__FILE__,__LINE__)
20 #define exAllocatePoolWithTag(x,y,z) ExAllocatePoolX(x,y,__FILE__,__LINE__)
21 #define exFreePool(x) ExFreePoolX(x,__FILE__,__LINE__)
22
23 extern LIST_ENTRY AllocatedObjectsHead;
24 extern KSPIN_LOCK AllocatedObjectsLock;
25
26 typedef struct _ALLOCATION_TRACKER {
27 LIST_ENTRY Entry;
28 DWORD Tag;
29 PVOID Thing;
30 PCHAR FileName;
31 DWORD LineNo;
32 } ALLOCATION_TRACKER, *PALLOCATION_TRACKER;
33
34 VOID TrackingInit();
35 VOID TrackWithTag( DWORD Tag, PVOID Thing, PCHAR File, DWORD Line );
36 #define Track(Tag,Thing) TrackWithTag(Tag,Thing,__FILE__,__LINE__)
37 VOID UntrackFL( PCHAR File, DWORD Line, PVOID Thing );
38 #define Untrack(Thing) UntrackFL(__FILE__,__LINE__,Thing)
39 VOID TrackDumpFL( PCHAR File, DWORD Line );
40 #define TrackDump() TrackDumpFL(__FILE__,__LINE__)
41 VOID TrackTag( DWORD Tag );
42
43 static __inline PVOID ExAllocatePoolX( POOL_TYPE type, SIZE_T size, PCHAR File, ULONG Line ) {
44 PVOID Out = PoolAllocateBuffer( size );
45 if( Out ) TrackWithTag( EXALLOC_TAG, Out, File, Line );
46 return Out;
47 }
48 static __inline VOID ExFreePoolX( PVOID Data, PCHAR File, ULONG Line ) {
49 UntrackFL(File, Line, Data);
50 PoolFreeBuffer(Data);
51 }
52
53 #define MEMTRACK_MAX_TAGS_TO_TRACK 64
54 #else
55 #define MTMARK()
56 #define Track(x,y)
57 #define TrackingInit()
58 #define TrackDump()
59 #define Untrack(x)
60 #define TrackTag(x)
61 #define exAllocatePoolWithTag(x,y,z) ExAllocatePoolWithTag(x,y,z)
62 #define exAllocatePool(x,y) PoolAllocateBuffer(y)
63 #define exFreePool(x) PoolFreeBuffer(x)
64 #define TrackWithTag(w,x,y,z)
65 #define UntrackFL(x,y,z)
66 #endif
67
68 #endif/*MEMMTRAC_H*/