-
-
IO完成端口原理
-
发表于: 2024-7-15 10:18 2282
-
IO完成端口原理
内核创建一个KQUEUE,
fileObject->CompletionContext->Port ==> PKQUEUE;
fileObject->CompletionContext->Key = 用户自定义的值,可以是buf指针;
typedef struct _KQUEUE {
DISPATCHER_HEADER Header;
LIST_ENTRY EntryListHead; // 已完成IO的IRP List: &irp->Tail.Overlay.ListEntry;
ULONG CurrentCount; // 当前运行状态线程数
ULONG MaximumCount; // 最大并行线程数(默认等于CPU核心数)
LIST_ENTRY ThreadListHead; // 所有调用过GetQueuedCompletionStatus()的线程List
} KQUEUE, *PKQUEUE;
IO完成时:
IopCompleteRequest()
irp->Tail.CompletionKey = fileObject->CompletionContext->Key;
KeInsertQueue(PRKQUEUE, PLIST_ENTRY)
PRKQUEUE = fileObject->CompletionContext->Port; PLIST_ENTRY = &irp->Tail.Overlay.ListEntry;
KiInsertQueue()
if (Queue->CurrentCount < Queue->MaximumCount)
{CurrentCount++; KiReadyThread(Queue->Header.WaitListHead[WaitBlock->Thread]);}
else
InsertTailList(&Queue->EntryListHead, Entry);
线程来GetQueuedCompletionStatus()时:
NtRemoveIoCompletion()
Entry = KeRemoveQueue()
once: InsertTailList(&Queue->ThreadListHead, Entry);
if (Queue->CurrentCount < Queue->MaximumCount)
Entry = RemoveEntryList(Queue->EntryListHead.Flink);
else
{CurrentCount--; InsertTailList(&Queue->Header.WaitListHead, &Thread->WaitBlock[0].WaitListEntry); KiSwapThread();}
赞赏
- [原创]Arm thumb Cortex-M0 opcode 解析 2220
- IO完成端口原理 2283
- 代码角度看SSL握手过程 13447
- 给Internet Download Manager打补丁 5659
- [原创]分析X绒hrdevmon.sys,突破U盘访问控制,摄像头保护原理 9051