ReactOS 0.4.15-dev-7842-g558ab78
version.cpp File Reference
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <ntverp.h>
#include <ntddk.h>
#include <ntstrsafe.h>
#include "fx.hpp"
#include <fxldr.h>
#include "fxbugcheck.h"
#include "wdfversionlog.h"
#include "fxifr.h"
#include "fxdynamics.h"
#include "fxlibrarycommon.h"
Include dependency graph for version.cpp:

Go to the source code of this file.

Classes

struct  _DRV_EXTENSION
 

Macros

#define FX_DYNAMICS_GENERATE_TABLE   1
 
#define DRIVER_OBJECT_EXTENSION_IDENTIFIER   DriverEntry
 
#define DRIVER_PARAMETERS   L"Parameters"
 
#define REGISTRY_KMDF_MAJOR_VERSION   L"MajorVersion"
 
#define REGISTRY_KMDF_MINOR_VERSION   L"MinorVersion"
 
#define REGISTRY_KMDF_BUILD_NUMBER   L"BuildNumber"
 
#define KMDF_DEFAULT_NAME
 
#define KMDF_DEVICE_NAME   L"\\Device\\KMDF"
 
#define EVTLOG_MESSAGE_SIZE   70
 
#define RAW_DATA_SIZE   4
 

Typedefs

typedef struct _DRV_EXTENSION DRV_EXTENSION
 
typedef struct _DRV_EXTENSIONPDRV_EXTENSION
 

Functions

 __drv_dispatchType (IRP_MJ_CREATE) __drv_dispatchType(IRP_MJ_CLEANUP) __drv_dispatchType(IRP_MJ_CLOSE) DRIVER_DISPATCH FxLibraryDispatch
 
_Must_inspect_result_ NTSTATUS WDF_LIBRARY_COMMISSION (VOID)
 
_Must_inspect_result_ NTSTATUS WDF_LIBRARY_DECOMMISSION (VOID)
 
_Must_inspect_result_ NTSTATUS WDF_LIBRARY_REGISTER_CLIENT (__inout PWDF_BIND_INFO Info, __deref_out PWDF_DRIVER_GLOBALS *WdfDriverGlobals, __deref_inout PVOID *Context)
 
_Must_inspect_result_ NTSTATUS WDF_LIBRARY_UNREGISTER_CLIENT (__in PWDF_BIND_INFO Info, __in PWDF_DRIVER_GLOBALS WdfDriverGlobals)
 
VOID FxLibraryDeleteDevice (VOID)
 
VOID FxLibraryCleanup (VOID)
 
VOID WdfWriteKmdfVersionToRegistry (__in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath)
 
VOID WdfDeleteKmdfVersionFromRegistry (__in PDRIVER_OBJECT DriverObject)
 
NTSTATUS FxLibraryDispatch (__in struct _DEVICE_OBJECT *DeviceObject, __in PIRP Irp)
 
_Must_inspect_result_ NTSTATUS FxLibraryCreateDevice (__in PUNICODE_STRING DeviceName)
 
NTSTATUS DriverEntry (__in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath)
 
VOID DriverUnload (__in PDRIVER_OBJECT DriverObject)
 
_Must_inspect_result_ NTSTATUS WDF_LIBRARY_REGISTER_CLIENT (__in PWDF_BIND_INFO Info, __deref_out PWDF_DRIVER_GLOBALS *WdfDriverGlobals, __deref_inout PVOID *Context)
 

Variables

union {
   WDF_IFR_HEADER *   typeWDF_IFR_HEADER
 
   WDF_IFR_RECORD *   typeWDF_IFR_RECORD
 
   WDF_IFR_OFFSET *   typeWDF_IFR_OFFSET
 
   WDF_BIND_INFO *   typeWDF_BIND_INFO
 
   WDF_OBJECT_CONTEXT_TYPE_INFO *   typeWDF_OBJECT_CONTEXT_TYPE_INFO
 
