aboutsummaryrefslogtreecommitdiffstats
path: root/example/example.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-08-08 16:47:57 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-08-08 22:57:27 +0200
commit64ea99302a010676789e2449f705e5cd5e12c28a (patch)
treedd999ef357686adf1416f1bc3b76961dabb1b0d1 /example/example.c
parentdriver: logging: add more ring buffer log entries (diff)
downloadwireguard-nt-64ea99302a010676789e2449f705e5cd5e12c28a.tar.xz
wireguard-nt-64ea99302a010676789e2449f705e5cd5e12c28a.zip
driver: logging: pass timestamp back to userspace
It turns out the precision is very useful for diagnosing weird errors. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'example/example.c')
-rw-r--r--example/example.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/example/example.c b/example/example.c
index 828a8d0..92015c4 100644
--- a/example/example.c
+++ b/example/example.c
@@ -68,12 +68,10 @@ InitializeWireGuardNT(void)
}
static void CALLBACK
-ConsoleLogger(_In_ WIREGUARD_LOGGER_LEVEL Level, _In_z_ const WCHAR *LogLine)
+ConsoleLogger(_In_ WIREGUARD_LOGGER_LEVEL Level, _In_ DWORD64 Timestamp, _In_z_ const WCHAR *LogLine)
{
- FILETIME Timestamp;
- GetSystemTimePreciseAsFileTime(&Timestamp);
SYSTEMTIME SystemTime;
- FileTimeToSystemTime(&Timestamp, &SystemTime);
+ FileTimeToSystemTime((FILETIME *)&Timestamp, &SystemTime);
WCHAR LevelMarker;
switch (Level)
{
@@ -103,6 +101,13 @@ ConsoleLogger(_In_ WIREGUARD_LOGGER_LEVEL Level, _In_z_ const WCHAR *LogLine)
LogLine);
}
+static DWORD64 Now(VOID)
+{
+ LARGE_INTEGER Timestamp;
+ NtQuerySystemTime(&Timestamp);
+ return Timestamp.QuadPart;
+}
+
static DWORD
LogError(_In_z_ const WCHAR *Prefix, _In_ DWORD Error)
{
@@ -125,7 +130,7 @@ LogError(_In_z_ const WCHAR *Prefix, _In_ DWORD Error)
0,
(va_list *)(DWORD_PTR[]){ (DWORD_PTR)Prefix, (DWORD_PTR)Error, (DWORD_PTR)SystemMessage });
if (FormattedMessage)
- ConsoleLogger(WIREGUARD_LOG_ERR, FormattedMessage);
+ ConsoleLogger(WIREGUARD_LOG_ERR, Now(), FormattedMessage);
LocalFree(FormattedMessage);
LocalFree(SystemMessage);
return Error;
@@ -148,7 +153,7 @@ Log(_In_ WIREGUARD_LOGGER_LEVEL Level, _In_z_ const WCHAR *Format, ...)
va_start(args, Format);
_vsnwprintf_s(LogLine, _countof(LogLine), _TRUNCATE, Format, args);
va_end(args);
- ConsoleLogger(Level, LogLine);
+ ConsoleLogger(Level, Now(), LogLine);
}
_Must_inspect_result_
@@ -442,10 +447,9 @@ int __cdecl main(void)
LastError = LogError(L"Failed to get configuration", GetLastError());
goto cleanupAdapter;
}
- FILETIME Timestamp;
- GetSystemTimePreciseAsFileTime(&Timestamp);
+ DWORD64 Timestamp = Now();
SYSTEMTIME SystemTime;
- FileTimeToSystemTime(&Timestamp, &SystemTime);
+ FileTimeToSystemTime((FILETIME *)&Timestamp, &SystemTime);
fwprintf(
stderr,
L"%04u-%02u-%02u %02u:%02u:%02u.%04u [#] RX: %llu, TX: %llu\r",