From 7d373dbb8dedc003dbf015d3a37dd077111f2610 Mon Sep 17 00:00:00 2001 From: Yuri Benditovich Date: Sat, 25 Jan 2020 19:57:57 +0200 Subject: [PATCH] driver: fix driver verifier assertion in FileCreate callback Previous commit 4de57a9ff causes driver verifier assertion with latest Windows builds. Note that this assertion is not in latest WDF sources on GitHub. The verifier does not allow to forward the MJ_CREATE requestto local IO target using "send-and-forget". It requires the request to set completion callback. There is an option to remove the file create callback at all, but we prefer to have printout on file open for better diagnostics. So we add completion callback for forwarded request and complete the request in it. Signed-off-by: Yuri Benditovich --- UsbDk/FilterDevice.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/UsbDk/FilterDevice.cpp b/UsbDk/FilterDevice.cpp index 8fe016e..22d4383 100644 --- a/UsbDk/FilterDevice.cpp +++ b/UsbDk/FilterDevice.cpp @@ -481,11 +481,19 @@ bool CUsbDkChildDevice::AttachToDeviceStack() void CUsbDkFilterDevice::OnFileCreate(WDFREQUEST Request) { - WDF_REQUEST_SEND_OPTIONS options; - WDF_REQUEST_SEND_OPTIONS_INIT(&options, WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET); + CWdfRequest r(Request); + WdfRequestFormatRequestUsingCurrentType(Request); // in the log we'll see which process created the file TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC!"); - WdfRequestSend(Request, IOTarget(), &options); + r.SendWithCompletion(IOTarget(), [](WDFREQUEST Request, WDFIOTARGET Target, PWDF_REQUEST_COMPLETION_PARAMS Params, WDFCONTEXT Context) + { + UNREFERENCED_PARAMETER(Target); + CWdfRequest r(Request); + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%s: completed", (LPCSTR)Context); + r.SetStatus(Params->IoStatus.Status); + r.SetBytesWritten(Params->IoStatus.Information); + }, + __FUNCTION__); } NTSTATUS CUsbDkFilterDevice::AttachToStack(WDFDRIVER Driver)