   WDF_POWER_ROUTINE_TIMED_OUT_DATA *   typeWDF_POWER_ROUTINE_TIMED_OUT_DATA
 
   WDF_BUGCHECK_CODES *   typeWDF_BUGCHECK_CODES
 
   WDF_REQUEST_FATAL_ERROR_CODES *   typeWDF_REQUEST_FATAL_ERROR_CODES
 
   FX_OBJECT_INFO *   typeFX_OBJECT_INFO
 
   FX_POOL_HEADER *   typeFX_POOL_HEADER
 
   FX_POOL *   typeFX_POOL
 
   FxObject *   typeFxObject
 
   FxContextHeader *   typeFxContextHeader
 
   FX_DUMP_DRIVER_INFO_ENTRY *   typeFX_DUMP_DRIVER_INFO_ENTRY
 
   FxTargetSubmitSyncParams *   typeFxTargetSubmitSyncParams
 
uAllPublicTypes
 
DRIVER_UNLOAD DriverUnload
 
DRIVER_INITIALIZE DriverEntry
 
RTL_OSVERSIONINFOW gOsVersion = { sizeof(RTL_OSVERSIONINFOW) }
 
ULONG WdfLdrDbgPrintOn = 0
 
PCHAR WdfLdrType = KMDF_DEFAULT_NAME
 
WDF_LIBRARY_INFO WdfLibraryInfo
 

Macro Definition Documentation

◆ DRIVER_OBJECT_EXTENSION_IDENTIFIER

#define DRIVER_OBJECT_EXTENSION_IDENTIFIER   DriverEntry

Definition at line 36 of file version.cpp.

◆ DRIVER_PARAMETERS

#define DRIVER_PARAMETERS   L"Parameters"

Definition at line 37 of file version.cpp.

◆ EVTLOG_MESSAGE_SIZE

#define EVTLOG_MESSAGE_SIZE   70

Definition at line 438 of file version.cpp.

◆ FX_DYNAMICS_GENERATE_TABLE

#define FX_DYNAMICS_GENERATE_TABLE   1

Definition at line 28 of file version.cpp.

◆ KMDF_DEFAULT_NAME

#define KMDF_DEFAULT_NAME
Value:
"Wdf" ## \
LITERAL(__WDF_MAJOR_VERSION_STRING) ## \
"000"

Definition at line 85 of file version.cpp.

◆ KMDF_DEVICE_NAME

#define KMDF_DEVICE_NAME   L"\\Device\\KMDF"

Definition at line 234 of file version.cpp.

◆ RAW_DATA_SIZE

#define RAW_DATA_SIZE   4

Definition at line 439 of file version.cpp.

◆ REGISTRY_KMDF_BUILD_NUMBER

#define REGISTRY_KMDF_BUILD_NUMBER   L"BuildNumber"

Definition at line 40 of file version.cpp.

◆ REGISTRY_KMDF_MAJOR_VERSION

#define REGISTRY_KMDF_MAJOR_VERSION   L"MajorVersion"

Definition at line 38 of file version.cpp.

◆ REGISTRY_KMDF_MINOR_VERSION

#define REGISTRY_KMDF_MINOR_VERSION   L"MinorVersion"

Definition at line 39 of file version.cpp.

Typedef Documentation

◆ DRV_EXTENSION

◆ PDRV_EXTENSION

Function Documentation

◆ __drv_dispatchType()

__drv_dispatchType ( IRP_MJ_CREATE  )

◆ DriverEntry()

NTSTATUS DriverEntry ( __in PDRIVER_OBJECT  DriverObject,
__in PUNICODE_STRING  RegistryPath 
)

Definition at line 305 of file version.cpp.

309{
313
314 //
315 // This creates a local buffer which is big enough to hold a copy of the
316 // constant string assigned to it. It does not point to the constant
317 // string. As such, it is a writeable buffer.
318 //
319 // NOTE: KMDF_DEVICE_NAME L"XXXX" creates a concatenated string of
320 // KMDF_DEVICE_NAME + L"XXXX". This is done to give us room for
321 // appending a number up to 4 digits long after KMDF_DEVICE_NAME if
322 // you want a null terminated string, 5 digits long if the string is
323 // not null terminated (as is the case for a UNICODE_STRING)
324 //
325 WCHAR buffer[] = KMDF_DEVICE_NAME L"XXXX";
326
327 //
328 // Initialize global to make NonPagedPool be treated as NxPool on Win8
329 // and NonPagedPool on down-level
330 //
331 ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
332
334
335 //
336 // Determine if debug prints are on.
337 //
338 (void) WdfLdrDiagnosticsValueByNameAsULONG(&string, &WdfLdrDbgPrintOn);
339
340 __Print(("DriverEntry\n"));
341
342 DriverObject->DriverUnload = DriverUnload;
343
345
349
350 RtlZeroMemory(&name, sizeof(name));
351 name.Buffer = buffer;
352 name.Length = 0x0;
353 name.MaximumLength = sizeof(buffer);
354
355 //
356 // We use the string when we declare the buffer to get the right sized
357 // buffer. Now we want to make sure there are no contents before we
358 // use it to create a device object.
359 //
360 RtlZeroMemory(buffer, sizeof(buffer));
361
363 if (!NT_SUCCESS(status)) {
364 __Print(("ERROR: FxLibraryCreateDevice failed with Status 0x%x\n", status));
365 return status;
366 }
367
368 //
369 // Register this library with WdfLdr
370 //
371 // NOTE: Once WdfRegisterLibrary returns NT_SUCCESS() we must return
372 // NT_SUCCESS from DriverEntry!
373 //
375 if (!NT_SUCCESS(status)) {
376 __Print(("ERROR: WdfRegisterLibrary failed with Status 0x%x\n", status));
378 return status;
379 }
380
381 //
382 // Write KMDF version to registry
383 //
385
386 return STATUS_SUCCESS;
387}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ NTSTATUS WdfRegisterLibrary(__in PWDF_LIBRARY_INFO LibraryInfo, __in PUNICODE_STRING ServicePath, __in PCUNICODE_STRING LibraryDeviceName)
#define WDF_REGISTRY_DBGPRINT_ON
Definition: fxldr.h:115
GLuint buffer
Definition: glext.h:5915
#define __Print(_x_)
char string[160]
Definition: util.h:11
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define L(x)
Definition: ntvdm.h:50
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
FxLibraryGlobalsType FxLibraryGlobals
Definition: globals.cpp:95
#define KMDF_DEVICE_NAME
Definition: version.cpp:234
VOID FxLibraryCleanup(VOID)
Definition: version.cpp:293
NTSTATUS FxLibraryDispatch(__in struct _DEVICE_OBJECT *DeviceObject, __in PIRP Irp)
Definition: version.cpp:191
ULONG WdfLdrDbgPrintOn
Definition: version.cpp:106
VOID WdfWriteKmdfVersionToRegistry(__in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath)
Definition: version.cpp:536
WDF_LIBRARY_INFO WdfLibraryInfo
Definition: version.cpp:178
_Must_inspect_result_ NTSTATUS FxLibraryCreateDevice(__in PUNICODE_STRING DeviceName)
Definition: version.cpp:238
DRIVER_UNLOAD DriverUnload
Definition: version.cpp:93
#define STATUS_SUCCESS
Definition: shellext.h:65
PDRIVER_OBJECT DriverObject
Definition: fxglobals.h:719
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2289
Definition: name.c:39
Definition: ps.c:97
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define IRP_MJ_CLEANUP
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ DriverUnload()

VOID DriverUnload ( __in PDRIVER_OBJECT  DriverObject)

Definition at line 394 of file version.cpp.

397{
398 __Print(("DriverUnload\n"));
399
400 //
401 // Delete KMDF version from registry before destroying the Driver Object
402 //
404
405 //
406 // Make sure everything is deleted. Since the driver is considered a legacy
407 // driver, it can be unloaded while there are still outstanding device objects.
408 //
410}
VOID WdfDeleteKmdfVersionFromRegistry(__in PDRIVER_OBJECT DriverObject)
Definition: version.cpp:680

◆ FxLibraryCleanup()

VOID FxLibraryCleanup ( VOID  )

Definition at line 293 of file version.cpp.

296{
300 }
301}
#define NULL
Definition: types.h:112
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PDEVICE_OBJECT LibraryDeviceObject
Definition: fxglobals.h:728

