kvm-guest-drivers-windows

Форк
0
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
#else
34
#define PRINT_DEBUG
35
#endif
36

37
int nDebugLevel = 0;
38
int bDebugPrint = 0;
39

40
#define     TEMP_BUFFER_SIZE        256
41

42
// Global debug printout level and enable\disable flag
43
int virtioDebugLevel;
44
int bDebugPrint;
45
int driverDebugLevel;
46
ULONG driverDebugFlags;
47

48

49

50
#if defined(COM_DEBUG)
51

52
#define RHEL_DEBUG_PORT     ((PUCHAR)0x3F8)
53

54
static void DebugPrintFuncSerial(const char *format, ...)
55
{
56
    char buf[TEMP_BUFFER_SIZE];
57
    NTSTATUS status;
58
    size_t len;
59
    va_list list;
60
    va_start(list, format);
61
    status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);
62
    if (status == STATUS_SUCCESS)
63
    {
64
        len = strlen(buf);
65
    }
66
    else
67
    {
68
        len = 2;
69
        buf[0] = 'O';
70
        buf[1] = '\n';
71
    }
72
    if (len)
73
    {
74
        WRITE_PORT_BUFFER_UCHAR(RHEL_DEBUG_PORT, (PUCHAR)buf, len);
75
        WRITE_PORT_UCHAR(RHEL_DEBUG_PORT, '\r');
76
    }
77
    va_end(list);
78
}
79
#endif
80

81
#if defined(PRINT_DEBUG)
82
static void DebugPrintFunc(const char *format, ...)
83
{
84
    va_list list;
85
    va_start(list, format);
86
    vDbgPrintEx(DPFLTR_DEFAULT_ID, 9 | DPFLTR_MASK, format, list);
87
    va_end(list);
88
}
89
#endif
90

91
#if defined(EVENT_TRACING)
92
static void DebugPrintFuncWPP(const char *format, ...)
93
{
94
    char buf[256];
95
    NTSTATUS status;
96
    va_list list;
97
    va_start(list, format);
98
    status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);
99
    if (status == STATUS_SUCCESS)
100
    {
101
        TraceEvents(TRACE_LEVEL_WARNING, DBG_HW_ACCESS, "%s", buf);
102
    }
103
    va_end(list);
104
}
105
#endif
106

107
static void NoDebugPrintFunc(const char *format, ...)
108
{
109

110
    UNREFERENCED_PARAMETER(format);
111
}
112

113

114
void InitializeDebugPrints(IN PDRIVER_OBJECT  DriverObject, PUNICODE_STRING RegistryPath)
115
{
116
    //TBD - Read nDebugLevel and bDebugPrint from the registry
117
    WPP_INIT_TRACING(DriverObject, RegistryPath);
118
    bDebugPrint = 1;
119
    virtioDebugLevel = 0;
120
#if defined(EVENT_TRACING)
121
    VirtioDebugPrintProc = DebugPrintFuncWPP;
122
#elif defined(PRINT_DEBUG)
123
    VirtioDebugPrintProc = DebugPrintFunc;
124
#elif defined(COM_DEBUG)
125
    VirtioDebugPrintProc = DebugPrintFuncSerial;
126
#else
127
    VirtioDebugPrintProc = NoDebugPrintFunc;
128
#endif
129
    driverDebugFlags = 0xffffffff;
130
    driverDebugLevel = TRACE_LEVEL_VERBOSE;
131
    virtioDebugLevel = 4;
132
}
133

134
tDebugPrintFunc VirtioDebugPrintProc;
135

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.