Passing a pointer from the driver back to the user

Hi,

I want to try and pass a pointer from the driver back to the user. I
tried using an IOCTL with METHOD_OUT_DIRECT and using the mdl to pass the
pointer. I pass in a pointer to a pointer (PULONG *) in the output buffer
of my IOCTL call and then inside my driver, I do:
*((PULONG*)irp->mdladdress = (PULONG)pointer

where pointer is a pointer to virtual addresses in my driver. Is this the
correct method to pass a pointer back from the driver? I want to use the
pointer to be able to access some registers on my PCI card directly. I
tried creating an mdl to translate my virtual address (See a post I made a
few hours earlier) and want to pass this back too. Am I supposed to use
the translated of my virtual address to access the registers?

I really appreciate any help and suggestions you may have.

Thanks,
Wynn

> where pointer is a pointer to virtual addresses in my driver.

No, you cannot pass such pointers to user mode.

Max

xxxxx@hotmail.com wrote:

I want to try and pass a pointer from the driver back to the user. I
tried using an IOCTL with METHOD_OUT_DIRECT and using the mdl to pass the
pointer. I pass in a pointer to a pointer (PULONG *) in the output buffer
of my IOCTL call and then inside my driver, I do:
*((PULONG*)irp->mdladdress = (PULONG)pointer

where pointer is a pointer to virtual addresses in my driver. Is this the
correct method to pass a pointer back from the driver? I want to use the
pointer to be able to access some registers on my PCI card directly. I
tried creating an mdl to translate my virtual address (See a post I made a
few hours earlier) and want to pass this back too. Am I supposed to use
the translated of my virtual address to access the registers?

This will certainly give the application a 32-bit number, but the
application won’t be able to dereference it as a pointer: the OS kernel
is protected against user-mode access.


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

Hi Maxim and Walter,

Thank you for the replies.

My main reason for asking if a pointer could be passed back from the
driver was because I want to achieve very fast reads and writes (about 30
a second). I am a student and am in my final year of study and my final
year project was to first program a PCI (using an FPGA) and then
interfacing with the card through a windows driver. Perhaps you can point
me in the right direction then.

I am trying to acheive reads from 307200 registers each time but I need to
pass this data back to my user application about 30 times a second. Can
you suggest the best and fastest way for this transfer to happen? I am
relunctant to use DMA because it would require many modifications to our
hardware.

I appreciate any suggestions!

Thanks,
Wynn

> My main reason for asking if a pointer could be passed back from the

driver was because I want to achieve very fast reads and writes
(about 30
a second). I am a student and am in my final year of study and my
final
year project was to first program a PCI (using an FPGA) and then

Well, for student’s project, this is fine, though a commercial device
would better use DMA.

Max

xxxxx@hotmail.com wrote:

I am trying to acheive reads from 307200 registers each time but I need to
pass this data back to my user application about 30 times a second. Can
you suggest the best and fastest way for this transfer to happen? I am
relunctant to use DMA because it would require many modifications to our
hardware.

30 times a second is not so very fast. You should be able to do that
legally by using standard driver techniques like IPR_MJ_READ or
IRP_MJ_DEVICE_CONTROL.


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

Hi Mr. Walter Oney,

I am currently using IRP_MJ_DEVICE_CONTROL and using Direct I/O (I am not
using DMA though). In the IOCTL, I use READ_REGISTER_BUFFER_ULONG to read
the registers and put them into the mdl to pass back to my user
application. BUT, it is still too slow (about 1 read a second). Am I
doing something incorrectly?

Thanks,
Wynn

xxxxx@hotmail.com wrote:

I am currently using IRP_MJ_DEVICE_CONTROL and using Direct I/O (I am not
using DMA though). In the IOCTL, I use READ_REGISTER_BUFFER_ULONG to read
the registers and put them into the mdl to pass back to my user
application. BUT, it is still too slow (about 1 read a second). Am I
doing something incorrectly?

Hard to tell from just that much info. Certainly, there’s nothing in the
normal path from an application to a driver and back again that would
cause this kind of delay. How many ULONGs are you reading each time?
What is your application doing between the completion of one IOCTL and
the beginning of the next one?


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

I am reading 307200 ULONGs each time.

In between IOCTL, I am just taking certain bytes of each ULONG (e.g.
variable a = last 2 bytes, variable b = bytes 2 and 3) which is stored in
a struct. I tested the speed by just doing this and I get the reads for
about 1 second each time I read the 307200 ULONGs

xxxxx@hotmail.com wrote:

I am reading 307200 ULONGs each time.

So, we’re talking about locking and unlocking a 1.2 MB buffer each time
you do a read. How much physical memory is on this machine? Is there a
lot of disk activity that might indicate page thrashing? What sort of
timing do you see in the actual hardware operations?


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

Yes, I am locking and unlocking about 1.2MB each time I do a read. There
is 196MB of physical memory. Not much else is going on when I am doing
this, I made sure all other applications were closed and any unecessary
processes were stopped.

Just to confirm with you, first I lock the pages and before I return to
the user mode application, I need to unlock the pages correct? Would the
user mode application be able to access the pages after unlocking?