Referenced by DriverEntry(), DriverUnload(), and FxLibraryDeleteDevice().

◆ FxLibraryCreateDevice()

_Must_inspect_result_ NTSTATUS FxLibraryCreateDevice ( __in PUNICODE_STRING  DeviceName)

Definition at line 238 of file version.cpp.

241{
243 ULONG i;
244
245 i = 0;
246
247 //
248 // Repeatedly try to create a named device object until we run out of buffer
249 // space or we succeed.
250 //
251 do {
253 if (!NT_SUCCESS(status)) {
254 return status;
255 }
256
257 //
258 // Create a device with no device extension
259 //
262 0,
265 0,
266 FALSE,
268 );
270
271 if (NT_SUCCESS(status)) {
272 //
273 // Clear the initializing bit now because the loader will attempt to
274 // open the device before we return from DriverEntry
275 //
277 FxLibraryGlobals.LibraryDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
278 }
279
280 return status;
281}
#define FALSE
Definition: types.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSTRSAFEVAPI RtlUnicodeStringPrintf(_In_ PUNICODE_STRING DestinationString, _In_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:3241
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

Referenced by DriverEntry().

◆ FxLibraryDeleteDevice()

VOID FxLibraryDeleteDevice ( VOID  )

Definition at line 285 of file version.cpp.

288{
290}

◆ FxLibraryDispatch()

NTSTATUS FxLibraryDispatch ( __in struct _DEVICE_OBJECT DeviceObject,
__in PIRP  Irp 
)

Definition at line 191 of file version.cpp.

195{
197
200
202
204 case IRP_MJ_CREATE:
205 //
206 // To limit our exposure for this device object, only allow kernel mode
207 // creates.
208 //
209 if (Irp->RequestorMode == KernelMode) {
211 }
212 break;
213
214 case IRP_MJ_CLEANUP:
215 case IRP_MJ_CLOSE:
216 //
217 // Since we allowed a create to succeed, succeed the cleanup and close
218 //
220 break;
221 }
222
223 Irp->IoStatus.Status = status;
224 Irp->IoStatus.Information = 0x0;
226
227 return status;
228}
_In_ PIRP Irp
Definition: csq.h:116
#define KernelMode
Definition: asm.h:34
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ WDF_LIBRARY_COMMISSION()

