ReactOS  0.4.15-dev-2776-g4130f0b
fxlibrarycommon.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _LIT_(a)   # a
 
#define LITERAL(a)   _LIT_(a)
 
#define __Print(_x_)
 
#define WDF_ENHANCED_VERIFIER_OPTIONS_VALUE_NAME   L"EnhancedVerifierOptions"
 

Typedefs

typedef NTSTATUS(* PFN_RTL_GET_VERSION) (OUT PRTL_OSVERSIONINFOW VersionInformation)
 

Functions

NTSTATUS FxLibraryCommonCommission (VOID)
 
NTSTATUS FxLibraryCommonDecommission (VOID)
 
NTSTATUS FxLibraryCommonRegisterClient (PWDF_BIND_INFO Info, PWDF_DRIVER_GLOBALS *WdfDriverGlobals, PCLIENT_INFO ClientInfo)
 
NTSTATUS FxLibraryCommonUnregisterClient (PWDF_BIND_INFO Info, PWDF_DRIVER_GLOBALS WdfDriverGlobals)
 
VOID GetEnhancedVerifierOptions (PCLIENT_INFO ClientInfo, PULONG Options)
 

Variables

ULONG WdfLdrDbgPrintOn
 
PCHAR WdfLdrType
 
WDFVERSION WdfVersion
 
RTL_OSVERSIONINFOW gOsVersion
 

Macro Definition Documentation

◆ __Print

#define __Print (   _x_)
Value:
{ \
} \
}
ULONG WdfLdrDbgPrintOn
Definition: version.cpp:106

Definition at line 24 of file fxlibrarycommon.h.

◆ _LIT_

#define _LIT_ (   a)    # a

Definition at line 18 of file fxlibrarycommon.h.

◆ LITERAL

#define LITERAL (   a)    _LIT_(a)

Definition at line 19 of file fxlibrarycommon.h.

◆ WDF_ENHANCED_VERIFIER_OPTIONS_VALUE_NAME

#define WDF_ENHANCED_VERIFIER_OPTIONS_VALUE_NAME   L"EnhancedVerifierOptions"

Definition at line 30 of file fxlibrarycommon.h.

Typedef Documentation

◆ PFN_RTL_GET_VERSION

typedef NTSTATUS(* PFN_RTL_GET_VERSION) (OUT PRTL_OSVERSIONINFOW VersionInformation)

Definition at line 34 of file fxlibrarycommon.h.

Function Documentation

◆ FxLibraryCommonCommission()

NTSTATUS FxLibraryCommonCommission ( VOID  )

Definition at line 224 of file fxlibrarycommon.cpp.

