Microsoft KB Archive/195394

{|
 * width="100%"|

DOC: IoInitializeIrp Function Documentation Is Incorrect

 * }

Q195394

-

The information in this article applies to:


 * Microsoft Win32 Device Driver Kit (DDK) for Windows NT, versions 3.1, 3.5, 3.51, 4.0, on platform(s):
 * the hardware: DEC Alpha
 * the hardware: Intel x86

-

SUMMARY
The following statement in the comments section of the IoInitializeIrp function reference documentation is incorrect:

If a driver calls IoAllocateIrp, it also must call IoInitializeIrp with

the same StackSize value and the pointer returned by IoAllocateIrp.

MORE INFORMATION
On the contrary, a driver should never call IoInitializeIrp on an IRP allocated with IoAllocateIrp. Since the IRP is completely initialized by IoAllocateIrp, there is no need to call this function.

IoAllocateIrp tries to allocate storage for an IRP first from a look-aside list, and, if that fails, from NonPagedPool. If both these attempts fail and if the caller's previous mode is kernel-mode, it allocates storage from NonPagedPoolMustSucceed. It keeps track of this memory pool information in Irp->AllocationFlags field so that the system can return memory to the appropriate pool during IoFreeIrp call.

Since the IoInitializeIrp function zeros the entire IRP before initializing it, it results in the loss of this important allocation information set in Irp->AllocationFlags by IoAllocateIrp. This could lead to memory corruption and subsequent system crash if the system returns memory to an inappropriate pool when the IRP is freed.

You should use this function to initialize an IRP only if you allocate storage for the IRP with ExAllocatePool function from NonPagedPool.

Keywords : kbdocerr kbDDK kbHWDecAlpha kbIFS kbKMode kbOSWinNT400 kbHWx86

Issue type :

Technology : kbAudDeveloper kbWinDDKSearch kbWin32sSearch kbWin32DDKSearch kbWin32DDKNTSearch