NTSTATUS WDF_LIBRARY_COMMISSION ( VOID  )

Definition at line 418 of file version.cpp.

421{
423}
_Must_inspect_result_ NTSTATUS FxLibraryCommonCommission(VOID)

◆ WDF_LIBRARY_DECOMMISSION()

NTSTATUS WDF_LIBRARY_DECOMMISSION ( VOID  )

Definition at line 431 of file version.cpp.

434{
436}
_Must_inspect_result_ NTSTATUS FxLibraryCommonDecommission(VOID)

◆ WDF_LIBRARY_REGISTER_CLIENT() [1/2]

_Must_inspect_result_ NTSTATUS WDF_LIBRARY_REGISTER_CLIENT ( __in PWDF_BIND_INFO  Info,
__deref_out PWDF_DRIVER_GLOBALS WdfDriverGlobals,
__deref_inout PVOID Context 
)

Definition at line 444 of file version.cpp.

449{
452 WCHAR insertString[EVTLOG_MESSAGE_SIZE];
454 PCLIENT_INFO clientInfo = NULL;
455
457
458 clientInfo = (PCLIENT_INFO)*Context;
459 *Context = NULL;
460
461 ASSERT(Info->Version.Major == WdfLibraryInfo.Version.Major);
462
463 //
464 // NOTE: If the currently loaded library < drivers minor version fail the load
465 // instead of binding to a lower minor version. The reason for that if there
466 // is a newer API or new contract change made the driver shouldn't be using older
467 // API than it was compiled with.
468 //
469
470 if (Info->Version.Minor > WdfLibraryInfo.Version.Minor) {
471 status = RtlStringCchPrintfW(insertString,
472 RTL_NUMBER_OF(insertString),
473 L"Driver Version: %d.%d Kmdf Lib. Version: %d.%d",
474 Info->Version.Major,
475 Info->Version.Minor,
478 if (!NT_SUCCESS(status)) {
479 __Print(("ERROR: RtlStringCchPrintfW failed with Status 0x%x\n", status));
480 return status;
481 }
482 rawData[0] = Info->Version.Major;
483 rawData[1] = Info->Version.Minor;
486
488 WDFVER_MINOR_VERSION_NOT_SUPPORTED,
490 insertString,
491 rawData,
492 sizeof(rawData) );
493 //
494 // this looks like the best status to return
495 //
497
498 }
499
502 clientInfo);
503
504 if (NT_SUCCESS(status)) {
505 //
506 // The context will be a pointer to FX_DRIVER_GLOBALS
507 //
509
510 //
511 // Set the WDF_BIND_INFO structure pointer in FxDriverGlobals
512 //
515 }
516
517 return status;
518}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
PFX_DRIVER_GLOBALS pFxDriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
#define WDF_LIBRARY_REGISTER_CLIENT
Definition: fxldr.h:112
struct _CLIENT_INFO * PCLIENT_INFO
_Must_inspect_result_ NTSTATUS FxLibraryCommonRegisterClient(__inout PWDF_BIND_INFO Info, __deref_out PWDF_DRIVER_GLOBALS *WdfDriverGlobals, __in_opt PCLIENT_INFO ClientInfo)
VOID LibraryLogEvent(__in PDRIVER_OBJECT DriverObject, __in NTSTATUS ErrorCode, __in NTSTATUS FinalStatus, __in PWSTR ErrorInsertionString, __in_bcount(RawDataLen) PVOID RawDataBuf, __in USHORT RawDataLen)
#define LITERAL(a)
static unsigned char rawData[2356]
Definition: data.c:573
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
#define RAW_DATA_SIZE
Definition: version.cpp:439
#define EVTLOG_MESSAGE_SIZE
Definition: version.cpp:438
PWDF_BIND_INFO WdfBindInfo
Definition: fxglobals.h:405
WDF_VERSION Version
Definition: fxldr.h:145
WDF_MAJOR_VERSION Major
Definition: fxldr.h:122
WDF_MINOR_VERSION Minor
Definition: fxldr.h:123
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
PWDF_DRIVER_GLOBALS WdfDriverGlobals

