1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
13 This file contains small set of debug macroses.
14 It is used by the UDF project.
21 //======================================
23 //#define ALWAYS_CHECK_WAIT_TIMEOUT
24 //#define PRINT_ALWAYS
28 //#define CHECK_ALLOC_FRAMES
30 //#define TRACK_SYS_ALLOCS
31 //#define TRACK_SYS_ALLOC_CALLERS
33 // Use internal deadlock detector
38 #define PROTECTED_MEM_RTL
40 //#define UDF_SIMULATE_WRITES
42 //#define USE_PERF_PRINT
47 #define UDF_DUMP_EXTENT
48 //#define USE_TH_PRINT
49 //#define USE_TIME_PRINT
50 //#define CHECK_REF_COUNTS
52 //======================================
54 #if defined UDF_DBG || defined PRINT_ALWAYS
69 #define KdPrint(_x_) DbgPrint _x_
71 #define KdPrint(a) {NOTHING;}
75 #define MmPrint(_x_) DbgPrint _x_
77 #define MmPrint(_x_) {NOTHING;}
81 extern ULONG UdfTimeStamp
;
82 #define TmPrint(_x_) {UdfTimeStamp++;KdPrint(("TM:%d: ",UdfTimeStamp));KdPrint(_x_);}
84 #define TmPrint KdPrint
88 #define PerfPrint(_x_) DbgPrint _x_
90 #define PerfPrint(_x_) {NOTHING;}
94 #define AdPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
96 #define AdPrint(_x_) {NOTHING;}
100 #define ThPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
102 #define ThPrint(_x_) {NOTHING;}
105 #ifdef UDF_DUMP_EXTENT
106 #define ExtPrint(_x_) KdPrint(_x_)
108 #define ExtPrint(_x_) {NOTHING;}
111 #else // defined UDF_DBG || defined PRINT_ALWAYS
113 #define MmPrint(_x_) {NOTHING;}
114 #define TmPrint(_x_) {NOTHING;}
115 #define PerfPrint(_x_) {NOTHING;}
116 #define AdPrint(_x_) {NOTHING;}
117 #define ThPrint(_x_) {NOTHING;}
118 #define ExtPrint(_x_) {NOTHING;}
120 #endif // defined UDF_DBG || defined PRINT_ALWAYS
123 DbgWaitForSingleObject_(
125 IN PLARGE_INTEGER Timeout OPTIONAL
128 #if defined ALWAYS_CHECK_WAIT_TIMEOUT
129 #define DbgWaitForSingleObject(o, to) DbgWaitForSingleObject_(o, to)
131 #define DbgWaitForSingleObject(o, to) KeWaitForSingleObject(o, Executive, KernelMode, FALSE, to);
137 // This is an illegal use of INT3
138 #define UDFBreakPoint() { __asm int 3 }
141 #define UDFBreakPoint() DbgBreakPoint()
145 #define BrutePoint() UDFBreakPoint()
147 #define BrutePoint() {}
150 #ifdef CHECK_REF_COUNTS
151 #define ASSERT_REF(_a_) ASSERT(_a_)
153 #define ASSERT_REF(_a_) {NOTHING;}
154 #endif //CHECK_REF_COUNTS
156 #ifdef TRACK_SYS_ALLOCS
158 PVOID
DebugAllocatePool(POOL_TYPE Type
,ULONG size
159 #ifdef TRACK_SYS_ALLOC_CALLERS
160 , ULONG SrcId
, ULONG SrcLine
161 #endif //TRACK_SYS_ALLOC_CALLERS
163 VOID
DebugFreePool(PVOID addr
);
165 #ifdef TRACK_SYS_ALLOC_CALLERS
166 #define DbgAllocatePoolWithTag(a,b,c) DebugAllocatePool(a,b,UDF_BUG_CHECK_ID,__LINE__)
167 #define DbgAllocatePool(x,y) DebugAllocatePool(x,y,UDF_BUG_CHECK_ID,__LINE__)
168 #else //TRACK_SYS_ALLOC_CALLERS
169 #define DbgAllocatePoolWithTag(a,b,c) DebugAllocatePool(a,b)
170 #define DbgAllocatePool(x,y) DebugAllocatePool(x,y)
171 #endif //TRACK_SYS_ALLOC_CALLERS
172 #define DbgFreePool(x) DebugFreePool(x)
174 #else //TRACK_SYS_ALLOCS
176 #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c)
177 #define DbgAllocatePool(x,y) ExAllocatePoolWithTag(x,y,'Fnwd')
178 #define DbgFreePool(x) ExFreePool(x)
180 #endif //TRACK_SYS_ALLOCS
183 #ifdef PROTECTED_MEM_RTL
185 #define DbgMoveMemory(d, s, l) \
187 RtlMoveMemory(d, s, l); \
188 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) { \
192 #define DbgCopyMemory(d, s, l) \
194 RtlCopyMemory(d, s, l); \
195 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) { \
201 DbgCompareMemory(PVOID d
, PVOID s
, ULONG l
) {
203 return RtlCompareMemory(d
, s
, l
);
204 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER
) {
210 #else //PROTECTED_MEM_RTL
212 #define DbgMoveMemory(d, s, l) RtlMoveMemory(d, s, l)
213 #define DbgCopyMemory(d, s, l) RtlCopyMemory(d, s, l)
214 #define DbgCompareMemory(d, s, l) RtlCompareMemory(d, s, l)
216 #endif //PROTECTED_MEM_RTL
218 //#define KdPrint(_x_)
220 #ifdef VALIDATE_STRUCTURES
221 #define ValidateFileInfo(fi) \
222 { /* validate FileInfo */ \
223 if(!fi || (fi)->IntegrityTag) { \
224 KdPrint(("UDF: ERROR! Using deallocated structure !!!\n"));\
227 if(fi && !fi->Dloc) { \
228 KdPrint(("UDF: ERROR! FI without Dloc !!!\n"));\
234 #define ValidateFileInfo(fi) {}
237 #if defined (_X86_) && defined (_MSC_VER)
239 __inline VOID
UDFTouch(IN PVOID addr
)
243 mov al
,[byte ptr eax
]
247 #else // NO X86 optimization , use generic C/C++
249 __inline VOID
UDFTouch(IN PVOID addr
)
251 UCHAR a
= ((PUCHAR
)addr
)[0];
259 #define DbgAllocatePool(x,y) ExAllocatePoolWithTag(x,y,'Fnwd')
260 #define DbgFreePool(x) ExFreePool(x)
261 #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c)
263 #define DbgMoveMemory(d, s, l) RtlMoveMemory(d, s, l)
264 #define DbgCopyMemory(d, s, l) RtlCopyMemory(d, s, l)
265 #define DbgCompareMemory(d, s, l) RtlCompareMemory(d, s, l)
267 #define ASSERT_REF(_a_) {NOTHING;}
269 #define UDFBreakPoint() {}
270 #define BrutePoint() {}
271 #define ValidateFileInfo(fi) {}
273 #define UDFTouch(addr) {}
277 #if defined UDF_DBG || defined PRINT_ALWAYS
279 #define KdDump(a,b) \
282 for(i=0; i<(b); i++) { \
284 c = (ULONG)(*(((PUCHAR)(a))+i)); \
285 KdPrint(("%2.2x ",c)); \
286 if ((i & 0x0f) == 0x0f) KdPrint(("\n")); \
293 #define KdDump(a,b) {}
297 #define UserPrint KdPrint
299 #endif // _UDF_DEBUG_H_