Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winsock Kernel (WSK) Interface for the VIOSOCK Driver #835

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buildAll.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ call tools\build.bat vioserial\sys\vioser.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :fail
call tools\build.bat viosock\sys\viosock.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :fail
call tools\build.bat viosock\wsk\wsk.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :fail
call tools\build.bat viosock\viosock-wsk-test\viosock-wsk-test.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :fail
call tools\build.bat viofs\pci\viofs.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :fail
call tools\build.bat vioinput\hidpassthrough\hidpassthrough.vcxproj "Win11_SDV" %*
Expand Down
4 changes: 4 additions & 0 deletions viosock/buildAll.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ if errorlevel 1 goto :eof
call ..\tools\build.bat viosock.sln "Win10 Win11" %*
if errorlevel 1 goto :eof
call ..\tools\build.bat sys\viosock.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :eof
call ..\tools\build.bat wsk\wsk.vcxproj "Win11_SDV" %*
if errorlevel 1 goto :eof
call ..\tools\build.bat viosock-wsk-test\viosock-wsk-test.vcxproj "Win11_SDV" %*
8 changes: 8 additions & 0 deletions viosock/cleanAll.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ pushd sys
call cleanAll.bat
popd

pushd wsk
call cleanAll.bat
popd

pushd viosock-wsk-test
call cleanAll.bat
popd

pushd viosock-test
call cleanAll.bat
popd
Expand Down
91 changes: 91 additions & 0 deletions viosock/inc/debug-utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Exports definition for virtio socket WSK interface
*
* Copyright (c) 2021 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.
*/

#ifndef __DEBUG_UTILS_H__
#define __DEBUG_UTILS_H__


#include <Evntrace.h>
#include "wpp-trace.h"
#include "..\..\virtio\kdebugprint.h"

#ifndef EVENT_TRACING


#if defined(DBG) || defined(_DEBUG)

#define DEBUG_ENTER_FUNCTION(Format, ...) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use existing debug printing infrastructure that depending one configuration will use different debug print methods?
Checkout: InitializeDebugPrints and VirtioDebugPrintProc

DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_TRACE_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ "(" Format ")\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql(), __VA_ARGS__)

#define DEBUG_ENTER_FUNCTION_NO_ARGS() \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_TRACE_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ "()\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql())

#define DEBUG_EXIT_FUNCTION(Format, ...) \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_TRACE_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ "(-):" Format "\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql(), __VA_ARGS__)

#define DEBUG_EXIT_FUNCTION_VOID() \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_TRACE_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ "(-)\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql())

#else

#define DEBUG_ENTER_FUNCTION(Format, ...) do { } while (FALSE)

#define DEBUG_ENTER_FUNCTION_NO_ARGS() do { } while (FALSE)

#define DEBUG_EXIT_FUNCTION(Format, ...) do { } while (FALSE)

#define DEBUG_EXIT_FUNCTION_VOID() do { } while (FALSE)

#endif


#define DEBUG_ERROR(Format, ...) \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ " (" __FILE__ ":%u): ERROR: " Format "\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql(), __LINE__, __VA_ARGS__)

#define DEBUG_WARNING(Format, ...) \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_WARNING_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ " (" __FILE__ ":%u): WARNING: " Format "\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql(), __LINE__, __VA_ARGS__)

#define DEBUG_TRACE(Format, ...) \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_TRACE_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ " (" __FILE__ ":%u): TRACE: " Format "\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql(), __LINE__, __VA_ARGS__)

#define DEBUG_INFO(Format, ...) \
DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_INFO_LEVEL, "[0x%x:0x%x:%u]: " __FUNCTION__ ": INFO: " Format "\n", \
PtrToUlong(PsGetCurrentProcessId()), PtrToUlong(PsGetCurrentThreadId()), KeGetCurrentIrql(), __VA_ARGS__)


#endif

#endif
16 changes: 16 additions & 0 deletions viosock/inc/vio_wsk.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ VioWskQueryProviderCharacteristics(
_Out_ PWSK_PROVIDER_CHARACTERISTICS WskProviderCharacteristics
);

_Must_inspect_result_
NTSTATUS
VioWskModuleInit(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath,
_In_opt_ PDEVICE_OBJECT DeviceObject
);

VOID
VioWskModuleFinit(
VOID
);




#ifdef __cplusplus
}
#endif
Expand Down
28 changes: 28 additions & 0 deletions viosock/viosock-wsk-test/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright 2019 Virtuozzo, Inc.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

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.

Neither the name of the copyright holder nor the names of its
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
HOLDER 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.
2 changes: 2 additions & 0 deletions viosock/viosock-wsk-test/cleanAll.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
call ..\..\Tools\clean.bat
Loading