◆ WDF_LIBRARY_REGISTER_CLIENT() [2/2]

_Must_inspect_result_ NTSTATUS WDF_LIBRARY_REGISTER_CLIENT ( __inout PWDF_BIND_INFO  Info,
__deref_out PWDF_DRIVER_GLOBALS WdfDriverGlobals,
__deref_inout PVOID Context 
)

◆ WDF_LIBRARY_UNREGISTER_CLIENT()

_Must_inspect_result_ NTSTATUS WDF_LIBRARY_UNREGISTER_CLIENT ( __in PWDF_BIND_INFO  Info,
__in PWDF_DRIVER_GLOBALS  WdfDriverGlobals 
)

Definition at line 527 of file version.cpp.

531{
533}
_Must_inspect_result_ NTSTATUS FxLibraryCommonUnregisterClient(__in PWDF_BIND_INFO Info, __in PWDF_DRIVER_GLOBALS WdfDriverGlobals)

◆ WdfDeleteKmdfVersionFromRegistry()

VOID WdfDeleteKmdfVersionFromRegistry ( __in PDRIVER_OBJECT  DriverObject)

Definition at line 680 of file version.cpp.

683{
685 OBJECT_ATTRIBUTES objectAttributes;
686 HANDLE driverKey;
687 HANDLE parametersKey;
688 UNICODE_STRING valueName;
690 UNICODE_STRING parametersPath;
691 PDRV_EXTENSION driverExtension;
692
693 RtlInitUnicodeString(&parametersPath, DRIVER_PARAMETERS);
694
695 driverKey = NULL;
696 parametersKey = NULL;
697
700
701 if (driverExtension == NULL || driverExtension->ParametersRegistryPath.Buffer == NULL) {
702 return;
703 }
704
705 registryPath = &driverExtension->ParametersRegistryPath;
706
707 InitializeObjectAttributes(&objectAttributes,
710 NULL,
711 NULL);
712
713 status = ZwOpenKey(&driverKey, KEY_SET_VALUE, &objectAttributes);
714 if (!NT_SUCCESS(status)) {
715 goto out;
716 }
717
718 InitializeObjectAttributes(&objectAttributes,
719 &parametersPath,
721 driverKey,
722 NULL);
723 //
724 // Open the key for deletion
725 //
726 status = ZwOpenKey(&parametersKey,
727 DELETE,
728 &objectAttributes);
729
730 if (!NT_SUCCESS(status)) {
731 goto out;
732 }
733
735 ZwDeleteValueKey(parametersKey, &valueName);
736
738 ZwDeleteValueKey(parametersKey, &valueName);
739
741 ZwDeleteValueKey(parametersKey, &valueName);
742
743 ZwDeleteKey(parametersKey);
744
745out:
746 if (driverExtension->ParametersRegistryPath.Buffer != NULL) {
747 ExFreePool(driverExtension->ParametersRegistryPath.Buffer);
748 }
749
750 if (driverKey != NULL) {
751 ZwClose(driverKey);
752 }
753
754 if (parametersKey != NULL) {
755 ZwClose(parametersKey);
756 }
757
758 return;
759}
LPCTSTR registryPath
Definition: butterflies.c:17
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSYSAPI NTSTATUS NTAPI ZwDeleteValueKey(__in IN HANDLE Key, __in IN PUNICODE_STRING ValueName)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define DELETE
Definition: nt_native.h:57
#define KEY_SET_VALUE
Definition: nt_native.h:1017
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
static FILE * out
Definition: regtests2xml.c:44
struct _DRV_EXTENSION * PDRV_EXTENSION
#define DRIVER_PARAMETERS
Definition: version.cpp:37
#define REGISTRY_KMDF_BUILD_NUMBER
Definition: version.cpp:40
#define REGISTRY_KMDF_MAJOR_VERSION
Definition: version.cpp:38
#define REGISTRY_KMDF_MINOR_VERSION
Definition: version.cpp:39
#define DRIVER_OBJECT_EXTENSION_IDENTIFIER
Definition: version.cpp:36
UNICODE_STRING ParametersRegistryPath
Definition: version.cpp:170

