From 3b9780e847cf68d6199dafe0f87650cf1f9c227f Mon Sep 17 00:00:00 2001 From: Wei Mao Date: Thu, 10 Nov 2022 13:42:44 -0800 Subject: [PATCH] Windows Release win-10.0.22621.1 22621 is Windows 11, version 22H2 --- src/framework/kmdf/inc/private/fxdynamics.h | 14 +- .../kmdf/inc/private/fxlibrarycommon.h | 6 - src/framework/kmdf/inc/private/vffxdynamics.h | 14 +- .../kmdf/src/core/fxbugcheckcallback.cpp | 128 +------ src/framework/kmdf/src/core/tracing.cpp | 114 ++++-- .../kmdf/src/dma/base/fxdmaenabler.cpp | 2 +- .../kmdf/src/dynamic/version/version.cpp | 21 +- .../src/librarycommon/fxlibrarycommon.cpp | 91 +++-- .../kmdf/src/support/fxqueryinterfaceapi.cpp | 11 + src/framework/shared/core/fxdevice.cpp | 8 +- src/framework/shared/core/fxdeviceapi.cpp | 4 +- src/framework/shared/core/fxdevicebase.cpp | 12 +- src/framework/shared/core/fxdeviceinitapi.cpp | 2 +- src/framework/shared/core/fxirpqueue.cpp | 4 + .../shared/core/fxpagedlookasidelist.cpp | 4 +- src/framework/shared/core/fxrequest.cpp | 12 +- src/framework/shared/core/fxrequestapi.cpp | 4 +- .../shared/core/fxrequestcontext.cpp | 2 +- .../shared/core/fxrequestoutputbuffer.cpp | 6 +- src/framework/shared/core/km/fxdriverkm.cpp | 1 + .../core/km/fxnpagedlookasidelistkm.cpp | 6 +- src/framework/shared/core/km/fxrequestkm.cpp | 8 +- .../core/km/fxrequestsystembufferkm.cpp | 4 +- src/framework/shared/core/um/fxdeviceum.cpp | 7 +- src/framework/shared/core/um/fxirpum.cpp | 2 +- src/framework/shared/core/verifierapi.cpp | 5 +- .../shared/enhancedverif/km/vfprivkm.hpp | 1 + .../shared/enhancedverif/km/vfwdfdynamics.cpp | 14 +- .../shared/enhancedverif/um/vfprivum.hpp | 4 +- .../shared/enhancedverif/um/vfwdfdynamics.cpp | 14 +- .../shared/inc/primitives/common/mxgeneral.h | 26 +- .../shared/inc/primitives/km/mxgeneralkm.h | 61 ++-- .../shared/inc/primitives/km/mxmemorykm.h | 1 + .../shared/inc/primitives/km/mxtimerkm.h | 10 - .../shared/inc/primitives/um/mxgeneralum.h | 94 +++-- .../shared/inc/primitives/um/mxlockum.h | 9 +- .../shared/inc/private/common/fxcallback.hpp | 2 + .../private/common/fxcallbackmutexlock.hpp | 1 + .../shared/inc/private/common/fxchildlist.hpp | 1 + .../shared/inc/private/common/fxglobals.h | 97 +----- .../shared/inc/private/common/fxifr.h | 28 +- .../shared/inc/private/common/fxifrkm.h | 2 - .../shared/inc/private/common/fxioqueue.hpp | 18 +- .../shared/inc/private/common/fxiotarget.hpp | 2 +- .../inc/private/common/fxiotargetremote.hpp | 30 +- .../shared/inc/private/common/fxirp.hpp | 2 +- .../shared/inc/private/common/fxobject.hpp | 4 +- .../shared/inc/private/common/fxpkgpnp.hpp | 31 +- .../common/fxpowerpolicystatemachine.hpp | 76 +++- .../inc/private/common/fxqueryinterface.hpp | 1 + .../shared/inc/private/common/fxrequest.hpp | 4 +- .../inc/private/common/fxrequestbuffer.hpp | 2 +- .../inc/private/common/fxrequestcontext.hpp | 2 +- .../shared/inc/private/common/fxspinlock.hpp | 3 +- .../inc/private/common/fxsyncrequest.hpp | 4 +- .../inc/private/common/fxtelemetrycommon.hpp | 25 +- .../shared/inc/private/common/fxusbdevice.hpp | 2 +- .../inc/private/common/fxusbinterface.hpp | 3 +- .../shared/inc/private/common/fxverifier.h | 3 + .../inc/private/common/fxverifierlock.hpp | 4 +- .../inc/private/common/fxwmiirphandler.hpp | 2 +- .../shared/inc/private/common/stringutil.hpp | 2 +- .../shared/inc/private/km/fxglobalskm.h | 245 +------------ .../shared/inc/private/km/fxirpkm.hpp | 2 +- .../inc/private/km/fxrequestbufferkm.hpp | 2 +- .../shared/inc/private/km/fxverifierkm.h | 21 +- .../irphandlers/general/fxpkggeneral.cpp | 3 +- .../shared/irphandlers/io/fxioqueue.cpp | 14 +- .../shared/irphandlers/io/fxpkgio.cpp | 1 + .../irphandlers/pnp/devicepowerirptracker.cpp | 74 ++++ .../shared/irphandlers/pnp/fxinterruptapi.cpp | 2 +- .../shared/irphandlers/pnp/fxpkgpnp.cpp | 78 ++++- .../shared/irphandlers/pnp/km/fxpkgpnpkm.cpp | 6 +- .../shared/irphandlers/pnp/km/supportkm.cpp | 2 +- .../irphandlers/pnp/pnpstatemachine.cpp | 35 -- .../pnp/powerpolicystatemachine.cpp | 42 ++- .../shared/irphandlers/pnp/poxinterface.cpp | 4 + .../irphandlers/pnp/um/fxchildlistum.cpp | 2 + .../shared/irphandlers/pnp/um/fxpkgpnpum.cpp | 4 +- .../irphandlers/pnp/um/fxqueryinterfaceum.cpp | 1 + src/framework/shared/object/fxobject.cpp | 17 +- .../shared/object/fxverifierbugcheck.cpp | 37 ++ .../shared/object/fxverifierlock.cpp | 15 +- src/framework/shared/object/globals.cpp | 270 ++------------- src/framework/shared/object/um/fxobjectum.cpp | 5 + .../shared/primitives/km/mxgeneralkm.cpp | 2 +- .../shared/primitives/um/mxgeneralum.cpp | 2 +- .../shared/support/fxregistryapi.cpp | 14 +- .../shared/support/fxrequestbuffer.cpp | 5 +- src/framework/shared/support/fxspinlock.cpp | 2 + .../shared/support/fxspinlockapi.cpp | 2 + src/framework/shared/support/fxstringapi.cpp | 1 + .../shared/support/fxtransactionedlist.cpp | 1 + src/framework/shared/support/stringutil.cpp | 2 +- src/framework/shared/support/um/tracingum.cpp | 327 +++++------------- .../shared/targets/general/fxiotarget.cpp | 4 +- .../targets/general/fxiotargetremote.cpp | 8 +- .../targets/general/km/fxiotargetremotekm.cpp | 78 ++--- .../targets/general/um/fxiotargetremoteum.cpp | 83 +++-- .../shared/targets/usb/fxusbdeviceapi.cpp | 4 +- .../shared/targets/usb/fxusbinterface.cpp | 3 +- .../shared/targets/usb/fxusbinterfaceapi.cpp | 4 +- .../targets/usb/km/fxusbdeviceapikm.cpp | 1 + src/framework/shared/targets/usb/usbutil.cpp | 5 +- src/framework/shared/targets/usb/usbutil.hpp | 4 +- .../fxlib/librarycommon/fxlibrarycommon.h | 6 - src/framework/umdf/fxlib/version/fxdynamics.h | 14 +- .../umdf/fxlib/version/vffxdynamics.h | 14 +- src/publicinc/wdf/kmdf/1.33/wdfdevice.h | 4 +- src/publicinc/wdf/kmdf/1.33/wdfinterrupt.h | 4 +- src/publicinc/wdf/kmdf/1.33/wdfrequest.h | 8 +- src/publicinc/wdf/kmdf/1.33/wdfusb.h | 12 +- src/publicinc/wdf/umdf/2.33/wdfdevice.h | 4 +- src/publicinc/wdf/umdf/2.33/wdfinterrupt.h | 4 +- src/publicinc/wdf/umdf/2.33/wdfrequest.h | 8 +- src/publicinc/wdf/umdf/2.33/wdfusb.h | 12 +- src/publicinc/wdf/umdf/2.33/wudfwdm.h | 1 + 117 files changed, 1077 insertions(+), 1525 deletions(-) diff --git a/src/framework/kmdf/inc/private/fxdynamics.h b/src/framework/kmdf/inc/private/fxdynamics.h index ff933fd..ee84d49 100644 --- a/src/framework/kmdf/inc/private/fxdynamics.h +++ b/src/framework/kmdf/inc/private/fxdynamics.h @@ -1168,7 +1168,7 @@ WDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ); @@ -3452,7 +3452,7 @@ WDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ); @@ -5388,7 +5388,7 @@ WDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ); @@ -5456,7 +5456,7 @@ WDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); @@ -6299,7 +6299,7 @@ WDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ); @@ -6963,7 +6963,7 @@ WDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ); @@ -7013,7 +7013,7 @@ WDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ); diff --git a/src/framework/kmdf/inc/private/fxlibrarycommon.h b/src/framework/kmdf/inc/private/fxlibrarycommon.h index 3bc2103..2cb109a 100644 --- a/src/framework/kmdf/inc/private/fxlibrarycommon.h +++ b/src/framework/kmdf/inc/private/fxlibrarycommon.h @@ -31,12 +31,6 @@ extern RTL_OSVERSIONINFOW gOsVersion; #define WDF_ENHANCED_VERIFIER_OPTIONS_VALUE_NAME L"EnhancedVerifierOptions" -typedef -NTSTATUS -(*PFN_RTL_GET_VERSION)( - __out PRTL_OSVERSIONINFOW VersionInformation - ); - _Must_inspect_result_ NTSTATUS FxLibraryCommonCommission( diff --git a/src/framework/kmdf/inc/private/vffxdynamics.h b/src/framework/kmdf/inc/private/vffxdynamics.h index 668d7ff..d1bf1df 100644 --- a/src/framework/kmdf/inc/private/vffxdynamics.h +++ b/src/framework/kmdf/inc/private/vffxdynamics.h @@ -603,7 +603,7 @@ VFWDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ); @@ -2887,7 +2887,7 @@ VFWDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ); @@ -4823,7 +4823,7 @@ VFWDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ); @@ -4891,7 +4891,7 @@ VFWDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); @@ -5734,7 +5734,7 @@ VFWDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ); @@ -6398,7 +6398,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ); @@ -6448,7 +6448,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ); diff --git a/src/framework/kmdf/src/core/fxbugcheckcallback.cpp b/src/framework/kmdf/src/core/fxbugcheckcallback.cpp index 2a0fc8b..a9c44d2 100644 --- a/src/framework/kmdf/src/core/fxbugcheckcallback.cpp +++ b/src/framework/kmdf/src/core/fxbugcheckcallback.cpp @@ -444,9 +444,7 @@ FxRegisterBugCheckCallback( __in PDRIVER_OBJECT DriverObject ) { - UNICODE_STRING funcName; PKBUGCHECK_REASON_CALLBACK_RECORD callbackRecord; - PFN_KE_REGISTER_BUGCHECK_REASON_CALLBACK funcPtr; BOOLEAN enableDriverTracking; // @@ -485,19 +483,6 @@ FxRegisterBugCheckCallback( - // - // The KeRegisterBugCheckReasonCallback exists for xp sp1 and above. So - // check whether this function is defined on the current OS and register - // for the bugcheck callback only if this function is defined. - // - RtlInitUnicodeString(&funcName, L"KeRegisterBugCheckReasonCallback"); - funcPtr = (PFN_KE_REGISTER_BUGCHECK_REASON_CALLBACK) - MmGetSystemRoutineAddress(&funcName); - - if (NULL == funcPtr) { - goto Done; - } - // // Register this driver with driver tracker. // @@ -516,7 +501,7 @@ FxRegisterBugCheckCallback( // // Register the bugcheck callback. // - funcPtr(callbackRecord, + KeRegisterBugCheckReasonCallback(callbackRecord, FxpBugCheckCallback, KbCallbackSecondaryDumpData, (PUCHAR)FxDriverGlobals->Public.DriverName); @@ -531,29 +516,14 @@ FxUnregisterBugCheckCallback( __inout PFX_DRIVER_GLOBALS FxDriverGlobals ) { - UNICODE_STRING funcName; PKBUGCHECK_REASON_CALLBACK_RECORD callbackRecord; - PFN_KE_DEREGISTER_BUGCHECK_REASON_CALLBACK funcPtr; callbackRecord = &FxDriverGlobals->BugCheckCallbackRecord; if (NULL == callbackRecord->CallbackRoutine) { goto Done; } - // - // The KeDeregisterBugCheckReasonCallback exists for xp sp1 and above. So - // check whether this function is defined on the current OS and deregister - // from the bugcheck callback only if this function is defined. - // - RtlInitUnicodeString(&funcName, L"KeDeregisterBugCheckReasonCallback"); - funcPtr = (PFN_KE_DEREGISTER_BUGCHECK_REASON_CALLBACK) - MmGetSystemRoutineAddress(&funcName); - - if (NULL == funcPtr) { - goto Done; - } - - funcPtr(callbackRecord); + KeDeregisterBugCheckReasonCallback(callbackRecord); callbackRecord->CallbackRoutine = NULL; // @@ -640,9 +610,7 @@ VOID FxInitializeBugCheckDriverInfo() { NTSTATUS status; - UNICODE_STRING funcName; PKBUGCHECK_REASON_CALLBACK_RECORD callbackRecord; - PFN_KE_REGISTER_BUGCHECK_REASON_CALLBACK funcPtr; SIZE_T arraySize; ULONG arrayCount; @@ -663,19 +631,6 @@ FxInitializeBugCheckDriverInfo() - // - // The KeRegisterBugCheckReasonCallback exists for xp sp1 and above. So - // check whether this function is defined on the current OS and register - // for the bugcheck callback only if this function is defined. - // - RtlInitUnicodeString(&funcName, L"KeRegisterBugCheckReasonCallback"); - funcPtr = (PFN_KE_REGISTER_BUGCHECK_REASON_CALLBACK) - MmGetSystemRoutineAddress(&funcName); - - if (NULL == funcPtr) { - goto Done; - } - arraySize = sizeof(FX_DUMP_DRIVER_INFO_ENTRY) * FX_DUMP_DRIVER_INFO_INCREMENT; arrayCount = FX_DUMP_DRIVER_INFO_INCREMENT; @@ -719,7 +674,7 @@ FxInitializeBugCheckDriverInfo() // // Register the bugcheck callback. // - funcPtr(callbackRecord, + KeRegisterBugCheckReasonCallback(callbackRecord, FxpLibraryBugCheckCallback, KbCallbackSecondaryDumpData, (PUCHAR)WdfLdrType); @@ -732,9 +687,7 @@ Done:; VOID FxUninitializeBugCheckDriverInfo() { - UNICODE_STRING funcName; PKBUGCHECK_REASON_CALLBACK_RECORD callbackRecord; - PFN_KE_DEREGISTER_BUGCHECK_REASON_CALLBACK funcPtr; // // Deregister callback. @@ -751,20 +704,7 @@ FxUninitializeBugCheckDriverInfo() goto Done; } - // - // The KeDeregisterBugCheckReasonCallback exists for xp sp1 and above. So - // check whether this function is defined on the current OS and deregister - // from the bugcheck callback only if this function is defined. - // - RtlInitUnicodeString(&funcName, L"KeDeregisterBugCheckReasonCallback"); - funcPtr = (PFN_KE_DEREGISTER_BUGCHECK_REASON_CALLBACK) - MmGetSystemRoutineAddress(&funcName); - - if (NULL == funcPtr) { - goto Done; - } - - funcPtr(callbackRecord); + KeDeregisterBugCheckReasonCallback(callbackRecord); callbackRecord->CallbackRoutine = NULL; // @@ -1027,8 +967,6 @@ FX_DRIVER_TRACKER_CACHE_AWARE::Register( ULONG index = 0; PFX_DRIVER_TRACKER_ENTRY pool = NULL; PFX_DRIVER_TRACKER_ENTRY driverUsage = NULL; - UNICODE_STRING funcName; - PVOID funcPtr = NULL; // // Nothing to do if tracker is already initialized. No need for a lock @@ -1048,44 +986,7 @@ FX_DRIVER_TRACKER_CACHE_AWARE::Register( // // Capture maximum number of processors. // - RtlInitUnicodeString(&funcName, L"KeQueryMaximumProcessorCountEx"); - funcPtr = MmGetSystemRoutineAddress(&funcName); - if (funcPtr != NULL) { - // - // Win 7 and forward. - // - m_Number = ((PFN_KE_QUERY_MAXIMUM_PROCESSOR_COUNT_EX)funcPtr)( - ALL_PROCESSOR_GROUPS); - } - else { - RtlInitUnicodeString(&funcName, L"KeQueryMaximumProcessorCount"); - funcPtr = MmGetSystemRoutineAddress(&funcName); - if (funcPtr != NULL) { - // - // Windows Server 2008. - // - m_Number = ((PFN_KE_QUERY_MAXIMUM_PROCESSOR_COUNT)funcPtr)(); - } - else { - if ((5 == FxLibraryGlobals.OsVersionInfo.dwMajorVersion && - 0 < FxLibraryGlobals.OsVersionInfo.dwMinorVersion) || - (6 == FxLibraryGlobals.OsVersionInfo.dwMajorVersion && - 0 == FxLibraryGlobals.OsVersionInfo.dwMinorVersion)){ - // - // XP (Major=5, Minor>0) and Vista (Major=6, Minor=0). - // - m_Number = (ULONG)(*((CCHAR *)&KeNumberProcessors)); - } - else { - // - // This feature is not supported for Windows 2000. - // - ASSERT(FALSE); - status = STATUS_NOT_SUPPORTED; - goto Done; - } - } - } + m_Number = KeQueryMaximumProcessorCountEx(ALL_PROCESSOR_GROUPS); // // Validate upper bound. @@ -1099,23 +1000,8 @@ FX_DRIVER_TRACKER_CACHE_AWARE::Register( // Determine padded size of each tracking entry structure. // if (m_Number > 1 ) { - RtlInitUnicodeString(&funcName, L"KeGetRecommendedSharedDataAlignment"); - funcPtr = MmGetSystemRoutineAddress(&funcName); - - if (funcPtr != NULL) { - // - //XP and forward - // - paddedSize = ((PFN_KE_GET_RECOMMENDED_SHARED_DATA_ALIGNMENT)funcPtr)(); - ASSERT ((paddedSize & (paddedSize - 1)) == 0); - } - else { - // - // This feature is not supported for Windows 2000. - // - status = STATUS_NOT_SUPPORTED; - goto Done; - } + paddedSize = KeGetRecommendedSharedDataAlignment(); + ASSERT ((paddedSize & (paddedSize - 1)) == 0); } else { paddedSize = sizeof(FX_DRIVER_TRACKER_ENTRY); diff --git a/src/framework/kmdf/src/core/tracing.cpp b/src/framework/kmdf/src/core/tracing.cpp index ac1c12a..6d92327 100644 --- a/src/framework/kmdf/src/core/tracing.cpp +++ b/src/framework/kmdf/src/core/tracing.cpp @@ -27,6 +27,8 @@ Revision History: --*/ #include "fxcorepch.hpp" +#include "FeatureStagingSupport.h" +#include // We use DoTraceMessage extern "C" { @@ -129,10 +131,13 @@ FxWmiTraceMessage( // Subcomponents for the In-Flight Recorder follow. //----------------------------------------------------------------------------- -ULONG -FxIFRGetSize( +VOID +FxIFRGetSettings( __in PFX_DRIVER_GLOBALS FxDriverGlobals, - __in PCUNICODE_STRING RegistryPath + __in PCUNICODE_STRING RegistryPath, + __out ULONG * Size, + __out BOOLEAN * UseTimeStamp, + __out BOOLEAN * PreciseTimeStamp ) /*++ @@ -142,15 +147,19 @@ Routine Description: Arguments: RegistryPath - path to the service - -Return Value: - The size of the IFR to create in bytes (not pages!) + [out] Size - The size of the IFR to create in bytes (not pages!) + [out] UseTimeStamp - Whether to store timestamp or not + [out] PreciseTimeStamp - Use precise timestamp. --*/ { FxAutoRegKey service, parameters; NTSTATUS status; ULONG numPages; + ULONG regValue; + BOOLEAN useTimeStamp; + BOOLEAN preciseTimeStamp; + UNREFERENCED_PARAMETER(RegistryPath); // @@ -159,12 +168,17 @@ Return Value: // numPages = FxIFRMinLogPages; + useTimeStamp = TRUE; + preciseTimeStamp = FALSE; + // // External representation of the IFR is the "LogPages", so use that term when // overriding the size via the registry. // DECLARE_CONST_UNICODE_STRING(parametersPath, L"Wdf"); DECLARE_CONST_UNICODE_STRING(valueName, L"LogPages"); + DECLARE_CONST_UNICODE_STRING(nameTimeStamp, L"LogUseTimeStamp"); + DECLARE_CONST_UNICODE_STRING(namePreciseTimeStamp, L"LogPreciseTimeStamp"); status = OpenDriverParamsKeyForRead(FxDriverGlobals, &service.m_Key); if (!NT_SUCCESS(status)) { @@ -177,29 +191,41 @@ Return Value: } status = FxRegKey::_QueryULong(parameters.m_Key, &valueName, &numPages); - if (!NT_SUCCESS(status)) { - goto defaultValues; + if (NT_SUCCESS(status)) { + if (numPages == 0) { + numPages = FxIFRMinLogPages; + } + // + // Use FxIFRAvgLogPages if user specifies greater than FxIFRMaxLogPages and if + // Verifier flag is on and so is Verbose flag. + // + if (numPages > FxIFRMaxLogPages) { + if (FxDriverGlobals->FxVerifierOn && FxDriverGlobals->FxVerboseOn) { + numPages = FxIFRAvgLogPages; + } + else { + numPages = FxIFRMinLogPages; + } + } } - if (numPages == 0) { - numPages = FxIFRMinLogPages; + status = FxRegKey::_QueryULong(parameters.m_Key, &nameTimeStamp, ®Value); + if (NT_SUCCESS(status)) { + useTimeStamp = (regValue != 0); } -defaultValues: - // - // Use FxIFRAvgLogPages if user specifies greater than FxIFRMaxLogPages and if - // Verifier flag is on and so is Verbose flag. - // - if (numPages > FxIFRMaxLogPages) { - if (FxDriverGlobals->FxVerifierOn && FxDriverGlobals->FxVerboseOn) { - numPages = FxIFRAvgLogPages; - } - else { - numPages = FxIFRMinLogPages; + if (useTimeStamp) { + status = FxRegKey::_QueryULong(parameters.m_Key, &namePreciseTimeStamp, ®Value); + if (NT_SUCCESS(status)) { + preciseTimeStamp = (regValue != 0); } } - return numPages * PAGE_SIZE; +defaultValues: + + *Size = numPages * PAGE_SIZE; + *UseTimeStamp = useTimeStamp; + *PreciseTimeStamp = preciseTimeStamp; } VOID @@ -223,11 +249,11 @@ Routine Description: { PWDF_IFR_HEADER pHeader; ULONG size; + BOOLEAN useTimeStamp; + BOOLEAN preciseTimeStamp; UNREFERENCED_PARAMETER( DriverObject ); - WDFCASSERT(FxIFRRecordSignature == WDF_IFR_RECORD_SIGNATURE); - // // Return early if IFR is disabled. // @@ -240,7 +266,8 @@ Routine Description: return; } - size = FxIFRGetSize(FxDriverGlobals, RegistryPath); + FxIFRGetSettings(FxDriverGlobals, RegistryPath, &size, + &useTimeStamp, &preciseTimeStamp); pHeader = (PWDF_IFR_HEADER) ExAllocatePool2(POOL_FLAG_NON_PAGED, size, @@ -258,6 +285,8 @@ Routine Description: pHeader->Base = (PUCHAR) &pHeader[1]; pHeader->Size = size - sizeof(WDF_IFR_HEADER); + pHeader->UseTimeStamp = useTimeStamp; + pHeader->PreciseTimeStamp = preciseTimeStamp; pHeader->Offset.u.s.Current = 0; pHeader->Offset.u.s.Previous = 0; @@ -416,7 +445,18 @@ Routine Description: } } - size += sizeof(WDF_IFR_RECORD); + header = (PWDF_IFR_HEADER) FxDriverGlobals->WdfLogHeader; + + FxVerifyLogHeader(FxDriverGlobals, header); + + // + // Allocate memory for timestamp only if necessary. + // + size_t recordSize = header->UseTimeStamp + ? sizeof(WDF_IFR_RECORD) + : sizeof(WDF_IFR_RECORD_V1); + + size += recordSize; // // Allocate log space of the calculated size @@ -427,10 +467,6 @@ Routine Description: WDF_IFR_OFFSET offsetNew; USHORT usSize = (USHORT) size; // for a prefast artifact. - header = (PWDF_IFR_HEADER) FxDriverGlobals->WdfLogHeader; - - FxVerifyLogHeader(FxDriverGlobals, header); - // // Allocate space for the log in our circular buffer in a lockless way. // The idea is: read the current buffer position, try and reserve space @@ -508,12 +544,26 @@ Routine Description: // // Build record (fill all fields!) // - record->Signature = FxIFRRecordSignature; record->Length = (USHORT) size; record->PrevOffset = (USHORT) offsetRet.u.s.Previous; record->MessageNumber = MessageNumber; record->Sequence = InterlockedIncrement( &header->Sequence ); record->MessageGuid = *MessageGuid; + + if (!header->UseTimeStamp) { + record->Signature = WDF_IFR_RECORD_SIGNATURE_V1; + } else { + record->Signature = WDF_IFR_RECORD_SIGNATURE; + LARGE_INTEGER timestamp; + if (header->PreciseTimeStamp) { + Mx::MxQuerySystemTimePrecise(×tamp); + } + else { + Mx::MxQuerySystemTime(×tamp); + } + record->TimeStamp.LowPart = timestamp.LowPart; + record->TimeStamp.HighPart = timestamp.HighPart; + } } // @@ -525,7 +575,7 @@ Routine Description: PVOID source; PUCHAR argsData; - argsData = (UCHAR*) &record[1]; + argsData = ((UCHAR*)record) + recordSize; va_start(ap, MessageNumber); diff --git a/src/framework/kmdf/src/dma/base/fxdmaenabler.cpp b/src/framework/kmdf/src/dma/base/fxdmaenabler.cpp index 2a96aa9..b5f4e3c 100644 --- a/src/framework/kmdf/src/dma/base/fxdmaenabler.cpp +++ b/src/framework/kmdf/src/dma/base/fxdmaenabler.cpp @@ -753,7 +753,7 @@ FxDmaEnabler::ConfigureBusMasterAdapters( ExInitializeNPagedLookasideList( &m_SGList.ScatterGatherProfile.Lookaside, NULL, // Allocate OPTIONAL NULL, // Free OPTIONAL - 0, // Flag - Reserved. Must be zero. + POOL_NX_ALLOCATION, m_SGListSize, GetDriverGlobals()->Tag, 0 ); // Depth - Reserved. Must be zero. diff --git a/src/framework/kmdf/src/dynamic/version/version.cpp b/src/framework/kmdf/src/dynamic/version/version.cpp index 7978606..1fb9351 100644 --- a/src/framework/kmdf/src/dynamic/version/version.cpp +++ b/src/framework/kmdf/src/dynamic/version/version.cpp @@ -23,6 +23,8 @@ Revision History: extern "C" { #include #include +#include +#include } #define FX_DYNAMICS_GENERATE_TABLE 1 @@ -343,6 +345,11 @@ DriverEntry( // ExInitializeDriverRuntime(DrvRtPoolNxOptIn); + + + + + RtlInitUnicodeString(&string, WDF_REGISTRY_DBGPRINT_ON); // @@ -375,7 +382,7 @@ DriverEntry( status = FxLibraryCreateDevice(&name); if (!NT_SUCCESS(status)) { __Print(("ERROR: FxLibraryCreateDevice failed with Status 0x%x\n", status)); - return status; + goto exit; } // @@ -388,7 +395,7 @@ DriverEntry( if (!NT_SUCCESS(status)) { __Print(("ERROR: WdfRegisterLibrary failed with Status 0x%x\n", status)); FxLibraryCleanup(); - return status; + goto exit; } // @@ -396,7 +403,13 @@ DriverEntry( // WdfWriteKmdfVersionToRegistry(DriverObject, RegistryPath); - return STATUS_SUCCESS; + status = STATUS_SUCCESS; + +exit: + + + + return status; } //----------------------------------------------------------------------------- @@ -420,6 +433,8 @@ DriverUnload( // driver, it can be unloaded while there are still outstanding device objects. // FxLibraryCleanup(); + + } //----------------------------------------------------------------------------- diff --git a/src/framework/kmdf/src/librarycommon/fxlibrarycommon.cpp b/src/framework/kmdf/src/librarycommon/fxlibrarycommon.cpp index 9660033..bd7e705 100644 --- a/src/framework/kmdf/src/librarycommon/fxlibrarycommon.cpp +++ b/src/framework/kmdf/src/librarycommon/fxlibrarycommon.cpp @@ -47,6 +47,9 @@ typedef enum _WDFFUNCENUM_NUMENTRIES { #include "WdfVersionLog.h" #include "minwindef.h" +#include "FeatureStagingSupport.h" +#include + extern "C" { // // Global triage Info for dbgeng and 0x9F work @@ -258,8 +261,6 @@ FxLibraryCommonCommission( VOID ) { - DECLARE_CONST_UNICODE_STRING(usName, L"RtlGetVersion"); - PFN_RTL_GET_VERSION pRtlGetVersion = NULL; NTSTATUS status; __Print((LITERAL(WDF_LIBRARY_COMMISSION) "\n")); @@ -295,19 +296,8 @@ FxLibraryCommonCommission( status = STATUS_SUCCESS; } - // - // Attempt to load RtlGetVersion (works for > w2k). - // - pRtlGetVersion = (PFN_RTL_GET_VERSION) MmGetSystemRoutineAddress( - (PUNICODE_STRING) &usName - ); - - // - // Now attempt to get this OS's version. - // - if (pRtlGetVersion != NULL) { - pRtlGetVersion(&gOsVersion); - } + gOsVersion.dwOSVersionInfoSize = sizeof(gOsVersion); + RtlGetVersion(&gOsVersion); __Print(("OsVersion(%d.%d)\n", gOsVersion.dwMajorVersion, @@ -441,14 +431,6 @@ FxLibraryCommonRegisterClient( goto Done; } } - - - - - - - - else { @@ -573,6 +555,63 @@ FxLibraryCommonRegisterClient( return status; } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _Must_inspect_result_ NTSTATUS FxLibraryCommonUnregisterClient( @@ -594,6 +633,12 @@ FxLibraryCommonUnregisterClient( pFxDriverGlobals = GetFxDriverGlobals(WdfDriverGlobals); + + + + + + // // Destroy this FxDriver instance, if its still indicated. // diff --git a/src/framework/kmdf/src/support/fxqueryinterfaceapi.cpp b/src/framework/kmdf/src/support/fxqueryinterfaceapi.cpp index a4d0823..647f268 100644 --- a/src/framework/kmdf/src/support/fxqueryinterfaceapi.cpp +++ b/src/framework/kmdf/src/support/fxqueryinterfaceapi.cpp @@ -67,6 +67,17 @@ WDFEXPORT(WdfDeviceAddQueryInterface)( return status; } + if (pDevice->IsLegacy()) { + status = STATUS_INVALID_DEVICE_REQUEST; + + DoTraceLevelMessage( + pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, + "WDFDEVICE 0x%p is not a PnP device %!STATUS!", + Device, status); + + goto Done; + } + pInterface = InterfaceConfig->Interface; if (InterfaceConfig->Size != sizeof(WDF_QUERY_INTERFACE_CONFIG)) { diff --git a/src/framework/shared/core/fxdevice.cpp b/src/framework/shared/core/fxdevice.cpp index adfea04..10c0809 100644 --- a/src/framework/shared/core/fxdevice.cpp +++ b/src/framework/shared/core/fxdevice.cpp @@ -376,7 +376,6 @@ FxDevice::_Create( WDFOBJECT object; PLIST_ENTRY pNext; PWDFCXDEVICE_INIT pCxInit; - FxWdmDeviceExtension* wdmDeviceExtension; *Device = NULL; pInit = *DeviceInit; @@ -489,6 +488,8 @@ FxDevice::_Create( } #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE) + FxWdmDeviceExtension* wdmDeviceExtension; + wdmDeviceExtension = _GetFxWdmExtension(pDevice->GetDeviceObject()); if (wdmDeviceExtension->RemoveLockOptionFlags & WDF_REMOVE_LOCK_OPTION_ACQUIRE_FOR_IO) { @@ -505,9 +506,6 @@ FxDevice::_Create( if (pDevice->m_SelfIoTargetNeeded) { pDevice->SetStackSize(pDevice->GetStackSize()+1); } - -#else - UNREFERENCED_PARAMETER(wdmDeviceExtension); #endif // @@ -851,7 +849,7 @@ Return Value: Mx::MxInitializeNPagedLookasideList(&m_RequestLookasideList, NULL, NULL, - 0, + POOL_NX_ALLOCATION, m_RequestLookasideListElementSize, pGlobals->Tag, 0); diff --git a/src/framework/shared/core/fxdeviceapi.cpp b/src/framework/shared/core/fxdeviceapi.cpp index d6f2cb0..d70ff44 100644 --- a/src/framework/shared/core/fxdeviceapi.cpp +++ b/src/framework/shared/core/fxdeviceapi.cpp @@ -732,7 +732,7 @@ WDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFDEVICE Device, - __out + _Inout_ PWDF_DEVICE_STATE DeviceState ) { @@ -1349,6 +1349,8 @@ StopIdleWorker( return status; } + pDevice->m_PkgPnp->SaveRequestD0IrpReasonHint(RequestD0ForStopIdle); + status = pDevice->m_PkgPnp->PowerReference(WaitForD0, Tag, Line, File); DoTraceLevelMessage( diff --git a/src/framework/shared/core/fxdevicebase.cpp b/src/framework/shared/core/fxdevicebase.cpp index b2f3859..0e8a421 100644 --- a/src/framework/shared/core/fxdevicebase.cpp +++ b/src/framework/shared/core/fxdevicebase.cpp @@ -221,6 +221,13 @@ FxDeviceBase::_SearchForDevice( FxQueryInterfaceParams cbParams = { (PVOID*) Callbacks, FX_TYPE_IHASCALLBACKS, 0 }; PVOID pTag; + // + // Init out parameter. + // + if (Callbacks != NULL) { + *Callbacks = NULL; + } + pDeviceBase = Object->GetDeviceBase(); if (pDeviceBase == NULL) { DoTraceLevelMessage( @@ -237,11 +244,6 @@ FxDeviceBase::_SearchForDevice( // return pDeviceBase; } - - // - // Init out parameter. - // - *Callbacks = NULL; pOrigParent = Object; pTag = pOrigParent; diff --git a/src/framework/shared/core/fxdeviceinitapi.cpp b/src/framework/shared/core/fxdeviceinitapi.cpp index 62118f4..3cbbf8c 100644 --- a/src/framework/shared/core/fxdeviceinitapi.cpp +++ b/src/framework/shared/core/fxdeviceinitapi.cpp @@ -758,7 +758,7 @@ WDFEXPORT(WdfDeviceInitRegisterPnpStateChangeCallback)( return status; } - if (normalizedState < WdfDevStatePnpObjectCreated || normalizedState > WdfDevStatePnpNull) { + if (normalizedState < WdfDevStatePnpObjectCreated || normalizedState >= WdfDevStatePnpNull) { status = STATUS_INVALID_PARAMETER; DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE, diff --git a/src/framework/shared/core/fxirpqueue.cpp b/src/framework/shared/core/fxirpqueue.cpp index d80e3ad..5707bc7 100644 --- a/src/framework/shared/core/fxirpqueue.cpp +++ b/src/framework/shared/core/fxirpqueue.cpp @@ -802,6 +802,10 @@ Routine Description: MdCancelRoutine cancelRoutine; FxIrp fxIrp(NULL); + if (pCsqContext != NULL) { + *pCsqContext = NULL; + } + fxIrp.SetIrp(PeekNextIrpFromQueue(NULL, PeekContext)); for (;;) { diff --git a/src/framework/shared/core/fxpagedlookasidelist.cpp b/src/framework/shared/core/fxpagedlookasidelist.cpp index 7bd3ea1..c8e3d23 100644 --- a/src/framework/shared/core/fxpagedlookasidelist.cpp +++ b/src/framework/shared/core/fxpagedlookasidelist.cpp @@ -120,7 +120,7 @@ FxPagedLookasideListFromPool::Initialize( Mx::MxInitializeNPagedLookasideList(&m_ObjectLookaside, NULL, NULL, - 0, + POOL_NX_ALLOCATION, m_MemoryObjectSize, m_PoolTag, 0); @@ -137,7 +137,7 @@ FxPagedLookasideListFromPool::Initialize( Mx::MxInitializePagedLookasideList(&m_PoolLookaside, NULL, NULL, - 0, + POOL_NX_ALLOCATION, m_RawBufferSize, m_PoolTag, 0); diff --git a/src/framework/shared/core/fxrequest.cpp b/src/framework/shared/core/fxrequest.cpp index 6b78232..4f0e041 100644 --- a/src/framework/shared/core/fxrequest.cpp +++ b/src/framework/shared/core/fxrequest.cpp @@ -1234,7 +1234,7 @@ FxRequest::GetStatus( _Must_inspect_result_ NTSTATUS FxRequest::GetParameters( - __out PWDF_REQUEST_PARAMETERS Parameters + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { PFX_DRIVER_GLOBALS pFxDriverGlobals; @@ -1486,7 +1486,7 @@ FxRequest::GetMemoryObject( // to do the initial mapping so that FxRequestSystemBuffer::GetBuffer() // will not return a NULL pointer. // - pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority); + pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority | MdlMappingNoExecute); if (pVA == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; @@ -1523,7 +1523,7 @@ FxRequest::GetMemoryObject( if (mapMdl) { *Buffer = Mx::MxGetSystemAddressForMdlSafe(m_SystemBuffer.m_Mdl, - NormalPagePriority); + NormalPagePriority | MdlMappingNoExecute); } else { *Buffer = m_SystemBuffer.m_Buffer; @@ -1734,7 +1734,7 @@ Routine Description: // to do the initial mapping so that FxRequestOutputBuffer::GetBuffer() // will not return a NULL pointer. // - pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority); + pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority | MdlMappingNoExecute); if (pVA == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; @@ -1761,7 +1761,7 @@ Routine Description: *MemoryObject = &m_OutputBuffer; if (mapMdl) { *Buffer = Mx::MxGetSystemAddressForMdlSafe(m_OutputBuffer.m_Mdl, - NormalPagePriority); + NormalPagePriority | MdlMappingNoExecute); } else { *Buffer = m_OutputBuffer.m_Buffer; @@ -2115,7 +2115,7 @@ FxRequest::PeekRequest( __in FxIrpQueue* IrpQueue, __in_opt FxRequest* TagRequest, __in_opt MdFileObject FileObject, - __out_opt PWDF_REQUEST_PARAMETERS Parameters, + _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters, __deref_out FxRequest** ppOutRequest ) { diff --git a/src/framework/shared/core/fxrequestapi.cpp b/src/framework/shared/core/fxrequestapi.cpp index 993cf0b..179ce3b 100644 --- a/src/framework/shared/core/fxrequestapi.cpp +++ b/src/framework/shared/core/fxrequestapi.cpp @@ -2414,7 +2414,7 @@ WDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFREQUEST Request, - __out + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { @@ -2463,7 +2463,7 @@ WDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFREQUEST Request, - __out + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ) { diff --git a/src/framework/shared/core/fxrequestcontext.cpp b/src/framework/shared/core/fxrequestcontext.cpp index cffe5f4..f9ae045 100644 --- a/src/framework/shared/core/fxrequestcontext.cpp +++ b/src/framework/shared/core/fxrequestcontext.cpp @@ -119,7 +119,7 @@ Return Value: VOID FxRequestContext::_StoreAndReferenceMemoryWorker( __in PVOID Tag, - __deref_out_opt IFxMemory** PPMemory, + __deref_inout IFxMemory** PPMemory, __in FxRequestBuffer* Buffer ) { diff --git a/src/framework/shared/core/fxrequestoutputbuffer.cpp b/src/framework/shared/core/fxrequestoutputbuffer.cpp index 5a88bcc..00752f2 100644 --- a/src/framework/shared/core/fxrequestoutputbuffer.cpp +++ b/src/framework/shared/core/fxrequestoutputbuffer.cpp @@ -50,7 +50,7 @@ Return Value: --*/ { FxIrp* irp = GetRequest()->GetFxIrp(); - + ASSERT(irp->GetMajorFunction() == IRP_MJ_DEVICE_CONTROL || irp->GetMajorFunction() == IRP_MJ_INTERNAL_DEVICE_CONTROL); @@ -69,7 +69,7 @@ Return Value: // we can safely call MmGetSystemAddressForMdlSafe again to get a // valid VA pointer. // - return Mx::MxGetSystemAddressForMdlSafe(m_Mdl, NormalPagePriority); + return Mx::MxGetSystemAddressForMdlSafe(m_Mdl, NormalPagePriority | MdlMappingNoExecute); case METHOD_NEITHER: return m_Buffer; @@ -124,7 +124,7 @@ Return Value: --*/ { FxIrp* irp = GetRequest()->GetFxIrp(); - + ASSERT(irp->GetMajorFunction() == IRP_MJ_DEVICE_CONTROL || irp->GetMajorFunction() == IRP_MJ_INTERNAL_DEVICE_CONTROL); diff --git a/src/framework/shared/core/km/fxdriverkm.cpp b/src/framework/shared/core/km/fxdriverkm.cpp index 64a9d54..398faa4 100644 --- a/src/framework/shared/core/km/fxdriverkm.cpp +++ b/src/framework/shared/core/km/fxdriverkm.cpp @@ -34,6 +34,7 @@ extern "C" { _Must_inspect_result_ NTSTATUS +#pragma prefast(suppress:__WARNING_INIT_NOT_CLEARED, "AddDevice-like function did not clear DO_DEVICE_INITIALIZING") FxDriver::AddDevice( __in MdDriverObject DriverObject, __in MdDeviceObject PhysicalDeviceObject diff --git a/src/framework/shared/core/km/fxnpagedlookasidelistkm.cpp b/src/framework/shared/core/km/fxnpagedlookasidelistkm.cpp index 6b08e41..528854d 100644 --- a/src/framework/shared/core/km/fxnpagedlookasidelistkm.cpp +++ b/src/framework/shared/core/km/fxnpagedlookasidelistkm.cpp @@ -80,7 +80,7 @@ FxNPagedLookasideList::Initialize( ExInitializeNPagedLookasideList(&m_ObjectLookaside, NULL, NULL, - 0, + POOL_NX_ALLOCATION, m_MemoryObjectSize, m_PoolTag, 0); @@ -182,7 +182,7 @@ FxNPagedLookasideListFromPool::Initialize( ExInitializeNPagedLookasideList(&m_ObjectLookaside, NULL, NULL, - 0, + POOL_NX_ALLOCATION, m_MemoryObjectSize, m_PoolTag, 0); @@ -199,7 +199,7 @@ FxNPagedLookasideListFromPool::Initialize( ExInitializeNPagedLookasideList(&m_PoolLookaside, NULL, NULL, - 0, + POOL_NX_ALLOCATION, m_BufferSize, m_PoolTag, 0); diff --git a/src/framework/shared/core/km/fxrequestkm.cpp b/src/framework/shared/core/km/fxrequestkm.cpp index 4a3f3a2..db9fdfe 100644 --- a/src/framework/shared/core/km/fxrequestkm.cpp +++ b/src/framework/shared/core/km/fxrequestkm.cpp @@ -52,8 +52,8 @@ Return Value: --*/ { - PWDF_REQUEST_PARAMETERS pWdfRequestParameters; - PIO_STACK_LOCATION pIoStackLocation; + PWDF_REQUEST_PARAMETERS pWdfRequestParameters = NULL; + PIO_STACK_LOCATION pIoStackLocation = NULL; UNREFERENCED_PARAMETER(pWdfRequestParameters); UNREFERENCED_PARAMETER(pIoStackLocation); @@ -693,7 +693,7 @@ Routine Description: // // Get a system address for the MDL // - pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority); + pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority | MdlMappingNoExecute); if (pVA == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; goto Done; @@ -853,7 +853,7 @@ Routine Description: // // Get a system address for the MDL // - pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority); + pVA = Mx::MxGetSystemAddressForMdlSafe(pMdl, NormalPagePriority | MdlMappingNoExecute); if (pVA == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; goto Done; diff --git a/src/framework/shared/core/km/fxrequestsystembufferkm.cpp b/src/framework/shared/core/km/fxrequestsystembufferkm.cpp index 673a722..c72f9f2 100644 --- a/src/framework/shared/core/km/fxrequestsystembufferkm.cpp +++ b/src/framework/shared/core/km/fxrequestsystembufferkm.cpp @@ -63,7 +63,7 @@ Return Value: case IRP_MJ_READ: case IRP_MJ_WRITE: pDevice = FxDevice::GetFxDevice(irp->GetDeviceObject()); - ioType = pDevice->GetIoType(); + ioType = pDevice->GetIoType(); switch (ioType) { case WdfDeviceIoBuffered: @@ -75,7 +75,7 @@ Return Value: // and returned success, so we know that we can safely call // MmGetSystemAddressForMdlSafe again to get a valid VA pointer. // - return Mx::MxGetSystemAddressForMdlSafe(m_Mdl, NormalPagePriority); + return Mx::MxGetSystemAddressForMdlSafe(m_Mdl, NormalPagePriority | MdlMappingNoExecute); case WdfDeviceIoNeither: return m_Buffer; diff --git a/src/framework/shared/core/um/fxdeviceum.cpp b/src/framework/shared/core/um/fxdeviceum.cpp index 7a0d903..1c25045 100644 --- a/src/framework/shared/core/um/fxdeviceum.cpp +++ b/src/framework/shared/core/um/fxdeviceum.cpp @@ -344,7 +344,6 @@ FxDevice::CreateDevice( MdDeviceObject pNewDeviceObject = NULL; ULONG characteristics; NTSTATUS status; - DEVICE_TYPE devType; HRESULT hr; IWudfDevice2* pNewDeviceObject2; IWudfDeviceStack2* pDevStack2; @@ -363,7 +362,7 @@ FxDevice::CreateDevice( - UNREFERENCED_PARAMETER(devType); + characteristics = DeviceInit->Characteristics; @@ -722,6 +721,8 @@ FxDevice::ProcessWmiPowerQueryOrSetData ( --*/ { + *QueryResult = FALSE; + if (Action == ActionInvalid) { return STATUS_INVALID_PARAMETER; } @@ -1791,6 +1792,8 @@ FxDevice::RetrieveDeviceInfoRegistrySettings( ASSERT(GroupId != NULL); ASSERT(DeviceRegInfo != NULL); + *GroupId = NULL; + ZeroMemory(DeviceRegInfo, sizeof(UMDF_DRIVER_REGSITRY_INFO)); type = REG_NONE; diff --git a/src/framework/shared/core/um/fxirpum.cpp b/src/framework/shared/core/um/fxirpum.cpp index 80cfd51..bff45e8 100644 --- a/src/framework/shared/core/um/fxirpum.cpp +++ b/src/framework/shared/core/um/fxirpum.cpp @@ -1691,7 +1691,7 @@ FxIrp::GetDriverContextSize( VOID FxIrp::CopyParameters( - _Out_ PWDF_REQUEST_PARAMETERS Parameters + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { IWudfIoIrp2* ioIrp; diff --git a/src/framework/shared/core/verifierapi.cpp b/src/framework/shared/core/verifierapi.cpp index 4b2f5e6..a679434 100644 --- a/src/framework/shared/core/verifierapi.cpp +++ b/src/framework/shared/core/verifierapi.cpp @@ -212,22 +212,21 @@ Return Value: { DDI_ENTRY_IMPERSONATION_OK(); - FxObject* pObject; PFX_DRIVER_GLOBALS pFxDriverGlobals; if (NULL == Object) { pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals); } else { + FxObject* pObject; FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Object, FX_TYPE_OBJECT, (PVOID*)&pObject, &pFxDriverGlobals); + UNREFERENCED_PARAMETER(pObject); } - UNREFERENCED_PARAMETER(pObject); - FxVerifierDriverReportedBugcheck(pFxDriverGlobals, BugCheckCode, BugCheckParameter1, diff --git a/src/framework/shared/enhancedverif/km/vfprivkm.hpp b/src/framework/shared/enhancedverif/km/vfprivkm.hpp index f2e0d15..61b3416 100644 --- a/src/framework/shared/enhancedverif/km/vfprivkm.hpp +++ b/src/framework/shared/enhancedverif/km/vfprivkm.hpp @@ -62,6 +62,7 @@ VerifyIrqlExit( __inline VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*CritRegion'") VerifyCriticalRegionEntry( __out BOOLEAN *CritRegion ) diff --git a/src/framework/shared/enhancedverif/km/vfwdfdynamics.cpp b/src/framework/shared/enhancedverif/km/vfwdfdynamics.cpp index c70a29a..f2115c8 100644 --- a/src/framework/shared/enhancedverif/km/vfwdfdynamics.cpp +++ b/src/framework/shared/enhancedverif/km/vfwdfdynamics.cpp @@ -1234,7 +1234,7 @@ VFWDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ) { @@ -4181,7 +4181,7 @@ VFWDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ) { @@ -6653,7 +6653,7 @@ VFWDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ) { @@ -6744,7 +6744,7 @@ VFWDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { @@ -7827,7 +7827,7 @@ VFWDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ) { @@ -8660,7 +8660,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ) { @@ -8726,7 +8726,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ) { diff --git a/src/framework/shared/enhancedverif/um/vfprivum.hpp b/src/framework/shared/enhancedverif/um/vfprivum.hpp index b87deb0..5eae026 100644 --- a/src/framework/shared/enhancedverif/um/vfprivum.hpp +++ b/src/framework/shared/enhancedverif/um/vfprivum.hpp @@ -30,7 +30,7 @@ VOID PerformanceAnalysisIOProcess( __in PFX_DRIVER_GLOBALS pFxDriverGlobals, __in WDFREQUEST Handle, - __inout FxRequest** ppReq, + _Out_ FxRequest** ppReq, __inout GUID* pActivityId ) { @@ -286,6 +286,7 @@ PerfEvtIoStopStop( __inline VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*Irql'") VerifyIrqlEntry( __out KIRQL *Irql ) @@ -305,6 +306,7 @@ VerifyIrqlExit( __inline VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*CritRegion'") VerifyCriticalRegionEntry( __out BOOLEAN *CritRegion ) diff --git a/src/framework/shared/enhancedverif/um/vfwdfdynamics.cpp b/src/framework/shared/enhancedverif/um/vfwdfdynamics.cpp index 213770c..5b26253 100644 --- a/src/framework/shared/enhancedverif/um/vfwdfdynamics.cpp +++ b/src/framework/shared/enhancedverif/um/vfwdfdynamics.cpp @@ -663,7 +663,7 @@ VFWDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ) { @@ -2314,7 +2314,7 @@ VFWDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ) { @@ -3994,7 +3994,7 @@ VFWDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ) { @@ -4065,7 +4065,7 @@ VFWDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { @@ -4738,7 +4738,7 @@ VFWDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ) { @@ -5354,7 +5354,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ) { @@ -5420,7 +5420,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ) { diff --git a/src/framework/shared/inc/primitives/common/mxgeneral.h b/src/framework/shared/inc/primitives/common/mxgeneral.h index 953d278..5da1c1a 100644 --- a/src/framework/shared/inc/primitives/common/mxgeneral.h +++ b/src/framework/shared/inc/primitives/common/mxgeneral.h @@ -187,25 +187,6 @@ class Mx __in PLARGE_INTEGER Interval ); - // - // Mode agnostic function to get address of a system function - // Should be used only for Rtl* functions applicable both to - // kernel mode and user mode - // - // User mode version is assumed to reside in ntdll.dll - // - // The argument type is MxFuncName so that it can be defined - // as LPCWSTR in kernel mode and LPCSTR in user mode - // which is what MmGetSystemRoutineAddress and GetProcAddress - // expect respectively - // - __inline - static - PVOID - MxGetSystemRoutineAddress( - __in MxFuncName FuncName - ); - __inline static VOID @@ -515,6 +496,13 @@ class Mx _Out_ PLARGE_INTEGER CurrentTime ); + __inline + static + VOID + MxQuerySystemTimePrecise( + _Out_ PLARGE_INTEGER CurrentTime + ); + __inline static NTSTATUS diff --git a/src/framework/shared/inc/primitives/km/mxgeneralkm.h b/src/framework/shared/inc/primitives/km/mxgeneralkm.h index 595db1e..0cae48c 100644 --- a/src/framework/shared/inc/primitives/km/mxgeneralkm.h +++ b/src/framework/shared/inc/primitives/km/mxgeneralkm.h @@ -121,7 +121,7 @@ Mx::MxQueryTickCount( } __inline -ULONG +ULONG Mx::MxQueryTimeIncrement( ) { @@ -207,7 +207,7 @@ Mx::MxDelayExecutionThread( ) { ASSERTMSG("Interval must be relative\n", Interval->QuadPart <= 0); - + KeDelayExecutionThread( WaitMode, Alertable, @@ -215,18 +215,6 @@ Mx::MxDelayExecutionThread( ); } -__inline -PVOID -Mx::MxGetSystemRoutineAddress( - __in MxFuncName FuncName - ) -{ - UNICODE_STRING funcName; - - RtlInitUnicodeString(&funcName, FuncName); - return MmGetSystemRoutineAddress(&funcName); -} - __inline VOID Mx::MxReferenceObject( @@ -261,7 +249,7 @@ __inline NTSTATUS Mx::MxAcquireRemoveLock( __in MdRemoveLock RemoveLock, - __in_opt PVOID Tag + __in_opt PVOID Tag ) { return IoAcquireRemoveLock(RemoveLock, Tag); @@ -271,7 +259,7 @@ __inline VOID Mx::MxReleaseRemoveLock( __in MdRemoveLock RemoveLock, - __in PVOID Tag + __in PVOID Tag ) { IoReleaseRemoveLock(RemoveLock, Tag); @@ -281,7 +269,7 @@ __inline VOID Mx::MxReleaseRemoveLockAndWait( __in MdRemoveLock RemoveLock, - __in PVOID Tag + __in PVOID Tag ) { IoReleaseRemoveLockAndWait(RemoveLock, Tag); @@ -317,9 +305,9 @@ Mx::CreateCallback( ) { return ExCreateCallback( - CallbackObject, - ObjectAttributes, - Create, + CallbackObject, + ObjectAttributes, + Create, AllowMultipleCallbacks); } @@ -333,7 +321,7 @@ Mx::RegisterCallback( { return ExRegisterCallback( CallbackObject, - CallbackFunction, + CallbackFunction, CallbackContext); } @@ -362,7 +350,7 @@ Mx::MxGetSystemAddressForMdlSafe( __in ULONG Priority ) { - return MmGetSystemAddressForMdlSafe(Mdl, Priority); + return MmGetSystemAddressForMdlSafe(Mdl, Priority | MdlMappingNoExecute); } __inline @@ -381,7 +369,7 @@ Mx::MxGetDriverObjectExtension( __in PVOID ClientIdentificationAddress ) { - return IoGetDriverObjectExtension(DriverObject, + return IoGetDriverObjectExtension(DriverObject, ClientIdentificationAddress); } @@ -510,7 +498,7 @@ Mx::MxAttachDeviceToDeviceStack( return IoAttachDeviceToDeviceStack(SourceDevice, TargetDevice); } -__inline +__inline NTSTATUS Mx::MxCreateDeviceSecure( _In_ PDRIVER_OBJECT DriverObject, @@ -536,7 +524,7 @@ Mx::MxCreateDeviceSecure( } __inline -NTSTATUS +NTSTATUS Mx::MxCreateDevice( _In_ PDRIVER_OBJECT DriverObject, _In_ ULONG DeviceExtensionSize, @@ -595,14 +583,14 @@ Mx::MxRegisterDeviceInterface( _Out_ PUNICODE_STRING SymbolicLinkName ) { - return IoRegisterDeviceInterface(PhysicalDeviceObject, - InterfaceClassGuid, - ReferenceString, + return IoRegisterDeviceInterface(PhysicalDeviceObject, + InterfaceClassGuid, + ReferenceString, SymbolicLinkName); } __inline -VOID +VOID Mx::MxInitializeMdl( _In_ PMDL MemoryDescriptorList, _In_ PVOID BaseVa, @@ -622,7 +610,7 @@ Mx::MxGetMdlVirtualAddress( } __inline -VOID +VOID Mx::MxBuildPartialMdl( _In_ PMDL SourceMdl, _Inout_ PMDL TargetMdl, @@ -638,7 +626,7 @@ Mx::MxBuildPartialMdl( } __inline -VOID +VOID Mx::MxQuerySystemTime( _Out_ PLARGE_INTEGER CurrentTime ) @@ -646,6 +634,15 @@ Mx::MxQuerySystemTime( KeQuerySystemTime(CurrentTime); } +__inline +VOID +Mx::MxQuerySystemTimePrecise( + _Out_ PLARGE_INTEGER CurrentTime + ) +{ + KeQuerySystemTimePrecise(CurrentTime); +} + __inline NTSTATUS Mx::MxReferenceObjectByHandle( @@ -705,7 +702,7 @@ Mx::MxReleaseInterruptSpinLock( } __inline -BOOLEAN +BOOLEAN Mx::MxInsertQueueDpc( __inout PRKDPC Dpc, __in_opt PVOID SystemArgument1, diff --git a/src/framework/shared/inc/primitives/km/mxmemorykm.h b/src/framework/shared/inc/primitives/km/mxmemorykm.h index e7fc0a5..2093f77 100644 --- a/src/framework/shared/inc/primitives/km/mxmemorykm.h +++ b/src/framework/shared/inc/primitives/km/mxmemorykm.h @@ -94,6 +94,7 @@ MxMemory::MxAllocatePoolWithTag( __in ULONG Tag ) { + #pragma warning( suppress : 4996 28751 ) return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag); } diff --git a/src/framework/shared/inc/primitives/km/mxtimerkm.h b/src/framework/shared/inc/primitives/km/mxtimerkm.h index 04f4167..f06ce6e 100644 --- a/src/framework/shared/inc/primitives/km/mxtimerkm.h +++ b/src/framework/shared/inc/primitives/km/mxtimerkm.h @@ -24,16 +24,6 @@ Revision History: #define TolerableDelayUnlimited ((ULONG)-1) -typedef -BOOLEAN -(*PFN_KE_SET_COALESCABLE_TIMER) ( - __inout PKTIMER Timer, - __in LARGE_INTEGER DueTime, - __in ULONG Period, - __in ULONG TolerableDelay, - __in_opt PKDPC Dpc - ); - typedef struct _MdTimer { diff --git a/src/framework/shared/inc/primitives/um/mxgeneralum.h b/src/framework/shared/inc/primitives/um/mxgeneralum.h index 3265ced..061f6b5 100644 --- a/src/framework/shared/inc/primitives/um/mxgeneralum.h +++ b/src/framework/shared/inc/primitives/um/mxgeneralum.h @@ -150,12 +150,13 @@ Mx::MxGetCurrentIrql( return PASSIVE_LEVEL; } +_Use_decl_annotations_ __inline VOID -#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations."); +#pragma prefast(suppress:__WARNING_IRQL_NOT_SET __WARNING_RETURN_UNINIT_VAR) Mx::MxRaiseIrql( - __in KIRQL NewIrql, - __out PKIRQL OldIrql + KIRQL NewIrql, + PKIRQL OldIrql ) { UNREFERENCED_PARAMETER(NewIrql); @@ -164,11 +165,12 @@ Mx::MxRaiseIrql( DO_NOTHING(); } +_Use_decl_annotations_ __inline VOID -#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations."); +#pragma prefast(suppress:__WARNING_IRQL_NOT_USED) Mx::MxLowerIrql( - __in KIRQL NewIrql + KIRQL NewIrql ) { UNREFERENCED_PARAMETER(NewIrql); @@ -292,37 +294,6 @@ Mx::MxDelayExecutionThread( SleepEx((DWORD)intervalMillisecond.QuadPart, Alertable); } -__inline -PVOID -Mx::MxGetSystemRoutineAddress( - __in MxFuncName FuncName - ) -/*++ -Description: - - This function is meant to be called only by mode agnostic code - System routine is assumed to be in ntdll.dll. - - This is because system routines (Rtl*) that can be used both - in kernel mode as well as user mode reside in ntdll.dll. - Kernel32.dll contains the user mode only Win32 API. - -Arguments: - - MxFuncName FuncName - - -Return Value: - - NTSTATUS Status code. ---*/ -{ - HMODULE hMod; - - hMod = GetModuleHandleW(L"ntdll.dll"); - - return GetProcAddress(hMod, FuncName); -} - __inline VOID Mx::MxReferenceObject( @@ -476,11 +447,12 @@ Mx::MxHasEnoughRemainingThreadStack( return TRUE; } +_Use_decl_annotations_ __inline VOID -#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations."); +#pragma prefast(suppress:__WARNING_IRQL_NOT_USED); Mx::ReleaseCancelSpinLock( - __in KIRQL Irql + KIRQL Irql ) { UNREFERENCED_PARAMETER(Irql); @@ -655,16 +627,18 @@ Mx::MxDeletePagedLookasideList( ASSERTMSG("Not implemented for UMDF\n", FALSE); } +_Use_decl_annotations_ __inline VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR) Mx::MxInitializeNPagedLookasideList( - _Out_ PNPAGED_LOOKASIDE_LIST Lookaside, - _In_opt_ PALLOCATE_FUNCTION Allocate, - _In_opt_ PFREE_FUNCTION Free, - _In_ ULONG Flags, - _In_ SIZE_T Size, - _In_ ULONG Tag, - _In_ USHORT Depth + PNPAGED_LOOKASIDE_LIST Lookaside, + PALLOCATE_FUNCTION Allocate, + PFREE_FUNCTION Free, + ULONG Flags, + SIZE_T Size, + ULONG Tag, + USHORT Depth ) { @@ -680,16 +654,18 @@ Mx::MxInitializeNPagedLookasideList( } +_Use_decl_annotations_ __inline VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR) Mx::MxInitializePagedLookasideList( - _Out_ PPAGED_LOOKASIDE_LIST Lookaside, - _In_opt_ PALLOCATE_FUNCTION Allocate, - _In_opt_ PFREE_FUNCTION Free, - _In_ ULONG Flags, - _In_ SIZE_T Size, - _In_ ULONG Tag, - _In_ USHORT Depth + PPAGED_LOOKASIDE_LIST Lookaside, + PALLOCATE_FUNCTION Allocate, + PFREE_FUNCTION Free, + ULONG Flags, + SIZE_T Size, + ULONG Tag, + USHORT Depth ) { @@ -914,6 +890,20 @@ Mx::MxQuerySystemTime( CurrentTime->HighPart = (LONG) filetime.dwHighDateTime; } +__inline +VOID +Mx::MxQuerySystemTimePrecise( + _Out_ PLARGE_INTEGER CurrentTime + ) +{ + FILETIME filetime; + + GetSystemTimePreciseAsFileTime(&filetime); + + CurrentTime->LowPart = filetime.dwLowDateTime; + CurrentTime->HighPart = (LONG) filetime.dwHighDateTime; +} + __inline NTSTATUS Mx::MxUnRegisterPlugPlayNotification( diff --git a/src/framework/shared/inc/primitives/um/mxlockum.h b/src/framework/shared/inc/primitives/um/mxlockum.h index f3e02c2..d8efe76 100644 --- a/src/framework/shared/inc/primitives/um/mxlockum.h +++ b/src/framework/shared/inc/primitives/um/mxlockum.h @@ -68,11 +68,11 @@ MxLockNoDynam::Initialize( } -__inline +_Use_decl_annotations_ VOID -#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations."); +#pragma prefast(suppress:__WARNING_IRQL_NOT_SET) MxLockNoDynam::Acquire( - __out KIRQL * OldIrql + KIRQL * OldIrql ) { ASSERT_DBGFLAG_INITIALIZED; @@ -128,9 +128,10 @@ MxLockNoDynam::AcquireAtDpcLevel( Acquire(&dontCare); } +_Use_decl_annotations_ __inline VOID -#pragma prefast(suppress:__WARNING_UNMATCHED_DEFN, "Can't apply kernel mode annotations."); +#pragma prefast(suppress:__WARNING_IRQL_NOT_USED); MxLockNoDynam::Release( KIRQL NewIrql ) diff --git a/src/framework/shared/inc/private/common/fxcallback.hpp b/src/framework/shared/inc/private/common/fxcallback.hpp index ce1e7e7..c0d5f88 100644 --- a/src/framework/shared/inc/private/common/fxcallback.hpp +++ b/src/framework/shared/inc/private/common/fxcallback.hpp @@ -110,8 +110,10 @@ class FxLockedCallback { } protected: + __inline void + #pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*PreviousIrql'") CallbackStart( __out PKIRQL PreviousIrql ) diff --git a/src/framework/shared/inc/private/common/fxcallbackmutexlock.hpp b/src/framework/shared/inc/private/common/fxcallbackmutexlock.hpp index 0cfa17b..32fd2b9 100644 --- a/src/framework/shared/inc/private/common/fxcallbackmutexlock.hpp +++ b/src/framework/shared/inc/private/common/fxcallbackmutexlock.hpp @@ -87,6 +87,7 @@ class FxCallbackMutexLock : public FxCallbackLock { virtual void + #pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*PreviousIrql'") Lock( __out PKIRQL PreviousIrql ) diff --git a/src/framework/shared/inc/private/common/fxchildlist.hpp b/src/framework/shared/inc/private/common/fxchildlist.hpp index 62b158e..4589240 100644 --- a/src/framework/shared/inc/private/common/fxchildlist.hpp +++ b/src/framework/shared/inc/private/common/fxchildlist.hpp @@ -525,6 +525,7 @@ class FxChildList : public FxNonPagedObject { } VOID + #pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*Dest'") CopyAddress( __out PWDF_CHILD_ADDRESS_DESCRIPTION_HEADER Dest, __in_opt PWDF_CHILD_ADDRESS_DESCRIPTION_HEADER Source diff --git a/src/framework/shared/inc/private/common/fxglobals.h b/src/framework/shared/inc/private/common/fxglobals.h index 679d24d..30c1fd6 100644 --- a/src/framework/shared/inc/private/common/fxglobals.h +++ b/src/framework/shared/inc/private/common/fxglobals.h @@ -829,26 +829,6 @@ FxObjectTypeToHandleName( __in WDFTYPE ObjectType ); -typedef -NTSTATUS -(*PFN_WMI_QUERY_TRACE_INFORMATION)( - __in TRACE_INFORMATION_CLASS TraceInformationClass, - __out PVOID TraceInformation, - __in ULONG TraceInformationLength, - __out_opt PULONG RequiredLength, - __in_opt PVOID Buffer - ); - -typedef -NTSTATUS -(*PFN_WMI_TRACE_MESSAGE_VA)( - __in TRACEHANDLE LoggerHandle, - __in ULONG MessageFlags, - __in LPGUID MessageGuid, - __in USHORT MessageNumber, - __in va_list MessageArgList - ); - enum FxMachineSleepStates { FxMachineS1Index = 0, FxMachineS2Index, @@ -885,46 +865,12 @@ struct FxLibraryGlobalsType { // PDEVICE_OBJECT LibraryDeviceObject; - PFN_IO_CONNECT_INTERRUPT_EX IoConnectInterruptEx; + PFN_IO_CONNECT_INTERRUPT_EX IoConnectInterruptEx; PFN_IO_DISCONNECT_INTERRUPT_EX IoDisconnectInterruptEx; - - PFN_KE_QUERY_ACTIVE_PROCESSORS KeQueryActiveProcessors; - - PFN_KE_SET_TARGET_PROCESSOR_DPC KeSetTargetProcessorDpc; - - PFN_KE_SET_COALESCABLE_TIMER KeSetCoalescableTimer; - - PFN_IO_UNREGISTER_PLUGPLAY_NOTIFICATION_EX IoUnregisterPlugPlayNotificationEx; - - PFN_POX_REGISTER_DEVICE PoxRegisterDevice; - - PFN_POX_START_DEVICE_POWER_MANAGEMENT PoxStartDevicePowerManagement; - - PFN_POX_UNREGISTER_DEVICE PoxUnregisterDevice; - - PFN_POX_ACTIVATE_COMPONENT PoxActivateComponent; - - PFN_POX_IDLE_COMPONENT PoxIdleComponent; - - PFN_POX_REPORT_DEVICE_POWERED_ON PoxReportDevicePoweredOn; - - PFN_POX_COMPLETE_IDLE_STATE PoxCompleteIdleState; - - PFN_POX_COMPLETE_IDLE_CONDITION PoxCompleteIdleCondition; - - PFN_POX_COMPLETE_DEVICE_POWER_NOT_REQUIRED PoxCompleteDevicePowerNotRequired; - - PFN_POX_SET_DEVICE_IDLE_TIMEOUT PoxSetDeviceIdleTimeout; - PFN_IO_REPORT_INTERRUPT_ACTIVE IoReportInterruptActive; - PFN_IO_REPORT_INTERRUPT_INACTIVE IoReportInterruptInactive; - PFN_VF_CHECK_NX_POOL_TYPE VfCheckNxPoolType; - - PFN_VF_IS_RULE_CLASS_ENABLED VfIsRuleClassEnabled; - #endif RTL_OSVERSIONINFOEXW OsVersionInfo; @@ -955,8 +901,6 @@ struct FxLibraryGlobalsType { // KBUGCHECK_REASON_CALLBACK_RECORD BugCheckCallbackRecord; - BOOLEAN ProcessorGroupSupport; - #endif // // WPP tracing. @@ -977,8 +921,6 @@ struct FxLibraryGlobalsType { PFX_DRIVER_GLOBALS BestDriverForDumpLog; #endif - BOOLEAN PassiveLevelInterruptSupport; - // // TRUE if compiled for user-mode // @@ -1042,41 +984,6 @@ struct FxLibraryGlobalsType { // timeout policy. // BOOLEAN WdfDirectedPowerTransitionEnabled; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - // If enabled, for device using SystemManagedIdleTimeout, WDF uses its - // internal idle timer instead of letting PoFx to manage the idle timeout. - // - BOOLEAN UseWdfTimerForPofx; }; extern FxLibraryGlobalsType FxLibraryGlobals; @@ -1294,7 +1201,7 @@ FxIsPassiveLevelInterruptSupported( // // Passive-level interrupt handling is supported in Win 8 and forward. // - return FxLibraryGlobals.PassiveLevelInterruptSupport; + return TRUE; } __inline diff --git a/src/framework/shared/inc/private/common/fxifr.h b/src/framework/shared/inc/private/common/fxifr.h index 1844e75..0b5a01a 100644 --- a/src/framework/shared/inc/private/common/fxifr.h +++ b/src/framework/shared/inc/private/common/fxifr.h @@ -102,23 +102,45 @@ typedef struct _WDF_IFR_HEADER { PLONG SequenceNumberPointer; // Global IFR Sequence Number #endif CHAR DriverName[WDF_IFR_HEADER_NAME_LEN]; + BOOLEAN UseTimeStamp; // If true, WDF_IFR_RECORD contains TimeStamp + BOOLEAN PreciseTimeStamp; // If true, use precise timestamp } WDF_IFR_HEADER, *PWDF_IFR_HEADER; -#define WDF_IFR_RECORD_SIGNATURE 'RL' // 'LR' +#define WDF_IFR_RECORD_SIGNATURE_V1 'RL' // 'LR' +#define WDF_IFR_RECORD_SIGNATURE '2L' // 'L2' typedef struct _WDF_IFR_RECORD { - USHORT Signature; // 'LR' Log Record signature - USHORT Length; // size of record including WDF_IFR_RECORD + USHORT Signature; // 'L2' Log Record signature v2 + USHORT Length; // sizeof(record) + variable-sized data LONG Sequence; USHORT PrevOffset; // offset to previous record USHORT MessageNumber; // message number see .tmf GUID MessageGuid; // message GUID see .tmf + // + // TimeStamp is meant to be a LARGE_INTEGER which is a 64-bit integer, and + // will align at 8-byte boundary. However, size of v1 RECORD is 0x1c, thus + // there will be a 4-byte wasted padding after the last field MessageGuid. + // To save space TimeStamp is defined as two 4-byte integers. + // + struct { + DWORD LowPart; + LONG HighPart; + } TimeStamp; // Current system time (in UTC) + } WDF_IFR_RECORD, *PWDF_IFR_RECORD; +typedef struct _WDF_IFR_RECORD_V1 { + USHORT Signature; // 'LR' Log Record signature + USHORT Length; // sizeof(record) + variable-sized data + LONG Sequence; + USHORT PrevOffset; // offset to previous record + USHORT MessageNumber; // message number see .tmf + GUID MessageGuid; // message GUID see .tmf +} WDF_IFR_RECORD_V1, *PWDF_IFR_RECORD_V1; #define WDF_GLOBAL_VALUE_IFR_REPLAY L"WdfIfrCaptureServiceList" // REG_MULTI_SZ diff --git a/src/framework/shared/inc/private/common/fxifrkm.h b/src/framework/shared/inc/private/common/fxifrkm.h index efe5cc0..074cea7 100644 --- a/src/framework/shared/inc/private/common/fxifrkm.h +++ b/src/framework/shared/inc/private/common/fxifrkm.h @@ -25,8 +25,6 @@ enum FxIFRValues { FxIFRAvgLogSize = FxIFRAvgLogPages * PAGE_SIZE, FxIFRMaxMessageSize = 256, - - FxIFRRecordSignature = WDF_IFR_RECORD_SIGNATURE, }; // diff --git a/src/framework/shared/inc/private/common/fxioqueue.hpp b/src/framework/shared/inc/private/common/fxioqueue.hpp index 7b34697..943efc5 100644 --- a/src/framework/shared/inc/private/common/fxioqueue.hpp +++ b/src/framework/shared/inc/private/common/fxioqueue.hpp @@ -894,7 +894,7 @@ class FxIoQueue : public FxNonPagedObject, IFxHasCallbacks { PeekRequest( __in_opt FxRequest* TagRequest, __in_opt MdFileObject FileObject, - __out_opt PWDF_REQUEST_PARAMETERS Parameters, + _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters, __deref_out FxRequest** pOutRequest ); @@ -934,7 +934,7 @@ class FxIoQueue : public FxNonPagedObject, IFxHasCallbacks { VOID ProcessAcknowledgedRequests( __in FxRequest* Request, - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); // Do not specify argument names @@ -1391,37 +1391,37 @@ class FxIoQueue : public FxNonPagedObject, IFxHasCallbacks { __drv_requiresIRQL(DISPATCH_LEVEL) VOID ProcessIdleComplete( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); __drv_requiresIRQL(DISPATCH_LEVEL) VOID ProcessPurgeComplete( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); __drv_requiresIRQL(DISPATCH_LEVEL) VOID ProcessReadyNotify( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); __drv_requiresIRQL(DISPATCH_LEVEL) BOOLEAN ProcessCancelledRequests( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); __drv_requiresIRQL(DISPATCH_LEVEL) BOOLEAN ProcessCancelledRequestsOnQueue( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); __drv_requiresIRQL(DISPATCH_LEVEL) BOOLEAN ProcessPowerEvents( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ); __inline @@ -1567,6 +1567,8 @@ class FxIoQueue : public FxNonPagedObject, IFxHasCallbacks { m_PowerManaged && m_PowerReferenced == FALSE) { + m_Device->m_PkgPnp->SaveRequestD0IrpReasonHint(RequestD0ForIoPresent); + if (NT_SUCCESS(m_Device->m_PkgPnp->PowerReference(FALSE))) { m_PowerReferenced = TRUE; } diff --git a/src/framework/shared/inc/private/common/fxiotarget.hpp b/src/framework/shared/inc/private/common/fxiotarget.hpp index c313a90..6272ac0 100644 --- a/src/framework/shared/inc/private/common/fxiotarget.hpp +++ b/src/framework/shared/inc/private/common/fxiotarget.hpp @@ -362,7 +362,7 @@ class FxIoTarget : public FxNonPagedObject { SubmitSync( __in FxRequestBase* Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options = NULL, - __out_opt PULONG Action = NULL + _Inout_opt_ PULONG Action = NULL ); VOID diff --git a/src/framework/shared/inc/private/common/fxiotargetremote.hpp b/src/framework/shared/inc/private/common/fxiotargetremote.hpp index 6931ac7..0b1b4b7 100644 --- a/src/framework/shared/inc/private/common/fxiotargetremote.hpp +++ b/src/framework/shared/inc/private/common/fxiotargetremote.hpp @@ -120,11 +120,11 @@ enum FxIoTargetRemoteOpenState { FxIoTargetRemoteOpenStateOpen, }; -struct FxIoTargetRemoveOpenParams { +struct FxIoTargetRemoteOpenParams { - FxIoTargetRemoveOpenParams() + FxIoTargetRemoteOpenParams() { - RtlZeroMemory(this, sizeof(FxIoTargetRemoveOpenParams)); + RtlZeroMemory(this, sizeof(FxIoTargetRemoteOpenParams)); } VOID @@ -209,10 +209,10 @@ class FxIoTargetRemote : public FxIoTarget { NTSTATUS GetTargetDeviceRelations( - _Out_ BOOLEAN* Close + _Inout_ BOOLEAN* Close ); - BOOLEAN + BOOLEAN CanRegisterForPnpNotification( VOID ) @@ -246,7 +246,7 @@ class FxIoTargetRemote : public FxIoTarget { NTSTATUS OpenTargetHandle( _In_ PWDF_IO_TARGET_OPEN_PARAMS OpenParams, - _Inout_ FxIoTargetRemoveOpenParams* pParams + _Inout_ FxIoTargetRemoteOpenParams* pParams ); VOID @@ -278,7 +278,7 @@ class FxIoTargetRemote : public FxIoTarget { return (WDFIOTARGET) GetObjectHandle(); } - virtual + virtual VOID Remove( VOID @@ -331,7 +331,7 @@ class FxIoTargetRemote : public FxIoTarget { // I/O dispatcher to be used for IRPs forwarded to this remote target. It is // created when the CWdfRemoteTarget is created. The win32 handle is // associated with it via a call to m_pRemoteDispatcher->BindToHandle() - // right after we call CreateFile(...). We must call + // right after we call CreateFile(...). We must call // m_pRemoteDispatcher->CloseHandle() to close the handle. // // Because of the plug-in pattern of the IoDispatcher, we need two @@ -373,7 +373,7 @@ class FxIoTargetRemote : public FxIoTarget { } private: - + NTSTATUS BindToHandle( VOID @@ -396,7 +396,7 @@ class FxIoTargetRemote : public FxIoTarget { ); #endif // FX_CORE_USER-MODE) - + public: // // File handle for m_TargetHandle @@ -404,10 +404,10 @@ class FxIoTargetRemote : public FxIoTarget { HANDLE m_TargetHandle; // - // Notification handle returned by IoRegisterPlugPlayNotification for KMDF, - // or host's notification registartion interface for UMDf. Note that host - // uses the term RegistrationId for the same (with WUDF_CONTEXT_TYPE which - // is UINT64). + // Notification handle returned by IoRegisterPlugPlayNotification for KMDF, + // or host's notification registartion interface for UMDf. Note that host + // uses the term RegistrationId for the same (with WUDF_CONTEXT_TYPE which + // is UINT64). // MdTargetNotifyHandle m_TargetNotifyHandle; @@ -428,7 +428,7 @@ class FxIoTargetRemote : public FxIoTarget { UCHAR m_OpenState; protected: - FxIoTargetRemoveOpenParams m_OpenParams; + FxIoTargetRemoteOpenParams m_OpenParams; }; #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE) diff --git a/src/framework/shared/inc/private/common/fxirp.hpp b/src/framework/shared/inc/private/common/fxirp.hpp index c4165c1..1c16fb5 100644 --- a/src/framework/shared/inc/private/common/fxirp.hpp +++ b/src/framework/shared/inc/private/common/fxirp.hpp @@ -791,7 +791,7 @@ Revision History: VOID CopyParameters( - _Out_ PWDF_REQUEST_PARAMETERS Parameters + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); VOID diff --git a/src/framework/shared/inc/private/common/fxobject.hpp b/src/framework/shared/inc/private/common/fxobject.hpp index 184442a..ce43caf 100644 --- a/src/framework/shared/inc/private/common/fxobject.hpp +++ b/src/framework/shared/inc/private/common/fxobject.hpp @@ -286,6 +286,8 @@ class FxObject { USHORT HasDebug : 1; USHORT EarlyDisposedExt : 1; USHORT TraceState : 1; + USHORT HasCleanup : 1; + USHORT DisposeOverride : 1; } m_ObjectFlagsByName; }; @@ -1398,7 +1400,7 @@ class FxObject { BOOLEAN ShouldDeferDisposeLocked( - __out_opt PKIRQL PreviousIrql = NULL + _In_opt_ PKIRQL PreviousIrql = NULL ) { if (IsForceDisposeThreadLocked()) { diff --git a/src/framework/shared/inc/private/common/fxpkgpnp.hpp b/src/framework/shared/inc/private/common/fxpkgpnp.hpp index cf7cca6..b87d11a 100644 --- a/src/framework/shared/inc/private/common/fxpkgpnp.hpp +++ b/src/framework/shared/inc/private/common/fxpkgpnp.hpp @@ -842,7 +842,7 @@ class FxPkgPnp : public FxPackage { _SetPowerCapState( __in ULONG Index, __in DEVICE_POWER_STATE State, - __out PULONG Result + _Inout_ PULONG Result ); static @@ -3675,7 +3675,7 @@ class FxPkgPnp : public FxPackage { RegisterPowerPolicyWmiInstance( __in const GUID* Guid, __in FxWmiInstanceInternalCallbacks* Callbacks, - __out FxWmiInstanceInternal** Instance + _Outptr_ FxWmiInstanceInternal** Instance ); NTSTATUS @@ -3695,6 +3695,25 @@ class FxPkgPnp : public FxPackage { __in BOOLEAN IndicateChildWakeOnParentWake ); + VOID + SaveRequestD0IrpReasonHint( + _In_ RequestDIrpReason Reason + ) + { + if (IsPowerPolicyOwner()) { + m_PowerPolicyMachine.m_Owner->m_DevicePowerIrpTracker.SaveRequestD0IrpReasonHint(Reason); + } + } + + static + ULONGLONG + CompactStatesToBytes( + _In_reads_(8) USHORT* History, + _In_ UCHAR Depth, + _In_ UCHAR Index, + _In_ USHORT FirstState + ); + private: VOID @@ -3710,7 +3729,7 @@ class FxPkgPnp : public FxPackage { VOID ReadRegistryS0Idle( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ); VOID @@ -3727,7 +3746,7 @@ class FxPkgPnp : public FxPackage { VOID ReadRegistrySxWake( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ); VOID @@ -3753,7 +3772,7 @@ class FxPkgPnp : public FxPackage { VOID ReadRegistrySleepstudyEnabled( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ); #endif @@ -4077,6 +4096,8 @@ class FxPkgPnp : public FxPackage { if (IsPowerPolicyOwner()) { NTSTATUS status; + SaveRequestD0IrpReasonHint(RequestD0ForChildDevice); + // // By referencing the parent (this device) we make sure that if the // parent is in Dx, we force it back into D0 so that this child can diff --git a/src/framework/shared/inc/private/common/fxpowerpolicystatemachine.hpp b/src/framework/shared/inc/private/common/fxpowerpolicystatemachine.hpp index 13d04c4..0a3b453 100644 --- a/src/framework/shared/inc/private/common/fxpowerpolicystatemachine.hpp +++ b/src/framework/shared/inc/private/common/fxpowerpolicystatemachine.hpp @@ -707,26 +707,42 @@ enum RequestDIrpReason { RequestDxForSx, // Device in D0. System sleeps RequestD0ForSx, // Device in Dx. Sx comes, Device wakes to D0 first - RequestD0ForOther, // Device in Dx. Wake by I/O present, StopIdle, USB - // selective suspend completed, PoFx power required - // callback, S0IdlePolicyChange + RequestD0ForOther, // deprecated + RequestD0ForDeviceWake, // Device in Dx. Wake by external signal RequestD0ForArmWakeFail,// Device in D0. Dx comes and it fails to arm wake. // Now in Dx. Return to D0 next RequestDxForIdleOut, // Device in D0. Sleep because of Idle out RequestDxForPnpStop, // Device in D0. Pnp remove, Device implicitly Dx RequestD0ForPnpStop, // Device in Dx. Pnp remove, Device wakes to D0 first + + RequestD0ForIoPresent, // Device in Dx. I/O is delivered to a power-managed queue + RequestD0ForStopIdle, // Device in Dx. Driver calls WdfDeviceStopIdle + RequestD0ForDfxPowerUp, // Device in Dx. PoFx DirectedPowerUpCallback is invoked + RequestD0ForUsbSs, // Device in Dx. USB selective suspend IRP is completed + RequestD0ForWakeFailed, // Device in Dx. Wait-wake IRP is completed with failure + RequestD0ForSpecialFile,// Device in Dx. Special file usage is changing + RequestD0ForChildDevice,// Device in Dx. Child device is powering up + RequestD0ForS0IdlePolicy,//Device in Dx. S0 idle policy is changed by either + // driver calling WdfDeviceAssignS0IdleSettings or + // user changing it in device manager property page + RequestD0ForPowerReqCb, // Device in Dx. PoFx DevicePowerRequiredCallback is + // invoked. Could be D0ForSx, D0ForPnpStop, or another + // device on the same power rail entering D0, etc. + }; class FxDevicePowerIrpTracker { public: FxDevicePowerIrpTracker( - VOID + _In_ FxPkgPnp* PkgPnp ) { InitHistory(); m_DIrpRequestedForSIrp = RequestDIrpReasonInvalid; + m_D0IrpReasonHint.Reason = RequestD0ForOther; + m_PkgPnp = PkgPnp; } VOID @@ -734,18 +750,11 @@ class FxDevicePowerIrpTracker { _In_ FxIrp *Irp ); - - // - // Record the reason of requesting D-IRP into an FIFO history which can be - // reviewed using `!wdfkd.wdfdevice _device_ ff` debugger command later. - // VOID LogRequestDIrpReason( - _In_ RequestDIrpReason Reason - ) - { - AddToHistory(Reason); - } + _In_ RequestDIrpReason Reason, + _In_ BOOLEAN PowerUp + ); VOID StartTrackingDevicePowerIrp( @@ -762,8 +771,27 @@ class FxDevicePowerIrpTracker { VOID ); + // + // Only save the first hint. The rest are ignored. + // + // This is especially important for DevicePowerRequiredCallback, which should + // be saved if it comes alone because of QuerySx, but should be ignored if it + // comes after IoPresent. + // + VOID + SaveRequestD0IrpReasonHint( + _In_ RequestDIrpReason Reason + ) + { + InterlockedCompareExchange(&m_D0IrpReasonHint.AsLong, + Reason, + RequestD0ForOther); + } + private: + FxPkgPnp* m_PkgPnp; + // // Special handling only for RequestD0ForS0 and RequestDxForSx. // @@ -776,6 +804,20 @@ class FxDevicePowerIrpTracker { // RequestDIrpReason m_DIrpRequestedForSIrp; + // + // Most of time the caller of PowerPolicySendDevicePowerRequest knows the + // exact reason of requesting D-IRP. But for RequestD0ForOther, only some + // prior code knows the real reason. Let's save it here. + // + // Note: this is a best-effort work, hence the name of "hint". For example, + // in prepare for Sx or pnp remove, power-required-callback will be invoked. + // The real reason behind is not known to WDF. + // + union { + RequestDIrpReason Reason; + LONG AsLong; + } m_D0IrpReasonHint; + POWER_ACTION m_S0PowerAction; POWER_ACTION m_SxPowerAction; @@ -1050,6 +1092,11 @@ struct FxPowerPolicyMachine : public FxThreadedEventQueue { VOID ); + ULONGLONG + CompactStates( + VOID + ); + public: FxPowerPolicyEvent m_Queue[FxPowerPolicyEventQueueDepth]; @@ -1087,6 +1134,7 @@ struct FxPowerPolicyMachine : public FxThreadedEventQueue { ULONG PwrPolPowerUpFailedKnown : 1; } m_SingularEventsPresentByName; }; + }; #endif // _FXPOWERPOLICYSTATEMACHINE_H_ diff --git a/src/framework/shared/inc/private/common/fxqueryinterface.hpp b/src/framework/shared/inc/private/common/fxqueryinterface.hpp index fce9294..3001e4e 100644 --- a/src/framework/shared/inc/private/common/fxqueryinterface.hpp +++ b/src/framework/shared/inc/private/common/fxqueryinterface.hpp @@ -38,6 +38,7 @@ class FxDeviceProcessQueryInterfaceRequest : public FxCallback { _Must_inspect_result_ NTSTATUS + #pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*ExposedInterface'") Invoke( __in WDFDEVICE Device, __in LPGUID InterfacType, diff --git a/src/framework/shared/inc/private/common/fxrequest.hpp b/src/framework/shared/inc/private/common/fxrequest.hpp index b8ae952..c6f5ed7 100644 --- a/src/framework/shared/inc/private/common/fxrequest.hpp +++ b/src/framework/shared/inc/private/common/fxrequest.hpp @@ -877,7 +877,7 @@ class FxRequest : public FxRequestBase { _Must_inspect_result_ NTSTATUS GetParameters( - __out PWDF_REQUEST_PARAMETERS Parameters + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); _Must_inspect_result_ @@ -1153,7 +1153,7 @@ class FxRequest : public FxRequestBase { __in FxIrpQueue* IrpQueue, __in_opt FxRequest* TagRequest, __in_opt MdFileObject FileObject, - __out_opt PWDF_REQUEST_PARAMETERS Parameters, + _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters, __deref_out FxRequest** ppOutRequest ); diff --git a/src/framework/shared/inc/private/common/fxrequestbuffer.hpp b/src/framework/shared/inc/private/common/fxrequestbuffer.hpp index 008f6a4..65c53ac 100644 --- a/src/framework/shared/inc/private/common/fxrequestbuffer.hpp +++ b/src/framework/shared/inc/private/common/fxrequestbuffer.hpp @@ -113,7 +113,7 @@ struct FxRequestBuffer { __in PVOID Buffer, __inout size_t* SizeOfMdl, __in BOOLEAN UnlockWhenFreed, - __deref_out_opt PMDL* MdlToFree + __inout PMDL* MdlToFree ); VOID diff --git a/src/framework/shared/inc/private/common/fxrequestcontext.hpp b/src/framework/shared/inc/private/common/fxrequestcontext.hpp index 330df8e..762e4a6 100644 --- a/src/framework/shared/inc/private/common/fxrequestcontext.hpp +++ b/src/framework/shared/inc/private/common/fxrequestcontext.hpp @@ -124,7 +124,7 @@ struct FxRequestContext : public FxStump { VOID _StoreAndReferenceMemoryWorker( __in PVOID Tag, - __deref_out_opt IFxMemory** PPMemory, + __deref_inout IFxMemory** PPMemory, __in FxRequestBuffer* Buffer ); diff --git a/src/framework/shared/inc/private/common/fxspinlock.hpp b/src/framework/shared/inc/private/common/fxspinlock.hpp index 318e9e3..33b0539 100644 --- a/src/framework/shared/inc/private/common/fxspinlock.hpp +++ b/src/framework/shared/inc/private/common/fxspinlock.hpp @@ -46,7 +46,7 @@ class FxSpinLock : public FxObject { __in USHORT ExtraSize ); - + _At_(this->m_Irql, __drv_savesIRQL) __drv_raisesIRQL(DISPATCH_LEVEL) __drv_maxIRQL(DISPATCH_LEVEL) VOID @@ -54,6 +54,7 @@ class FxSpinLock : public FxObject { __in PVOID CallersAddress ); + _At_(this->m_Irql, __drv_restoresIRQL) __drv_requiresIRQL(DISPATCH_LEVEL) VOID ReleaseLock( diff --git a/src/framework/shared/inc/private/common/fxsyncrequest.hpp b/src/framework/shared/inc/private/common/fxsyncrequest.hpp index bee418f..e9c6497 100644 --- a/src/framework/shared/inc/private/common/fxsyncrequest.hpp +++ b/src/framework/shared/inc/private/common/fxsyncrequest.hpp @@ -81,9 +81,8 @@ class DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) FxSyncRequest : protected FxRe VOID ) { - NTSTATUS status; - #if (FX_CORE_MODE == FX_CORE_USER_MODE) + NTSTATUS status; // // FxCrEvent initialization can fail in UMDF so check for status. // @@ -92,7 +91,6 @@ class DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) FxSyncRequest : protected FxRe return status; } #else - UNREFERENCED_PARAMETER(status); DO_NOTHING(); #endif return STATUS_SUCCESS; diff --git a/src/framework/shared/inc/private/common/fxtelemetrycommon.hpp b/src/framework/shared/inc/private/common/fxtelemetrycommon.hpp index 14d3381..44f35e3 100644 --- a/src/framework/shared/inc/private/common/fxtelemetrycommon.hpp +++ b/src/framework/shared/inc/private/common/fxtelemetrycommon.hpp @@ -26,13 +26,6 @@ Revision History: #pragma once -// -// The TraceLogging infrastructure calls EtwSetInformation API that is not available on Win7. -// Setting TLG_HAVE_EVENT_SET_INFORMATION, modifies the behavior of TraceLoggingProvider.h. -// The value 2 indicates that the trace logging infra would find "EtwSetInformation" via -// MmGetSystemRoutineAddress. This allows our code to be backwards compatible to Win7 -// -#define TLG_HAVE_EVENT_SET_INFORMATION 2 #include #include @@ -51,8 +44,20 @@ Revision History: // WdfLdr.sys #define KMDF_LDR_TRACE_LOGGING_PROVIDER_NAME "Microsoft.Wdf.KMDF.Ldr" -// WudfSvc.dll +// UMDF driver manager, now running inside services.exe #define UMDF_DM_TRACE_LOGGING_PROVIDER_NAME "Microsoft.Wdf.UMDF.Dm" -// Common telemetry related keyword used across all telemetry events -#define WDF_TELEMETRY_EVT_KEYWORDS TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) +// WUDFPlatform.dll +#define UMDF_PLATFORM_TRACE_LOGGING_PROVIDER_NAME "Microsoft.Wdf.UMDF.Platform" + + + + + + + + + + + + diff --git a/src/framework/shared/inc/private/common/fxusbdevice.hpp b/src/framework/shared/inc/private/common/fxusbdevice.hpp index 5cdffe5..853eb66 100644 --- a/src/framework/shared/inc/private/common/fxusbdevice.hpp +++ b/src/framework/shared/inc/private/common/fxusbdevice.hpp @@ -241,7 +241,7 @@ class FxUsbDevice : public FxIoTarget { __inline NTSTATUS GetCurrentFrameNumber( - __in PULONG Current + _Out_ PULONG Current ) { if (m_QueryBusTime != NULL) { diff --git a/src/framework/shared/inc/private/common/fxusbinterface.hpp b/src/framework/shared/inc/private/common/fxusbinterface.hpp index 16b7244..1596863 100644 --- a/src/framework/shared/inc/private/common/fxusbinterface.hpp +++ b/src/framework/shared/inc/private/common/fxusbinterface.hpp @@ -96,7 +96,7 @@ class FxUsbInterface : public FxNonPagedObject { //any base class VOID GetDescriptor( - __in PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, + _Out_ PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, __in UCHAR SettingIndex ); @@ -107,6 +107,7 @@ class FxUsbInterface : public FxNonPagedObject { //any base class VOID ) ; + _Success_(return != NULL) WDFUSBPIPE GetConfiguredPipe( __in UCHAR PipeIndex, diff --git a/src/framework/shared/inc/private/common/fxverifier.h b/src/framework/shared/inc/private/common/fxverifier.h index 5a878cd..e54682e 100644 --- a/src/framework/shared/inc/private/common/fxverifier.h +++ b/src/framework/shared/inc/private/common/fxverifier.h @@ -56,6 +56,7 @@ enum FxEnhancedVerifierBitFlags { #if (FX_CORE_MODE == FX_CORE_USER_MODE) #define FxVerifierBugCheck(FxDriverGlobals, Error, ...) \ + FxVerifierBugCheckWorker(FxDriverGlobals, Error, __VA_ARGS__); \ FX_VERIFY_WITH_NAME(DRIVER(BadAction, Error), \ TRAPMSG("WDF Violation: Please check" \ "tracelog for a description of this error"), \ @@ -146,7 +147,9 @@ IsFxVerifierFunctionTableHooking( } VOID +#if FX_CORE_MODE == FX_CORE_KERNEL_MODE __declspec(noreturn) +#endif FxVerifierBugCheckWorker( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in WDF_BUGCHECK_CODES WdfBugCheckCode, diff --git a/src/framework/shared/inc/private/common/fxverifierlock.hpp b/src/framework/shared/inc/private/common/fxverifierlock.hpp index bfeb29b..12378a6 100644 --- a/src/framework/shared/inc/private/common/fxverifierlock.hpp +++ b/src/framework/shared/inc/private/common/fxverifierlock.hpp @@ -492,13 +492,13 @@ class FxVerifierLock : public FxGlobalsStump { VOID Lock( - __out PKIRQL PreviousIrql, + __out __drv_deref(__drv_savesIRQL) PKIRQL PreviousIrql, __in BOOLEAN AtDpc ); VOID Unlock( - __in KIRQL PreviousIrql, + __in __drv_restoresIRQL KIRQL PreviousIrql, __in BOOLEAN AtDpc ); diff --git a/src/framework/shared/inc/private/common/fxwmiirphandler.hpp b/src/framework/shared/inc/private/common/fxwmiirphandler.hpp index ecc8436..f207f6e 100644 --- a/src/framework/shared/inc/private/common/fxwmiirphandler.hpp +++ b/src/framework/shared/inc/private/common/fxwmiirphandler.hpp @@ -107,7 +107,7 @@ class FxWmiIrpHandler : public FxPackage { AddPowerPolicyProviderAndInstance( __in PWDF_WMI_PROVIDER_CONFIG ProviderConfig, __in FxWmiInstanceInternalCallbacks* Callbacks, - __inout FxWmiInstanceInternal** Instance + _Outptr_ FxWmiInstanceInternal** Instance ); protected: diff --git a/src/framework/shared/inc/private/common/stringutil.hpp b/src/framework/shared/inc/private/common/stringutil.hpp index 0042286..75ced43 100644 --- a/src/framework/shared/inc/private/common/stringutil.hpp +++ b/src/framework/shared/inc/private/common/stringutil.hpp @@ -27,7 +27,7 @@ NTSTATUS FxDuplicateUnicodeString( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in const UNICODE_STRING* Source, - __out PUNICODE_STRING Destination + _Inout_ PUNICODE_STRING Destination ); _Must_inspect_result_ diff --git a/src/framework/shared/inc/private/km/fxglobalskm.h b/src/framework/shared/inc/private/km/fxglobalskm.h index b3d910a..c357dde 100644 --- a/src/framework/shared/inc/private/km/fxglobalskm.h +++ b/src/framework/shared/inc/private/km/fxglobalskm.h @@ -55,44 +55,6 @@ struct FxAllocatedMdls { #define DDI_ENTRY_IMPERSONATION_OK() #define DDI_ENTRY() -typedef -BOOLEAN -(*PFN_KD_REFRESH)( - ); - -typedef -VOID -(*PFN_KE_FLUSH_QUEUED_DPCS)( - VOID - ); - -typedef -NTSTATUS -(*PFN_IO_SET_COMPLETION_ROUTINE_EX)( - __in PDEVICE_OBJECT DeviceObject, - __in PIRP Irp, - __in PIO_COMPLETION_ROUTINE CompletionRoutine, - __in PVOID Context, - __in BOOLEAN InvokeOnSuccess, - __in BOOLEAN InvokeOnError, - __in BOOLEAN InvokeOnCancel - ); - -typedef -BOOLEAN -(*PFN_KE_REGISTER_BUGCHECK_REASON_CALLBACK) ( - __in PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord, - __in PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine, - __in KBUGCHECK_CALLBACK_REASON Reason, - __in PUCHAR Component - ); - -typedef -BOOLEAN -(*PFN_KE_DEREGISTER_BUGCHECK_REASON_CALLBACK) ( - __in PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecords - ); - typedef NTSTATUS (*PFN_IO_CONNECT_INTERRUPT_EX)( @@ -105,197 +67,6 @@ NTSTATUS __in PIO_DISCONNECT_INTERRUPT_PARAMETERS Parameters ); -typedef -NTSTATUS -(*PFN_IO_CONNECT_INTERRUPT)( - __out PKINTERRUPT *InterruptObject, - __in PKSERVICE_ROUTINE ServiceRoutine, - __in_opt PVOID ServiceContext, - __in_opt PKSPIN_LOCK SpinLock, - __in ULONG Vector, - __in KIRQL Irql, - __in KIRQL SynchronizeIrql, - __in KINTERRUPT_MODE InterruptMode, - __in BOOLEAN ShareVector, - __in KAFFINITY ProcessorEnableMask, - __in BOOLEAN FloatingSave - ); - -typedef -VOID -(*PFN_IO_DISCONNECT_INTERRUPT)( - __in PKINTERRUPT InterruptObject - ); - -typedef -KIRQL -(FASTCALL *PFN_KF_RAISE_IRQL) ( - __in KIRQL NewIrql - ); - -typedef -VOID -(FASTCALL *PFN_KF_LOWER_IRQL) ( - __in KIRQL NewIrql - ); - -typedef -PSLIST_ENTRY -(FASTCALL *PFN_INTERLOCKED_POP_ENTRY_SLIST)( - __inout PSLIST_HEADER ListHead - ); - -typedef -PSLIST_ENTRY -(FASTCALL *PFN_INTERLOCKED_PUSH_ENTRY_SLIST)( - __inout PSLIST_HEADER ListHead, - __inout PSLIST_ENTRY ListEntry - ); - -typedef -BOOLEAN -(*PFN_PO_GET_SYSTEM_WAKE)( - __in PIRP Irp - ); - -typedef -VOID -(*PFN_PO_SET_SYSTEM_WAKE)( - __inout PIRP Irp - ); - -typedef -KAFFINITY -(*PFN_KE_QUERY_ACTIVE_PROCESSORS)( - VOID - ); - -typedef -VOID -(*PFN_KE_SET_TARGET_PROCESSOR_DPC)( - __in PRKDPC Dpc, - __in CCHAR Number - ); - -typedef -BOOLEAN -(*PFN_KE_SET_COALESCABLE_TIMER)( - __inout PKTIMER Timer, - __in LARGE_INTEGER DueTime, - __in ULONG Period, - __in ULONG TolerableDelay, - __in_opt PKDPC Dpc - ); - -typedef -ULONG -(*PFN_KE_GET_CURRENT_PROCESSOR_NUMBER)( - VOID - ); - -typedef -ULONG -(*PFN_KE_GET_CURRENT_PROCESSOR_NUMBER_EX)( - __out_opt PPROCESSOR_NUMBER ProcNumber - ); - -typedef -ULONG -(*PFN_KE_QUERY_MAXIMUM_PROCESSOR_COUNT_EX)( - __in USHORT GroupNumber - ); - -typedef -ULONG -(*PFN_KE_QUERY_MAXIMUM_PROCESSOR_COUNT)( - VOID - ); - -typedef -BOOLEAN -(*PFN_KE_ARE_APCS_DISABLED)( - VOID - ); - -typedef -ULONG -(*PFN_KE_GET_RECOMMENDED_SHARED_DATA_ALIGNMENT)( - VOID - ); - -typedef -NTSTATUS -(*PFN_IO_UNREGISTER_PLUGPLAY_NOTIFICATION_EX)( - __in PVOID NotificationEntry - ); - -typedef -NTSTATUS -(*PFN_POX_REGISTER_DEVICE) ( - __in MdDeviceObject Pdo, - __in PPO_FX_DEVICE PoxDevice, - __out POHANDLE * Handle - ); - -typedef -VOID -(*PFN_POX_START_DEVICE_POWER_MANAGEMENT) ( - __in POHANDLE Handle - ); - -typedef -VOID -(*PFN_POX_UNREGISTER_DEVICE) ( - __in POHANDLE Handle - ); - -typedef -(*PFN_POX_ACTIVATE_COMPONENT) ( - __in POHANDLE Handle, - __in ULONG Component, - __in ULONG Flags - ); - -typedef -(*PFN_POX_IDLE_COMPONENT) ( - __in POHANDLE Handle, - __in ULONG Component, - __in ULONG Flags - ); - -typedef -VOID -(*PFN_POX_REPORT_DEVICE_POWERED_ON) ( - __in POHANDLE Handle - ); - -typedef -VOID -(*PFN_POX_COMPLETE_IDLE_STATE) ( - __in POHANDLE Handle, - __in ULONG Component - ); - -typedef -VOID -(*PFN_POX_COMPLETE_IDLE_CONDITION) ( - __in POHANDLE Handle, - __in ULONG Component - ); - -typedef -VOID -(*PFN_POX_COMPLETE_DEVICE_POWER_NOT_REQUIRED) ( - __in POHANDLE Handle - ); - -typedef -VOID -(*PFN_POX_SET_DEVICE_IDLE_TIMEOUT) ( - __in POHANDLE Handle, - __in ULONGLONG IdleTimeout - ); - typedef VOID (*PFN_IO_REPORT_INTERRUPT_ACTIVE) ( @@ -308,20 +79,6 @@ VOID _In_ PIO_REPORT_INTERRUPT_ACTIVE_STATE_PARAMETERS Parameters ); -typedef -VOID -(*PFN_VF_CHECK_NX_POOL_TYPE) ( - _In_ POOL_TYPE PoolType, - _In_ PVOID CallingAddress, - _In_ ULONG PoolTag - ); - -typedef -BOOLEAN -(*PFN_VF_IS_RULE_CLASS_ENABLED) ( - _In_ ULONG RuleClassId - ); - VOID FxRegisterBugCheckCallback( __inout PFX_DRIVER_GLOBALS FxDriverGlobals, @@ -742,7 +499,7 @@ FxIsProcessorGroupSupported( // // Groups are supported in Win 7 and forward. // - return FxLibraryGlobals.ProcessorGroupSupport; + return TRUE; } #ifdef __cplusplus diff --git a/src/framework/shared/inc/private/km/fxirpkm.hpp b/src/framework/shared/inc/private/km/fxirpkm.hpp index ab33fdd..d7e6cb6 100644 --- a/src/framework/shared/inc/private/km/fxirpkm.hpp +++ b/src/framework/shared/inc/private/km/fxirpkm.hpp @@ -1299,7 +1299,7 @@ FxIrp::GetDriverContextSize( __inline VOID FxIrp::CopyParameters( - _Out_ PWDF_REQUEST_PARAMETERS Parameters + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { RtlMoveMemory(&Parameters->Parameters, diff --git a/src/framework/shared/inc/private/km/fxrequestbufferkm.hpp b/src/framework/shared/inc/private/km/fxrequestbufferkm.hpp index 467db2c..47c7ccd 100644 --- a/src/framework/shared/inc/private/km/fxrequestbufferkm.hpp +++ b/src/framework/shared/inc/private/km/fxrequestbufferkm.hpp @@ -47,7 +47,7 @@ FxRequestBuffer::GetOrAllocateMdlWorker( __in PVOID Buffer, __inout size_t* SizeOfMdl, __in BOOLEAN UnlockWhenFreed, - __deref_out_opt PMDL* MdlToFree + __inout PMDL* MdlToFree ) { size_t sizeofCurrentMdl; diff --git a/src/framework/shared/inc/private/km/fxverifierkm.h b/src/framework/shared/inc/private/km/fxverifierkm.h index 93539bc..7729a57 100644 --- a/src/framework/shared/inc/private/km/fxverifierkm.h +++ b/src/framework/shared/inc/private/km/fxverifierkm.h @@ -23,6 +23,22 @@ Revision History: #ifndef _FXVERIFIERKM_H_ #define _FXVERIFIERKM_H_ +extern "C" { + +BOOLEAN +VfIsRuleClassEnabled ( + _In_ ULONG RuleClassID + ); + +VOID +VfCheckNxPoolType ( + _In_ POOL_TYPE PoolType, + _In_ PVOID CallingAddress, + _In_ ULONG PoolTag + ); + +} // extern "C" + FORCEINLINE VOID FxVerifierCheckNxPoolType( @@ -57,15 +73,14 @@ Return Value: --*/ { - if (FxDriverGlobals->FxVerifierOn && - FxLibraryGlobals.VfCheckNxPoolType != NULL) { + if (FxDriverGlobals->FxVerifierOn) { // // Forward the call to Driver Verifier. This will provide a consistent // behavior across all verified drivers. // - FxLibraryGlobals.VfCheckNxPoolType(PoolType, _ReturnAddress(), PoolTag); + VfCheckNxPoolType(PoolType, _ReturnAddress(), PoolTag); } } diff --git a/src/framework/shared/irphandlers/general/fxpkggeneral.cpp b/src/framework/shared/irphandlers/general/fxpkggeneral.cpp index c995eba..f999bb1 100644 --- a/src/framework/shared/irphandlers/general/fxpkggeneral.cpp +++ b/src/framework/shared/irphandlers/general/fxpkggeneral.cpp @@ -605,7 +605,6 @@ Return Value: --*/ { - MdDeviceObject pDevice; NTSTATUS status; WDF_IO_QUEUE_CONFIG queueConfig; WDF_OBJECT_ATTRIBUTES attributes; @@ -618,6 +617,7 @@ Return Value: #if ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE)) + MdDeviceObject pDevice; if (Init->Control.Flags != 0) { pDevice = m_Device->GetDeviceObject(); @@ -648,7 +648,6 @@ Return Value: } #else UNREFERENCED_PARAMETER(Init); - UNREFERENCED_PARAMETER(pDevice); #endif if (NT_SUCCESS(status) && (m_Flags & FX_PKG_GENERAL_FLAG_CREATE)) { diff --git a/src/framework/shared/irphandlers/io/fxioqueue.cpp b/src/framework/shared/irphandlers/io/fxioqueue.cpp index e5643b6..82b4a50 100644 --- a/src/framework/shared/irphandlers/io/fxioqueue.cpp +++ b/src/framework/shared/irphandlers/io/fxioqueue.cpp @@ -4691,7 +4691,7 @@ Return Value: __drv_requiresIRQL(DISPATCH_LEVEL) VOID FxIoQueue::ProcessIdleComplete( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ @@ -4744,7 +4744,7 @@ Return Value: __drv_requiresIRQL(DISPATCH_LEVEL) VOID FxIoQueue::ProcessPurgeComplete( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ @@ -4795,7 +4795,7 @@ Return Value: __drv_requiresIRQL(DISPATCH_LEVEL) VOID FxIoQueue::ProcessReadyNotify( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ @@ -4857,7 +4857,7 @@ Return Value: __drv_requiresIRQL(DISPATCH_LEVEL) BOOLEAN FxIoQueue::ProcessCancelledRequests( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ @@ -4941,7 +4941,7 @@ FxIoQueue::ProcessCancelledRequests( __drv_requiresIRQL(DISPATCH_LEVEL) BOOLEAN FxIoQueue::ProcessCancelledRequestsOnQueue( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ @@ -5014,7 +5014,7 @@ FxIoQueue::ProcessCancelledRequestsOnQueue( __drv_requiresIRQL(DISPATCH_LEVEL) BOOLEAN FxIoQueue::ProcessPowerEvents( - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ @@ -5648,7 +5648,7 @@ __drv_requiresIRQL(DISPATCH_LEVEL) VOID FxIoQueue::ProcessAcknowledgedRequests( __in FxRequest* Request, - __out PKIRQL PreviousIrql + _In_ PKIRQL PreviousIrql ) /*++ diff --git a/src/framework/shared/irphandlers/io/fxpkgio.cpp b/src/framework/shared/irphandlers/io/fxpkgio.cpp index 0d30e5f..b064245 100644 --- a/src/framework/shared/irphandlers/io/fxpkgio.cpp +++ b/src/framework/shared/irphandlers/io/fxpkgio.cpp @@ -919,6 +919,7 @@ FxPkgIo::ConfigureForwarding( NTSTATUS status; ASSERT(RequestType <= IRP_MJ_MAXIMUM_FUNCTION); + _Analysis_assume_(RequestType <= IRP_MJ_MAXIMUM_FUNCTION && RequestType >= 0); if(TargetQueue->IsIoEventHandlerRegistered(RequestType) == FALSE){ status = STATUS_INVALID_DEVICE_REQUEST; diff --git a/src/framework/shared/irphandlers/pnp/devicepowerirptracker.cpp b/src/framework/shared/irphandlers/pnp/devicepowerirptracker.cpp index 5c48da3..5231c23 100644 --- a/src/framework/shared/irphandlers/pnp/devicepowerirptracker.cpp +++ b/src/framework/shared/irphandlers/pnp/devicepowerirptracker.cpp @@ -219,3 +219,77 @@ FxDevicePowerIrpTracker::GetSystemPowerAction( return PowerActionNone; } } + +VOID +FxDevicePowerIrpTracker::LogRequestDIrpReason( + _In_ RequestDIrpReason Reason, + _In_ BOOLEAN PowerUp + ) +/*++ + +Routine Description: + Record the reason of requesting D-IRP into an FIFO history which can be + reviewed using `!wdfkd.wdfdevice _device_ ff` debugger command later. + +Arguments: + Reason - The reason why D-IRP is requested, e.g. idle out, system wakes up + PowerUp - TRUE the device is powering up, FALSE power down + +Return Value: + None + + --*/ +{ + if (Reason == RequestD0ForOther) { + ASSERT(PowerUp); + Reason = (RequestDIrpReason) InterlockedOr(&m_D0IrpReasonHint.AsLong, 0); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + + // + // Clear the saved D0 reason hint but only when we're requesting D0 IRP. + // + // For example, right after idle times out but before requesting Dx IRP, driver + // calls WdfDeviceStopIdle which SaveRequestD0IrpReasonHint(RequestD0ForStopIdle). + // The device will still enter Dx and then exit immediately. If D0 reason hint + // is cleared when requesting Dx, later when requesting D0, WDF will assert that + // D0 reason hint is invalid. Thus, D0 reason hint should not be cleared on Dx. + // + if (PowerUp) { + InterlockedExchange(&m_D0IrpReasonHint.AsLong, RequestD0ForOther); + } + + AddToHistory(Reason); +} diff --git a/src/framework/shared/irphandlers/pnp/fxinterruptapi.cpp b/src/framework/shared/irphandlers/pnp/fxinterruptapi.cpp index 9a4882b..20eb36a 100644 --- a/src/framework/shared/irphandlers/pnp/fxinterruptapi.cpp +++ b/src/framework/shared/irphandlers/pnp/fxinterruptapi.cpp @@ -809,7 +809,7 @@ WDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFINTERRUPT Interrupt, - __out + _Inout_ PWDF_INTERRUPT_INFO Info ) diff --git a/src/framework/shared/irphandlers/pnp/fxpkgpnp.cpp b/src/framework/shared/irphandlers/pnp/fxpkgpnp.cpp index d6fd446..530f4e2 100644 --- a/src/framework/shared/irphandlers/pnp/fxpkgpnp.cpp +++ b/src/framework/shared/irphandlers/pnp/fxpkgpnp.cpp @@ -2945,7 +2945,7 @@ NTSTATUS FxPkgPnp::RegisterPowerPolicyWmiInstance( __in const GUID* Guid, __in FxWmiInstanceInternalCallbacks* Callbacks, - __out FxWmiInstanceInternal** Instance + _Outptr_ FxWmiInstanceInternal** Instance ) { WDF_WMI_PROVIDER_CONFIG config; @@ -3257,11 +3257,13 @@ Return Value: // // Policy on UseWdfTimerForPofx: - // // - Enabled if the driver (that created the WDFDEVICE) targets v33+ WDF - // - Can be disabled through per-device registry setting + // - Can be modified through per-device registry setting + // + // If enabled, for device using SystemManagedIdleTimeout, WDF uses its + // internal idle timer instead of letting PoFx to manage the idle timeout. // - BOOLEAN useWdfTimerForPofx = FxLibraryGlobals.UseWdfTimerForPofx; + BOOLEAN useWdfTimerForPofx = FALSE; if (GetDriverGlobals()->IsMinorVersionGreaterThanOrEqualTo(33)) { useWdfTimerForPofx = TRUE; } @@ -3991,6 +3993,7 @@ FxPkgPnp::PowerPolicySetS0IdleState( __in BOOLEAN State ) { + SaveRequestD0IrpReasonHint(RequestD0ForS0IdlePolicy); m_PowerPolicyMachine.m_Owner->m_IdleSettings.Enabled = State ? TRUE : FALSE; m_PowerPolicyMachine.m_Owner->m_IdleSettings.Dirty = TRUE; PowerPolicyProcessEvent(PwrPolS0IdlePolicyChanged); @@ -4068,9 +4071,9 @@ Return Value: --*/ { +#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE) MdDeviceObject pdo; -#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE) // // In between creating a PDO WDFDEVICE and it starting, if this DDI is called, // we will not have a valid PDO. Make sure it is valid before we proceed. @@ -4090,7 +4093,6 @@ Return Value: #else // USER_MODE m_Device->GetMxDeviceObject()->InvalidateDeviceState( m_Device->GetDeviceObject()); - UNREFERENCED_PARAMETER(pdo); #endif } @@ -4568,6 +4570,9 @@ FxPkgPnp::PnpDeviceUsageNotification( // when the make the transition from power pageable to non or vice versa. // if (IsPowerPolicyOwner()) { + + SaveRequestD0IrpReasonHint(RequestD0ForSpecialFile); + status = PowerReference(TRUE); if (NT_SUCCESS(status)) { @@ -5761,6 +5766,8 @@ Return Value: --*/ { if (IsPowerPolicyOwner()) { + SaveRequestD0IrpReasonHint(RequestD0ForPnpStop); + // // We want to synchronously wait to move into D0 // @@ -5989,7 +5996,7 @@ VOID FxPkgPnp::_SetPowerCapState( __in ULONG Index, __in DEVICE_POWER_STATE State, - __out PULONG Result + _Inout_ PULONG Result ) /*++ @@ -6901,3 +6908,60 @@ FxPkgPnp::GetSystemPowerAction( return m_PowerPolicyMachine.m_Owner-> m_DevicePowerIrpTracker.GetSystemPowerAction(); } + +static +BYTE +CompactStateToByte( + _In_ USHORT State, + _In_ USHORT FirstState + ) +/*-- + WdfDevStatePwrPolInvalid = 0 ==> 0xFF + WdfDevStatePwrPolObjectCreated = 0x500 ==> 0x00 + WdfDevStatePwrPolStarting = 0x501 ==> 0x01 + ... + WdfDevStatePwrPolSleepingWakeCancelWakeNP = 0x5BD | WdfDevStateNP ==> 0xBD + WdfDevStatePwrPolNull = 0x5BE ==> 0xBE +--*/ +{ + // ignore WdfDevStateNP + USHORT n = (USHORT)(State & (~WdfDevStateNP)); + + // special case WdfDevStatePwrPolInvalid = 0 + if (n == 0) { + n = 0xFF; + } else { + n -= FirstState; + } + return (BYTE) (n & 0xFF); +} + +ULONGLONG +FxPkgPnp::CompactStatesToBytes( + _In_reads_(8) USHORT* History, + _In_ UCHAR Depth, + _In_ UCHAR Index, + _In_ USHORT FirstState + ) +/*-- + + Read at most 8 entries from history array. If the history size < 8, hopefully + the compiler will catch the issue and report the error. + + Each entry is compressed to a single byte. In total it returns 64-bit data. + +--*/ +{ + union { + BYTE Bytes[8]; + ULONGLONG UI64; + } states = { 0 }; + + UCHAR cur = Index; + for (UCHAR i = 0; i < 8; i++) { + states.Bytes[i] = CompactStateToByte(History[cur], FirstState); + cur = (cur + 1) % Depth; + } + + return states.UI64; +} diff --git a/src/framework/shared/irphandlers/pnp/km/fxpkgpnpkm.cpp b/src/framework/shared/irphandlers/pnp/km/fxpkgpnpkm.cpp index 78bc620..12ae78f 100644 --- a/src/framework/shared/irphandlers/pnp/km/fxpkgpnpkm.cpp +++ b/src/framework/shared/irphandlers/pnp/km/fxpkgpnpkm.cpp @@ -375,7 +375,7 @@ FxPkgPnp::UpdateWmiInstanceForS0Idle( VOID FxPkgPnp::ReadRegistryS0Idle( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ) { NTSTATUS status; @@ -497,7 +497,7 @@ FxPkgPnp::UpdateWmiInstanceForSxWake( VOID FxPkgPnp::ReadRegistrySxWake( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ) { FxAutoRegKey hKey; @@ -1147,7 +1147,7 @@ Return Value: VOID FxPkgPnp::ReadRegistrySleepstudyEnabled( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ) { NTSTATUS status; diff --git a/src/framework/shared/irphandlers/pnp/km/supportkm.cpp b/src/framework/shared/irphandlers/pnp/km/supportkm.cpp index 586ba4f..756f988 100644 --- a/src/framework/shared/irphandlers/pnp/km/supportkm.cpp +++ b/src/framework/shared/irphandlers/pnp/km/supportkm.cpp @@ -208,7 +208,7 @@ IdleTimeoutManagement::_SystemManagedIdleTimeoutAvailable( VOID ) { - return (NULL != FxLibraryGlobals.PoxRegisterDevice); + return TRUE; } _Must_inspect_result_ diff --git a/src/framework/shared/irphandlers/pnp/pnpstatemachine.cpp b/src/framework/shared/irphandlers/pnp/pnpstatemachine.cpp index 4eb5312..83e2a44 100644 --- a/src/framework/shared/irphandlers/pnp/pnpstatemachine.cpp +++ b/src/framework/shared/irphandlers/pnp/pnpstatemachine.cpp @@ -1057,41 +1057,6 @@ Routine Description: } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - m_PnpMachine.IncrementHead(); m_PnpMachine.Unlock(oldIrql); diff --git a/src/framework/shared/irphandlers/pnp/powerpolicystatemachine.cpp b/src/framework/shared/irphandlers/pnp/powerpolicystatemachine.cpp index e4736dc..d4ecf7f 100644 --- a/src/framework/shared/irphandlers/pnp/powerpolicystatemachine.cpp +++ b/src/framework/shared/irphandlers/pnp/powerpolicystatemachine.cpp @@ -1589,6 +1589,11 @@ const POWER_POLICY_STATE_TABLE FxPkgPnp::m_WdfPowerPolicyStates[] = PwrPolPowerTimeoutExpired | // idle timer fired right before stopping // pwr policy and before pwr pol could process // the timeout + + PwrPolS0 | // PwrPolS0 is special handled in PowerPolicyProcessEventInner + // when no valid response is specified. It is still marked as + // a known drop event here to avoid an error trace message. + PwrPolIoPresent | // I/O arrived while transitioning to the // stopped state PwrPolDevicePowerRequired // Due to a power-related failure, we declared our device state @@ -1621,6 +1626,15 @@ const POWER_POLICY_STATE_TABLE FxPkgPnp::m_WdfPowerPolicyStates[] = { PwrPolSx, WdfDevStatePwrPolSleeping DEBUGGED_EVENT }, FxPkgPnp::m_PowerPolStartedOtherStates, { TRUE, +#if !defined(WDF_ALLOW_DFX_FOR_NON_IDLE_CAPABLE_DEVICES) + PwrPolDeviceDirectedPowerUp | // A not idle-capable device got a directed power down request. + // This is not supported. Device went from Started state to + // StartedNotIdleCapableDirectedDown, and back to Started. + // Now the device got a directed power up, which should be + // dropped. Note the device power requirement state machine + // will still complete the directed power up request back to + // PoFx even though this event is being ignored here. +#endif PwrPolS0 | // If the machine send a query Sx and it fails, it will send // an S0 while in the running state (w/out ever sending a true set Sx irp) PwrPolWakeArrived | // If the wake request is failed by the bus in between WakeArrived @@ -3077,9 +3091,22 @@ FxPowerPolicyMachine::AcknowledgeS0( m_Owner->m_PoxInterface.PoxReportDevicePoweredOn(); } +ULONGLONG +FxPowerPolicyMachine::CompactStates( + VOID + ) +{ + return FxPkgPnp::CompactStatesToBytes( + m_States.History, + FxPowerPolicyEventQueueDepth, + m_HistoryIndex, + WdfDevStatePwrPolObjectCreated); +} + FxPowerPolicyOwnerSettings::FxPowerPolicyOwnerSettings( __in FxPkgPnp* PkgPnp ) : m_PoxInterface(PkgPnp) + , m_DevicePowerIrpTracker(PkgPnp) { ULONG i; @@ -3716,6 +3743,7 @@ FxPkgPnp::PowerPolicyProcessEventInner( switch (state) { case WdfDevStatePwrPolDevicePowerRequestFailed: + case WdfDevStatePwrPolStopped: // // If a device fails either D0 or Dx during system sleep, // when system wakes up, the device will stay in this @@ -3761,6 +3789,8 @@ FxPkgPnp::PowerPolicyProcessEventInner( + + break; } break; @@ -6995,6 +7025,8 @@ Return Value: ASSERT_PWR_POL_STATE(This, WdfDevStatePwrPolWakeFailedUsbSS); + This->SaveRequestD0IrpReasonHint(RequestD0ForWakeFailed); + if (This->m_PowerPolicyMachine.m_Owner->m_IdleSettings.UsbSSCapable) { This->m_PowerPolicyMachine.UsbSSCallbackProcessingComplete(); } @@ -9637,7 +9669,8 @@ Return Value: devicePowerIrpTracker = &m_PowerPolicyMachine.m_Owner->m_DevicePowerIrpTracker; - devicePowerIrpTracker->LogRequestDIrpReason(Reason); + devicePowerIrpTracker->LogRequestDIrpReason(Reason, + (DeviceState == PowerDeviceD0)); if (Reason == RequestD0ForS0 || Reason == RequestDxForSx) { devicePowerIrpTracker->StartTrackingDevicePowerIrp(Reason); @@ -9675,7 +9708,8 @@ Return Value: // // We are no longer requesting a power irp // - devicePowerIrpTracker->LogRequestDIrpReason(RequestDIrpFailed); + devicePowerIrpTracker->LogRequestDIrpReason(RequestDIrpFailed, + (DeviceState == PowerDeviceD0)); if (Reason == RequestD0ForS0 || Reason == RequestDxForSx) { devicePowerIrpTracker->StopTrackingDevicePowerIrp(); @@ -9961,6 +9995,8 @@ FxPkgPnp::_PowerPolicyUsbSelectiveSuspendCompletionRoutine( This = (FxPkgPnp*) Context; + This->SaveRequestD0IrpReasonHint(RequestD0ForUsbSs); + // // Parameters DeviceObejct and Irp are always set to NULL in UMDF, so // don't touch these in UMDF trace @@ -10276,6 +10312,8 @@ Return Value: { ASSERT_PWR_POL_STATE(This, WdfDevStatePwrPolWaitingArmedWakeFailedCancelUsbSS); + This->SaveRequestD0IrpReasonHint(RequestD0ForWakeFailed); + if (This->PowerPolicyCancelUsbSSIfCapable()) { // // Usbss completion event will move us from this state. diff --git a/src/framework/shared/irphandlers/pnp/poxinterface.cpp b/src/framework/shared/irphandlers/pnp/poxinterface.cpp index 9490372..01ec949 100644 --- a/src/framework/shared/irphandlers/pnp/poxinterface.cpp +++ b/src/framework/shared/irphandlers/pnp/poxinterface.cpp @@ -548,6 +548,8 @@ FxPoxInterface::PowerRequiredCallbackWorker( { KIRQL irql; + m_PkgPnp->SaveRequestD0IrpReasonHint(RequestD0ForPowerReqCb); + // // Make a note of the fact that device power is required // @@ -618,6 +620,8 @@ Return Value: // SetDirectedTransitionInProgress(); + m_PkgPnp->SaveRequestD0IrpReasonHint(RequestD0ForDfxPowerUp); + // // Send the device-power-not-required event to the device power // requirement state machine. diff --git a/src/framework/shared/irphandlers/pnp/um/fxchildlistum.cpp b/src/framework/shared/irphandlers/pnp/um/fxchildlistum.cpp index a6f20e2..acb7585 100644 --- a/src/framework/shared/irphandlers/pnp/um/fxchildlistum.cpp +++ b/src/framework/shared/irphandlers/pnp/um/fxchildlistum.cpp @@ -190,6 +190,7 @@ FxChildList::GetAddressDescription( } VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*AddressDescription'") FxChildList::GetAddressDescriptionFromEntry( __in FxDeviceDescriptionEntry* Entry, __out PWDF_CHILD_ADDRESS_DESCRIPTION_HEADER AddressDescription @@ -199,6 +200,7 @@ FxChildList::GetAddressDescriptionFromEntry( } VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*ScanTag'") FxChildList::BeginScan( __out_opt PULONG ScanTag ) diff --git a/src/framework/shared/irphandlers/pnp/um/fxpkgpnpum.cpp b/src/framework/shared/irphandlers/pnp/um/fxpkgpnpum.cpp index 9a79f02..783e060 100644 --- a/src/framework/shared/irphandlers/pnp/um/fxpkgpnpum.cpp +++ b/src/framework/shared/irphandlers/pnp/um/fxpkgpnpum.cpp @@ -258,7 +258,7 @@ FxPkgPnp::UpdateWmiInstanceForS0Idle( VOID FxPkgPnp::ReadRegistryS0Idle( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ) { NTSTATUS status; @@ -340,7 +340,7 @@ FxPkgPnp::UpdateWmiInstanceForSxWake( VOID FxPkgPnp::ReadRegistrySxWake( __in PCUNICODE_STRING ValueName, - __out BOOLEAN *Enabled + _Inout_ BOOLEAN *Enabled ) { NTSTATUS status; diff --git a/src/framework/shared/irphandlers/pnp/um/fxqueryinterfaceum.cpp b/src/framework/shared/irphandlers/pnp/um/fxqueryinterfaceum.cpp index 2158422..0702c4f 100644 --- a/src/framework/shared/irphandlers/pnp/um/fxqueryinterfaceum.cpp +++ b/src/framework/shared/irphandlers/pnp/um/fxqueryinterfaceum.cpp @@ -44,6 +44,7 @@ FxQueryInterface::~FxQueryInterface() } VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*Interface'") FxQueryInterface::_FormatIrp( __in PIRP Irp, __in const GUID* InterfaceGuid, diff --git a/src/framework/shared/object/fxobject.cpp b/src/framework/shared/object/fxobject.cpp index a4d3c55..c96ee70 100644 --- a/src/framework/shared/object/fxobject.cpp +++ b/src/framework/shared/object/fxobject.cpp @@ -686,7 +686,15 @@ FxObject::AddContext( m_ObjectFlags |= FXOBJECT_FLAGS_HAS_CLEANUP; } } - + else { + // + // When called from MoveContexts, Attributes is NULL and Header's + // callbacks are already initialized. + // + if (Header->EvtCleanupCallback != NULL) { + m_ObjectFlags |= FXOBJECT_FLAGS_HAS_CLEANUP; + } + } } } else { @@ -762,10 +770,9 @@ Return Value: // // All contexts for a object is linked together through a head. When moving // all contexts from one object to another object, it might be tempting to - // take a shortcut by modifying head only. That is wrong, e.g. the target - // object may need to set FXOBJECT_FLAGS_HAS_CLEANUP if any of the incoming - // contexts has the cleanup callback. Therefore we have to traverse the link - // one by one. + // take a shortcut by modifying head only. That is wrong as we need to verify + // there is no context type name conflict between two objects. Therefore we + // have to traverse the link and call AddContext one by one. // while ((cur = header->NextHeader) != NULL) { diff --git a/src/framework/shared/object/fxverifierbugcheck.cpp b/src/framework/shared/object/fxverifierbugcheck.cpp index a60ac76..0cc591b 100644 --- a/src/framework/shared/object/fxverifierbugcheck.cpp +++ b/src/framework/shared/object/fxverifierbugcheck.cpp @@ -40,7 +40,9 @@ extern "C" { VOID +#if FX_CORE_MODE == FX_CORE_KERNEL_MODE __declspec(noreturn) +#endif FxVerifierBugCheckWorker( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in WDF_BUGCHECK_CODES WdfBugCheckCode, @@ -60,6 +62,23 @@ Routine Description: --*/ { +#if (FX_CORE_MODE == FX_CORE_USER_MODE) + + + + + + + + + + + + + + + +#else // // Indicate to the BugCheck callback filter which IFR to dump. // @@ -70,6 +89,7 @@ Routine Description: BugCheckParameter2, BugCheckParameter3, (ULONG_PTR) FxDriverGlobals ); +#endif } VOID @@ -147,6 +167,23 @@ Returns: VOID FxDriverGlobals->FxForceLogsInMiniDump = TRUE; #if (FX_CORE_MODE == FX_CORE_USER_MODE) + + + + + + + + + + + + + + + + + FX_VERIFY_WITH_NAME(DRIVER(BadAction, BugCheckCode), TRAPMSG("A UMDF driver " "reported a fatal error"), FxDriverGlobals->Public.DriverName); #else diff --git a/src/framework/shared/object/fxverifierlock.cpp b/src/framework/shared/object/fxverifierlock.cpp index c5f13f9..539c31b 100644 --- a/src/framework/shared/object/fxverifierlock.cpp +++ b/src/framework/shared/object/fxverifierlock.cpp @@ -147,10 +147,12 @@ FxVerifierLockDestroy( return; } +_Use_decl_annotations_ VOID +#pragma prefast(suppress:__WARNING_IRQL_NOT_SET, "No IRQL was saved into '*PreviousIrql'") FxVerifierLock::Lock( - __out PKIRQL PreviousIrql, - __in BOOLEAN AtDpc + PKIRQL PreviousIrql, + BOOLEAN AtDpc ) { MxThread curThread; @@ -298,10 +300,12 @@ FxVerifierLock::Lock( return; } +_Use_decl_annotations_ void +#pragma prefast(suppress:__WARNING_IRQL_NOT_USED, "The IRQL in 'PreviousIrql' was never restored") FxVerifierLock::Unlock( - __in KIRQL PreviousIrql, - __in BOOLEAN AtDpc + KIRQL PreviousIrql, + BOOLEAN AtDpc ) { MxThread curThread; @@ -631,7 +635,8 @@ FxVerifierLock::InitializeLockOrder() p++; } - DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE, + + DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_INFORMATION, TRACINGDEVICE, "Object Type 0x%x does not have a lock order " "defined in fx\\inc\\FxVerifierLock.hpp", ObjectType); diff --git a/src/framework/shared/object/globals.cpp b/src/framework/shared/object/globals.cpp index d2709e9..f4e3c11 100644 --- a/src/framework/shared/object/globals.cpp +++ b/src/framework/shared/object/globals.cpp @@ -113,7 +113,20 @@ VOID FxOverrideDefaultVerifierSettings( __in HANDLE Key, __in LPWSTR Name, - __out PBOOLEAN OverrideValue + _Inout_ PBOOLEAN OverrideValue + ); + +_IRQL_requires_max_(PASSIVE_LEVEL) +NTSYSAPI +NTSTATUS +NTAPI +RtlQueryRegistryValuesEx( + _In_ ULONG RelativeTo, + _In_ PCWSTR Path, + _Inout_ _At_(*(*QueryTable).EntryContext, _Pre_unknown_) + PRTL_QUERY_REGISTRY_TABLE QueryTable, + _In_opt_ PVOID Context, + _In_opt_ PVOID Environment ); // @@ -443,69 +456,6 @@ FxVerifyObjectTableIsSorted( } } -typedef -NTSTATUS -(*PFN_RTL_GET_VERSION)( - __out PRTL_OSVERSIONINFOW VersionInformation - ); - -typedef -NTSTATUS -(*PFN_RTL_VERIFY_VERSION_INFO)( - __in PRTL_OSVERSIONINFOEXW VersionInfo, - __in ULONG TypeMask, - __in ULONGLONG ConditionMask - ); - -typedef -ULONGLONG -(*PFN_VER_SET_CONDITION_MASK)( - __in ULONGLONG ConditionMask, - __in ULONG TypeMask, - __in UCHAR Condition - ); - -VOID -FxLibraryGlobalsVerifyVersion( - VOID - ) -{ - RTL_OSVERSIONINFOEXW info; - PFN_RTL_VERIFY_VERSION_INFO pRtlVerifyVersionInfo; - PFN_VER_SET_CONDITION_MASK pVerSetConditionMask; - ULONGLONG condition; - NTSTATUS status; - - pRtlVerifyVersionInfo = (PFN_RTL_VERIFY_VERSION_INFO) - Mx::MxGetSystemRoutineAddress(MAKE_MX_FUNC_NAME("RtlVerifyVersionInfo")); - - if (pRtlVerifyVersionInfo == NULL) { - return; - } - - pVerSetConditionMask = (PFN_VER_SET_CONDITION_MASK) - Mx::MxGetSystemRoutineAddress(MAKE_MX_FUNC_NAME("VerSetConditionMask")); - - // - // Check for Win8 (6.2) and later for passive-level interrupt support. - // - RtlZeroMemory(&info, sizeof(info)); - info.dwOSVersionInfoSize = sizeof(info); - info.dwMajorVersion = 6; - info.dwMinorVersion = 2; - - condition = 0; - condition = pVerSetConditionMask(condition, VER_MAJORVERSION, VER_GREATER_EQUAL); - condition = pVerSetConditionMask(condition, VER_MINORVERSION, VER_GREATER_EQUAL); - - status = pRtlVerifyVersionInfo(&info, - VER_MAJORVERSION | VER_MINORVERSION, - condition); - if (NT_SUCCESS(status)) { - FxLibraryGlobals.PassiveLevelInterruptSupport = TRUE; - } -} - VOID FxLibraryGlobalsQueryRegistrySettings( VOID @@ -558,7 +508,6 @@ FxLibraryGlobalsCommission( VOID ) { - PFN_RTL_GET_VERSION pRtlGetVersion; NTSTATUS status; // @@ -596,49 +545,10 @@ FxLibraryGlobalsCommission( // FxLibraryGlobals.SleepStudyDisabled = FALSE; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // + // Directed Power Transition support + // + FxLibraryGlobals.WdfDirectedPowerTransitionEnabled = FALSE; // // Query global WDF settings (both KMDF and UMDF). @@ -648,7 +558,7 @@ FxLibraryGlobalsCommission( #if ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE)) UNICODE_STRING funcName; - // For DSF support. + RtlInitUnicodeString(&funcName, L"IoConnectInterruptEx"); FxLibraryGlobals.IoConnectInterruptEx = (PFN_IO_CONNECT_INTERRUPT_EX) MmGetSystemRoutineAddress(&funcName); @@ -657,120 +567,18 @@ FxLibraryGlobalsCommission( FxLibraryGlobals.IoDisconnectInterruptEx = (PFN_IO_DISCONNECT_INTERRUPT_EX) MmGetSystemRoutineAddress(&funcName); - // 32 bit: W2k and forward. - // 64 bit: W2k -> Windows Server 2008 (obsolete otherwise). - RtlInitUnicodeString(&funcName, L"KeQueryActiveProcessors"); - FxLibraryGlobals.KeQueryActiveProcessors = (PFN_KE_QUERY_ACTIVE_PROCESSORS) - MmGetSystemRoutineAddress(&funcName); - - RtlInitUnicodeString(&funcName, L"KeSetTargetProcessorDpc"); - FxLibraryGlobals.KeSetTargetProcessorDpc = (PFN_KE_SET_TARGET_PROCESSOR_DPC) - MmGetSystemRoutineAddress(&funcName); - - // These should always be there (obsolete in 64 bit Win 7 and forward). - ASSERT(FxLibraryGlobals.KeQueryActiveProcessors != NULL && - FxLibraryGlobals.KeSetTargetProcessorDpc != NULL); - - // Win 7 and forward. - RtlInitUnicodeString(&funcName, L"KeQueryActiveGroupCount"); - if (MmGetSystemRoutineAddress(&funcName) != NULL) { - FxLibraryGlobals.ProcessorGroupSupport = TRUE; - } - - // Win 7 and forward. - RtlInitUnicodeString(&funcName, L"KeSetCoalescableTimer"); - FxLibraryGlobals.KeSetCoalescableTimer = (PFN_KE_SET_COALESCABLE_TIMER) - MmGetSystemRoutineAddress(&funcName); - - // Win 7 and forward. - RtlInitUnicodeString(&funcName, L"IoUnregisterPlugPlayNotificationEx"); - FxLibraryGlobals.IoUnregisterPlugPlayNotificationEx = (PFN_IO_UNREGISTER_PLUGPLAY_NOTIFICATION_EX) - MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxRegisterDevice"); - FxLibraryGlobals.PoxRegisterDevice = - (PFN_POX_REGISTER_DEVICE) MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxStartDevicePowerManagement"); - FxLibraryGlobals.PoxStartDevicePowerManagement = - (PFN_POX_START_DEVICE_POWER_MANAGEMENT) - MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxUnregisterDevice"); - FxLibraryGlobals.PoxUnregisterDevice = - (PFN_POX_UNREGISTER_DEVICE) - MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxActivateComponent"); - FxLibraryGlobals.PoxActivateComponent = (PFN_POX_ACTIVATE_COMPONENT) - MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxIdleComponent"); - FxLibraryGlobals.PoxIdleComponent = (PFN_POX_IDLE_COMPONENT) - MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxReportDevicePoweredOn"); - FxLibraryGlobals.PoxReportDevicePoweredOn = - (PFN_POX_REPORT_DEVICE_POWERED_ON) MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxCompleteIdleState"); - FxLibraryGlobals.PoxCompleteIdleState = - (PFN_POX_COMPLETE_IDLE_STATE) MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxCompleteIdleCondition"); - FxLibraryGlobals.PoxCompleteIdleCondition = - (PFN_POX_COMPLETE_IDLE_CONDITION) MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxCompleteDevicePowerNotRequired"); - FxLibraryGlobals.PoxCompleteDevicePowerNotRequired = - (PFN_POX_COMPLETE_DEVICE_POWER_NOT_REQUIRED) MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward - RtlInitUnicodeString(&funcName, L"PoFxSetDeviceIdleTimeout"); - FxLibraryGlobals.PoxSetDeviceIdleTimeout = - (PFN_POX_SET_DEVICE_IDLE_TIMEOUT) MmGetSystemRoutineAddress(&funcName); - - // Win 8 and forward RtlInitUnicodeString(&funcName, L"IoReportInterruptActive"); FxLibraryGlobals.IoReportInterruptActive = (PFN_IO_REPORT_INTERRUPT_ACTIVE) MmGetSystemRoutineAddress(&funcName); - // Win 8 and forward RtlInitUnicodeString(&funcName, L"IoReportInterruptInactive"); FxLibraryGlobals.IoReportInterruptInactive = (PFN_IO_REPORT_INTERRUPT_INACTIVE) MmGetSystemRoutineAddress(&funcName); - // Win 8.2 and forward - RtlInitUnicodeString(&funcName, L"VfCheckNxPoolType"); - FxLibraryGlobals.VfCheckNxPoolType = - (PFN_VF_CHECK_NX_POOL_TYPE) MmGetSystemRoutineAddress(&funcName); - - // RS5 and forward - RtlInitUnicodeString(&funcName, L"VfIsRuleClassEnabled"); - FxLibraryGlobals.VfIsRuleClassEnabled = - (PFN_VF_IS_RULE_CLASS_ENABLED) MmGetSystemRoutineAddress(&funcName); - #endif //((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE)) FxLibraryGlobals.OsVersionInfo.dwOSVersionInfoSize = sizeof(FxLibraryGlobals.OsVersionInfo); - - // User/Kernel agnostic. - - pRtlGetVersion = (PFN_RTL_GET_VERSION) - Mx::MxGetSystemRoutineAddress(MAKE_MX_FUNC_NAME("RtlGetVersion")); - - ASSERT(pRtlGetVersion != NULL); - pRtlGetVersion((PRTL_OSVERSIONINFOW) &FxLibraryGlobals.OsVersionInfo); - FxLibraryGlobalsVerifyVersion(); + RtlGetVersion((PRTL_OSVERSIONINFOW) &FxLibraryGlobals.OsVersionInfo); // // Initialize power management-related stuff. @@ -1093,8 +901,8 @@ Routine Description: const ULONG VrfWDFRuleClass = 33; - if (MmIsDriverVerifying (DriverObject) > 0 && (FxLibraryGlobals.VfIsRuleClassEnabled != NULL)) { - isWDFRuleClassTurnedOn = FxLibraryGlobals.VfIsRuleClassEnabled (VrfWDFRuleClass); + if (MmIsDriverVerifying (DriverObject) > 0) { + isWDFRuleClassTurnedOn = VfIsRuleClassEnabled (VrfWDFRuleClass); } return isWDFRuleClassTurnedOn; @@ -1613,7 +1421,7 @@ VOID FxOverrideDefaultVerifierSettings( __in HANDLE Key, __in LPWSTR Name, - __out PBOOLEAN OverrideValue + _Inout_ PBOOLEAN OverrideValue ) { UNICODE_STRING valueName; @@ -1679,13 +1487,7 @@ Routine Description: ULONG timeoutValue = 0; FxAutoRegKey hDriver, hWdf; - typedef NTSTATUS NTAPI QUERYFN( - ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID); - - QUERYFN* queryFn; - #if (FX_CORE_MODE==FX_CORE_KERNEL_MODE) - UNICODE_STRING FunctionName; DECLARE_CONST_UNICODE_STRING(parametersPath, L"Wdf"); UNREFERENCED_PARAMETER(RegistryPath); @@ -1800,31 +1602,7 @@ Routine Description: ASSERT(paramTable[i].QueryRoutine == NULL); ASSERT(paramTable[i].Name == NULL); -#if (FX_CORE_MODE==FX_CORE_USER_MODE) - - queryFn = (QUERYFN*) GetProcAddress( - GetModuleHandle(TEXT("ntdll.dll")), - "RtlQueryRegistryValuesEx" - ); - -#else - - RtlInitUnicodeString(&FunctionName, L"RtlQueryRegistryValuesEx"); - -#pragma warning(push) -#pragma warning(disable: 4055) - - queryFn = (QUERYFN*)MmGetSystemRoutineAddress(&FunctionName); - -#pragma warning(pop) - -#endif - - if (queryFn == NULL) { - queryFn = &RtlQueryRegistryValues; - } - - status = queryFn( + status = RtlQueryRegistryValuesEx( RTL_REGISTRY_OPTIONAL | RTL_REGISTRY_HANDLE, (PWSTR) hWdf.m_Key, ¶mTable[0], diff --git a/src/framework/shared/object/um/fxobjectum.cpp b/src/framework/shared/object/um/fxobjectum.cpp index 6a532e5..84ec399 100644 --- a/src/framework/shared/object/um/fxobjectum.cpp +++ b/src/framework/shared/object/um/fxobjectum.cpp @@ -170,6 +170,11 @@ Routine Description: // // Check the struct version (require an exact match for a private DDI) // + // NOTE: doc on WdfObjectQuery says the QueryBuffer is _Out_ only, but + // it is used as _Inout_ here. For now, let's keep the existing public + // contract as is, unless we have strong reason to change it. + // + #pragma prefast(suppress:__WARNING_USING_UNINIT_VAR, "Using uninitialized memory '*QueryBuffer'") if (FileObjectInterface->Size != RequiredBufferLength) { DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE, diff --git a/src/framework/shared/primitives/km/mxgeneralkm.cpp b/src/framework/shared/primitives/km/mxgeneralkm.cpp index 4b609c9..a2b5aaf 100644 --- a/src/framework/shared/primitives/km/mxgeneralkm.cpp +++ b/src/framework/shared/primitives/km/mxgeneralkm.cpp @@ -12,7 +12,7 @@ Mx::MxDbgPrint( { #if DBG -#define TEMP_BUFFER_SIZE 1024 +#define TEMP_BUFFER_SIZE 512 va_list list; CHAR debugMessageBuffer[TEMP_BUFFER_SIZE]; NTSTATUS status; diff --git a/src/framework/shared/primitives/um/mxgeneralum.cpp b/src/framework/shared/primitives/um/mxgeneralum.cpp index ec93b46..9d511d8 100644 --- a/src/framework/shared/primitives/um/mxgeneralum.cpp +++ b/src/framework/shared/primitives/um/mxgeneralum.cpp @@ -37,7 +37,7 @@ Mx::MxDbgPrint( { #if DBG -#define TEMP_BUFFER_SIZE 1024 +#define TEMP_BUFFER_SIZE 512 va_list list; CHAR debugMessageBuffer[TEMP_BUFFER_SIZE]; HRESULT hr; diff --git a/src/framework/shared/support/fxregistryapi.cpp b/src/framework/shared/support/fxregistryapi.cpp index 9de84e1..5f0cb02 100644 --- a/src/framework/shared/support/fxregistryapi.cpp +++ b/src/framework/shared/support/fxregistryapi.cpp @@ -498,19 +498,15 @@ WDFEXPORT(WdfRegistryQueryValue)( ValueLengthQueried, ValueType); if (!NT_SUCCESS(status)) { - UCHAR traceLevel = TRACE_LEVEL_ERROR; - // - // Label message as Verbose if this is the known pattern of + // Only log the error if it's not the known pattern of // passing a 0-length NULL buffer to query the required buffer size. // - if (status == STATUS_BUFFER_OVERFLOW && Value == NULL && ValueLength == 0) { - traceLevel = TRACE_LEVEL_VERBOSE; + if (!(status == STATUS_BUFFER_OVERFLOW && Value == NULL && ValueLength == 0)) { + DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, + "WDFKEY %p QueryValue failed, %!STATUS!", + Key, status); } - - DoTraceLevelMessage(pFxDriverGlobals, traceLevel, TRACINGERROR, - "WDFKEY %p QueryValue failed, %!STATUS!", - Key, status); } return status; diff --git a/src/framework/shared/support/fxrequestbuffer.cpp b/src/framework/shared/support/fxrequestbuffer.cpp index 41b4f22..70eba44 100644 --- a/src/framework/shared/support/fxrequestbuffer.cpp +++ b/src/framework/shared/support/fxrequestbuffer.cpp @@ -242,7 +242,7 @@ FxRequestBuffer::GetBuffer( return STATUS_SUCCESS; case FxRequestBufferMdl: - *Buffer = Mx::MxGetSystemAddressForMdlSafe(u.Mdl.Mdl, NormalPagePriority); + *Buffer = Mx::MxGetSystemAddressForMdlSafe(u.Mdl.Mdl, NormalPagePriority | MdlMappingNoExecute); if (*Buffer != NULL) { return STATUS_SUCCESS; } @@ -251,7 +251,7 @@ FxRequestBuffer::GetBuffer( } case FxRequestBufferReferencedMdl: - *Buffer = Mx::MxGetSystemAddressForMdlSafe(u.RefMdl.Mdl, NormalPagePriority); + *Buffer = Mx::MxGetSystemAddressForMdlSafe(u.RefMdl.Mdl, NormalPagePriority | MdlMappingNoExecute); if (*Buffer != NULL) { if (u.RefMdl.Offsets != NULL) { *Buffer = WDF_PTR_ADD_OFFSET(*Buffer, @@ -304,6 +304,7 @@ FxRequestBuffer::AssignValues( } } + *PPMdl = NULL; *PPBuffer = pBuffer; *BufferLength = (ULONG) bufferSize; break; diff --git a/src/framework/shared/support/fxspinlock.cpp b/src/framework/shared/support/fxspinlock.cpp index 7adb740..5093ba5 100644 --- a/src/framework/shared/support/fxspinlock.cpp +++ b/src/framework/shared/support/fxspinlock.cpp @@ -50,6 +50,7 @@ FxSpinLock::FxSpinLock( } +_At_(this->m_Irql, __drv_savesIRQL) __drv_raisesIRQL(DISPATCH_LEVEL) __drv_maxIRQL(DISPATCH_LEVEL) VOID @@ -83,6 +84,7 @@ FxSpinLock::AcquireLock( } } +_At_(this->m_Irql, __drv_restoresIRQL) __drv_requiresIRQL(DISPATCH_LEVEL) VOID FxSpinLock::ReleaseLock( diff --git a/src/framework/shared/support/fxspinlockapi.cpp b/src/framework/shared/support/fxspinlockapi.cpp index a9c5765..66f5350 100644 --- a/src/framework/shared/support/fxspinlockapi.cpp +++ b/src/framework/shared/support/fxspinlockapi.cpp @@ -108,6 +108,7 @@ WDFEXPORT(WdfSpinLockCreate)( __drv_raisesIRQL(DISPATCH_LEVEL) __drv_maxIRQL(DISPATCH_LEVEL) VOID +#pragma prefast(suppress:__WARNING_IRQL_NOT_SET, "No IRQL was saved into 'SpinLock'") WDFEXPORT(WdfSpinLockAcquire)( __in PWDF_DRIVER_GLOBALS DriverGlobals, @@ -145,6 +146,7 @@ WDFEXPORT(WdfSpinLockAcquire)( __drv_maxIRQL(DISPATCH_LEVEL) __drv_minIRQL(DISPATCH_LEVEL) VOID +#pragma prefast(suppress:__WARNING_IRQL_NOT_USED, "The IRQL in 'SpinLock' was never restored") WDFEXPORT(WdfSpinLockRelease)( __in PWDF_DRIVER_GLOBALS DriverGlobals, diff --git a/src/framework/shared/support/fxstringapi.cpp b/src/framework/shared/support/fxstringapi.cpp index 34f3f18..c238418 100644 --- a/src/framework/shared/support/fxstringapi.cpp +++ b/src/framework/shared/support/fxstringapi.cpp @@ -116,6 +116,7 @@ WDFEXPORT(WdfStringCreate)( __drv_maxIRQL(PASSIVE_LEVEL) VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*UnicodeString'") WDFEXPORT(WdfStringGetUnicodeString)( __in PWDF_DRIVER_GLOBALS DriverGlobals, diff --git a/src/framework/shared/support/fxtransactionedlist.cpp b/src/framework/shared/support/fxtransactionedlist.cpp index e970f1a..76cd648 100644 --- a/src/framework/shared/support/fxtransactionedlist.cpp +++ b/src/framework/shared/support/fxtransactionedlist.cpp @@ -529,6 +529,7 @@ FxSpinLockTransactionedList::ReleaseLock( _Acquires_lock_(_Global_critical_region_) VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*Irql'") FxWaitLockTransactionedList::AcquireLock( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __out PKIRQL Irql diff --git a/src/framework/shared/support/stringutil.cpp b/src/framework/shared/support/stringutil.cpp index 40a9e60..8dea755 100644 --- a/src/framework/shared/support/stringutil.cpp +++ b/src/framework/shared/support/stringutil.cpp @@ -180,7 +180,7 @@ NTSTATUS FxDuplicateUnicodeString( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in const UNICODE_STRING* Source, - __out PUNICODE_STRING Destination + _Inout_ PUNICODE_STRING Destination ) /*++ diff --git a/src/framework/shared/support/um/tracingum.cpp b/src/framework/shared/support/um/tracingum.cpp index 929cf5a..cec3ff2 100644 --- a/src/framework/shared/support/um/tracingum.cpp +++ b/src/framework/shared/support/um/tracingum.cpp @@ -24,6 +24,7 @@ Revision History: #include "FxSupportPch.hpp" #include "fxldrum.h" +#include extern "C" { #if defined(EVENT_TRACING) @@ -36,221 +37,6 @@ extern "C" { #include "fxIFR.h" // shared struct between IFR and debug ext. #include "fxIFRKm.h" // kernel mode only IFR definitions - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _Must_inspect_result_ NTSTATUS FxTraceInitialize( @@ -358,10 +144,13 @@ FxWmiTraceMessage( // Subcomponents for the In-Flight Recorder follow. //----------------------------------------------------------------------------- -ULONG -FxIFRGetSize( +VOID +FxIFRGetSettings( __in PFX_DRIVER_GLOBALS FxDriverGlobals, - __in PCUNICODE_STRING RegistryPath + __in PCUNICODE_STRING RegistryPath, + __out ULONG * Size, + __out BOOLEAN * UseTimeStamp, + __out BOOLEAN * PreciseTimeStamp ) /*++ @@ -371,15 +160,18 @@ Routine Description: Arguments: RegistryPath - path to the service - -Return Value: - The size of the IFR to create in bytes (not pages!) + [out] Size - The size of the IFR to create in bytes (not pages!) + [out] UseTimeStamp - Whether to store timestamp or not + [out] PreciseTimeStamp - Use precise timestamp. --*/ { FxAutoRegKey service, parameters; NTSTATUS status; ULONG numPages; + ULONG regValue; + BOOLEAN useTimeStamp; + BOOLEAN preciseTimeStamp; // // This is the value used in case of any error while retrieving 'LogPages' @@ -387,12 +179,17 @@ Return Value: // numPages = FxIFRMinLogPages; + useTimeStamp = TRUE; + preciseTimeStamp = FALSE; + // // External representation of the IFR is the "log", so use tha term when // overriding the size via the registry. // DECLARE_CONST_UNICODE_STRING(parametersPath, L"Parameters\\Wdf"); DECLARE_CONST_UNICODE_STRING(valueName, L"LogPages"); + DECLARE_CONST_UNICODE_STRING(nameTimeStamp, L"LogUseTimeStamp"); + DECLARE_CONST_UNICODE_STRING(namePreciseTimeStamp, L"LogPreciseTimeStamp"); // // UMDF may not provide this registry path @@ -418,26 +215,38 @@ Return Value: } status = FxRegKey::_QueryULong(parameters.m_Key, &valueName, &numPages); - if (!NT_SUCCESS(status)) { - goto defaultValues; + if (NT_SUCCESS(status)) { + if (numPages == 0) { + numPages = FxIFRMinLogPages; + } + // + // This behavior is different from KMDF. KMDF would allocate Average page count (5) + // if Verifier is on otherwise 1 page if the request is large. + // Since for UMDF the memory is coming from WudfRd, which does not know about verifier + // we will give it max pages here. + // + if (numPages > FxIFRMaxLogPages) { + numPages = FxIFRMaxLogPages; + } } - if (numPages == 0) { - numPages = FxIFRMinLogPages; + status = FxRegKey::_QueryULong(parameters.m_Key, &nameTimeStamp, ®Value); + if (NT_SUCCESS(status)) { + useTimeStamp = (regValue != 0); } -defaultValues: - // - // This behavior is different from KMDF. KMDF would allocate Average page count (5) - // if Verifier is on otherwise 1 page if the request is large. - // Since for UMDF the memory is coming from WudfRd, which does not know about verifier - // we will give it max pages here. - // - if (numPages > FxIFRMaxLogPages) { - numPages = FxIFRMaxLogPages; + if (useTimeStamp) { + status = FxRegKey::_QueryULong(parameters.m_Key, &namePreciseTimeStamp, ®Value); + if (NT_SUCCESS(status)) { + preciseTimeStamp = (regValue != 0); + } } - return numPages * PAGE_SIZE; +defaultValues: + + *Size = numPages * PAGE_SIZE; + *UseTimeStamp = useTimeStamp; + *PreciseTimeStamp = preciseTimeStamp; } VOID @@ -476,6 +285,8 @@ Routine Description: LONG i; DECLARE_UNICODE_STRING_SIZE(svcNameW, WDF_DRIVER_GLOBALS_NAME_LEN); NTSTATUS ntStatus; + BOOLEAN useTimeStamp; + BOOLEAN preciseTimeStamp; // // Return early if IFR is disabled. @@ -485,8 +296,6 @@ Routine Description: return; } - WDFCASSERT(FxIFRRecordSignature == WDF_IFR_RECORD_SIGNATURE); - if (FxDriverGlobals == NULL || FxDriverGlobals->WdfLogHeader != NULL) { return; } @@ -519,7 +328,9 @@ Routine Description: serviceName = &RegistryPath->Buffer[i+1]; - sizeCb = FxIFRGetSize(FxDriverGlobals, RegistryPath); + FxIFRGetSettings(FxDriverGlobals, RegistryPath, &sizeCb, + &useTimeStamp, &preciseTimeStamp); + pageCount = sizeCb / PAGE_SIZE; umDriverObject = (PDRIVER_OBJECT_UM)DriverObject; @@ -573,6 +384,8 @@ Routine Description: pHeader->Base = (PUCHAR) &pHeader[1]; pHeader->Size = allocatedBufferLengthCb - sizeof(WDF_IFR_HEADER); + pHeader->UseTimeStamp = useTimeStamp; + pHeader->PreciseTimeStamp = preciseTimeStamp; pHeader->Offset.u.s.Current = 0; pHeader->Offset.u.s.Previous = 0; @@ -674,6 +487,7 @@ Routine Description: { size_t size; PWDF_IFR_RECORD record; + PWDF_IFR_HEADER header; UNREFERENCED_PARAMETER( MessageLevel ); @@ -757,22 +571,29 @@ Routine Description: } } - size += sizeof(WDF_IFR_RECORD); + header = (PWDF_IFR_HEADER) FxDriverGlobals->WdfLogHeader; + ASSERT(header->Size < FxIFRMaxLogSize); // size doesn't include header. + ASSERT(header->Size >= header->Offset.u.s.Current); + ASSERT(header->Size >= header->Offset.u.s.Previous); + + // + // Allocate memory for timestamp only if necessary. + // + size_t recordSize = header->UseTimeStamp + ? sizeof(WDF_IFR_RECORD) + : sizeof(WDF_IFR_RECORD_V1); + + size += recordSize; // // Allocate log space of the calculated size // { - PWDF_IFR_HEADER header; WDF_IFR_OFFSET offsetRet; WDF_IFR_OFFSET offsetCur; WDF_IFR_OFFSET offsetNew; USHORT usSize = (USHORT) size; // for a prefast artifact. - header = (PWDF_IFR_HEADER) FxDriverGlobals->WdfLogHeader; - ASSERT(header->Size < FxIFRMaxLogSize); // size doesn't include header. - ASSERT(header->Size >= header->Offset.u.s.Current); - ASSERT(header->Size >= header->Offset.u.s.Previous); // // Allocate space for the log in our circular buffer in a lockless way. @@ -851,12 +672,26 @@ Routine Description: // // Build record (fill all fields!) // - record->Signature = FxIFRRecordSignature; record->Length = (USHORT) size; record->PrevOffset = (USHORT) offsetRet.u.s.Previous; record->MessageNumber = MessageNumber; record->Sequence = InterlockedIncrement(header->SequenceNumberPointer); record->MessageGuid = *MessageGuid; + + if (!header->UseTimeStamp) { + record->Signature = WDF_IFR_RECORD_SIGNATURE_V1; + } else { + record->Signature = WDF_IFR_RECORD_SIGNATURE; + LARGE_INTEGER timestamp; + if (header->PreciseTimeStamp) { + Mx::MxQuerySystemTimePrecise(×tamp); + } + else { + Mx::MxQuerySystemTime(×tamp); + } + record->TimeStamp.LowPart = timestamp.LowPart; + record->TimeStamp.HighPart = timestamp.HighPart; + } } // @@ -868,7 +703,7 @@ Routine Description: PVOID source; PUCHAR argsData; - argsData = (UCHAR*) &record[1]; + argsData = ((UCHAR*)record) + recordSize; va_start(ap, MessageNumber); diff --git a/src/framework/shared/targets/general/fxiotarget.cpp b/src/framework/shared/targets/general/fxiotarget.cpp index 36f238f..0ff1e6b 100644 --- a/src/framework/shared/targets/general/fxiotarget.cpp +++ b/src/framework/shared/targets/general/fxiotarget.cpp @@ -1656,11 +1656,11 @@ NTSTATUS FxIoTarget::SubmitSync( __in FxRequestBase* Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options, - __out_opt PULONG Action + _Inout_opt_ PULONG Action ) { FxTargetSubmitSyncParams params = {0}; - LONGLONG timeout; + LONGLONG timeout = 0; ULONG action; NTSTATUS status; KIRQL irql; diff --git a/src/framework/shared/targets/general/fxiotargetremote.cpp b/src/framework/shared/targets/general/fxiotargetremote.cpp index f5dc56e..f55de6f 100644 --- a/src/framework/shared/targets/general/fxiotargetremote.cpp +++ b/src/framework/shared/targets/general/fxiotargetremote.cpp @@ -202,7 +202,7 @@ FxIoTargetRemote::Open( __in PWDF_IO_TARGET_OPEN_PARAMS OpenParams ) { - FxIoTargetRemoveOpenParams params, *pParams; + FxIoTargetRemoteOpenParams params, *pParams; UNICODE_STRING name; LIST_ENTRY pended; WDF_IO_TARGET_OPEN_TYPE type; @@ -779,7 +779,7 @@ FxIoTargetRemote::Remove( } VOID -FxIoTargetRemoveOpenParams::Clear( +FxIoTargetRemoteOpenParams::Clear( VOID ) { @@ -791,11 +791,11 @@ FxIoTargetRemoveOpenParams::Clear( FxPoolFree(TargetDeviceName.Buffer); } - RtlZeroMemory(this, sizeof(FxIoTargetRemoveOpenParams)); + RtlZeroMemory(this, sizeof(FxIoTargetRemoteOpenParams)); } VOID -FxIoTargetRemoveOpenParams::Set( +FxIoTargetRemoteOpenParams::Set( __in PWDF_IO_TARGET_OPEN_PARAMS OpenParams, __in PUNICODE_STRING Name, __in PVOID Ea, diff --git a/src/framework/shared/targets/general/km/fxiotargetremotekm.cpp b/src/framework/shared/targets/general/km/fxiotargetremotekm.cpp index 57e09a7..3242911 100644 --- a/src/framework/shared/targets/general/km/fxiotargetremotekm.cpp +++ b/src/framework/shared/targets/general/km/fxiotargetremotekm.cpp @@ -143,7 +143,7 @@ FxIoTargetRemote::RegisterForPnpNotification( ) { NTSTATUS status; - + // // Register for PNP notifications on the handle we just opened. // This will notify us of pnp state changes on the handle. @@ -166,42 +166,14 @@ FxIoTargetRemote::UnregisterForPnpNotification( ) { if (Handle != NULL) { - - - - - - - - - - - - - - - - - - - - - - - - if (FxLibraryGlobals.IoUnregisterPlugPlayNotificationEx != NULL) { - FxLibraryGlobals.IoUnregisterPlugPlayNotificationEx(Handle); - } - else { - IoUnregisterPlugPlayNotification(Handle); - } + IoUnregisterPlugPlayNotificationEx(Handle); } } NTSTATUS FxIoTargetRemote::OpenTargetHandle( _In_ PWDF_IO_TARGET_OPEN_PARAMS OpenParams, - _Inout_ FxIoTargetRemoveOpenParams* pParams + _Inout_ FxIoTargetRemoteOpenParams* pParams ) { OBJECT_ATTRIBUTES oa; @@ -213,7 +185,7 @@ FxIoTargetRemote::OpenTargetHandle( OBJ_KERNEL_HANDLE, NULL, NULL); - + status = ZwCreateFile(&m_TargetHandle, pParams->DesiredAccess, &oa, @@ -225,15 +197,15 @@ FxIoTargetRemote::OpenTargetHandle( pParams->CreateOptions, pParams->EaBuffer, pParams->EaBufferLength); - + OpenParams->FileInformation = (ULONG)ioStatus.Information; - + if (NT_SUCCESS(status)) { DoTraceLevelMessage( GetDriverGlobals(), TRACE_LEVEL_WARNING, TRACINGIOTARGET, "ZwCreateFile for WDFIOTARGET %p returned status %!STATUS!, info 0x%x", GetObjectHandle(), status, (ULONG) ioStatus.Information); - + // // The open operation was successful. Dereference the file handle and // obtain a pointer to the device object for the handle. @@ -245,16 +217,16 @@ FxIoTargetRemote::OpenTargetHandle( KernelMode, (PVOID*) &m_TargetFileObject, NULL); - + if (NT_SUCCESS(status)) { m_TargetDevice = IoGetRelatedDeviceObject(m_TargetFileObject); - + if (m_TargetDevice == NULL) { DoTraceLevelMessage( GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIOTARGET, "WDFIOTARGET %p, could not convert filobj %p to devobj", GetObjectHandle(), m_TargetFileObject); - + status = STATUS_NO_SUCH_DEVICE; } } @@ -285,42 +257,42 @@ FxIoTargetRemote::GetTargetDeviceRelations( FxAutoIrp irp(NULL); PIRP pIrp; NTSTATUS status; - + pTopOfStack = IoGetAttachedDeviceReference(m_TargetDevice); - + pIrp = IoAllocateIrp(pTopOfStack->StackSize, FALSE); - + if (pIrp != NULL) { PIO_STACK_LOCATION stack; - + irp.SetIrp(pIrp); - + stack = irp.GetNextIrpStackLocation(); stack->MajorFunction = IRP_MJ_PNP; stack->MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS; stack->Parameters.QueryDeviceRelations.Type = TargetDeviceRelation; - + // // Initialize the status to error in case the bus driver decides not // to set it correctly. // irp.SetStatus(STATUS_NOT_SUPPORTED); - + status = irp.SendIrpSynchronously(pTopOfStack); - + if (NT_SUCCESS(status)) { PDEVICE_RELATIONS pRelations; - + pRelations = (PDEVICE_RELATIONS) irp.GetInformation(); - + ASSERT(pRelations != NULL); - + // // m_TargetPdo was referenced by the bus driver, it will be // dereferenced when the target is closed. // m_TargetPdo = pRelations->Objects[0]; - + // // We, as the caller, are responsible for freeing the relations // that the bus driver allocated. @@ -341,10 +313,10 @@ FxIoTargetRemote::GetTargetDeviceRelations( status = STATUS_INSUFFICIENT_RESOURCES; DoTraceLevelMessage( GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIOTARGET, - "Unable to allocate memory for IRP WDFIOTARGET %p, %!STATUS!", + "Unable to allocate memory for IRP WDFIOTARGET %p, %!STATUS!", GetObjectHandle(), status); } - + // // Only fail the open if we cannot allocate an irp or if the lower // driver could not allocate a relations. @@ -355,7 +327,7 @@ FxIoTargetRemote::GetTargetDeviceRelations( else { status = STATUS_SUCCESS; } - + // // Remove the reference taken by IoGetAttachedDeviceReference // diff --git a/src/framework/shared/targets/general/um/fxiotargetremoteum.cpp b/src/framework/shared/targets/general/um/fxiotargetremoteum.cpp index 97deff7..b2eb673 100644 --- a/src/framework/shared/targets/general/um/fxiotargetremoteum.cpp +++ b/src/framework/shared/targets/general/um/fxiotargetremoteum.cpp @@ -37,9 +37,9 @@ FxIoTargetRemote::InitRemoteModeSpecific( IWudfDeviceStack* devStack; devStack = Device->GetDeviceObject()->GetDeviceStackInterface(); - + // - // Event initialization can fail in UM so initialize it now instead of in + // Event initialization can fail in UM so initialize it now instead of in // constructor. // status = m_OpenedEvent.Initialize(); @@ -68,15 +68,14 @@ FxIoTargetRemote::InitRemoteModeSpecific( "Failed to Create RemoteDispatcher, %!STATUS!", status); return status; } - - return status; + + return status; } VOID FxIoTargetRemote::RemoveModeSpecific( VOID ) - { // // Delete callback object @@ -89,7 +88,7 @@ FxIoTargetRemote::RemoveModeSpecific( NTSTATUS FxIoTargetRemote::OpenTargetHandle( _In_ PWDF_IO_TARGET_OPEN_PARAMS OpenParams, - _Inout_ FxIoTargetRemoveOpenParams* pParams + _Inout_ FxIoTargetRemoteOpenParams* pParams ) { NTSTATUS status; @@ -106,11 +105,11 @@ FxIoTargetRemote::OpenTargetHandle( // DWORD dwDesiredAccess // typedef struct _UMDF_IO_TARGET_OPEN_PARAMS // { - // DWORD dwShareMode; // + // DWORD dwShareMode; // // DWORD dwCreationDisposition; // DWORD dwFlagsAndAttributes; // } UMDF_IO_TARGET_OPEN_PARAMS; - // + // // // We always use overlapped I/O // @@ -139,7 +138,7 @@ FxIoTargetRemote::OpenTargetHandle( m_TargetHandle = hTarget; status = STATUS_SUCCESS; } - + return status; } @@ -161,11 +160,11 @@ FxIoTargetRemote::GetTargetHandle( } else { ASSERT(m_TargetHandle == NULL); - + hrQi = m_TargetFileObject->QueryInterface(IID_IWudfFile2, (PVOID*)&pFile); FX_VERIFY(INTERNAL, CHECK_QI(hrQi, pFile)); pFile->Release(); - + handle = pFile->GetWeakRefHandle(); } } @@ -216,7 +215,7 @@ FxIoTargetRemote::UnbindHandle( // Close the handle we gave to the RemoteDispatcher // // NOTE: IWudfRemoteDispatcher::CloseHandle can be safely called even if - // we've not previously given it a handle. In this case, it does + // we've not previously given it a handle. In this case, it does // nothing. // DoTraceLevelMessage( @@ -258,13 +257,11 @@ FxIoTargetRemote::RegisterForPnpNotification( HRESULT hr; FxIoTargetRemoteNotificationCallback* callback; - UNREFERENCED_PARAMETER(hr); - // // Allocate callback object // if (m_NotificationCallback == NULL) { - callback = new (GetDriverGlobals()) + callback = new (GetDriverGlobals()) FxIoTargetRemoteNotificationCallback(GetDriverGlobals(), this); if (callback == NULL) { @@ -279,7 +276,7 @@ FxIoTargetRemote::RegisterForPnpNotification( m_NotificationCallback = callback; } - + // // Register for Target Device Change notifications // These notifications will arrive asynchronously. @@ -293,7 +290,7 @@ FxIoTargetRemote::RegisterForPnpNotification( if (FAILED(hr)) { SAFE_RELEASE(m_NotificationCallback); - + status = m_Device->NtStatusFromHr(hr); DoTraceLevelMessage( GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIOTARGET, @@ -322,13 +319,13 @@ FxIoTargetRemote::UnregisterForPnpNotification( if (NotifyHandle == WUDF_TARGET_CONTEXT_INVALID) { return; } - + // // Unregister. // IWudfDeviceStack * pDevStack = m_Device->GetDeviceStack(); pDevStack->UnregisterTargetDeviceNotification(NotifyHandle); - + } NTSTATUS @@ -345,16 +342,16 @@ FxIoTargetRemote::OpenLocalTargetByFile( ASSERT(OpenParams->Type == WdfIoTargetOpenLocalTargetByFile); m_OpenParams.OpenType = OpenParams->Type; - // + // // Create a file object. This is UM-specific feature, where host opens // the reflector control device (optionally supplying the reference string - // provided by caller). If there are lower device drivers in the um stack, + // provided by caller). If there are lower device drivers in the um stack, // host sends them IRP_MJ_CREATE as well. The lower drivers in kernel see // IRP_MJ_CREATE as well as a result of opening the reflector control - // object. + // object. // Note that m_TargetDevice is already set to next lower device during init. // - status = CreateWdfFileObject(&OpenParams->FileName, + status = CreateWdfFileObject(&OpenParams->FileName, &m_TargetFileObject); if (!NT_SUCCESS(status)) { @@ -423,7 +420,7 @@ FxIoTargetRemote::CloseWdfFileObject( SAFE_RELEASE(FileObject); } -BOOL +BOOL __stdcall FxIoTargetRemoteNotificationCallback::OnQueryRemove( _In_ WUDF_TARGET_CONTEXT RegistrationID @@ -448,13 +445,13 @@ FxIoTargetRemoteNotificationCallback::OnQueryRemove( status = STATUS_SUCCESS; bStatus = TRUE; - + if (GetRegistrationId() != RegistrationID) { // // By design, we can get notification callbacks even after we have - // unregistered for notifications. This can happen if there were - // callbacks already in flight before we unregistered. In this case, we - // simply succeed on query-remove. Since we have already unregistered, + // unregistered for notifications. This can happen if there were + // callbacks already in flight before we unregistered. In this case, we + // simply succeed on query-remove. Since we have already unregistered, // there is no reason for us to fail query-remove. // DoTraceLevelMessage( @@ -467,9 +464,9 @@ FxIoTargetRemoteNotificationCallback::OnQueryRemove( DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, - "WDFIOTARGET %p: query remove notification", + "WDFIOTARGET %p: query remove notification", m_RemoteTarget->GetObjectHandle()); - + // // Device is gracefully being removed. PnP is asking us to close down // the target. If there is a driver callback, there is *no* default @@ -486,7 +483,7 @@ FxIoTargetRemoteNotificationCallback::OnQueryRemove( pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFIOTARGET %p: query remove, default action (close for QR)", pRemoteTarget->GetObjectHandle()); - + // // No callback, close it down conditionally. // @@ -498,13 +495,13 @@ FxIoTargetRemoteNotificationCallback::OnQueryRemove( } exit: - + pRemoteTarget->RELEASE(this); return bStatus; } -VOID +VOID __stdcall FxIoTargetRemoteNotificationCallback::OnRemoveComplete( _In_ WUDF_TARGET_CONTEXT RegistrationID @@ -536,7 +533,7 @@ FxIoTargetRemoteNotificationCallback::OnRemoveComplete( DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFIOTARGET %p: remove complete notification", pRemoteTarget->GetObjectHandle()); - + // // The device was surprise removed, close it for good if the driver has // no override. @@ -549,7 +546,7 @@ FxIoTargetRemoteNotificationCallback::OnRemoveComplete( pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFIOTARGET %p: remove complete, default action (close)", pRemoteTarget->GetObjectHandle()); - + // // The device is now gone for good. Close down the target for good. // @@ -557,11 +554,11 @@ FxIoTargetRemoteNotificationCallback::OnRemoveComplete( } exit: - + pRemoteTarget->RELEASE(this); } -VOID +VOID __stdcall FxIoTargetRemoteNotificationCallback::OnRemoveCanceled( _In_ WUDF_TARGET_CONTEXT RegistrationID @@ -595,20 +592,20 @@ FxIoTargetRemoteNotificationCallback::OnRemoveCanceled( DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFIOTARGET %p: remove canceled notification", pRemoteTarget->GetObjectHandle()); - + if (pRemoteTarget->m_EvtRemoveCanceled.m_Method != NULL) { pRemoteTarget->m_EvtRemoveCanceled.Invoke(pRemoteTarget->GetHandle()); } else { WDF_IO_TARGET_OPEN_PARAMS params; - + DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET, "WDFIOTARGET %p: remove canceled, default action (reopen)", pRemoteTarget->GetObjectHandle()); - + WDF_IO_TARGET_OPEN_PARAMS_INIT_REOPEN(¶ms); - + // // Attempt to reopen the target with stored settings // @@ -624,11 +621,11 @@ FxIoTargetRemoteNotificationCallback::OnRemoveCanceled( } exit: - + pRemoteTarget->RELEASE(this); } -VOID +VOID __stdcall FxIoTargetRemoteNotificationCallback::OnCustomEvent( _In_ WUDF_TARGET_CONTEXT RegistrationID, diff --git a/src/framework/shared/targets/usb/fxusbdeviceapi.cpp b/src/framework/shared/targets/usb/fxusbdeviceapi.cpp index 4196218..ffee465 100644 --- a/src/framework/shared/targets/usb/fxusbdeviceapi.cpp +++ b/src/framework/shared/targets/usb/fxusbdeviceapi.cpp @@ -256,7 +256,7 @@ WDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFUSBDEVICE UsbDevice, - __out + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ) { @@ -291,6 +291,7 @@ WDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( __drv_maxIRQL(PASSIVE_LEVEL) VOID WDFAPI +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "On failure case, '*UsbDeviceDescriptor' is not initialized") WDFEXPORT(WdfUsbTargetDeviceGetDeviceDescriptor)( __in PWDF_DRIVER_GLOBALS DriverGlobals, @@ -1293,6 +1294,7 @@ Return Value: return status; } + #pragma prefast(suppress:__WARNING_USING_UNINIT_VAR, "Using uninitialized memory '**Urb'") status = pUsbDevice->CreateIsochUrb(Attributes, NumberOfIsochPackets, UrbMemory, diff --git a/src/framework/shared/targets/usb/fxusbinterface.cpp b/src/framework/shared/targets/usb/fxusbinterface.cpp index 8dcec5e..9c7c4d0 100644 --- a/src/framework/shared/targets/usb/fxusbinterface.cpp +++ b/src/framework/shared/targets/usb/fxusbinterface.cpp @@ -1016,6 +1016,7 @@ Return Value: PipeInfo->SettingIndex = SettingIndex; } +_Success_(return != NULL) WDFUSBPIPE FxUsbInterface::GetConfiguredPipe( __in UCHAR PipeIndex, @@ -1050,7 +1051,7 @@ Return Value: VOID FxUsbInterface::GetDescriptor( - __in PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, + _Out_ PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, __in UCHAR SettingIndex ) /*++ diff --git a/src/framework/shared/targets/usb/fxusbinterfaceapi.cpp b/src/framework/shared/targets/usb/fxusbinterfaceapi.cpp index 6095efe..ee41310 100644 --- a/src/framework/shared/targets/usb/fxusbinterfaceapi.cpp +++ b/src/framework/shared/targets/usb/fxusbinterfaceapi.cpp @@ -240,7 +240,7 @@ WDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, __in UCHAR EndpointIndex, - __out + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ) /*++ @@ -445,7 +445,7 @@ WDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, __in UCHAR PipeIndex, - __out_opt + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ) /*++ diff --git a/src/framework/shared/targets/usb/km/fxusbdeviceapikm.cpp b/src/framework/shared/targets/usb/km/fxusbdeviceapikm.cpp index 677d69f..796d892 100644 --- a/src/framework/shared/targets/usb/km/fxusbdeviceapikm.cpp +++ b/src/framework/shared/targets/usb/km/fxusbdeviceapikm.cpp @@ -437,6 +437,7 @@ Return Value: return status; } + #pragma prefast(suppress:__WARNING_USING_UNINIT_VAR, "Using uninitialized memory '**Urb'") status = pUsbDevice->CreateUrb(Attributes, UrbMemory, Urb); return status; diff --git a/src/framework/shared/targets/usb/usbutil.cpp b/src/framework/shared/targets/usb/usbutil.cpp index 7f8c0b1..e9966cf 100644 --- a/src/framework/shared/targets/usb/usbutil.cpp +++ b/src/framework/shared/targets/usb/usbutil.cpp @@ -552,12 +552,13 @@ Return Value: } VOID +#pragma prefast(suppress:__WARNING_RETURN_UNINIT_VAR, "Returning uninitialized memory '*Buffer'") FxUsbUmInitDescriptorUrb( - __inout PUMURB UmUrb, + _Out_ PUMURB UmUrb, __in WINUSB_INTERFACE_HANDLE WinUsbHandle, __in UCHAR DescriptorType, __in ULONG BufferLength, - __in PVOID Buffer + _Out_ PVOID Buffer ) { RtlZeroMemory(UmUrb, sizeof(UMURB)); diff --git a/src/framework/shared/targets/usb/usbutil.hpp b/src/framework/shared/targets/usb/usbutil.hpp index f823cc3..c84f6c7 100644 --- a/src/framework/shared/targets/usb/usbutil.hpp +++ b/src/framework/shared/targets/usb/usbutil.hpp @@ -143,11 +143,11 @@ FxUsbUmFormatRequest( VOID FxUsbUmInitDescriptorUrb( - __inout PUMURB UmUrb, + _Out_ PUMURB UmUrb, __in WINUSB_INTERFACE_HANDLE WinUsbHandle, __in UCHAR DescriptorType, __in ULONG BufferLength, - __in PVOID Buffer + _Out_ PVOID Buffer ); VOID diff --git a/src/framework/umdf/fxlib/librarycommon/fxlibrarycommon.h b/src/framework/umdf/fxlib/librarycommon/fxlibrarycommon.h index 5e86de1..bbdcb6d 100644 --- a/src/framework/umdf/fxlib/librarycommon/fxlibrarycommon.h +++ b/src/framework/umdf/fxlib/librarycommon/fxlibrarycommon.h @@ -35,12 +35,6 @@ extern RTL_OSVERSIONINFOW gOsVersion; #define WIDEN2(str) L##str #define WDF_UNKNOWN_SERVICE_NAME "Unknown" -typedef -NTSTATUS -(*PFN_RTL_GET_VERSION)( - OUT PRTL_OSVERSIONINFOW VersionInformation - ); - NTSTATUS FxLibraryCommonCommission( VOID diff --git a/src/framework/umdf/fxlib/version/fxdynamics.h b/src/framework/umdf/fxlib/version/fxdynamics.h index 24d2e32..a88c75b 100644 --- a/src/framework/umdf/fxlib/version/fxdynamics.h +++ b/src/framework/umdf/fxlib/version/fxdynamics.h @@ -677,7 +677,7 @@ WDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ); @@ -1974,7 +1974,7 @@ WDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ); @@ -3283,7 +3283,7 @@ WDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ); @@ -3336,7 +3336,7 @@ WDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); @@ -3857,7 +3857,7 @@ WDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ); @@ -4348,7 +4348,7 @@ WDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ); @@ -4398,7 +4398,7 @@ WDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ); diff --git a/src/framework/umdf/fxlib/version/vffxdynamics.h b/src/framework/umdf/fxlib/version/vffxdynamics.h index b1de709..f91c1ca 100644 --- a/src/framework/umdf/fxlib/version/vffxdynamics.h +++ b/src/framework/umdf/fxlib/version/vffxdynamics.h @@ -299,7 +299,7 @@ VFWDFEXPORT(WdfDeviceGetDeviceState)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ); @@ -1596,7 +1596,7 @@ VFWDFEXPORT(WdfInterruptGetInfo)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ); @@ -2905,7 +2905,7 @@ VFWDFEXPORT(WdfRequestGetCompletionParams)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ); @@ -2958,7 +2958,7 @@ VFWDFEXPORT(WdfRequestGetParameters)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); @@ -3479,7 +3479,7 @@ VFWDFEXPORT(WdfUsbTargetDeviceRetrieveInformation)( PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ); @@ -3970,7 +3970,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetEndpointInformation)( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ); @@ -4020,7 +4020,7 @@ VFWDFEXPORT(WdfUsbInterfaceGetConfiguredPipe)( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ); diff --git a/src/publicinc/wdf/kmdf/1.33/wdfdevice.h b/src/publicinc/wdf/kmdf/1.33/wdfdevice.h index 1c0b061..f4bda21 100644 --- a/src/publicinc/wdf/kmdf/1.33/wdfdevice.h +++ b/src/publicinc/wdf/kmdf/1.33/wdfdevice.h @@ -2066,7 +2066,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ); @@ -2076,7 +2076,7 @@ VOID WdfDeviceGetDeviceState( _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ) { diff --git a/src/publicinc/wdf/kmdf/1.33/wdfinterrupt.h b/src/publicinc/wdf/kmdf/1.33/wdfinterrupt.h index 9273804..8452393 100644 --- a/src/publicinc/wdf/kmdf/1.33/wdfinterrupt.h +++ b/src/publicinc/wdf/kmdf/1.33/wdfinterrupt.h @@ -616,7 +616,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ); @@ -626,7 +626,7 @@ VOID WdfInterruptGetInfo( _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ) { diff --git a/src/publicinc/wdf/kmdf/1.33/wdfrequest.h b/src/publicinc/wdf/kmdf/1.33/wdfrequest.h index 60029cd..c503868 100644 --- a/src/publicinc/wdf/kmdf/1.33/wdfrequest.h +++ b/src/publicinc/wdf/kmdf/1.33/wdfrequest.h @@ -953,7 +953,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ); @@ -963,7 +963,7 @@ VOID WdfRequestGetCompletionParams( _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ) { @@ -1104,7 +1104,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); @@ -1114,7 +1114,7 @@ VOID WdfRequestGetParameters( _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { diff --git a/src/publicinc/wdf/kmdf/1.33/wdfusb.h b/src/publicinc/wdf/kmdf/1.33/wdfusb.h index d3235df..378e32e 100644 --- a/src/publicinc/wdf/kmdf/1.33/wdfusb.h +++ b/src/publicinc/wdf/kmdf/1.33/wdfusb.h @@ -974,7 +974,7 @@ NTSTATUS PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ); @@ -985,7 +985,7 @@ NTSTATUS WdfUsbTargetDeviceRetrieveInformation( _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ) { @@ -2426,7 +2426,7 @@ VOID UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ); @@ -2440,7 +2440,7 @@ WdfUsbInterfaceGetEndpointInformation( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ) { @@ -2542,7 +2542,7 @@ WDFUSBPIPE WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ); @@ -2554,7 +2554,7 @@ WdfUsbInterfaceGetConfiguredPipe( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ) { diff --git a/src/publicinc/wdf/umdf/2.33/wdfdevice.h b/src/publicinc/wdf/umdf/2.33/wdfdevice.h index fd96641..ad0c745 100644 --- a/src/publicinc/wdf/umdf/2.33/wdfdevice.h +++ b/src/publicinc/wdf/umdf/2.33/wdfdevice.h @@ -2136,7 +2136,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ); @@ -2146,7 +2146,7 @@ VOID WdfDeviceGetDeviceState( _In_ WDFDEVICE Device, - _Out_ + _Inout_ PWDF_DEVICE_STATE DeviceState ) { diff --git a/src/publicinc/wdf/umdf/2.33/wdfinterrupt.h b/src/publicinc/wdf/umdf/2.33/wdfinterrupt.h index cfba04e..e4acbb1 100644 --- a/src/publicinc/wdf/umdf/2.33/wdfinterrupt.h +++ b/src/publicinc/wdf/umdf/2.33/wdfinterrupt.h @@ -591,7 +591,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ); @@ -601,7 +601,7 @@ VOID WdfInterruptGetInfo( _In_ WDFINTERRUPT Interrupt, - _Out_ + _Inout_ PWDF_INTERRUPT_INFO Info ) { diff --git a/src/publicinc/wdf/umdf/2.33/wdfrequest.h b/src/publicinc/wdf/umdf/2.33/wdfrequest.h index d46156a..50c7511 100644 --- a/src/publicinc/wdf/umdf/2.33/wdfrequest.h +++ b/src/publicinc/wdf/umdf/2.33/wdfrequest.h @@ -896,7 +896,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ); @@ -906,7 +906,7 @@ VOID WdfRequestGetCompletionParams( _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_COMPLETION_PARAMS Params ) { @@ -1018,7 +1018,7 @@ VOID PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ); @@ -1028,7 +1028,7 @@ VOID WdfRequestGetParameters( _In_ WDFREQUEST Request, - _Out_ + _Inout_ PWDF_REQUEST_PARAMETERS Parameters ) { diff --git a/src/publicinc/wdf/umdf/2.33/wdfusb.h b/src/publicinc/wdf/umdf/2.33/wdfusb.h index 68c34e0..8a8e57d 100644 --- a/src/publicinc/wdf/umdf/2.33/wdfusb.h +++ b/src/publicinc/wdf/umdf/2.33/wdfusb.h @@ -963,7 +963,7 @@ NTSTATUS PWDF_DRIVER_GLOBALS DriverGlobals, _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ); @@ -974,7 +974,7 @@ NTSTATUS WdfUsbTargetDeviceRetrieveInformation( _In_ WDFUSBDEVICE UsbDevice, - _Out_ + _Inout_ PWDF_USB_DEVICE_INFORMATION Information ) { @@ -2067,7 +2067,7 @@ VOID UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ); @@ -2081,7 +2081,7 @@ WdfUsbInterfaceGetEndpointInformation( UCHAR SettingIndex, _In_ UCHAR EndpointIndex, - _Out_ + _Inout_ PWDF_USB_PIPE_INFORMATION EndpointInfo ) { @@ -2187,7 +2187,7 @@ WDFUSBPIPE WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ); @@ -2199,7 +2199,7 @@ WdfUsbInterfaceGetConfiguredPipe( WDFUSBINTERFACE UsbInterface, _In_ UCHAR PipeIndex, - _Out_opt_ + _Inout_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo ) { diff --git a/src/publicinc/wdf/umdf/2.33/wudfwdm.h b/src/publicinc/wdf/umdf/2.33/wudfwdm.h index cd87587..563f822 100644 --- a/src/publicinc/wdf/umdf/2.33/wudfwdm.h +++ b/src/publicinc/wdf/umdf/2.33/wudfwdm.h @@ -598,6 +598,7 @@ typedef struct _PO_FX_DEVICE_V2 { #define PO_FX_DEVICE_FLAG_DISABLE_FAST_RESUME (0x0000000000000008ull) #define PO_FX_DEVICE_FLAG_ENABLE_FAST_RESUME (0x0000000000000010ull) +#define PO_FX_DEVICE_FLAG_NO_FAULT_CALLBACKS (0x0000000000000020ull) #define PO_FX_DIRECTED_FX_DEFAULT_IDLE_TIMEOUT (0ul) #define PO_FX_DIRECTED_FX_IMMEDIATE_IDLE_TIMEOUT ((ULONG)-1)