-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdebug.c
77 lines (66 loc) · 1.75 KB
/
debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright (c) 2019 SUSE LLC
*
* Licensed under LGPL-2.1 (see LICENSE)
*/
#include <ntstatus.h>
#include <ntstrsafe.h>
#include <wdm.h>
#include "debug.h"
#include "options.h"
#include "events.h"
#define WNBD_LOG_BUFFER_SIZE 512
VOID EtwPrint(UINT32 Level,
PCHAR FuncName,
UINT32 Line,
PCHAR Buf)
{
BOOLEAN Enabled = WnbdDriverOptions[OptEtwLoggingEnabled].Value.Data.AsBool;
if (!Enabled) {
return;
}
switch (Level) {
case WNBD_LVL_ERROR:
EventWriteErrorEvent(NULL, FuncName, Line, Buf);
break;
case WNBD_LVL_WARN:
EventWriteWarningEvent(NULL, FuncName, Line, Buf);
break;
default:
EventWriteInformationalEvent(NULL, FuncName, Line, Buf);
break;
}
}
_Use_decl_annotations_
VOID
WnbdLog(UINT32 Level,
PCHAR FuncName,
UINT32 Line,
PCHAR Format,
...)
{
UNREFERENCED_PARAMETER(Level);
UNREFERENCED_PARAMETER(FuncName);
UNREFERENCED_PARAMETER(Line);
UNREFERENCED_PARAMETER(Format);
va_list Args;
CHAR Buf[WNBD_LOG_BUFFER_SIZE];
UINT64 WnbdLogLevel = WnbdDriverOptions[OptLogLevel].Value.Data.AsInt64;
if (Level > WnbdLogLevel) {
return;
}
Buf[0] = 0;
va_start(Args, Format);
RtlStringCbVPrintfA(Buf, sizeof(Buf), Format, Args);
va_end(Args);
/* Log via ETW */
EtwPrint(Level, FuncName, Line, Buf);
/* DbgPrint logging */
if (WnbdDriverOptions[OptDbgPrintEnabled].Value.Data.AsBool) {
DbgPrintEx(DPFLTR_SCSIMINIPORT_ID, Level, "%s:%lu %s\n", FuncName, Line, Buf);
}
/* Log via WPP */
if (WnbdDriverOptions[OptWppLoggingEnabled].Value.Data.AsBool) {
WnbdWppTrace(Level, "%s:%lu %s\n", FuncName, Line, Buf);
}
}