Referenced by DriverUnload().

◆ WdfWriteKmdfVersionToRegistry()

VOID WdfWriteKmdfVersionToRegistry ( __in PDRIVER_OBJECT  DriverObject,
__in PUNICODE_STRING  RegistryPath 
)

Definition at line 536 of file version.cpp.

540{
542 OBJECT_ATTRIBUTES objectAttributes;
543 HANDLE driverKey;
544 HANDLE parametersKey;
545 UNICODE_STRING valueName;
546 UNICODE_STRING parametersPath;
547 PDRV_EXTENSION driverExtension;
548
549 driverKey = NULL;
550 parametersKey = NULL;
551 driverExtension = NULL;
552
553 RtlInitUnicodeString(&parametersPath, DRIVER_PARAMETERS);
554
555 InitializeObjectAttributes(&objectAttributes,
558 NULL,
559 NULL);
560
561 status = ZwOpenKey(&driverKey, KEY_CREATE_SUB_KEY, &objectAttributes);
562 if (!NT_SUCCESS(status)) {
563 __Print(("WdfWriteKmdfVersionToRegistry: Failed to open HKLM\\%S\n",
564 RegistryPath->Buffer));
565 goto out;
566 }
567
568 InitializeObjectAttributes(&objectAttributes,
569 &parametersPath,
571 driverKey,
572 NULL);
573
574 //
575 // Open or create key and get a handle
576 //
577 status = ZwCreateKey(&parametersKey,
579 &objectAttributes,
580 0,
583 NULL);
584
585 if (!NT_SUCCESS(status)) {
586 __Print(("WdfWriteKmdfVersionToRegistry: Failed to open HKLM\\%S\\%S\n",
587 RegistryPath->Buffer, parametersPath.Buffer));
588 goto out;
589 }
590
591 //
592 // Set Major Version
593 //
595
596 status = ZwSetValueKey(parametersKey,
597 &valueName,
598 0,
599 REG_DWORD,
602
603 if (!NT_SUCCESS(status)) {
604 __Print(("WdfWriteKmdfVersionToRegistry: Failed to set Major Version\n"));
605 goto out;
606 }
607
608 //
609 // Set Minor Version
610 //
612
613 status = ZwSetValueKey(parametersKey,
614 &valueName,
615 0,
616 REG_DWORD,
619
620 if (!NT_SUCCESS(status)) {
621 __Print(("WdfWriteKmdfVersionToRegistry: Failed to set Minor Version\n"));
622 goto out;
623 }
624
625
626 //
627 // Set Build Number
628 //
630
631 status = ZwSetValueKey(parametersKey,
632 &valueName,
633 0,
634 REG_DWORD,
637
638 if (!NT_SUCCESS(status)) {
639 __Print(("WdfWriteKmdfVersionToRegistry: Failed to set Build Number\n"));
640 goto out;
641 }
642
643 //
644 // Create a Driver Extension to store the registry path, where we write the
645 // version of the wdf01000.sys that's loaded in memory
646 //
649 sizeof(DRV_EXTENSION),
650 (PVOID *)&driverExtension);
651
652 if (!NT_SUCCESS(status) || driverExtension == NULL) {
653 goto out;
654 }
655
657 PagedPool,
658 RegistryPath->MaximumLength,
659 FX_TAG);
660 if (driverExtension->ParametersRegistryPath.Buffer == NULL) {
661 goto out;
662 }
663
664 driverExtension->ParametersRegistryPath.MaximumLength = RegistryPath->MaximumLength;
666
667out:
668 if (driverKey != NULL) {
669 ZwClose(driverKey);
670 }
671
672 if (parametersKey != NULL) {
673 ZwClose(parametersKey);
674 }
675
676 return;
677}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define FX_TAG
Definition: fxmacros.hpp:155
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
#define REG_DWORD
Definition: sdbapi.c:596
USHORT MaximumLength
Definition: env_spec_w32.h:370
WDF_BUILD_NUMBER Build
Definition: fxldr.h:124
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by DriverEntry().

Variable Documentation

◆ DriverEntry

DRIVER_INITIALIZE DriverEntry

Definition at line 96 of file version.cpp.

Referenced by TestDriverObject().

◆ DriverUnload

DRIVER_UNLOAD DriverUnload

Definition at line 93 of file version.cpp.

Referenced by DriverEntry().

◆ gOsVersion

Definition at line 104 of file version.cpp.

Referenced by FxLibraryCommonCommission().

◆ typeFX_DUMP_DRIVER_INFO_ENTRY

FX_DUMP_DRIVER_INFO_ENTRY* typeFX_DUMP_DRIVER_INFO_ENTRY

Definition at line 70 of file version.cpp.

◆ typeFX_OBJECT_INFO

FX_OBJECT_INFO* typeFX_OBJECT_INFO

Definition at line 65 of file version.cpp.

◆ typeFX_POOL

FX_POOL* typeFX_POOL

Definition at line 67 of file version.cpp.

◆ typeFX_POOL_HEADER

FX_POOL_HEADER* typeFX_POOL_HEADER

Definition at line 66 of file version.cpp.

◆ typeFxContextHeader

FxContextHeader* typeFxContextHeader

Definition at line 69 of file version.cpp.

◆ typeFxObject

FxObject* typeFxObject

Definition at line 68 of file version.cpp.

◆ typeFxTargetSubmitSyncParams

FxTargetSubmitSyncParams* typeFxTargetSubmitSyncParams

Definition at line 71 of file version.cpp.

◆ typeWDF_BIND_INFO

WDF_BIND_INFO* typeWDF_BIND_INFO

Definition at line 60 of file version.cpp.

◆ typeWDF_BUGCHECK_CODES

WDF_BUGCHECK_CODES* typeWDF_BUGCHECK_CODES

Definition at line 63 of file version.cpp.

◆ typeWDF_IFR_HEADER

WDF_IFR_HEADER* typeWDF_IFR_HEADER

Definition at line 57 of file version.cpp.

◆ typeWDF_IFR_OFFSET

WDF_IFR_OFFSET* typeWDF_IFR_OFFSET

Definition at line 59 of file version.cpp.

◆ typeWDF_IFR_RECORD

WDF_IFR_RECORD* typeWDF_IFR_RECORD

Definition at line 58 of file version.cpp.

◆ typeWDF_OBJECT_CONTEXT_TYPE_INFO

WDF_OBJECT_CONTEXT_TYPE_INFO* typeWDF_OBJECT_CONTEXT_TYPE_INFO

Definition at line 61 of file version.cpp.

◆ typeWDF_POWER_ROUTINE_TIMED_OUT_DATA

WDF_POWER_ROUTINE_TIMED_OUT_DATA* typeWDF_POWER_ROUTINE_TIMED_OUT_DATA

Definition at line 62 of file version.cpp.

◆ typeWDF_REQUEST_FATAL_ERROR_CODES

WDF_REQUEST_FATAL_ERROR_CODES* typeWDF_REQUEST_FATAL_ERROR_CODES

Definition at line 64 of file version.cpp.

◆ 

union { ... } uAllPublicTypes

◆ WdfLdrDbgPrintOn

ULONG WdfLdrDbgPrintOn = 0

Definition at line 106 of file version.cpp.

Referenced by DriverEntry().

◆ WdfLdrType

PCHAR WdfLdrType = KMDF_DEFAULT_NAME

Definition at line 108 of file version.cpp.

◆ WdfLibraryInfo

WDF_LIBRARY_INFO WdfLibraryInfo
Initial value:
= {
{ __WDF_MAJOR_VERSION, __WDF_MINOR_VERSION, __WDF_BUILD_NUMBER }
}
#define WDF_LIBRARY_COMMISSION
Definition: fxldr.h:110
_Must_inspect_result_ NTSTATUS(* PFNLIBRARYREGISTERCLIENT)(__in PWDF_BIND_INFO Info, __deref_out PWDF_COMPONENT_GLOBALS *ComponentGlobals, __deref_inout PVOID *Context)
Definition: fxldr.h:69
struct _WDF_LIBRARY_INFO WDF_LIBRARY_INFO
#define WDF_LIBRARY_UNREGISTER_CLIENT
Definition: fxldr.h:113
#define WDF_LIBRARY_DECOMMISSION
Definition: fxldr.h:111
_Must_inspect_result_ NTSTATUS(* PFNLIBRARYCOMMISSION)(VOID)
Definition: fxldr.h:55
_Must_inspect_result_ NTSTATUS(* PFNLIBRARYDECOMMISSION)(VOID)
Definition: fxldr.h:62
_Must_inspect_result_ NTSTATUS(* PFNLIBRARYUNREGISTERCLIENT)(__in PWDF_BIND_INFO Info, __in PWDF_COMPONENT_GLOBALS DriverGlobals)
Definition: fxldr.h:78

Definition at line 178 of file version.cpp.

Referenced by DriverEntry(), WDF_LIBRARY_REGISTER_CLIENT(), and WdfWriteKmdfVersionToRegistry().