kvm-guest-drivers-windows
134 строки · 3.9 Кб
1/*
2* This file contains various balloon driver routines
3*
4* Copyright (c) 2009-2017 Red Hat, Inc.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions
8* are met :
9* 1. Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* 2. Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and / or other materials provided with the distribution.
14* 3. Neither the names of the copyright holders nor the names of their contributors
15* may be used to endorse or promote products derived from this software
16* without specific prior written permission.
17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27* SUCH DAMAGE.
28*/
29#include "precomp.h"30
31#if defined(EVENT_TRACING)32#include "utils.tmh"33#else34#define PRINT_DEBUG35#endif36
37int nDebugLevel = 0;38int bDebugPrint = 0;39
40#define TEMP_BUFFER_SIZE 25641
42// Global debug printout level and enable\disable flag
43int virtioDebugLevel;44int bDebugPrint;45int driverDebugLevel;46ULONG driverDebugFlags;47
48
49
50#if defined(COM_DEBUG)51
52#define RHEL_DEBUG_PORT ((PUCHAR)0x3F8)53
54static void DebugPrintFuncSerial(const char *format, ...)55{
56char buf[TEMP_BUFFER_SIZE];57NTSTATUS status;58size_t len;59va_list list;60va_start(list, format);61status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);62if (status == STATUS_SUCCESS)63{64len = strlen(buf);65}66else67{68len = 2;69buf[0] = 'O';70buf[1] = '\n';71}72if (len)73{74WRITE_PORT_BUFFER_UCHAR(RHEL_DEBUG_PORT, (PUCHAR)buf, len);75WRITE_PORT_UCHAR(RHEL_DEBUG_PORT, '\r');76}77va_end(list);78}
79#endif80
81#if defined(PRINT_DEBUG)82static void DebugPrintFunc(const char *format, ...)83{
84va_list list;85va_start(list, format);86vDbgPrintEx(DPFLTR_DEFAULT_ID, 9 | DPFLTR_MASK, format, list);87va_end(list);88}
89#endif90
91#if defined(EVENT_TRACING)92static void DebugPrintFuncWPP(const char *format, ...)93{
94char buf[256];95NTSTATUS status;96va_list list;97va_start(list, format);98status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);99if (status == STATUS_SUCCESS)100{101TraceEvents(TRACE_LEVEL_WARNING, DBG_HW_ACCESS, "%s", buf);102}103va_end(list);104}
105#endif106
107static void NoDebugPrintFunc(const char *format, ...)108{
109
110UNREFERENCED_PARAMETER(format);111}
112
113
114void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)115{
116//TBD - Read nDebugLevel and bDebugPrint from the registry117WPP_INIT_TRACING(DriverObject, RegistryPath);118bDebugPrint = 1;119virtioDebugLevel = 0;120#if defined(EVENT_TRACING)121VirtioDebugPrintProc = DebugPrintFuncWPP;122#elif defined(PRINT_DEBUG)123VirtioDebugPrintProc = DebugPrintFunc;124#elif defined(COM_DEBUG)125VirtioDebugPrintProc = DebugPrintFuncSerial;126#else127VirtioDebugPrintProc = NoDebugPrintFunc;128#endif129driverDebugFlags = 0xffffffff;130driverDebugLevel = TRACE_LEVEL_VERBOSE;131virtioDebugLevel = 4;132}
133
134tDebugPrintFunc VirtioDebugPrintProc;135