diff --git a/viosock/inc/debug-utils.h b/viosock/inc/debug-utils.h index ce8c319c1..465d0e9bf 100644 --- a/viosock/inc/debug-utils.h +++ b/viosock/inc/debug-utils.h @@ -31,6 +31,12 @@ #define __DEBUG_UTILS_H__ +#include +#include "trace.h" +#include "..\..\virtio\kdebugprint.h" + +#ifndef EVENT_TRACING + #if defined(DBG) || defined(_DEBUG) @@ -81,3 +87,5 @@ #endif + +#endif diff --git a/viosock/viosock-wsk-test/test-messages.c b/viosock/viosock-wsk-test/test-messages.c index f5ea0d6dc..42f4b1709 100644 --- a/viosock/viosock-wsk-test/test-messages.c +++ b/viosock/viosock-wsk-test/test-messages.c @@ -4,6 +4,9 @@ #include #include "..\inc\debug-utils.h" #include "test-messages.h" +#ifdef EVENT_TRACING +#include "test-messages.tmh" +#endif static ULONG _randSeed; diff --git a/viosock/viosock-wsk-test/trace.h b/viosock/viosock-wsk-test/trace.h new file mode 100644 index 000000000..5d188545a --- /dev/null +++ b/viosock/viosock-wsk-test/trace.h @@ -0,0 +1,117 @@ +/* + * This file contains trace and debugging related definitions + * + * Copyright (c) 2019 Virtuozzo International GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met : + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and / or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of their contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + + +#define EVENT_TRACING + +#if !defined(EVENT_TRACING) + +extern ULONG driverDebugFlags; +extern int driverDebugLevel; + +#if !defined(TRACE_LEVEL_NONE) + #define TRACE_LEVEL_NONE 0 + #define TRACE_LEVEL_CRITICAL 1 + #define TRACE_LEVEL_FATAL 1 + #define TRACE_LEVEL_ERROR 2 + #define TRACE_LEVEL_WARNING 3 + #define TRACE_LEVEL_INFORMATION 4 + #define TRACE_LEVEL_VERBOSE 5 + #define TRACE_LEVEL_RESERVED6 6 + #define TRACE_LEVEL_RESERVED7 7 + #define TRACE_LEVEL_RESERVED8 8 + #define TRACE_LEVEL_RESERVED9 9 +#endif + + +// +// Define Debug Flags +// +#define DBG_VIOWSK 0x00000001 + +#define DBG_TEST 0x00000001 + +#define TraceEvents(level, flags, message, ...) \ +if (level > driverDebugLevel || !bDebugPrint || !(driverDebugFlags & flags)) {} \ +else VirtioDebugPrintProc(message, __VA_ARGS__) + +#define WPP_INIT_TRACING(a,b) +#define WPP_CLEANUP(DriverObject) + +#else +#define WPP_CHECK_FOR_NULL_STRING + +// +// Define the tracing flags. +// +// Tracing GUID - C2D7F82F-CE5F-4408-8A37-8B9FE2B3D52E +// + +#define WPP_CONTROL_GUIDS \ + WPP_DEFINE_CONTROL_GUID(WskTraceGuid,(13b9cfb4,b962,4b43,b59d,92242fab52e3), \ + WPP_DEFINE_BIT(DBG_VIOWSK) /* bit 0 = 0x00000001 */ \ + ) \ + WPP_DEFINE_CONTROL_GUID(WskTestTraceGuid,(46e3298a,70b1,49c6,b9fd,8691980b7adf), \ + WPP_DEFINE_BIT(DBG_TEST) /* bit 0 = 0x00000001 */ \ + ) + + +#define WPP_FLAG_LEVEL_LOGGER(flag, level) \ + WPP_LEVEL_LOGGER(flag) + +#define WPP_FLAG_LEVEL_ENABLED(flag, level) \ + (WPP_LEVEL_ENABLED(flag) && WPP_CONTROL(WPP_BIT_ ## flag).Level >= level) + +#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ + WPP_LEVEL_LOGGER(flags) + +#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ + (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) + + // + // This comment block is scanned by the trace preprocessor to define our + // Trace function. + // + // begin_wpp config + // + // FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); + // FUNC DEBUG_ENTER_FUNCTION{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(MSG, ...); + // FUNC DEBUG_ENTER_FUNCTION_NO_ARGS{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(); + // FUNC DEBUG_EXIT_FUNCTION{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(MSG, ...); + // FUNC DEBUG_EXIT_FUNCTION_VOID{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(); + // FUNC DEBUG_ERROR{LEVEL=TRACE_LEVEL_ERROR, FLAGS=DBG_TEST}(MSG, ...); + // FUNC DEBUG_WARNING{LEVEL=TRACE_LEVEL_WARNING, FLAGS=DBG_TEST}(MSG, ...); + // FUNC DEBUG_TRACE{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(MSG, ...); + // FUNC DEBUG_INFO{LEVEL=TRACE_LEVEL_INFORMATION, FLAGS=DBG_TEST}(MSG, ...); + // + // end_wpp + // + +#endif diff --git a/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj b/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj index 4bc7488de..b1c965320 100644 --- a/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj +++ b/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj @@ -234,63 +234,159 @@ - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_ARM64_;ARM64;_USE_DECLSPECS_FOR_SAL=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_ARM64_;ARM64;_USE_DECLSPECS_FOR_SAL=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_ARM64_;ARM64;_USE_DECLSPECS_FOR_SAL=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + - cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib + + true + trace.h + TRACE_PROJECT_NAME=VioWskTest;_ARM64_;ARM64;_USE_DECLSPECS_FOR_SAL=1;STD_CALL;%(PreprocessorDefinitions) + + + SHA256 + @@ -306,6 +402,7 @@ + diff --git a/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj.filters b/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj.filters index c745a968c..74155cd30 100644 --- a/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj.filters +++ b/viosock/viosock-wsk-test/viosock-wsk-test.vcxproj.filters @@ -26,5 +26,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/viosock/viosock-wsk-test/viosockwsk-test.c b/viosock/viosock-wsk-test/viosockwsk-test.c index 40476ebbf..ce8907369 100644 --- a/viosock/viosock-wsk-test/viosockwsk-test.c +++ b/viosock/viosock-wsk-test/viosockwsk-test.c @@ -9,7 +9,9 @@ #include "..\inc\vio_sockets.h" #include "..\sys\public.h" #include "test-messages.h" - +#ifdef EVENT_TRACING +#include "viosockwsk-test.tmh" +#endif #define LISTEN_PORT_MIN 1337 @@ -688,6 +690,7 @@ DriverUnload( VioWskDeregister(&_vioWskRegistration); VioWskModuleFinit(); IoDeleteDevice(_shutdownDeviceObject); + WPP_CLEANUP(DriverObject); DEBUG_EXIT_FUNCTION_VOID(); return; @@ -704,6 +707,7 @@ DriverEntry( NTSTATUS Status = STATUS_UNSUCCESSFUL; DEBUG_ENTER_FUNCTION("DriverObject=0x%p; RegistryPath=\"%wZ\"", DriverObject, RegistryPath); + WPP_INIT_TRACING(DriverObject, RegistryPath); Status = IoCreateDevice(DriverObject, 0, NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &Device); if (!NT_SUCCESS(Status)) goto Exit; @@ -756,6 +760,11 @@ DriverEntry( if (Device) IoDeleteDevice(Device); Exit: + if (!NT_SUCCESS(Status)) + { + WPP_CLEANUP(DriverObject); + } + DEBUG_EXIT_FUNCTION("0x%x", Status); return Status; } \ No newline at end of file diff --git a/viosock/wsk/provider.c b/viosock/wsk/provider.c index c35e704c3..e8d8c82b2 100644 --- a/viosock/wsk/provider.c +++ b/viosock/wsk/provider.c @@ -34,6 +34,10 @@ #include "viowsk-internal.h" #include "wsk-workitem.h" #include "..\inc\vio_wsk.h" +#ifdef EVENT_TRACING +#include "provider.tmh" +#endif + #ifdef ALLOC_PRAGMA #pragma alloc_text (PAGE, VioWskGetAddressInfo) @@ -61,7 +65,7 @@ VioWskSocket( PWSK_WORKITEM WorkItem = NULL; PVIOWSK_SOCKET pSocket = NULL; NTSTATUS Status = STATUS_UNSUCCESSFUL; - DEBUG_ENTER_FUNCTION("Client=0x%p; AddressFamily=%u; SocketType=%u; Protocol=%u; Flags=0x%x; SocketContext=0x%p; Dispatch=0x%p; OwningProcess=0x%p; OwningThread=0x%p; SecurityDescriptor=0x%p; Irp=0x%p", Client, AddressFamily, SocketType, Protocol, Flags, SocketContext, Dispatch, OwningProcess, OwningThread, SecurityDescriptor, Irp); + DEBUG_ENTER_FUNCTION("Client=0x%p; AddressFamily=%u; SocketType=%u; Protocol=%u; Flags=0x%x; SocketContext=0x%p; Dispatch=0x%p; OwningProcess=0x%p; OwningThread=0x%p; SecurityDescriptor=0x%p; Irp=0x%p", Client, AddressFamily, SocketType, Protocol, Flags, SocketContext, Dispatch, OwningProcess, OwningThread, SecurityDescriptor, Irp); _At_((void*)Irp->IoStatus.Information, __drv_allocatesMem(Mem)) @@ -153,7 +157,7 @@ VioWskControlClient( ) { NTSTATUS Status = STATUS_UNSUCCESSFUL; - DEBUG_ENTER_FUNCTION("Client=0x%p; ControlCode=0x%x; InputSize=%zu; InputBuffer=0x%p; OutputSize=%zu; OutputBuffer=0x%p; OutputSizeReturned=0x%p; Irp=0x%p", Client, ControlCode, InputSize, InputBuffer, OutputSize, OutputBuffer, OutputSizeReturned, Irp); + DEBUG_ENTER_FUNCTION("Client=0x%p; ControlCode=0x%x; InputSize=%Iu; InputBuffer=0x%p; OutputSize=%Iu; OutputBuffer=0x%p; OutputSizeReturned=0x%p; Irp=0x%p", Client, ControlCode, InputSize, InputBuffer, OutputSize, OutputBuffer, OutputSizeReturned, Irp); UNREFERENCED_PARAMETER(Client); UNREFERENCED_PARAMETER(ControlCode); diff --git a/viosock/wsk/socket-internal.c b/viosock/wsk/socket-internal.c index 9204c03e3..0b5578aad 100644 --- a/viosock/wsk/socket-internal.c +++ b/viosock/wsk/socket-internal.c @@ -32,6 +32,9 @@ #include "..\inc\debug-utils.h" #include "wsk-utils.h" #include "viowsk-internal.h" +#ifdef EVENT_TRACING +#include "socket-internal.tmh" +#endif #ifdef ALLOC_PRAGMA #pragma alloc_text (PAGE, VioWskSocketInternal) @@ -39,6 +42,8 @@ #endif + + _Must_inspect_result_ static NTSTATUS diff --git a/viosock/wsk/socket.c b/viosock/wsk/socket.c index 30b0d6114..986622ccf 100644 --- a/viosock/wsk/socket.c +++ b/viosock/wsk/socket.c @@ -35,6 +35,11 @@ #include "wsk-completion.h" #include "wsk-workitem.h" #include "..\inc\vio_wsk.h" +#ifdef EVENT_TRACING +#include "socket.tmh" +#endif + + NTSTATUS WSKAPI @@ -293,7 +298,7 @@ VioWskControlSocket( PVIOSOCKET_COMPLETION_CONTEXT CompContext = NULL; NTSTATUS Status = STATUS_UNSUCCESSFUL; PVIOWSK_SOCKET pSocket = CONTAINING_RECORD(Socket, VIOWSK_SOCKET, WskSocket); - DEBUG_ENTER_FUNCTION("Socket=0x%p; RequestType=%u; ControlCode=0x%x; Level=%u; InputSize=%zu; InputBuffer=0x%p; OutputSize=%zu; OutputBuffer=0x%p; OutputSizeReturned=0x%p; Irp=0x%p", Socket, RequestType, ControlCode, Level, InputSize, InputBuffer, OutputSize, OutputBuffer, OutputSizeReturned, Irp); + DEBUG_ENTER_FUNCTION("Socket=0x%p; RequestType=%u; ControlCode=0x%x; Level=%u; InputSize=%Iu; InputBuffer=0x%p; OutputSize=%Iu; OutputBuffer=0x%p; OutputSizeReturned=0x%p; Irp=0x%p", Socket, RequestType, ControlCode, Level, InputSize, InputBuffer, OutputSize, OutputBuffer, OutputSizeReturned, Irp); UNREFERENCED_PARAMETER(OutputSizeReturned); diff --git a/viosock/wsk/trace.h b/viosock/wsk/trace.h new file mode 100644 index 000000000..b1eaccbdd --- /dev/null +++ b/viosock/wsk/trace.h @@ -0,0 +1,105 @@ +/* + * This file contains trace and debugging related definitions + * + * Copyright (c) 2019 Virtuozzo International GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met : + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and / or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of their contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + #pragma once + +#define EVENT_TRACING + +#if !defined(EVENT_TRACING) + +#if !defined(TRACE_LEVEL_NONE) +#define TRACE_LEVEL_NONE 0 +#define TRACE_LEVEL_CRITICAL 1 +#define TRACE_LEVEL_FATAL 1 +#define TRACE_LEVEL_ERROR 2 +#define TRACE_LEVEL_WARNING 3 +#define TRACE_LEVEL_INFORMATION 4 +#define TRACE_LEVEL_VERBOSE 5 +#define TRACE_LEVEL_RESERVED6 6 +#define TRACE_LEVEL_RESERVED7 7 +#define TRACE_LEVEL_RESERVED8 8 +#define TRACE_LEVEL_RESERVED9 9 +#endif + + +// +// Define Debug Flags +// +#define DBG_VIOWSK 0x00000001 + +#define WPP_INIT_TRACING(a,b) +#define WPP_CLEANUP(DriverObject) + +#else + +#define WPP_CHECK_FOR_NULL_STRING + +// +// Define the tracing flags. +// +// Tracing GUID - C2D7F82F-CE5F-4408-8A37-8B9FE2B3D52E +// + +#define WPP_CONTROL_GUIDS \ + WPP_DEFINE_CONTROL_GUID(WskTraceGuid,(13b9cfb4,b962,4b43,b59d,92242fab52e3), \ + WPP_DEFINE_BIT(DBG_VIOWSK) /* bit 0 = 0x00000001 */ \ + ) + +#define WPP_FLAG_LEVEL_LOGGER(flag, level) \ + WPP_LEVEL_LOGGER(flag) + +#define WPP_FLAG_LEVEL_ENABLED(flag, level) \ + (WPP_LEVEL_ENABLED(flag) && WPP_CONTROL(WPP_BIT_ ## flag).Level >= level) + +#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ + WPP_LEVEL_LOGGER(flags) + +#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ + (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) + + // + // This comment block is scanned by the trace preprocessor to define our + // Trace function. + // + // begin_wpp config + // + // FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); + // FUNC DEBUG_ENTER_FUNCTION{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_VIOWSK}(MSG, ...); + // FUNC DEBUG_ENTER_FUNCTION_NO_ARGS{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_VIOWSK}(); + // FUNC DEBUG_EXIT_FUNCTION{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_VIOWSK}(MSG, ...); + // FUNC DEBUG_EXIT_FUNCTION_VOID{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_VIOWSK}(); + // FUNC DEBUG_ERROR{LEVEL=TRACE_LEVEL_ERROR, FLAGS=DBG_VIOWSK}(MSG, ...); + // FUNC DEBUG_WARNING{LEVEL=TRACE_LEVEL_WARNING, FLAGS=DBG_VIOWSK}(MSG, ...); + // FUNC DEBUG_TRACE{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_VIOWSK}(MSG, ...); + // FUNC DEBUG_INFO{LEVEL=TRACE_LEVEL_INFORMATION, FLAGS=DBG_VIOWSK}(MSG, ...); + // + // end_wpp + // + +#endif diff --git a/viosock/wsk/viowsk.c b/viosock/wsk/viowsk.c index 012d67499..4e6c8f10b 100644 --- a/viosock/wsk/viowsk.c +++ b/viosock/wsk/viowsk.c @@ -32,6 +32,9 @@ #include "viowsk.h" #include "..\inc\vio_wsk.h" #include "viowsk-internal.h" +#ifdef EVENT_TRACING +#include "viowsk.tmh" +#endif #ifdef ALLOC_PRAGMA #pragma alloc_text (PAGE, VioWskRegister) @@ -39,6 +42,7 @@ #endif + typedef struct _VIOSOCK_WAIT_CONTEXT { UNICODE_STRING SymbolicLinkName; KEVENT Event; diff --git a/viosock/wsk/wsk-completion.c b/viosock/wsk/wsk-completion.c index 9f2895c36..500af96f5 100644 --- a/viosock/wsk/wsk-completion.c +++ b/viosock/wsk/wsk-completion.c @@ -32,7 +32,9 @@ #include "wsk-utils.h" #include "viowsk-internal.h" #include "wsk-completion.h" - +#ifdef EVENT_TRACING +#include "wsk-completion.tmh" +#endif @@ -227,7 +229,7 @@ WskGeneralIrpCompletion( VioWskIrpFree(Irp, Ctx->DeviceObject, TRUE); WskCompContextDereference(Ctx); - DEBUG_EXIT_FUNCTION("0x%x", STATUS_MORE_PROCESSING_REQUIRED); + DEBUG_EXIT_FUNCTION("0x%ix", STATUS_MORE_PROCESSING_REQUIRED); return STATUS_MORE_PROCESSING_REQUIRED; } diff --git a/viosock/wsk/wsk-utils.c b/viosock/wsk/wsk-utils.c index 5e005e017..fb4f7f661 100644 --- a/viosock/wsk/wsk-utils.c +++ b/viosock/wsk/wsk-utils.c @@ -34,12 +34,17 @@ #include "viowsk-internal.h" #include "wsk-completion.h" #include "wsk-utils.h" +#ifdef EVENT_TRACING +#include "wsk-utils.tmh" +#endif #ifdef ALLOC_PRAGMA #endif + + #define IRP_NEXT_LOCATION_TAG 13371337 @@ -93,6 +98,7 @@ VioWskIrpRelease( } + NTSTATUS VioWskIrpComplete( _Inout_opt_ PVIOWSK_SOCKET Socket, @@ -101,7 +107,7 @@ VioWskIrpComplete( _In_ ULONG_PTR Information ) { - DEBUG_ENTER_FUNCTION("Socket=0x%p; Irp=0x%p; Status=0x%x; Information=%zu", Socket, Irp, Status, Information); + DEBUG_ENTER_FUNCTION("Socket=0x%p; Irp=0x%p; Status=0x%x; Information=%Iu", Socket, Irp, Status, (ULONG64)Information); IoSetCancelRoutine(Irp, NULL); if (Socket) diff --git a/viosock/wsk/wsk-workitem.c b/viosock/wsk/wsk-workitem.c index 70223530a..caa9dfabc 100644 --- a/viosock/wsk/wsk-workitem.c +++ b/viosock/wsk/wsk-workitem.c @@ -34,6 +34,9 @@ #include "..\inc\vio_wsk.h" #include "viowsk-internal.h" #include "wsk-workitem.h" +#ifdef EVENT_TRACING +#include "wsk-workitem.tmh" +#endif #pragma warning(disable : 4996) diff --git a/viosock/wsk/wsk.vcxproj b/viosock/wsk/wsk.vcxproj index 589e39a2f..0f63eb3e1 100644 --- a/viosock/wsk/wsk.vcxproj +++ b/viosock/wsk/wsk.vcxproj @@ -37,6 +37,7 @@ + @@ -130,12 +131,30 @@ - WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP;WINAPI_PARTITION_DESKTOP=1;WINAPI_PARTITION_SYSTEM=1;WINAPI_PARTITION_APP=1;WINAPI_PARTITION_PC_APP=1;%(PreprocessorDefinitions) + TRACE_PROJECT_NAME=VioWsk;WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP;WINAPI_PARTITION_DESKTOP=1;WINAPI_PARTITION_SYSTEM=1;WINAPI_PARTITION_APP=1;WINAPI_PARTITION_PC_APP=1;%(PreprocessorDefinitions) + true + true + true + true + true + trace.h + trace.h + trace.h + trace.h + trace.h - _DEBUG;%(PreprocessorDefinitions) + TRACE_PROJECT_NAME=VioWsk;_DEBUG;%(PreprocessorDefinitions) + true + true + true + true + trace.h + trace.h + trace.h + trace.h diff --git a/viosock/wsk/wsk.vcxproj.filters b/viosock/wsk/wsk.vcxproj.filters index a2e1b70c1..5e3560f5b 100644 --- a/viosock/wsk/wsk.vcxproj.filters +++ b/viosock/wsk/wsk.vcxproj.filters @@ -36,6 +36,9 @@ Header Files + + Header Files +