RE: How to read contents of DMA scattergather list within driver conte by AntonBassov
AntonBassov
Sun Jul 15 23:22:01 CDT 2007
> Can anybody tell me how to read the contents of a scatter/gather list
> created in a WDM driver? In this case, the scatter/gather list is
> created with GetScatterGatherList(), and later freed with
> PutScatterGatherList(). I would like to read the contents of this
> list as soon as possible after it has been filled in by the hardware,
> before the IO Manager returns the results to the calling application.
Well, MDL that you have passed to GetScatterGatherList() seems to be
an obvious source of info, don't you think???
> When I try to read the contents of the scatter/gather list just before
> PutScatterGatherList() is called, I get a IRQL_NOT_LESS_THAN_OR_EQUAL
> bug check.
I really have no idea how you do it, but if your driver does direct IO,
then, by the time IRP reaches your driver, Irp->MdlAddress has been already
locked in RAM by IO Manager , so that it can be accessed at elevated IRQL.....
> When I try to read the contents of the list within the context of a
> worker thread later on (to avoid the the above bug check by executing
> at a lower IRQL), I get a memory access fault.
The above statement is just an additional proof to the fact that you do
something the wrong way - you just cannot get access violation if you do
everything properly....
> Trying to read the the virtual address of the user buffer associated
> with the MDL of the IRP request causes a memory access fault because
> that address is not valid within the context of the worker thread.
Correct - MDL->StartVa is valid only in context of the process that has
originated the request. If MDL has been already mapped to the system address
space you can
access the buffer that MDL describes as MDL->MappedSystemVa, and if is not
mapped, you can map it with MmMapLockedPagesSpecifyCache(). In practical
tersms, it is better to use MmGetSystemAddressForMdlSafe() macro - it does
the above mentioned check for you....
Anton Bassov
"Robert Cohn" wrote:
> Hello -
>
> Can anybody tell me how to read the contents of a scatter/gather list
> created in a WDM driver? In this case, the scatter/gather list is
> created with GetScatterGatherList(), and later freed with
> PutScatterGatherList(). I would like to read the contents of this
> list as soon as possible after it has been filled in by the hardware,
> before the IO Manager returns the results to the calling application.
>
> When I try to read the contents of the scatter/gather list just before
> PutScatterGatherList() is called, I get a IRQL_NOT_LESS_THAN_OR_EQUAL
> bug check.
>
> When I try to read the contents of the list within the context of a
> worker thread later on (to avoid the the above bug check by executing
> at a lower IRQL), I get a memory access fault.
>
> Trying to read the the virtual address of the user buffer associated
> with the MDL of the IRP request causes a memory access fault because
> that address is not valid within the context of the worker thread.
>
> As yet, the only way I can read the results of the scatter/gather
> operation is from a user buffer in the calling client application.
> The device doing the DMA access is DIRECT_IO (not buffered).
>
> The target system is WindowsXP.
>
> Any pointers would be very much appreciated.
>
> Robert Cohn
>
> Tektronix, Inc.
> Any ideas, opinions, random thoughts or
> professional goals expressed here do not
> necessarily reflect the ideas, opinions, random
> thoughts or professional goals of my employer.
>
>
>