227 {
228  DECLARE_CONST_UNICODE_STRING(usName, L"RtlGetVersion");
229  PFN_RTL_GET_VERSION pRtlGetVersion = NULL;
231 
233 
234  //
235  // Commission this version's DLL globals.
236  //
238 
239  if (!NT_SUCCESS(status)) {
240  __Print(("FxLibraryGlobalsCommission failed %X\n", status));
241  return status;
242  }
243 
244  //
245  // register telemetry provider.
246  //
248 
249  //
250  // Initialize internal WPP tracing.
251  //
253  if (NT_SUCCESS(status)) {
255  }
256  else {
257  __Print(("Failed to initialize tracing for WDF\n"));
258 
259  //
260  // Failure to initialize is not critical enough to fail driver load.
261  //
263  }
264 
265  //
266  // Attempt to load RtlGetVersion (works for > w2k).
267  //
269  (PUNICODE_STRING) &usName
270  );
271 
272  //
273  // Now attempt to get this OS's version.
274  //
275  if (pRtlGetVersion != NULL) {
276  pRtlGetVersion(&gOsVersion);
277  }
278 
279  __Print(("OsVersion(%d.%d)\n",
282 
283  //
284  // Init triage info for 9f bugcheck analysis.
285  //
286  GetTriageInfo();
287 
288  return STATUS_SUCCESS;
289 }
NTSTATUS(* PFN_RTL_GET_VERSION)(__out PRTL_OSVERSIONINFOW VersionInformation)
RTL_OSVERSIONINFOW gOsVersion
Definition: version.cpp:104
BOOLEAN InternalTracingInitialized
Definition: fxglobals.h:804
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
VOID GetTriageInfo(VOID)
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3514
#define WDF_LIBRARY_COMMISSION
Definition: fxldr.h:110
#define LITERAL(a)
ULONG dwMajorVersion
Definition: rtltypes.h:247
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
static const WCHAR L[]
Definition: oid.c:1250
_Must_inspect_result_ NTSTATUS FxTraceInitialize(VOID)
Definition: tracing.cpp:47
_Must_inspect_result_ NTSTATUS FxLibraryGlobalsCommission(VOID)
Definition: globals.cpp:494
FxLibraryGlobalsType FxLibraryGlobals
Definition: globals.cpp:95
#define NULL
Definition: types.h:112
ULONG dwMinorVersion
Definition: rtltypes.h:248
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
VOID RegisterTelemetryProvider(VOID)
#define __Print(_x_)
Definition: ps.c:97

◆ FxLibraryCommonDecommission()

NTSTATUS FxLibraryCommonDecommission ( VOID  )

Definition at line 293 of file fxlibrarycommon.cpp.

296 {
297  __Print((LITERAL(WDF_LIBRARY_DECOMMISSION) ": enter\n"));
298 
299  //
300  // Uninitialize WPP tracing.
301  //
305  }
306 
307  //
308  // Unregister telemetry provider.
309  //
311 
312  EventUnregisterMicrosoft_Windows_DriverFrameworks_KernelMode_Performance();
313 
314  //
315  // Decommission this version's DLL globals.
316  //
318 
319  //
320  // Note: This is the absolute last action from WDF library (dynamic or static).
321  // The image is likely to be deleted after returning.
322  //
324 
325  return STATUS_SUCCESS;
326 }
BOOLEAN InternalTracingInitialized
Definition: fxglobals.h:804
VOID FxLibraryGlobalsDecommission(VOID)
Definition: globals.cpp:742
#define FALSE
Definition: types.h:117
#define LITERAL(a)
#define WDF_LIBRARY_DECOMMISSION
Definition: fxldr.h:111
FxLibraryGlobalsType FxLibraryGlobals
Definition: globals.cpp:95
VOID UnregisterTelemetryProvider(VOID)
VOID TraceUninitialize(VOID)
Definition: tracing.cpp:79
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __Print(_x_)

◆ FxLibraryCommonRegisterClient()

NTSTATUS FxLibraryCommonRegisterClient ( PWDF_BIND_INFO  Info,
PWDF_DRIVER_GLOBALS WdfDriverGlobals,
PCLIENT_INFO  ClientInfo 
)

Definition at line 240 of file fxlibrarycommon.cpp.

