IrqlExApcLte3 规则 (wdm)
IrqlExApcLte3 规则指定驱动程序仅在 IRQL <= APC_LEVEL 调用以下执行支持例程。
具有与 IRQL 相关的错误的驱动程序可能会导致严重问题,并可能导致计算机崩溃。
驱动程序模型:WDM
通过以下规则找到的 Bug 检查 () :Bug 检查0xC4:DRIVER_VERIFIER_DETECTED_VIOLATION (0x20007) 、Bug 检查0xA:IRQL_NOT_LESS_OR_EQUAL
示例
以下代码违反了此规则:
NTSTATUS
DispatchRequest (
_In_ PDEVICE_REQUEST DeviceRequest
)
{
KIRQL OldIrql;
KSPIN_LOCK SpinLock;
NTSTATUS Status;
...
KeInitializeSpinLock(&SpinLock);
//
// KeAcquireSpinLock sets IRQL to DISPATCH_LEVEL and the previous IRQL is
// written to OldIrql after the lock is acquired.
//
KeAcquireSpinLock(&SpinLock, &OldIrql);
...
Status = ProcessRequest(DeviceRequest);
//
// KeReleaseSpinLock sets IRQL to the OldIrql returned by KeAcquireSpinLock.
//
KeReleaseSpinLock(&SpinLock, &OldIrql);
...
}
NTSTATUS
ProcessRequest (
_In_ PDEVICE_REQUEST DeviceRequest
)
{
ERESOURCE Resource;
NTSTATUS Status;
...
Resource = DeviceRequest->GetTableLock();
//
// RULE VIOLATION! - ExAcquireSharedStarveExclusive can be called only at
// IRQL <= APC_LEVEL.
//
if(!ExAcquireSharedStarveExclusive(&Resource, FALSE)) {
return STATUS_UNSUCCESSFUL;
}
...
ExReleaseResourceLite(&Resource);
...
return Status;
}
如何测试
编译时 |
---|
运行 静态驱动程序验证程序 并指定 IrqlExApcLte3 规则。 使用以下步骤运行代码分析:有关详细信息,请参阅 使用静态驱动程序验证程序查找驱动程序中的缺陷。 |
运行时 |
---|
适用于
ExAcquireResourceExclusiveLiteExAcquireResourceSharedLiteExAcquireSharedStarveExclusiveExAcquireSharedWaitForExclusiveExConvertExclusiveToSharedLiteExDeleteResourceLiteLite