ReactOS  0.4.15-dev-3163-gf17c2c0
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
7 extern "C" {
8 #if defined(EVENT_TRACING)
9 #include "globalskm.tmh"
10 #endif
11 
12 // #include <wdfcxbase.h>
13 #include <fxldr.h>
14 
15 
16 }
17 extern "C" {
18 
19 VOID
21  __in FxDriverGlobalsDebugExtension* DebugExtension
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 
40 KDEFERRED_ROUTINE FxFlushDpc;
41 
42 __drv_functionClass(KDEFERRED_ROUTINE)
47 VOID
48 STDCALL
49 FxFlushDpc (
50  __in struct _KDPC *Dpc,
54  )
55 
56 /*++
57 
58 Routine Description:
59 
60  This DPC is called on a processor to assist in flushing previous DPC's
61 
62 Arguments:
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 
72 Return 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 
91 BOOLEAN
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 
111 BOOLEAN
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,
126  KEY_READ
127  );
128  if (!NT_SUCCESS(status)) {
129  return FALSE;
130  }
131 
132  status = FxRegKey::_OpenKey(hDriver.m_Key,
133  &parametersPath,
134  &hWdf.m_Key,
135  KEY_READ
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 
161 VOID
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 
249 BOOLEAN
251  VOID
252  )
253 {
254  return (FALSE == KdRefreshDebuggerNotPresent());
255 }
struct FxAllocatedMdls * Next
Definition: fxglobalskm.h:52
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
_Must_inspect_result_ BOOLEAN IsCorrectVersionRegistered(_In_ PCUNICODE_STRING ServiceKeyName)
Definition: globalskm.cpp:112
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:107
__in_opt PVOID __in_opt PVOID __in_opt PVOID SystemArgument2
Definition: globalskm.cpp:78
__drv_functionClass(KDEFERRED_ROUTINE) __drv_maxIRQL(DISPATCH_LEVEL) __drv_minIRQL(DISPATCH_LEVEL) __drv_requiresIRQL(DISPATCH_LEVEL) __drv_sameIRQL VOID STDCALL FxFlushDpc(__in struct _KDPC *Dpc
#define __in_opt
Definition: dbghelp.h:38
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:290
__in_opt PVOID DeferredContext
Definition: globalskm.cpp:51
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
#define TRACINGDRIVER
Definition: dbgtrace.h:68
WDF_VERSION Version
Definition: fxldr.h:133
#define FALSE
Definition: types.h:117
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
__in_opt PVOID __in_opt PVOID SystemArgument1
Definition: globalskm.cpp:51
unsigned char BOOLEAN
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
#define _In_
Definition: ms_sal.h:308
UNREFERENCED_PARAMETER(SystemArgument1)
#define KEY_WRITE
Definition: nt_native.h:1031
#define __drv_sameIRQL
Definition: driverspecs.h:324
#define STDCALL
Definition: wdf.h:45
#define __drv_requiresIRQL(irql)
Definition: driverspecs.h:320
VOID RegisterClientVersion(_In_ PCUNICODE_STRING ServiceKeyName)
Definition: globalskm.cpp:162
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
KDEFERRED_ROUTINE FxFlushDpc
Definition: globalskm.cpp:40
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
PWDF_BIND_INFO WdfBindInfo
Definition: fxglobals.h:405
#define WDF_MINOR_VERSION_VALUE
Definition: globalskm.cpp:108
WDF_MAJOR_VERSION Major
Definition: fxldr.h:122
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
static const WCHAR L[]
Definition: oid.c:1250
Definition: ketypes.h:687
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Must_inspect_result_ BOOLEAN IsDebuggerAttached(VOID)
Definition: globalskm.cpp:250
SINGLE_LIST_ENTRY * pCur
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define WDF_MAJOR_VERSION_VALUE
Definition: globalskm.cpp:107
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN NTAPI KdRefreshDebuggerNotPresent(VOID)
Definition: kdapi.c:2319
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define __in
Definition: dbghelp.h:35
#define REG_DWORD
Definition: sdbapi.c:596
static SERVICE_STATUS status
Definition: service.c:31
#define __drv_minIRQL(irql)
Definition: driverspecs.h:292
WDF_MINOR_VERSION Minor
Definition: fxldr.h:123
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID FxFreeAllocatedMdlsDebugInfo(__in FxDriverGlobalsDebugExtension *DebugExtension)
Definition: globalskm.cpp:20
Definition: ps.c:97