Hi,
I’m upgrading my WDM driver to a UMDF driver.
My applications send to the driver (using DeviceIoControl) a buffer which is a struct that includes the request parameters (wIndex, wValue, etc.) and a pointer to a data buffer and its length.
The WDM driver could access the buffer and send it to the device.
But now, when I’m writing the UMDF buffer, doing exactly what the fx2_driver does (for example in the ioctl case of IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY),
it seems that I cannot access the data buffer. When I do CreatePreallocatedWdfMemory, the pointer is being put in the IWDFMemory object, but when I try to derefernce it in the Watch window in the WinDbg, it indicates that there is an invalid access to memory, and GetCompletionStatus retrieves error 998 (ERROR_NOACCESS - Invalid access to memory location), and the data in the buffer is not transfered to the device.
So I understand there is an address mapping issue here, which worked in the WDM because kernel mode can do whatever it wants and access anywhere, and apperantly the User Mode pointer should be mapped into a kernel mode pointer, and cannot access the application’s address space, but I thought CreatePreallocatedWdfMemory is supposed to do that (as IoAllocateMdl and MmGetSystemAddressForMdl do in WDM).
So, my question is, how do I map my application pointer to something the UMDF driver can understand and send the data located in that user mode pointer to the device?
I wend through all the samples and could not find such an example. Usually the data itself is being transferred there and not a pointer.
Thanks,
Gadi
The general rule on UMDF is that it can only perform buffered I/O and using
a pointer is basically METHOD_NEITHER. Note, you WDM driver unless it is
doing more that you describe is a bug check waiting to happen. Accessing a
poiuter in a buffer passes in is a really poor idea. There is a ton of
validation you need to do to reference the pointer safely in the dispatch
routine for the IOCTL, and if you need to access it later you need to lock
it down and create a kernel address. This is why METHOD_IN_DIRECT is
there, since it allows a control struct and a buffer to be passed in the
IOCTL.
Unfortunately, in UMDF you want to make everything METHOD_BUFFERED so you
need to combine the structure and the buffer into on block.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
wrote in message news:xxxxx@ntdev…
> Hi,
> I’m upgrading my WDM driver to a UMDF driver.
> My applications send to the driver (using DeviceIoControl) a buffer which
> is a struct that includes the request parameters (wIndex, wValue, etc.)
> and a pointer to a data buffer and its length.
> The WDM driver could access the buffer and send it to the device.
> But now, when I’m writing the UMDF buffer, doing exactly what the
> fx2_driver does (for example in the ioctl case of
> IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY),
> it seems that I cannot access the data buffer. When I do
> CreatePreallocatedWdfMemory, the pointer is being put in the IWDFMemory
> object, but when I try to derefernce it in the Watch window in the
> WinDbg, it indicates that there is an invalid access to memory, and
> GetCompletionStatus retrieves error 998 (ERROR_NOACCESS - Invalid access
> to memory location), and the data in the buffer is not transfered to the
> device.
> So I understand there is an address mapping issue here, which worked in
> the WDM because kernel mode can do whatever it wants and access anywhere,
> and apperantly the User Mode pointer should be mapped into a kernel mode
> pointer, and cannot access the application’s address space, but I thought
> CreatePreallocatedWdfMemory is supposed to do that (as IoAllocateMdl and
> MmGetSystemAddressForMdl do in WDM).
> So, my question is, how do I map my application pointer to something the
> UMDF driver can understand and send the data located in that user mode
> pointer to the device?
> I wend through all the samples and could not find such an example.
> Usually the data itself is being transferred there and not a pointer.
> Thanks,
> Gadi
>
What you have is a hybrid METHOD_NEITHER since the top level structure
is buffered while it points to process specific buffers. This MSDN
topic describes what you can do to support a pure METHOD_NEITHER buffer
in UMDF, http://msdn2.microsoft.com/en-us/library/aa510978.aspx. But
like Don said, this is fraught with danger. You have to ask yourself if
it is worth it and if the perceived positives (like a supposed perf gain
which is probably non existant) are worth it. You should seriously
consider refactoring the IOCTL buffer such that you are not passing
unmapped buffers around.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Thursday, January 18, 2007 7:39 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Memory Access in UMDF
The general rule on UMDF is that it can only perform buffered I/O and
using
a pointer is basically METHOD_NEITHER. Note, you WDM driver unless it
is
doing more that you describe is a bug check waiting to happen.
Accessing a
poiuter in a buffer passes in is a really poor idea. There is a ton of
validation you need to do to reference the pointer safely in the
dispatch
routine for the IOCTL, and if you need to access it later you need to
lock
it down and create a kernel address. This is why METHOD_IN_DIRECT is
there, since it allows a control struct and a buffer to be passed in the
IOCTL.
Unfortunately, in UMDF you want to make everything METHOD_BUFFERED so
you
need to combine the structure and the buffer into on block.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
wrote in message news:xxxxx@ntdev…
> Hi,
> I’m upgrading my WDM driver to a UMDF driver.
> My applications send to the driver (using DeviceIoControl) a buffer
which
> is a struct that includes the request parameters (wIndex, wValue,
etc.)
> and a pointer to a data buffer and its length.
> The WDM driver could access the buffer and send it to the device.
> But now, when I’m writing the UMDF buffer, doing exactly what the
> fx2_driver does (for example in the ioctl case of
> IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY),
> it seems that I cannot access the data buffer. When I do
> CreatePreallocatedWdfMemory, the pointer is being put in the
IWDFMemory
> object, but when I try to derefernce it in the Watch window in the
> WinDbg, it indicates that there is an invalid access to memory, and
> GetCompletionStatus retrieves error 998 (ERROR_NOACCESS - Invalid
access
> to memory location), and the data in the buffer is not transfered to
the
> device.
> So I understand there is an address mapping issue here, which worked
in
> the WDM because kernel mode can do whatever it wants and access
anywhere,
> and apperantly the User Mode pointer should be mapped into a kernel
mode
> pointer, and cannot access the application’s address space, but I
thought
> CreatePreallocatedWdfMemory is supposed to do that (as IoAllocateMdl
and
> MmGetSystemAddressForMdl do in WDM).
> So, my question is, how do I map my application pointer to something
the
> UMDF driver can understand and send the data located in that user mode
> pointer to the device?
> I wend through all the samples and could not find such an example.
> Usually the data itself is being transferred there and not a pointer.
> Thanks,
> Gadi
>
—
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
UMDF supports METHOD_DIRECT (currently by buffering the data but we hope
to fix that some day ![]()
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Thursday, January 18, 2007 7:39 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Memory Access in UMDF
The general rule on UMDF is that it can only perform buffered I/O and
using
a pointer is basically METHOD_NEITHER. Note, you WDM driver unless it
is
doing more that you describe is a bug check waiting to happen.
Accessing a
poiuter in a buffer passes in is a really poor idea. There is a ton of
validation you need to do to reference the pointer safely in the
dispatch
routine for the IOCTL, and if you need to access it later you need to
lock
it down and create a kernel address. This is why METHOD_IN_DIRECT is
there, since it allows a control struct and a buffer to be passed in the
IOCTL.
Unfortunately, in UMDF you want to make everything METHOD_BUFFERED so
you
need to combine the structure and the buffer into on block.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
wrote in message news:xxxxx@ntdev…
> Hi,
> I’m upgrading my WDM driver to a UMDF driver.
> My applications send to the driver (using DeviceIoControl) a buffer
which
> is a struct that includes the request parameters (wIndex, wValue,
etc.)
> and a pointer to a data buffer and its length.
> The WDM driver could access the buffer and send it to the device.
> But now, when I’m writing the UMDF buffer, doing exactly what the
> fx2_driver does (for example in the ioctl case of
> IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY),
> it seems that I cannot access the data buffer. When I do
> CreatePreallocatedWdfMemory, the pointer is being put in the
IWDFMemory
> object, but when I try to derefernce it in the Watch window in the
> WinDbg, it indicates that there is an invalid access to memory, and
> GetCompletionStatus retrieves error 998 (ERROR_NOACCESS - Invalid
access
> to memory location), and the data in the buffer is not transfered to
the
> device.
> So I understand there is an address mapping issue here, which worked
in
> the WDM because kernel mode can do whatever it wants and access
anywhere,
> and apperantly the User Mode pointer should be mapped into a kernel
mode
> pointer, and cannot access the application’s address space, but I
thought
> CreatePreallocatedWdfMemory is supposed to do that (as IoAllocateMdl
and
> MmGetSystemAddressForMdl do in WDM).
> So, my question is, how do I map my application pointer to something
the
> UMDF driver can understand and send the data located in that user mode
> pointer to the device?
> I wend through all the samples and could not find such an example.
> Usually the data itself is being transferred there and not a pointer.
> Thanks,
> Gadi
>
—
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
User-mode drivers cannot blindly access the address space of applications like their predecessors could.
Change your I/O control to METHOD_DIRECT_[IN|OUT]. Use InputBuffer to carry command data and the OutputBuffer to carry the data.
CreatePreallocatedWdfMemory lets you create a memory object around a buffer in your driver’s address space. Nothing in UMDF lets you access memory outside of the host’s address space though.
If you can tell me what in the docs led you to believe that CreatePreallocatedWdfMemory allows you to access the client’s address space I’d like to get the docs fixed.
-p
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@n-trig.com
Sent: Thursday, January 18, 2007 7:01 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Memory Access in UMDF
Hi,
I’m upgrading my WDM driver to a UMDF driver.
My applications send to the driver (using DeviceIoControl) a buffer which is a struct that includes the request parameters (wIndex, wValue, etc.) and a pointer to a data buffer and its length.
The WDM driver could access the buffer and send it to the device.
But now, when I’m writing the UMDF buffer, doing exactly what the fx2_driver does (for example in the ioctl case of IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY),
it seems that I cannot access the data buffer. When I do CreatePreallocatedWdfMemory, the pointer is being put in the IWDFMemory object, but when I try to derefernce it in the Watch window in the WinDbg, it indicates that there is an invalid access to memory, and GetCompletionStatus retrieves error 998 (ERROR_NOACCESS - Invalid access to memory location), and the data in the buffer is not transfered to the device.
So I understand there is an address mapping issue here, which worked in the WDM because kernel mode can do whatever it wants and access anywhere, and apperantly the User Mode pointer should be mapped into a kernel mode pointer, and cannot access the application’s address space, but I thought CreatePreallocatedWdfMemory is supposed to do that (as IoAllocateMdl and MmGetSystemAddressForMdl do in WDM).
So, my question is, how do I map my application pointer to something the UMDF driver can understand and send the data located in that user mode pointer to the device?
I wend through all the samples and could not find such an example. Usually the data itself is being transferred there and not a pointer.
Thanks,
Gadi
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