I got a bit confused today when wrote my code!
If I allocate a Irp using *IoBuildAsynchronousFsdRequest, and the target
device set the flag (DO_DIRECT_IO). **IoBuildAsynchronousFsdRequest will
help us allocate a MDL to describe the buffer. The question is, who will
release the MDL allocated by this routine, the caller or the IoManager?
I understand the Irp allocated by **IoBuildAsynchronousFsdRequest should
be release by IoFreeIrp in my completion routine. However, who should be
responsible for the MDL?
What would happen if I use *IoBuildSynchronousFsdRequest, will the
IoManager release all the resource for us, including the MDL and Irp?
Hi,
you must release the Irp and the MDL.
For example
NTSTATUS
CompletionRoutine( … IRP Irp … )
{
…
if( Irp->MdlAddress != NULL ){
MmUnlockPages(Irp->MdlAddress);
IoFreeMdl(Irp->MdlAddress);
Irp->MdlAddress = NULL;
}
IoFreeIrp(Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}
Because there is no target thread associated with the IRP you must return
STATUS_MORE_PROCESSING_REQUIRED to avoid calling KeInsertQueueApc in
IoCompleteRequest.
wrote in message news:xxxxx@ntdev…
>I got a bit confused today when wrote my code!
> If I allocate a Irp using *IoBuildAsynchronousFsdRequest, and the target
> device set the flag (DO_DIRECT_IO). IoBuildAsynchronousFsdRequest will
> help us allocate a MDL to describe the buffer. The question is, who will
> release the MDL allocated by this routine, the caller or the IoManager?
> I understand the Irp allocated by IoBuildAsynchronousFsdRequest should
> be release by IoFreeIrp in my completion routine. However, who should be
> responsible for the MDL?
> What would happen if I use *IoBuildSynchronousFsdRequest, will the
> IoManager release all the resource for us, including the MDL and Irp?
>
actually, you have to walk the entire MDL chain (following Mdl->Next,
remember to capture the Next pointer before freeing the current MDL) and
free each one, esp if you are sending i/o to a file system.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Slava Imameyev
Sent: Monday, June 05, 2006 2:20 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about IoBuildAsynchronousFsdRequest
Hi,
you must release the Irp and the MDL.
For example
NTSTATUS
CompletionRoutine( … IRP Irp … )
{
…
if( Irp->MdlAddress != NULL ){
MmUnlockPages(Irp->MdlAddress);
IoFreeMdl(Irp->MdlAddress);
Irp->MdlAddress = NULL;
}
IoFreeIrp(Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}
Because there is no target thread associated with the IRP you must
return
STATUS_MORE_PROCESSING_REQUIRED to avoid calling KeInsertQueueApc in
IoCompleteRequest.
wrote in message news:xxxxx@ntdev…
>I got a bit confused today when wrote my code!
> If I allocate a Irp using *IoBuildAsynchronousFsdRequest, and the
target
> device set the flag (DO_DIRECT_IO). IoBuildAsynchronousFsdRequest
will
> help us allocate a MDL to describe the buffer. The question is, who
will
> release the MDL allocated by this routine, the caller or the
IoManager?
> I understand the Irp allocated by IoBuildAsynchronousFsdRequest
should
> be release by IoFreeIrp in my completion routine. However, who should
be
> responsible for the MDL?
> What would happen if I use *IoBuildSynchronousFsdRequest, will the
> IoManager release all the resource for us, including the MDL and Irp?
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Hi
From which OS’s version( build ) does IoBuildAsynchronousFsdRequest build
MDLs chain?
e.g.
In WinXP SP2 x86
8081eb18 33ff xor edi,edi
8081eb1a 57 push edi
8081eb1b 57 push edi
8081eb1c 57 push edi
8081eb1d ff7514 push dword ptr [ebp+0x14]
8081eb20 ff7510 push dword ptr [ebp+0x10]
8081eb23 e822fcffff call nt!IoAllocateMdl (8081e74a)
chain is impossible, because the third parameter is FALSE.
“Doron Holan” wrote in message
news:xxxxx@ntdev…
actually, you have to walk the entire MDL chain (following Mdl->Next,
remember to capture the Next pointer before freeing the current MDL) and
free each one, esp if you are sending i/o to a file system.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Slava Imameyev
Sent: Monday, June 05, 2006 2:20 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about IoBuildAsynchronousFsdRequest
Hi,
you must release the Irp and the MDL.
For example
NTSTATUS
CompletionRoutine( … IRP Irp … )
{
…
if( Irp->MdlAddress != NULL ){
MmUnlockPages(Irp->MdlAddress);
IoFreeMdl(Irp->MdlAddress);
Irp->MdlAddress = NULL;
}
IoFreeIrp(Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}
Because there is no target thread associated with the IRP you must
return
STATUS_MORE_PROCESSING_REQUIRED to avoid calling KeInsertQueueApc in
IoCompleteRequest.
wrote in message news:xxxxx@ntdev…
>I got a bit confused today when wrote my code!
> If I allocate a Irp using *IoBuildAsynchronousFsdRequest, and the
target
> device set the flag (DO_DIRECT_IO). IoBuildAsynchronousFsdRequest
will
> help us allocate a MDL to describe the buffer. The question is, who
will
> release the MDL allocated by this routine, the caller or the
IoManager?
> I understand the Irp allocated by IoBuildAsynchronousFsdRequest
should
> be release by IoFreeIrp in my completion routine. However, who should
be
> responsible for the MDL?
> What would happen if I use *IoBuildSynchronousFsdRequest, will the
> IoManager release all the resource for us, including the MDL and Irp?
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
The underlying FS can build the MDL chain on your behalf while
processing the irp you sent it and you have to free it,
IoBuildAsynchronousFsdRequest will not build the chain before the irp is
sent down though.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Slava Imameyev
Sent: Monday, June 05, 2006 7:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about IoBuildAsynchronousFsdRequest
Hi
From which OS’s version( build ) does IoBuildAsynchronousFsdRequest
build
MDLs chain?
e.g.
In WinXP SP2 x86
8081eb18 33ff xor edi,edi
8081eb1a 57 push edi
8081eb1b 57 push edi
8081eb1c 57 push edi
8081eb1d ff7514 push dword ptr [ebp+0x14]
8081eb20 ff7510 push dword ptr [ebp+0x10]
8081eb23 e822fcffff call nt!IoAllocateMdl (8081e74a)
chain is impossible, because the third parameter is FALSE.
“Doron Holan” wrote in message
news:xxxxx@ntdev…
actually, you have to walk the entire MDL chain (following Mdl->Next,
remember to capture the Next pointer before freeing the current MDL) and
free each one, esp if you are sending i/o to a file system.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Slava Imameyev
Sent: Monday, June 05, 2006 2:20 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about IoBuildAsynchronousFsdRequest
Hi,
you must release the Irp and the MDL.
For example
NTSTATUS
CompletionRoutine( … IRP Irp … )
{
…
if( Irp->MdlAddress != NULL ){
MmUnlockPages(Irp->MdlAddress);
IoFreeMdl(Irp->MdlAddress);
Irp->MdlAddress = NULL;
}
IoFreeIrp(Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}
Because there is no target thread associated with the IRP you must
return
STATUS_MORE_PROCESSING_REQUIRED to avoid calling KeInsertQueueApc in
IoCompleteRequest.
wrote in message news:xxxxx@ntdev…
>I got a bit confused today when wrote my code!
> If I allocate a Irp using *IoBuildAsynchronousFsdRequest, and the
target
> device set the flag (DO_DIRECT_IO). IoBuildAsynchronousFsdRequest
will
> help us allocate a MDL to describe the buffer. The question is, who
will
> release the MDL allocated by this routine, the caller or the
IoManager?
> I understand the Irp allocated by IoBuildAsynchronousFsdRequest
should
> be release by IoFreeIrp in my completion routine. However, who should
be
> responsible for the MDL?
> What would happen if I use *IoBuildSynchronousFsdRequest, will the
> IoManager release all the resource for us, including the MDL and Irp?
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
> help us allocate a MDL to describe the buffer. The
question is, who will
release the MDL allocated by this routine, the caller
or the IoManager?
IO manager in IoCompleteRequest and IopCompleteRequest.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
Yes, Slava is correct and I was wrong.
I was correct for threaded IRPs built by IoBuildSynchronousFsdRequest and
IoBuildDeviceIoControlRequest.
Slava is correct for non-threaded IRPs built by
IoBuildAsynchronousFsdRequest and IoAllocateIrp.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “Slava Imameyev”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, June 05, 2006 1:19 PM
Subject: Re:[ntdev] question about IoBuildAsynchronousFsdRequest
> Hi,
> you must release the Irp and the MDL.
> For example
> NTSTATUS
> CompletionRoutine( … IRP Irp … )
> {
> …
> if( Irp->MdlAddress != NULL ){
>
> MmUnlockPages(Irp->MdlAddress);
> IoFreeMdl(Irp->MdlAddress);
>
> Irp->MdlAddress = NULL;
> }
>
> IoFreeIrp(Irp);
>
> return STATUS_MORE_PROCESSING_REQUIRED;
> }
>
> Because there is no target thread associated with the IRP you must return
> STATUS_MORE_PROCESSING_REQUIRED to avoid calling KeInsertQueueApc in
> IoCompleteRequest.
>
> wrote in message news:xxxxx@ntdev…
> >I got a bit confused today when wrote my code!
> > If I allocate a Irp using *IoBuildAsynchronousFsdRequest, and the target
> > device set the flag (DO_DIRECT_IO). IoBuildAsynchronousFsdRequest will
> > help us allocate a MDL to describe the buffer. The question is, who will
> > release the MDL allocated by this routine, the caller or the IoManager?
> > I understand the Irp allocated by IoBuildAsynchronousFsdRequest should
> > be release by IoFreeIrp in my completion routine. However, who should be
> > responsible for the MDL?
> > What would happen if I use *IoBuildSynchronousFsdRequest, will the
> > IoManager release all the resource for us, including the MDL and Irp?
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer