ReactOS 0.4.16-dev-1946-g52006dd
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 "reactos_special.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 NTAPI WDF_LIBRARY_COMMISSION (VOID)
 
_Must_inspect_result_ NTSTATUS NTAPI WDF_LIBRARY_DECOMMISSION (VOID)
 
_Must_inspect_result_ NTSTATUS NTAPI WDF_LIBRARY_REGISTER_CLIENT (__inout PWDF_BIND_INFO Info, __deref_out PWDF_DRIVER_GLOBALS *WdfDriverGlobals, __deref_inout PVOID *Context)
 
_Must_inspect_result_ NTSTATUS NTAPI 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 NTAPI FxLibraryDispatch (__in struct _DEVICE_OBJECT *DeviceObject, __in PIRP Irp)
 
_Must_inspect_result_ NTSTATUS FxLibraryCreateDevice (__in PUNICODE_STRING DeviceName)
 
NTSTATUS NTAPI DriverEntry (__in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath)
 
VOID NTAPI DriverUnload (__in PDRIVER_OBJECT DriverObject)
 
_Must_inspect_result_ NTSTATUS NTAPI 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 37 of file version.cpp.

◆ DRIVER_PARAMETERS

#define DRIVER_PARAMETERS   L"Parameters"

Definition at line 38 of file version.cpp.

◆ EVTLOG_MESSAGE_SIZE

#define EVTLOG_MESSAGE_SIZE   70

Definition at line 455 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 91 of file version.cpp.

◆ KMDF_DEVICE_NAME

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

Definition at line 246 of file version.cpp.

◆ RAW_DATA_SIZE

#define RAW_DATA_SIZE   4

Definition at line 456 of file version.cpp.

◆ REGISTRY_KMDF_BUILD_NUMBER

#define REGISTRY_KMDF_BUILD_NUMBER   L"BuildNumber"

Definition at line 41 of file version.cpp.

◆ REGISTRY_KMDF_MAJOR_VERSION

#define REGISTRY_KMDF_MAJOR_VERSION   L"MajorVersion"

Definition at line 39 of file version.cpp.

◆ REGISTRY_KMDF_MINOR_VERSION

#define REGISTRY_KMDF_MINOR_VERSION   L"MinorVersion"

Definition at line 40 of file version.cpp.

Typedef Documentation

◆ DRV_EXTENSION

◆ PDRV_EXTENSION

Function Documentation

◆ __drv_dispatchType()

__drv_dispatchType ( IRP_MJ_CREATE  )

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( __in PDRIVER_OBJECT  DriverObject,
__in PUNICODE_STRING  RegistryPath 
)

Definition at line 318 of file version.cpp.

322{
326
327 //
328 // This creates a local buffer which is big enough to hold a copy of the
329 // constant string assigned to it. It does not point to the constant
330 // string. As such, it is a writeable buffer.
331 //
332 // NOTE: KMDF_DEVICE_NAME L"XXXX" creates a concatenated string of
333 // KMDF_DEVICE_NAME + L"XXXX". This is done to give us room for
334 // appending a number up to 4 digits long after KMDF_DEVICE_NAME if
335 // you want a null terminated string, 5 digits long if the string is
336 // not null terminated (as is the case for a UNICODE_STRING)
337 //
338 WCHAR buffer[] = KMDF_DEVICE_NAME L"XXXX";
339
340 //
341 // Initialize global to make NonPagedPool be treated as NxPool on Win8
342 // and NonPagedPool on down-level
343 //
344#ifndef __REACTOS__
345 ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
346#endif
348
349 //
350 // Determine if debug prints are on.
351 //
353
354 __Print(("DriverEntry\n"));
355
356 DriverObject->DriverUnload = DriverUnload;
357
359
363
364 RtlZeroMemory(&name, sizeof(name));
365 name.Buffer = buffer;
366 name.Length = 0x0;
367 name.MaximumLength = sizeof(buffer);
368
369 //
370 // We use the string when we declare the buffer to get the right sized
371 // buffer. Now we want to make sure there are no contents before we
372 // use it to create a device object.
373 //
374 RtlZeroMemory(buffer, sizeof(buffer));
375
377 if (!NT_SUCCESS(status)) {
378 __Print(("ERROR: FxLibraryCreateDevice failed with Status 0x%x\n", status));
379 return status;
380 }
381
382 //
383 // Register this library with WdfLdr
384 //
385 // NOTE: Once WdfRegisterLibrary returns NT_SUCCESS() we must return
386 // NT_SUCCESS from DriverEntry!
387 //
389 if (!NT_SUCCESS(status)) {
390 __Print(("ERROR: WdfRegisterLibrary failed with Status 0x%x\n", status));
392 return status;
393 }
394
395 //
396 // Write KMDF version to registry
397 //
399
400 return STATUS_SUCCESS;
401}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
FxLibraryGlobalsType FxLibraryGlobals
Definition: globals.cpp:95
#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 IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define KMDF_DEVICE_NAME
Definition: version.cpp:246
NTSTATUS NTAPI FxLibraryDispatch(__in struct _DEVICE_OBJECT *DeviceObject, __in PIRP Irp)
Definition: version.cpp:203
VOID FxLibraryCleanup(VOID)
Definition: version.cpp:305
ULONG WdfLdrDbgPrintOn
Definition: version.cpp:113
VOID WdfWriteKmdfVersionToRegistry(__in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath)
Definition: version.cpp:555
WDF_LIBRARY_INFO WdfLibraryInfo
Definition: version.cpp:189
_Must_inspect_result_ NTSTATUS FxLibraryCreateDevice(__in PUNICODE_STRING DeviceName)
Definition: version.cpp:250
DRIVER_UNLOAD DriverUnload
Definition: version.cpp:100
#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:2291
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
NTSTATUS NTAPI WdfRegisterLibrary(_In_ PWDF_LIBRARY_INFO LibraryInfo, _In_ PUNICODE_STRING ServicePath, _In_ PCUNICODE_STRING LibraryDeviceName)
Register wdf01000 library.
Definition: wdfldr.c:311
NTSTATUS NTAPI WdfLdrDiagnosticsValueByNameAsULONG(_In_ PUNICODE_STRING ValueName, _Out_ PULONG Value)
Retrieves an ULONG value from KMDF diagnostics registry key.
Definition: wdfldr.c:54
#define IRP_MJ_CLEANUP
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ DriverUnload()

VOID NTAPI DriverUnload ( __in PDRIVER_OBJECT  DriverObject)

Definition at line 409 of file version.cpp.

412{
413 __Print(("DriverUnload\n"));
414
415 //
416 // Delete KMDF version from registry before destroying the Driver Object
417 //
419
420 //
421 // Make sure everything is deleted. Since the driver is considered a legacy
422 // driver, it can be unloaded while there are still outstanding device objects.
423 //
425}
VOID WdfDeleteKmdfVersionFromRegistry(__in PDRIVER_OBJECT DriverObject)
Definition: version.cpp:699

◆ FxLibraryCleanup()

VOID FxLibraryCleanup ( VOID  )

Definition at line 305 of file version.cpp.

308{
312 }
313}
#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 250 of file version.cpp.

253{
255 ULONG i;
256
257 i = 0;
258
259 //
260 // Repeatedly try to create a named device object until we run out of buffer
261 // space or we succeed.
262 //
263 do {
265 if (!NT_SUCCESS(status)) {
266 return status;
267 }
268
269 //
270 // Create a device with no device extension
271 //
274 0,
277 0,
278 FALSE,
280 );
282
283 if (NT_SUCCESS(status)) {
284 //
285 // Clear the initializing bit now because the loader will attempt to
286 // open the device before we return from DriverEntry
287 //
289 FxLibraryGlobals.LibraryDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
290 }
291
292 return status;
293}
#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:79
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:3281

Referenced by DriverEntry().

◆ FxLibraryDeleteDevice()

VOID FxLibraryDeleteDevice ( VOID  )

Definition at line 297 of file version.cpp.

300{
302}

◆ FxLibraryDispatch()

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

Definition at line 203 of file version.cpp.

207{
209
212
214
216 case IRP_MJ_CREATE:
217 //
218 // To limit our exposure for this device object, only allow kernel mode
219 // creates.
220 //
221 if (Irp->RequestorMode == KernelMode) {
223 }
224 break;
225
226 case IRP_MJ_CLEANUP:
227 case IRP_MJ_CLOSE:
228 //
229 // Since we allowed a create to succeed, succeed the cleanup and close
230 //
232 break;
233 }
234
235 Irp->IoStatus.Status = status;
236 Irp->IoStatus.Information = 0x0;
238
239 return status;
240}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define KernelMode
Definition: asm.h:38
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1703
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ WDF_LIBRARY_COMMISSION()

NTSTATUS WDF_LIBRARY_COMMISSION ( VOID  )

Definition at line 434 of file version.cpp.

437{
439}
_Must_inspect_result_ NTSTATUS NTAPI FxLibraryCommonCommission(VOID)

◆ WDF_LIBRARY_DECOMMISSION()

NTSTATUS WDF_LIBRARY_DECOMMISSION ( VOID  )

Definition at line 448 of file version.cpp.

451{
453}
_Must_inspect_result_ NTSTATUS NTAPI FxLibraryCommonDecommission(VOID)

◆ WDF_LIBRARY_REGISTER_CLIENT() [1/2]

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

Definition at line 462 of file version.cpp.

467{
470 WCHAR insertString[EVTLOG_MESSAGE_SIZE];
472 PCLIENT_INFO clientInfo = NULL;
473
475
476 clientInfo = (PCLIENT_INFO)*Context;
477 *Context = NULL;
478
479 ASSERT(Info->Version.Major == WdfLibraryInfo.Version.Major);
480
481 //
482 // NOTE: If the currently loaded library < drivers minor version fail the load
483 // instead of binding to a lower minor version. The reason for that if there
484 // is a newer API or new contract change made the driver shouldn't be using older
485 // API than it was compiled with.
486 //
487
488 if (Info->Version.Minor > WdfLibraryInfo.Version.Minor) {
489 status = RtlStringCchPrintfW(insertString,
490 RTL_NUMBER_OF(insertString),
491 L"Driver Version: %d.%d Kmdf Lib. Version: %d.%d",
492 Info->Version.Major,
493 Info->Version.Minor,
496 if (!NT_SUCCESS(status)) {
497 __Print(("ERROR: RtlStringCchPrintfW failed with Status 0x%x\n", status));
498 return status;
499 }
500 rawData[0] = Info->Version.Major;
501 rawData[1] = Info->Version.Minor;
504
508 insertString,
509 rawData,
510 sizeof(rawData) );
511 //
512 // this looks like the best status to return
513 //
515
516 }
517
520 clientInfo);
521
522 if (NT_SUCCESS(status)) {
523 //
524 // The context will be a pointer to FX_DRIVER_GLOBALS
525 //
527
528 //
529 // Set the WDF_BIND_INFO structure pointer in FxDriverGlobals
530 //
533 }
534
535 return status;
536}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: d3dkmdt.h:46
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 NTAPI 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
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 WDFVER_MINOR_VERSION_NOT_SUPPORTED
#define RAW_DATA_SIZE
Definition: version.cpp:456
#define EVTLOG_MESSAGE_SIZE
Definition: version.cpp:455
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 NTAPI 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 NTAPI WDF_LIBRARY_UNREGISTER_CLIENT ( __in PWDF_BIND_INFO  Info,
__in PWDF_DRIVER_GLOBALS  WdfDriverGlobals 
)

Definition at line 546 of file version.cpp.

550{
552}
_Must_inspect_result_ NTSTATUS NTAPI FxLibraryCommonUnregisterClient(__in PWDF_BIND_INFO Info, __in PWDF_DRIVER_GLOBALS WdfDriverGlobals)

◆ WdfDeleteKmdfVersionFromRegistry()

VOID WdfDeleteKmdfVersionFromRegistry ( __in PDRIVER_OBJECT  DriverObject)

Definition at line 699 of file version.cpp.

702{
704 OBJECT_ATTRIBUTES objectAttributes;
705 HANDLE driverKey;
706 HANDLE parametersKey;
707 UNICODE_STRING valueName;
709 UNICODE_STRING parametersPath;
710 PDRV_EXTENSION driverExtension;
711
712 RtlInitUnicodeString(&parametersPath, DRIVER_PARAMETERS);
713
714 driverKey = NULL;
715 parametersKey = NULL;
716
719
720 if (driverExtension == NULL || driverExtension->ParametersRegistryPath.Buffer == NULL) {
721 return;
722 }
723
724 registryPath = &driverExtension->ParametersRegistryPath;
725
726 InitializeObjectAttributes(&objectAttributes,
729 NULL,
730 NULL);
731
732 status = ZwOpenKey(&driverKey, KEY_SET_VALUE, &objectAttributes);
733 if (!NT_SUCCESS(status)) {
734 goto out;
735 }
736
737 InitializeObjectAttributes(&objectAttributes,
738 &parametersPath,
740 driverKey,
741 NULL);
742 //
743 // Open the key for deletion
744 //
745 status = ZwOpenKey(&parametersKey,
746 DELETE,
747 &objectAttributes);
748
749 if (!NT_SUCCESS(status)) {
750 goto out;
751 }
752
754 ZwDeleteValueKey(parametersKey, &valueName);
755
757 ZwDeleteValueKey(parametersKey, &valueName);
758
760 ZwDeleteValueKey(parametersKey, &valueName);
761
762 ZwDeleteKey(parametersKey);
763
764out:
765 if (driverExtension->ParametersRegistryPath.Buffer != NULL) {
766 ExFreePool(driverExtension->ParametersRegistryPath.Buffer);
767 }
768
769 if (driverKey != NULL) {
770 ZwClose(driverKey);
771 }
772
773 if (parametersKey != NULL) {
774 ZwClose(parametersKey);
775 }
776
777 return;
778}
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:1020
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1916
struct _DRV_EXTENSION * PDRV_EXTENSION
#define DRIVER_PARAMETERS
Definition: version.cpp:38
#define REGISTRY_KMDF_BUILD_NUMBER
Definition: version.cpp:41
#define REGISTRY_KMDF_MAJOR_VERSION
Definition: version.cpp:39
#define REGISTRY_KMDF_MINOR_VERSION
Definition: version.cpp:40
#define DRIVER_OBJECT_EXTENSION_IDENTIFIER
Definition: version.cpp:37
UNICODE_STRING ParametersRegistryPath
Definition: version.cpp:181
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by DriverUnload().

◆ WdfWriteKmdfVersionToRegistry()

VOID WdfWriteKmdfVersionToRegistry ( __in PDRIVER_OBJECT  DriverObject,
__in PUNICODE_STRING  RegistryPath 
)

Definition at line 555 of file version.cpp.

559{
561 OBJECT_ATTRIBUTES objectAttributes;
562 HANDLE driverKey;
563 HANDLE parametersKey;
564 UNICODE_STRING valueName;
565 UNICODE_STRING parametersPath;
566 PDRV_EXTENSION driverExtension;
567
568 driverKey = NULL;
569 parametersKey = NULL;
570 driverExtension = NULL;
571
572 RtlInitUnicodeString(&parametersPath, DRIVER_PARAMETERS);
573
574 InitializeObjectAttributes(&objectAttributes,
577 NULL,
578 NULL);
579
580 status = ZwOpenKey(&driverKey, KEY_CREATE_SUB_KEY, &objectAttributes);
581 if (!NT_SUCCESS(status)) {
582 __Print(("WdfWriteKmdfVersionToRegistry: Failed to open HKLM\\%S\n",
583 RegistryPath->Buffer));
584 goto out;
585 }
586
587 InitializeObjectAttributes(&objectAttributes,
588 &parametersPath,
590 driverKey,
591 NULL);
592
593 //
594 // Open or create key and get a handle
595 //
596 status = ZwCreateKey(&parametersKey,
598 &objectAttributes,
599 0,
602 NULL);
603
604 if (!NT_SUCCESS(status)) {
605 __Print(("WdfWriteKmdfVersionToRegistry: Failed to open HKLM\\%S\\%S\n",
606 RegistryPath->Buffer, parametersPath.Buffer));
607 goto out;
608 }
609
610 //
611 // Set Major Version
612 //
614
615 status = ZwSetValueKey(parametersKey,
616 &valueName,
617 0,
618 REG_DWORD,
621
622 if (!NT_SUCCESS(status)) {
623 __Print(("WdfWriteKmdfVersionToRegistry: Failed to set Major Version\n"));
624 goto out;
625 }
626
627 //
628 // Set Minor Version
629 //
631
632 status = ZwSetValueKey(parametersKey,
633 &valueName,
634 0,
635 REG_DWORD,
638
639 if (!NT_SUCCESS(status)) {
640 __Print(("WdfWriteKmdfVersionToRegistry: Failed to set Minor Version\n"));
641 goto out;
642 }
643
644
645 //
646 // Set Build Number
647 //
649
650 status = ZwSetValueKey(parametersKey,
651 &valueName,
652 0,
653 REG_DWORD,
656
657 if (!NT_SUCCESS(status)) {
658 __Print(("WdfWriteKmdfVersionToRegistry: Failed to set Build Number\n"));
659 goto out;
660 }
661
662 //
663 // Create a Driver Extension to store the registry path, where we write the
664 // version of the wdf01000.sys that's loaded in memory
665 //
668 sizeof(DRV_EXTENSION),
669 (PVOID *)&driverExtension);
670
671 if (!NT_SUCCESS(status) || driverExtension == NULL) {
672 goto out;
673 }
674
676 PagedPool,
677 RegistryPath->MaximumLength,
678 FX_TAG);
679 if (driverExtension->ParametersRegistryPath.Buffer == NULL) {
680 goto out;
681 }
682
683 driverExtension->ParametersRegistryPath.MaximumLength = RegistryPath->MaximumLength;
685
686out:
687 if (driverKey != NULL) {
688 ZwClose(driverKey);
689 }
690
691 if (parametersKey != NULL) {
692 ZwClose(parametersKey);
693 }
694
695 return;
696}
#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:1021
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1838
#define REG_DWORD
Definition: sdbapi.c:615
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 103 of file version.cpp.

Referenced by TestDriverObject().

◆ DriverUnload

DRIVER_UNLOAD DriverUnload

Definition at line 100 of file version.cpp.

Referenced by DriverEntry().

◆ gOsVersion

Definition at line 111 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 71 of file version.cpp.

◆ typeFX_OBJECT_INFO

FX_OBJECT_INFO* typeFX_OBJECT_INFO

Definition at line 66 of file version.cpp.

◆ typeFX_POOL

FX_POOL* typeFX_POOL

Definition at line 68 of file version.cpp.

◆ typeFX_POOL_HEADER

FX_POOL_HEADER* typeFX_POOL_HEADER

Definition at line 67 of file version.cpp.

◆ typeFxContextHeader

FxContextHeader* typeFxContextHeader

Definition at line 70 of file version.cpp.

◆ typeFxObject

FxObject* typeFxObject

Definition at line 69 of file version.cpp.

◆ typeFxTargetSubmitSyncParams

FxTargetSubmitSyncParams* typeFxTargetSubmitSyncParams

Definition at line 72 of file version.cpp.

◆ typeWDF_BIND_INFO

WDF_BIND_INFO* typeWDF_BIND_INFO

Definition at line 61 of file version.cpp.

◆ typeWDF_BUGCHECK_CODES

WDF_BUGCHECK_CODES* typeWDF_BUGCHECK_CODES

Definition at line 64 of file version.cpp.

◆ typeWDF_IFR_HEADER

WDF_IFR_HEADER* typeWDF_IFR_HEADER

Definition at line 58 of file version.cpp.

◆ typeWDF_IFR_OFFSET

WDF_IFR_OFFSET* typeWDF_IFR_OFFSET

Definition at line 60 of file version.cpp.

◆ typeWDF_IFR_RECORD

WDF_IFR_RECORD* typeWDF_IFR_RECORD

Definition at line 59 of file version.cpp.

◆ typeWDF_OBJECT_CONTEXT_TYPE_INFO

WDF_OBJECT_CONTEXT_TYPE_INFO* typeWDF_OBJECT_CONTEXT_TYPE_INFO

Definition at line 62 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 63 of file version.cpp.

◆ typeWDF_REQUEST_FATAL_ERROR_CODES

WDF_REQUEST_FATAL_ERROR_CODES* typeWDF_REQUEST_FATAL_ERROR_CODES

Definition at line 65 of file version.cpp.

◆ 

union { ... } uAllPublicTypes

◆ WdfLdrDbgPrintOn

ULONG WdfLdrDbgPrintOn = 0

Definition at line 113 of file version.cpp.

Referenced by DriverEntry().

◆ WdfLdrType

PCHAR WdfLdrType = KMDF_DEFAULT_NAME

Definition at line 115 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(NTAPI * PFNLIBRARYUNREGISTERCLIENT)(__in PWDF_BIND_INFO Info, __in PWDF_COMPONENT_GLOBALS DriverGlobals)
Definition: fxldr.h:78
struct _WDF_LIBRARY_INFO WDF_LIBRARY_INFO
#define WDF_LIBRARY_UNREGISTER_CLIENT
Definition: fxldr.h:113
_Must_inspect_result_ NTSTATUS(NTAPI * PFNLIBRARYDECOMMISSION)(VOID)
Definition: fxldr.h:62
#define WDF_LIBRARY_DECOMMISSION
Definition: fxldr.h:111
_Must_inspect_result_ NTSTATUS(NTAPI * PFNLIBRARYCOMMISSION)(VOID)
Definition: fxldr.h:55
_Must_inspect_result_ NTSTATUS(NTAPI * PFNLIBRARYREGISTERCLIENT)(__in PWDF_BIND_INFO Info, __deref_out PWDF_COMPONENT_GLOBALS *ComponentGlobals, __deref_inout PVOID *Context)
Definition: fxldr.h:69

Definition at line 189 of file version.cpp.

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