1 /*
2  * This file contains debug-related definitions for kernel driver
3  *
4  * Copyright (c) 2008-2017 Red Hat, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met :
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and / or other materials provided with the distribution.
14  * 3. Neither the names of the copyright holders nor the names of their contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /**********************************************************************
31 WARNING: this file is incompatible with Logo requirements
32 TODO:    Optional WPP technique
33 **********************************************************************/
34 
35 #ifndef _K_DEBUG_PRINT_H
36 #define _K_DEBUG_PRINT_H
37 
38 extern int nDebugLevel;
39 extern int bDebugPrint;
40 
41 
42 typedef void (*DEBUGPRINTFUNC)(const char *fmt, ...);
43 extern  DEBUGPRINTFUNC pDebugPrint;
44 
45 void _LogOutEntry(int level, const char *s);
46 void _LogOutExitValue(int level, const char *s, ULONG value);
47 void _LogOutString(int level, const char *s);
48 
49 #define DEBUG_ENTRY(level)  _LogOutEntry(level, __FUNCTION__)
50 #define DEBUG_EXIT_STATUS(level, status)  _LogOutExitValue(level, __FUNCTION__, status)
51 #define DPrintFunctionName(Level) _LogOutString(Level, __FUNCTION__)
52 
53 
54 #ifndef WPP_EVENT_TRACING
55 
56 #define WPP_INIT_TRACING(a,b)
57 #define WPP_CLEANUP(a)
58 
59 #define MAX_DEBUG_LEVEL 1
60 
61 #define DPrintf(Level, Fmt) { if ( (Level) > MAX_DEBUG_LEVEL || (Level) > nDebugLevel || !bDebugPrint ) {} else { pDebugPrint Fmt; } }
62 
63 #define DPrintfBypass(Level, Fmt) DPrintf(Level, Fmt)
64 
65 #else
66 
67 //#define WPP_USE_BYPASS
68 
69 
70 #define DPrintfAnyway(Level, Fmt) \
71 { \
72     if (bDebugPrint && (Level) <= nDebugLevel) \
73     { \
74         pDebugPrint Fmt; \
75     } \
76 }
77 
78 //{05F77115-E57E-49bf-90DF-C0E6B6478E5F}
79 #define WPP_CONTROL_GUIDS \
80     WPP_DEFINE_CONTROL_GUID(NetKVM, (05F77115,E57E,49bf,90DF,C0E6B6478E5F),  \
81         WPP_DEFINE_BIT(TRACE_DEBUG)\
82                                     )
83 
84 
85 #define WPP_LEVEL_ENABLED(LEVEL) \
86     (nDebugLevel >= (LEVEL))
87 
88 #define WPP_LEVEL_LOGGER(LEVEL)      (WPP_CONTROL(WPP_BIT_ ## TRACE_DEBUG).Logger),
89 
90 
91 #if WPP_USE_BYPASS
92 #define DPrintfBypass(Level, Fmt) DPrintfAnyway(Level, Fmt)
93 #else
94 #define DPrintfBypass(Level, Fmt)
95 #endif
96 
97 #define WPP_PRIVATE_ENABLE_CALLBACK     WppEnableCallback
98 
99 extern VOID WppEnableCallback(
100     __in LPCGUID Guid,
101     __in __int64 Logger,
102     __in BOOLEAN Enable,
103     __in ULONG Flags,
104     __in UCHAR Level);
105 
106 
107 #endif
108 #endif
109