busbdbg.c
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*++
Copyright (c) 1997-1998 Microsoft Corporation
Module Name:
BusbDbg.c
Abstract:
Debug output logic .
This entire module is a noop in the free build
Environment:
kernel mode only
Notes:
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Copyright (c) 1997-1998 Microsoft Corporation. All Rights Reserved.
Revision History:
1/27/98: created
--*/
#if DBG
#include "wdm.h"
#include "stdarg.h"
#include "stdio.h"
#include "usbdi.h"
#include "usbdlib.h"
#include "Blk82930.h"
// begin, data/code used only in DBG build
// may be overridden in registry in DBG buils only
// higher == more verbose, default is 1, 0 turns off all
int gDebugLevel = DBGLVL_DEFAULT ;
// count outstanding allocations via ExAllocatePool
int gExAllocCount =0;
BULKUSB_DBGDATA gDbgBuf = { 0, 0, 0, 0 };
// ptr to global debug data struct; txt buffer is only allocated in DBG builds
PBULKUSB_DBGDATA gpDbg = &gDbgBuf;
BOOLEAN
BulkUsb_GetRegistryDword(
IN PWCHAR RegPath,
IN PWCHAR ValueName,
IN OUT PULONG Value
)
/*++
Routine Description:
Obtain a Dword value from the registry
Arguments:
RegPath -- supplies absolute registry path
ValueName - Supplies the Value Name.
Value - receives the REG_DWORD value.
Return Value:
TRUE if successfull, FALSE on fail.
--*/
{
UNICODE_STRING path;
RTL_QUERY_REGISTRY_TABLE paramTable[2]; //zero'd second table terminates parms
ULONG lDef = *Value; // default
NTSTATUS status;
BOOLEAN fres;
WCHAR wbuf[ MAXIMUM_FILENAME_LENGTH ];
BULKUSB_KdPrint( DBGLVL_HIGH,("Enter BulkUsb_GetRegistryDword() RegPath = %ws\n ValueName =%ws\n", RegPath, ValueName));
path.Length = 0;
path.MaximumLength = MAXIMUM_FILENAME_LENGTH * sizeof( WCHAR ); // MAXIMUM_FILENAME_LENGTH defined in wdm.h
path.Buffer = wbuf;
RtlZeroMemory(path.Buffer, path.MaximumLength);
RtlMoveMemory(path.Buffer, RegPath, wcslen( RegPath) * sizeof( WCHAR ));
BULKUSB_KdPrint( DBGLVL_HIGH,("BulkUsb_GetRegistryDword() path= %ws\n", path.Buffer ));
RtlZeroMemory(paramTable, sizeof(paramTable));
paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
paramTable[0].Name = ValueName;
paramTable[0].EntryContext = Value;
paramTable[0].DefaultType = REG_DWORD;
paramTable[0].DefaultData = &lDef;
paramTable[0].DefaultLength = sizeof(ULONG);
status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
path.Buffer, paramTable, NULL, NULL);
if (NT_SUCCESS(status)) {
BULKUSB_KdPrint( DBGLVL_MEDIUM,("Exit BulkUsb_GetRegistryDWord() SUCCESS, value = decimal %d 0x%x\n", *Value, *Value));
fres = TRUE;
} else {
BULKUSB_KdPrintCond( DBGLVL_MEDIUM, (status == STATUS_INVALID_PARAMETER) ,("BulkUsb_GetRegistryDWord() STATUS_INVALID_PARAMETER\n"));
BULKUSB_KdPrintCond( DBGLVL_MEDIUM, (status == STATUS_OBJECT_NAME_NOT_FOUND) ,("BulkUsb_GetRegistryDWord() STATUS_OBJECT_NAME_NOT_FOUND\n"));
fres = FALSE;
}
return fres;
}
PVOID
BULKUSB_ExAllocatePool(
IN POOL_TYPE PoolType,
IN ULONG NumberOfBytes
)
{
gExAllocCount++;
BULKUSB_KdPrint( DBGLVL_HIGH,("BULKUSB_ExAllocatePool() gExAllocCount = dec %d\n", gExAllocCount ));
return ExAllocatePool( PoolType, NumberOfBytes );
}
VOID
BULKUSB_ExFreePool(
IN PVOID p
)
{
gExAllocCount--;
BULKUSB_KdPrint( DBGLVL_HIGH,("BULKUSB_ExFreePool() gExAllocCount = dec %d\n", gExAllocCount ));
ExFreePool( p );
}
#endif // end , if DBG