谁在WDFREQUEST中拥有WDFMEMORY?

时间:2018-10-07 18:32:22

标签: windows driver wdk wdf

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

1 个答案:

答案 0 :(得分:0)

根据this,驱动程序对象拥有内存,只有在卸载驱动程序时才会清理该对象。

如果可以用完内存,则应调用WdfObjectDelete()来保留未使用的内存。