我正在编写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)
会破坏内存和请求?另外,对于函数内部和完成例程中的错误清除,答案是否相同?