我正在编写一个 Windows 内核驱动程序。我需要创建一个新的 I/O 请求并为输入缓冲区分配我自己的内存。
// Create request
WDFREQUEST request;
status = WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES, target, &request);
if (!NT_SUCCESS(status)) {
goto exit;
}
// Allocate buffer for request
WDFMEMORY inputMemory;
status = WdfMemoryCreate(WDF_NO_OBJECT_ATTRIBUTES, PagedPool, 0, 1024, &inputMemory, NULL);
if (!NT_SUCCESS(status)) {
goto exit;
}
// Assign input buffer to request
status = WdfIoTargetFormatRequestForIoctl(target, request, IOCTL_FOO, inputMemory, NULL, NULL, NULL);
if (!NT_SUCCESS(status)) {
goto exit;
}
// Asynchronously send the ioctl request
WdfRequestSetCompletionRoutine(request, MyCompletionRoutine, NULL);
if (!WdfRequestSend(request, target, NULL)) {
status = WdfRequestGetStatus(request);
goto exit;
}
我的问题是,如果WdfIoTargetFormatRequestForIoctl
成功完成,我是否也应该WdfObjectDelete(inputMemory)
在清理中执行,还是会WdfObjectDelete(request)
破坏内存和请求?此外,对于函数内的错误清理和完成例程中的错误清理,答案是否相同?