IRP与LIST_ENTRY的关联使用
2021-09-07
41
0
IRP是Windows内核中的一个很重要的概念,代表着应用或内核对设备的请求。
LIST_ENTRY又是Windows内核提供的一个链表。
IRP挂入LIST_ENTRY
VOID RecyleFrame(PFDO_DEVICE_EXTENSION deviceExtension, FrameHeader* frame)
{
KIRQL oldIrql;
KeAcquireSpinLock(&deviceExtension->FrameLock, &oldIrql);
if (deviceExtension->FrameCount > 50)
{
ExFreePool(frame);
}
else
{
++deviceExtension->FrameCount;
InsertTailList(&deviceExtension->FrameList, &frame->ListEntry);
}
KeReleaseSpinLock(&deviceExtension->FrameLock, oldIrql);
}
VOID RecycleIrp(PFDO_DEVICE_EXTENSION DeviceExtension, PIRP Irp)
{
KIRQL OldLevel;
KeAcquireSpinLock(&DeviceExtension->IrpRecyledListLock, &OldLevel);
InsertTailList(&DeviceExtension->IrpRecyledListHead, &Irp->Tail.Overlay.ListEntry);
KeReleaseSpinLock(&DeviceExtension->IrpRecyledListLock, OldLevel);
}
将IRP从LIST_ENTRY中摘取
PIRP
GetIrp(
IN PFDO_DEVICE_EXTENSION DeviceExtension)
{
KIRQL OldLevel;
PIRP Irp = NULL;
PLIST_ENTRY ListEntry;
KeAcquireSpinLock(&DeviceExtension->IrpRecyledListLock, &OldLevel);
if (!IsListEmpty(&DeviceExtension->IrpRecyledListHead))
{
ListEntry = RemoveHeadList(&DeviceExtension->IrpRecyledListHead);
Irp = CONTAINING_RECORD(ListEntry, IRP, Tail.Overlay.ListEntry);
}
KeReleaseSpinLock(&DeviceExtension->IrpRecyledListLock, OldLevel);
return Irp;
}