-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtrace.h
More file actions
152 lines (130 loc) · 5.39 KB
/
trace.h
File metadata and controls
152 lines (130 loc) · 5.39 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* 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
#if defined(_KERNEL_MODE)
#include <ntddk.h>
#include <wdf.h>
#include <ntintsafe.h>
#include <evntrace.h>
#include <TraceLoggingProvider.h>
TRACELOGGING_DECLARE_PROVIDER(g_hOvpnEtwProvider);
#else
#include <windows.h>
#endif
#if defined(_KERNEL_MODE)
#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, \
TraceLoggingString(#Expression, "Expression"), \
__VA_ARGS__); \
goto Label; \
} \
} while (0)
#else /* user-mode / tests */
#define LOG_INFO(Info, ...)
#define GOTO_IF_NOT_NT_SUCCESS(Label, StatusLValue, Expression, ...) \
do \
{ \
StatusLValue = (Expression); \
if (!NT_SUCCESS(StatusLValue)) \
{ \
goto Label; \
} \
} while (0)
#endif
#ifndef TraceLoggingIPv4Address
#define TraceLoggingIPv4Address(value, ...) _tlgArgScalarVal(UINT32, value, TlgInUINT32, (TlgOutIPV4), __VA_ARGS__)
#endif
#ifndef TraceLoggingIPv6Address
#define TraceLoggingIPv6Address(pValue, ...) _tlgArgBinary(void, pValue, 16u, TlgInBINARY, (TlgOutIPV6), __VA_ARGS__)
#endif