ReactOS 0.4.15-dev-7842-g558ab78
globalskm.cpp
Go to the documentation of this file.
1//
2// Copyright (C) Microsoft. All rights reserved.
3//
4#include "fxobjectpch.hpp"
5
6// Tracing support
7extern "C" {
8#if defined(EVENT_TRACING)
9#include "globalskm.tmh"
10#endif
11
12// #include <wdfcxbase.h>
13#include <fxldr.h>
14
15
16}
17extern "C" {
18
19VOID
22 )
23{
24 FxAllocatedMdls* pNext, *pCur;
25
26 pNext = DebugExtension->AllocatedMdls.Next;
27
28 //
29 // MDL leaks were already checked for in FxPoolDestroy, just free all
30 // the tables here.
31 //
32 while (pNext != NULL) {
33 pCur = pNext;
34 pNext = pCur->Next;
35
37 }
38}
39
40KDEFERRED_ROUTINE FxFlushDpc;
41
42__drv_functionClass(KDEFERRED_ROUTINE)
47VOID
50 __in struct _KDPC *Dpc,
54 )
55
56/*++
57
58Routine Description:
59
60 This DPC is called on a processor to assist in flushing previous DPC's
61
62Arguments:
63
64 Dpc - Supplies a pointer to DPC object.
65
66 DeferredContext - Supplies the deferred context (event object address).
67
68 SystemArgument1 - Supplies the first system context parameter (not used).
69
70 SystemArgument2 - Supplies the second system context parameter (not used).
71
72Return Value:
73
74 None.
75
76--*/
77
78{
79
83
84 //
85 // Signal that this routine has been called.
86 //
87 ((FxCREvent*)DeferredContext)->Set();
88}
89
93 __in ULONG Major,
95 )
96{
97 if ((WdfBindInfo->Version.Major > Major) ||
98 (WdfBindInfo->Version.Major == Major &&
100 return TRUE;
101 }
102 else {
103 return FALSE;
104 }
105}
106
107#define WDF_MAJOR_VERSION_VALUE L"WdfMajorVersion"
108#define WDF_MINOR_VERSION_VALUE L"WdfMinorVersion"
109
113 _In_ PCUNICODE_STRING ServiceKeyName
114 )
115{
116 FxAutoRegKey hDriver, hWdf;
117 DECLARE_CONST_UNICODE_STRING(parametersPath, L"Parameters\\Wdf");
120 ULONG registeredMajor = 0, registeredMinor = 0;
122
123 status = FxRegKey::_OpenKey(NULL,
124 ServiceKeyName,
125 &hDriver.m_Key,
127 );
128 if (!NT_SUCCESS(status)) {
129 return FALSE;
130 }
131
132 status = FxRegKey::_OpenKey(hDriver.m_Key,
133 &parametersPath,
134 &hWdf.m_Key,
136 );
137 if (!NT_SUCCESS(status)) {
138 return FALSE;
139 }
140
141 status = FxRegKey::_QueryULong(hWdf.m_Key,
142 &wdfMajorValue,
143 &registeredMajor);
144
145 if (!NT_SUCCESS(status) || registeredMajor != WdfBindInfo->Version.Major) {
146 return FALSE;
147 }
148
149 status = FxRegKey::_QueryULong(hWdf.m_Key,
150 &wdfMinorValue,
151 &registeredMinor);
152
153 if (!NT_SUCCESS(status) || registeredMinor != WdfBindInfo->Version.Minor){
154 return FALSE;
155 }
156 else {
157 return TRUE;
158 }
159}
160
161VOID
163 _In_ PCUNICODE_STRING ServiceKeyName
164 )
165{
166 FxAutoRegKey hDriver, hParameters, hWdf;
167 DECLARE_CONST_UNICODE_STRING(parametersPart, L"Parameters");
168 DECLARE_CONST_UNICODE_STRING(wdfPart, L"Wdf");
169 //
170 // Not defined with the macro because ZwSetValue doesn't use PCUNICODE_STRING
171 //
172 UNICODE_STRING wdfMajorValue;
173 UNICODE_STRING wdfMinorValue;
175
178
179 status = FxRegKey::_OpenKey(NULL,
180 ServiceKeyName,
181 &hDriver.m_Key,
183 );
184 if (!NT_SUCCESS(status)) {
186 "Unable to open driver's service key, status %!STATUS!", status);
187 return;
188 }
189 //
190 // Key creation, unlike user mode, must happen one level at a time, since
191 // create will also open take both steps instead of trying open first
192 //
193 status = FxRegKey::_Create(hDriver.m_Key,
194 &parametersPart,
195 &hParameters.m_Key,
197 );
198 if (!NT_SUCCESS(status)) {
200 "Unable to write Parameters key, status %!STATUS!", status);
201 return;
202 }
203
204 status = FxRegKey::_Create(hParameters.m_Key,
205 &wdfPart,
206 &hWdf.m_Key,
208 );
209 if (!NT_SUCCESS(status)) {
211 "Unable to write Parameters key, status %!STATUS!", status);
212 return;
213 }
214
215 //
216 // Using ZwSetValueKey here to avoid having to change the implementation
217 // in FxRegKey of SetValue to a static / thiscall pair
218 //
219 status = ZwSetValueKey(hWdf.m_Key,
220 &wdfMajorValue,
221 0,
222 REG_DWORD,
224 sizeof(WdfBindInfo->Version.Major)
225 );
226
227 if (!NT_SUCCESS(status)) {
229 "Failed to record driver major version value, status %!STATUS!", status);
230 }
231
232 status = ZwSetValueKey(hWdf.m_Key,
233 &wdfMinorValue,
234 0,
235 REG_DWORD,
237 sizeof(WdfBindInfo->Version.Minor)
238 );
239
240 if (!NT_SUCCESS(status)) {
242 "Failed to record driver version value, status %!STATUS!", status);
243 }
244}
245
246} // extern "C"
247
251 VOID
252 )
253{
255}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGDRIVER
Definition: dbgtrace.h:68
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define __drv_requiresIRQL(irql)
Definition: driverspecs.h:321
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define __drv_functionClass(x)
Definition: driverspecs.h:274
#define __drv_sameIRQL
Definition: driverspecs.h:325
#define __drv_minIRQL(irql)
Definition: driverspecs.h:293
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
SINGLE_LIST_ENTRY * pCur
KDEFERRED_ROUTINE FxFlushDpc
Definition: globalskm.cpp:40
#define WDF_MAJOR_VERSION_VALUE
Definition: globalskm.cpp:107
#define WDF_MINOR_VERSION_VALUE
Definition: globalskm.cpp:108
VOID FxFreeAllocatedMdlsDebugInfo(__in FxDriverGlobalsDebugExtension *DebugExtension)
Definition: globalskm.cpp:20
__in_opt PVOID DeferredContext
Definition: globalskm.cpp:51
__in_opt PVOID __in_opt PVOID __in_opt PVOID SystemArgument2
Definition: globalskm.cpp:78
__in_opt PVOID __in_opt PVOID SystemArgument1
Definition: globalskm.cpp:52
BOOLEAN NTAPI KdRefreshDebuggerNotPresent(VOID)
Definition: kdapi.c:2324
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_WRITE
Definition: nt_native.h:1031
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
#define REG_DWORD
Definition: sdbapi.c:596
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
struct FxAllocatedMdls * Next
Definition: fxglobalskm.h:52
_Must_inspect_result_ BOOLEAN IsCorrectVersionRegistered(_In_ PCUNICODE_STRING ServiceKeyName)
Definition: globalskm.cpp:112
PWDF_BIND_INFO WdfBindInfo
Definition: fxglobals.h:405
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
VOID RegisterClientVersion(_In_ PCUNICODE_STRING ServiceKeyName)
Definition: globalskm.cpp:162
_Must_inspect_result_ BOOLEAN IsDebuggerAttached(VOID)
Definition: globalskm.cpp:250
Definition: ketypes.h:699
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
WDF_VERSION Version
Definition: fxldr.h:133
WDF_MAJOR_VERSION Major
Definition: fxldr.h:122
WDF_MINOR_VERSION Minor
Definition: fxldr.h:123
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
#define STDCALL
Definition: wdf.h:45
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3557
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44