Clarification for thread: "a bug in swapBuffers sample of DDK?"

I created a new thread since it was too late to post a reply to the original thread.

The sample is correct.

If a minifilter calls “FltDoCompletionProcessingWhenSafe” and the “SafePostCallback” is invoked in a worker thread because it is not safe to invoke it in the current thread context, then filter manager will resume completion processing as long as the minifilter does not return “FLT_POSTOP_MORE_PROCESSING_REQUIRED” from the “SafePostCallback”.

If the minifilter infact does return “FLT_POSTOP_MORE_PROCESSING_REQUIRED” from the “SafePostCallback”, then the minifilter will have to call “FltCompletePendedPostOperation” to resume completion processing.

Regards,
Sarosh.

THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS


Shangwu wrote:

The sample code swapBuffers.c seems missing a call of
FltCompletePendedPostOperation in its
SwapPostDirCtrlBuffersWhenSafe routine. In SwapPostDirCtrlBuffers, there is
a piece of code like this:

FltDoCompletionProcessingWhenSafe( Data, FltObjects, CompletionContext,
Flags,
SwapPostDirCtrlBuffersWhenSafe, &retValue );

return retValue;

In SwapPostDirCtrlBuffersWhenSafe, it returns
FLT_POSTOP_FINISHED_PROCESSING.

The DDK document says that retValue can be
FLT_POSTOP_MORE_PROCESSING_REQUIRED if FltDoCompletionProcessingWhenSafe
posts the I/O operation to a worker thread and calls the SafePostCallback
routine from the worker thread. In this case, the Post-Op returns
FLT_POSTOP_MORE_PROCESSING_REQUIRED, but the Callback data will never be
completed.

Should the routine of SwapPostDirCtrlBuffersWhenSafe call
FltCompletePendedPostOperation to complete the IRP?
I am not sure that the sample is incorrect or the document is incorrect.
I believe that many developers are referring DDK samples for their
production filters. Please clarify this by any MS engineer or some experts.

Thanks,

Shangwu

Don’t knock non-paged memory if you can use it; it makes things so much
simpler.

mm

xxxxx@microsoft.com wrote:

I created a new thread since it was too late to post a reply to the original thread.

The sample is correct.

If a minifilter calls “FltDoCompletionProcessingWhenSafe” and the “SafePostCallback” is invoked in a worker thread because it is not safe to invoke it in the current thread context, then filter manager will resume completion processing as long as the minifilter does not return “FLT_POSTOP_MORE_PROCESSING_REQUIRED” from the “SafePostCallback”.

If the minifilter infact does return “FLT_POSTOP_MORE_PROCESSING_REQUIRED” from the “SafePostCallback”, then the minifilter will have to call “FltCompletePendedPostOperation” to resume completion processing.

Regards,
Sarosh.

THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS


Shangwu wrote:

The sample code swapBuffers.c seems missing a call of
FltCompletePendedPostOperation in its
SwapPostDirCtrlBuffersWhenSafe routine. In SwapPostDirCtrlBuffers, there is
a piece of code like this:

FltDoCompletionProcessingWhenSafe( Data, FltObjects, CompletionContext,
Flags,
SwapPostDirCtrlBuffersWhenSafe, &retValue );

return retValue;

In SwapPostDirCtrlBuffersWhenSafe, it returns
FLT_POSTOP_FINISHED_PROCESSING.

The DDK document says that retValue can be
FLT_POSTOP_MORE_PROCESSING_REQUIRED if FltDoCompletionProcessingWhenSafe
posts the I/O operation to a worker thread and calls the SafePostCallback
routine from the worker thread. In this case, the Post-Op returns
FLT_POSTOP_MORE_PROCESSING_REQUIRED, but the Callback data will never be
completed.

Should the routine of SwapPostDirCtrlBuffersWhenSafe call
FltCompletePendedPostOperation to complete the IRP?
I am not sure that the sample is incorrect or the document is incorrect.
I believe that many developers are referring DDK samples for their
production filters. Please clarify this by any MS engineer or some experts.

Thanks,

Shangwu

Sarosh,

Thanks for your response. The document of WDK 6001 says:

FltDoCompletionProcessingWhenSafe does one of the following:

  • If the current IRQL is >= DISPATCH_LEVEL,
    FltDoCompletionProcessingWhenSafe posts the I/O operation to a worker thread
    and calls the SafePostCallback routine from the worker thread. If the
    operation is successfully posted, the RetPostOperationStatus parameter
    receives FLT_POSTOP_MORE_PROCESSING_REQUIRED, and
    FltDoCompletionProcessingWhenSafe returns TRUE. If the operation cannot
    safely be posted, RetPostOperationStatus receives
    FLT_POSTOP_FINISHED_PROCESSING, and FltDoCompletionProcessingWhenSafe
    returns FALSE.
    ===================
    “the RetPostOperationStatus parameter receives
    FLT_POSTOP_MORE_PROCESSING_REQUIRED”
    menas that the caller, which is SwapPostDirCtrlBuffers() in the sample, will
    return FLT_POSTOP_MORE_PROCESSING_REQUIRED if the SafePostCallback routine
    is executed in a worker item later. But the sample does not call
    FltCompletePendedPostOperation anywhere.

There must be something wrong - the sample or the document.

Regards,
Shangwu

wrote in message news:xxxxx@ntfsd…
>I created a new thread since it was too late to post a reply to the
>original thread.
>
> The sample is correct.
>
> If a minifilter calls “FltDoCompletionProcessingWhenSafe” and the
> “SafePostCallback” is invoked in a worker thread because it is not safe to
> invoke it in the current thread context, then filter manager will resume
> completion processing as long as the minifilter does not return
> “FLT_POSTOP_MORE_PROCESSING_REQUIRED” from the “SafePostCallback”.
>
> If the minifilter infact does return “FLT_POSTOP_MORE_PROCESSING_REQUIRED”
> from the “SafePostCallback”, then the minifilter will have to call
> “FltCompletePendedPostOperation” to resume completion processing.
>
> Regards,
> Sarosh.
>
> THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS
>
>
>
> --------------------------------------------------------------------------------
>
> Shangwu wrote:
>
>
> The sample code swapBuffers.c seems missing a call of
> FltCompletePendedPostOperation in its
> SwapPostDirCtrlBuffersWhenSafe routine. In SwapPostDirCtrlBuffers, there
> is
> a piece of code like this:
>
> FltDoCompletionProcessingWhenSafe( Data, FltObjects, CompletionContext,
> Flags,
> SwapPostDirCtrlBuffersWhenSafe, &retValue );
> …
> return retValue;
>
> In SwapPostDirCtrlBuffersWhenSafe, it returns
> FLT_POSTOP_FINISHED_PROCESSING.
>
> The DDK document says that retValue can be
> FLT_POSTOP_MORE_PROCESSING_REQUIRED if FltDoCompletionProcessingWhenSafe
> posts the I/O operation to a worker thread and calls the SafePostCallback
> routine from the worker thread. In this case, the Post-Op returns
> FLT_POSTOP_MORE_PROCESSING_REQUIRED, but the Callback data will never be
> completed.
>
> Should the routine of SwapPostDirCtrlBuffersWhenSafe call
> FltCompletePendedPostOperation to complete the IRP?
> I am not sure that the sample is incorrect or the document is incorrect.
> I believe that many developers are referring DDK samples for their
> production filters. Please clarify this by any MS engineer or some
> experts.
>
> Thanks,
>
> Shangwu
>
>
>