- In Win32 DBG is defined to 0 for a non-debug build and to 1 for a debug build....
[reactos.git] / reactos / lib / drivers / oskittcp / include / memtrack.h
1 #ifndef MEMTRACK_H
2 #define MEMTRACK_H
3
4 #ifndef FOURCC
5 #define FOURCC(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
6 #endif
7
8 #define FBSD_MALLOC FOURCC('d','s','b','f')
9 #define EXALLOC_TAG FOURCC('E','x','A','l')
10
11 #if DBG
12 #define MTMARK() TrackDumpFL(__FILE__, __LINE__)
13 #define NdisAllocateBuffer(x,y,z,a,b) { \
14 NdisAllocateBuffer(x,y,z,a,b); \
15 if( *x == NDIS_STATUS_SUCCESS ) { \
16 Track(NDIS_BUFFER_TAG, *y); \
17 } \
18 }
19 #define NdisAllocatePacket(x,y,z) { \
20 NdisAllocatePacket(x,y,z); \
21 if( *x == NDIS_STATUS_SUCCESS ) { \
22 Track(NDIS_PACKET_TAG, *y); \
23 } \
24 }
25 #define FreeNdisPacket(x) { TI_DbgPrint(MID_TRACE,("Deleting Packet %x\n", x)); FreeNdisPacketX(x); }
26 #define NdisFreePacket(x) { Untrack(x); NdisFreePacket(x); }
27 #define NdisFreeBuffer(x) { Untrack(x); NdisFreeBuffer(x); }
28 #define exAllocatePool(x,y) ExAllocatePoolX(x,y,__FILE__,__LINE__)
29 #define exAllocatePoolWithTag(x,y,z) ExAllocatePoolX(x,y,__FILE__,__LINE__)
30 #define exFreePool(x) ExFreePoolX(x,__FILE__,__LINE__)
31
32 extern LIST_ENTRY AllocatedObjectsHead;
33 extern KSPIN_LOCK AllocatedObjectsLock;
34
35 typedef struct _ALLOCATION_TRACKER {
36 LIST_ENTRY Entry;
37 DWORD Tag;
38 PVOID Thing;
39 PCHAR FileName;
40 DWORD LineNo;
41 } ALLOCATION_TRACKER, *PALLOCATION_TRACKER;
42
43 VOID TrackingInit();
44 VOID TrackWithTag( DWORD Tag, PVOID Thing, PCHAR File, DWORD Line );
45 #define Track(Tag,Thing) TrackWithTag(Tag,Thing,__FILE__,__LINE__)
46 VOID UntrackFL( PCHAR File, DWORD Line, PVOID Thing );
47 #define Untrack(Thing) UntrackFL(__FILE__,__LINE__,Thing)
48 VOID TrackDumpFL( PCHAR File, DWORD Line );
49 #define TrackDump() TrackDumpFL(__FILE__,__LINE__)
50 VOID TrackTag( DWORD Tag );
51
52 static __inline PVOID ExAllocatePoolX( POOL_TYPE type, SIZE_T size, PCHAR File, ULONG Line ) {
53 PVOID Out = ExAllocatePool( type, size );
54 if( Out ) TrackWithTag( EXALLOC_TAG, Out, File, Line );
55 return Out;
56 }
57 static __inline VOID ExFreePoolX( PVOID Data, PCHAR File, ULONG Line ) {
58 UntrackFL(File, Line, Data);
59 ExFreePool(Data);
60 }
61
62 #define MEMTRACK_MAX_TAGS_TO_TRACK 64
63 #else
64 #define MTMARK()
65 #define Track(x,y)
66 #define TrackingInit()
67 #define TrackDump()
68 #define Untrack(x)
69 #define TrackTag(x)
70 #define FreeNdisPacket FreeNdisPacketX
71 #define exFreePool(x) ExFreePool(x)
72 #define exAllocatePool(x,y) ExAllocatePool(x,y)
73 #define exAllocatePoolWithTag(x,y,z) ExAllocatePoolWithTag(x,y,z)
74 #define exAllocateFromNPagedLookasideList(x) ExAllocateFromNPagedLookasideList(x)
75 #define exFreeToNPagedLookasideList(x,y) ExFreeToNPagedLookasideList(x,y)
76 #define TrackWithTag(w,x,y,z)
77 #define UntrackFL(w,x,y,z)
78 #endif
79
80 #endif/*MEMMTRAC_H*/