245 {
247 
249 
251 
252  ASSERT(Info != NULL && Info->FuncCount != 0);
253  ASSERT(WdfDriverGlobals != 0);
254 
255  if (Info == NULL || WdfDriverGlobals == NULL || Info->FuncTable == NULL) {
257  ": NULL parameter -- %s\n",
258  (Info == NULL) ? "PWDF_BIND_INFO" :
259  (WdfDriverGlobals == NULL) ? "PWDF_DRIVER_GLOBALS *" :
260  (Info->FuncTable == NULL) ? "PWDF_BIND_INFO->FuncTable" :
261  "unknown" ));
262  goto Done;
263  }
264 
266 
267  ASSERT(Info->FuncCount <= WdfVersion.FuncCount);
268 
269  //
270  // WdfVersion.Count is initialized in FxDynamics.h and is never changed.
271  // Prefast is unable to make that determination.
272  //
273  __assume(WdfVersion.FuncCount == sizeof(WDFFUNCTIONS)/sizeof(PVOID));
274 
275  if (Info->FuncCount > WdfVersion.FuncCount) {
277  ": version mismatch detected in function table count: client"
278  "has 0x%x, library has 0x%x\n",
279  Info->FuncCount, WdfVersion.FuncCount));
280  goto Done;
281  }
282 
283  if (Info->FuncCount <= WdfFunctionTableNumEntries_V2_15) {
284 
285  switch (Info->FuncCount) {
286 
289  break;
290 
291  default:
293  ": Function table count 0x%x doesn't match any previously "
294  "released framework version table size\n",
295  Info->FuncCount));
296  goto Done;
297  }
298  }
299  else {
300  //
301  // Client version is same as framework version. Make
302  // sure table count is exact.
303  //
304  // Note that in order for build-to-build upgrade to work, the following
305  // check should be commented out during active development.
306  //
307  // DO CHANGE it to a real failure towards the tail end of release to
308  // prevent cases where a driver sneaks out into public after being built
309  // with a non-RTM version of WDF and has a function count less than the
310  // final count. An HCK test has been added to ensure such drivers are
311  // caught early. This check is an additional prevention.
312  //
313  if (Info->FuncCount != WdfFunctionTableNumEntries) {
314  __Print(("Framework function table size (%d) doesn't match "
315  "with client (%d). Rebuild the client driver.",
316  WdfFunctionTableNumEntries, Info->FuncCount));
317 
318  ASSERT(FALSE);
319  goto Done;
320  }
321  }
322 
323  //
324  // Allocate an new FxDriverGlobals area for this driver.
325  //
327 
328  if (*WdfDriverGlobals) {
329  BOOLEAN isFunctinTableHookingOn = FALSE;
330  BOOLEAN isPerformanceAnalysisOn = FALSE;
332  //
333  // Check the registry to see if Enhanced verifier is on for this driver.
334  // if registry read fails, options value remains unchanged.
335  // store enhanced verifier options in driver globals
336  //
339  isFunctinTableHookingOn = IsFxVerifierFunctionTableHooking(fxDriverGlobals);
340  isPerformanceAnalysisOn = IsFxPerformanceAnalysis(fxDriverGlobals);
341 
342  //
343  // Set-up the function table. Enhanced verifier and Performance analysis is off by default.
344  //
345  if (isFunctinTableHookingOn == FALSE && isPerformanceAnalysisOn == FALSE) {
346  //
347  // Set-up the function table
348  //
349  // Starting in 2.15 we reference a copy of the DDI table in WDF01000,
350  // prior to that we copy the entire table to local memory.
351  //
352  if (Info->FuncCount <= WdfFunctionTableNumEntries_V2_0) {
353  RtlCopyMemory( Info->FuncTable,
355  Info->FuncCount * sizeof(PVOID) );
356  }
357  else {
358  //
359  // FuncTable arrives with a ptr to &WdfFunctions, so we update
360  // what WdfFunctions points to
361  //
362  *((WDFFUNC**) Info->FuncTable) = (WDFFUNC*) &WdfVersion.Functions;
363  }
364  }
365  else {
367  ": Enhanced Verification is ON \n"));
368 
369  if (Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle == NULL)
370  {
371  EventRegisterMicrosoft_Windows_DriverFrameworks_UserMode_Performance();
372  }
373 
374  //
375  // Enhanced verification is on. Return verifier function table
376  //
377  // Starting in 1.15 we reference a copy of the DDI table in WDF01000,
378  // prior to that we copy the entire table to local memory.
379  //
380  if (Info->FuncCount <= WdfFunctionTableNumEntries_V2_0) {
381  RtlCopyMemory( Info->FuncTable,
382  &VfWdfVersion.Functions,
383  Info->FuncCount * sizeof(PVOID) );
384  }
385  else {
386  //
387  // FuncTable arrives with a ptr to &WdfFunctions, so we update
388  // what WdfFunctions points to.
389  //
390  *((WDFFUNC**) Info->FuncTable) = (WDFFUNC*) &VfWdfVersion.Functions;
391  }
392  }
393 
395 
397  ": WdfFunctions %p\n", Info->FuncTable));
398  }
399 
400 Done:
402  ": exit: status %X\n", status));
403 
404  if (!NT_SUCCESS(status)) {
405  FX_VERIFY(DRIVER(BadArgument, TODO),
406  TRAPMSG("Version mismatch detected in function table count. Recompile"
407  " driver with correct headers"));
408  }
409 
410  return status;
411 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _WDFFUNCTIONS WDFFUNCTIONS
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
CLIENT_DATA ClientInfo
WDFFUNCTIONS Functions
Definition: fxdynamics.h:594
#define TODO
Definition: SAX2.c:49
#define FALSE
Definition: types.h:117
ULONG FxEnhancedVerifierOptions
Definition: fxglobals.h:518
unsigned char BOOLEAN
VOID GetEnhancedVerifierOptions(__in PCLIENT_INFO ClientInfo, __out PULONG Options)
__inline BOOLEAN IsFxVerifierFunctionTableHooking(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:127
#define LITERAL(a)
VOID(* WDFFUNC)(VOID)
Definition: wdf.h:68
PWDF_DRIVER_GLOBALS WdfDriverGlobals
FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost))
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ PWDF_DRIVER_GLOBALS FxAllocateDriverGlobals(VOID)
Definition: globals.cpp:1052
PFX_DRIVER_GLOBALS fxDriverGlobals
#define NULL
Definition: types.h:112
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
static SERVICE_STATUS status
Definition: service.c:31
WDFVERSION WdfVersion
ULONG FuncCount
Definition: fxdynamics.h:593
#define WDF_LIBRARY_REGISTER_CLIENT
Definition: fxldr.h:112
#define __Print(_x_)
__inline BOOLEAN IsFxPerformanceAnalysis(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:250
Definition: ps.c:97

◆ FxLibraryCommonUnregisterClient()

NTSTATUS FxLibraryCommonUnregisterClient ( PWDF_BIND_INFO  Info,
PWDF_DRIVER_GLOBALS  WdfDriverGlobals 
)

Definition at line 414 of file fxlibrarycommon.cpp.

418 {
420 
422 
423  ASSERT(Info != NULL);
425 
426  if (Info != NULL && WdfDriverGlobals != NULL) {
428 
430 
432 
433  //
434  // Destroy this FxDriver instance, if its still indicated.
435  //
436  if (pFxDriverGlobals->Driver != NULL) {
437  //
438  // Association support, we are a root with no parent
439  //
441 
443  }
444 
445  //
446  // Stop IFR logging
447  //
449 
450  //
451  // This will free the client's FxDriverGlobals area
452  //
454  }
455  else {
457  }
458 
460  ": exit: status %X\n", status));
461 
462  return status;
463 }
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
#define WDF_LIBRARY_UNREGISTER_CLIENT
Definition: fxldr.h:113
VOID FxFreeDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: globals.cpp:1181
FxDriver * Driver
Definition: fxglobals.h:374
#define LITERAL(a)
PWDF_DRIVER_GLOBALS WdfDriverGlobals
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define ASSERT(a)
Definition: mode.c:44
virtual VOID DeleteObject(VOID)
Definition: fxdriver.hpp:332
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
VOID FxIFRStop(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: tracing.cpp:297
VOID FxDestroy(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: globals.cpp:981
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
static SERVICE_STATUS status
Definition: service.c:31
#define __Print(_x_)
Definition: ps.c:97

◆ GetEnhancedVerifierOptions()

VOID GetEnhancedVerifierOptions ( PCLIENT_INFO  ClientInfo,
PULONG  Options 
)

Definition at line 466 of file fxlibrarycommon.cpp.

470 {
472  ULONG value;
473  FxAutoRegKey hWdf;
475 
476  *Options = 0;
477  if (ClientInfo == NULL ||
478  ClientInfo->Size != sizeof(CLIENT_INFO) ||
479  ClientInfo->RegistryPath == NULL ||
480  ClientInfo->RegistryPath->Length == 0 ||
481  ClientInfo->RegistryPath->Buffer == NULL ||
482  Options == NULL) {
483 
485  ": Invalid ClientInfo received from wudfldr \n"));
486  return;
487  }
488 
489  status = FxRegKey::_OpenKey(NULL,
490  ClientInfo->RegistryPath,
491  &hWdf.m_Key,
492  KEY_READ);
493  if (!NT_SUCCESS(status)) {
494  return;
495  }
496 
497  status = FxRegKey::_QueryULong(
498  hWdf.m_Key, &valueName, &value);
499 
500  //
501  // Examine key values and set Options only on success.
502  //
503  if (NT_SUCCESS(status)) {
504  if (value) {
505  *Options = value;
506  }
507  }
508 }
Definition: pdh_main.c:93
#define KEY_READ
Definition: nt_native.h:1023
LONG NTSTATUS
Definition: precomp.h:26
CLIENT_DATA ClientInfo
#define LITERAL(a)
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3531
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
GLsizei const GLfloat * value
Definition: glext.h:6069
#define WDF_ENHANCED_VERIFIER_OPTIONS_VALUE_NAME
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
#define WDF_LIBRARY_REGISTER_CLIENT
Definition: fxldr.h:112
#define __Print(_x_)
Definition: ps.c:97

Variable Documentation

◆ gOsVersion

RTL_OSVERSIONINFOW gOsVersion

Definition at line 104 of file version.cpp.

◆ WdfLdrDbgPrintOn

ULONG WdfLdrDbgPrintOn

Definition at line 106 of file version.cpp.

Referenced by DriverEntry().

◆ WdfLdrType

PCHAR WdfLdrType

Definition at line 108 of file version.cpp.

◆ WdfVersion

WDFVERSION WdfVersion