IO a manager Kernel APC

Noob question here! Why does the IO manager need to queue an apc to complete an IO request (copy system buffer to requestor buffer / return status etc?) I’ve read it’s that way only for asynchronous IO, Initially my guess was its to make sure the requestor thread is currently scheduled before copying the system buffer to the virtual requestor buffer . That would make sense for Asynchronous IO , but wouldn’t it also be make sense for synchronous IO? Other than the dispatch routine at the top of the device stack MSDN suggests dispatch routines may run in arbitrary thread context, so doesn’t that suggest even for Synchronous IO apc is needed ? What’s the actual purpose of the Apc ? I guess I got it wrong

The kernel handles ALL I/O as asynchronous. If you do I/O without FILE_FLAG_OVERLAPPED, it submits an asynchronous IRP and then blocks on the completion on your behalf.

> @Tim_Roberts said: > The kernel handles ALL I/O as asynchronous. If you do I/O without FILE_FLAG_OVERLAPPED, it submits an asynchronous IRP and then blocks on the completion on your behalf. Interesting, what’s the purpose of the APC tho? Did I get it right?

It took a while to find the doc page that describes what special kernel apcs do: https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/how-completion-processing-is-performed
Basically it boils down to “do all the stuff required to be done before the originating user thread can observe the IO results, some of which might just have to be done in the correct process and/or thread context.”

1 Like

An extremely ancient, yet still elucidating, explanation appears here: https://www.osronline.com/article.cfm^article=83.htm

When the I/O Manager is providing synchronous service to the user app (regardless of whether the DRIVER completes the request synchronously or not) the I/O Manager blocks in the context of the requesting thread (before returning to the thread’s I/O operation function call). Therefore, there’s no need for the APC… the requesting thread is just “woken up”.

That… and what Mr. Roddy said.

Does that help?

1 Like