-
Notifications
You must be signed in to change notification settings - Fork 22
/
trace.h
118 lines (105 loc) · 3.7 KB
/
trace.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* ovpn-dco-win OpenVPN protocol accelerator for Windows
*
* Copyright (C) 2020-2021 OpenVPN Inc <[email protected]>
*
* Author: Lev Stipakov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <ntddk.h>
#include <wdf.h>
#include <ntintsafe.h>
#include <evntrace.h>
#include <TraceLoggingProvider.h>
TRACELOGGING_DECLARE_PROVIDER(g_hOvpnEtwProvider);
#define TraceLoggingFunctionName() TraceLoggingWideString(__FUNCTIONW__, "Func")
#define LOG_NTSTATUS(Status, ...) do {\
TraceLoggingWrite( \
g_hOvpnEtwProvider, \
"Status", \
TraceLoggingLevel(TRACE_LEVEL_ERROR), \
TraceLoggingFunctionName(), \
TraceLoggingUInt32(__LINE__, "Line"), \
TraceLoggingNTStatus(Status, "Status"), \
__VA_ARGS__); \
} while (0,0)
#define LOG_ERROR(Error, ...) do {\
TraceLoggingWrite( \
g_hOvpnEtwProvider, \
"Error", \
TraceLoggingLevel(TRACE_LEVEL_ERROR), \
TraceLoggingFunctionName(), \
TraceLoggingUInt32(__LINE__, "Line"), \
TraceLoggingValue(Error, "Msg"), \
__VA_ARGS__); \
} while (0,0)
#define LOG_WARN(Info, ...) do {\
TraceLoggingWrite( \
g_hOvpnEtwProvider, \
"Warn", \
TraceLoggingLevel(TRACE_LEVEL_WARNING), \
TraceLoggingFunctionName(), \
TraceLoggingUInt32(__LINE__, "Line"), \
TraceLoggingValue(Info, "Msg"), \
__VA_ARGS__); \
} while (0,0)
#define LOG_ENTER(...) do {\
TraceLoggingWrite( \
g_hOvpnEtwProvider, \
"FunctionEntry", \
TraceLoggingLevel(TRACE_LEVEL_VERBOSE), \
TraceLoggingFunctionName(), \
TraceLoggingUInt32(__LINE__, "Line"), \
__VA_ARGS__); \
} while (0,0)
#define LOG_EXIT(...) do {\
TraceLoggingWrite( \
g_hOvpnEtwProvider, \
"FunctionExit", \
TraceLoggingLevel(TRACE_LEVEL_VERBOSE), \
TraceLoggingFunctionName(), \
TraceLoggingUInt32(__LINE__, "Line"), \
__VA_ARGS__); \
} while (0,0)
#define LOG_INFO(Info, ...) do {\
TraceLoggingWrite( \
g_hOvpnEtwProvider, \
"Info", \
TraceLoggingLevel(TRACE_LEVEL_INFORMATION), \
TraceLoggingFunctionName(), \
TraceLoggingUInt32(__LINE__, "Line"), \
TraceLoggingValue(Info, "Msg"), \
__VA_ARGS__); \
} while (0,0)
#define LOG_IF_NOT_NT_SUCCESS(Expression, ...) do {\
NTSTATUS p_status = (Expression); \
if (!NT_SUCCESS(p_status)) \
{ \
LOG_NTSTATUS(p_status, \
TraceLoggingWideString(L#Expression, "Expression"), \
__VA_ARGS__); \
} \
} while(0,0)
#define GOTO_IF_NOT_NT_SUCCESS(Label, StatusLValue, Expression, ...) do {\
StatusLValue = (Expression); \
if (!NT_SUCCESS(StatusLValue)) \
{ \
LOG_NTSTATUS(StatusLValue, \
TraceLoggingWideString(L#Expression, "Expression"), \
__VA_ARGS__); \
goto Label; \
} \
} while(0,0)