Hi all,
I recently write a virtual network card driver. And also, I created an application to receive some sensative data directly from driver by using DeviceIoControl).
What I did like this.
- Create an Event in my application and pass down event handle to driver, then keep on waiting it.
- Driver will set event to wake up the application, when driver gets some data.
- Then application is waked up and call DeviceIoControl() to send IRP to driver.
- Driver copy the data to buffer and return.
This way works. But I don’t think it is good one, because it takes a lot of time. Set event and application calling DeviceIoControl, all these take a lot of time. I am thinking why not let driver pass data directly to application. Is it possible ??
I think this can be done if a driver can call functions in application, or if driver has a way like “DeviceIoControl” to send any request up to application. But How can I do it???
Thanks and regards
Elton
Why not use WriteFile and ReadFile?
----- Original Message -----
From: “Li Dong”
To: “NT Developers Interest List”
Sent: Friday, March 07, 2003 3:19 PM
Subject: [ntdev] How to pass data from driver to Application
> Hi all,
>
> I recently write a virtual network card driver. And also, I created an application to receive some sensative data directly from driver by using DeviceIoControl).
>
> What I did like this.
>
> 1. Create an Event in my application and pass down event handle to driver, then keep on waiting it.
> 2. Driver will set event to wake up the application, when driver gets some data.
> 3. Then application is waked up and call DeviceIoControl() to send IRP to driver.
> 4. Driver copy the data to buffer and return.
>
> This way works. But I don’t think it is good one, because it takes a lot of time. Set event and application calling DeviceIoControl, all these take a lot of time. I am thinking why not let driver pass data directly to application. Is it possible ??
>
> I think this can be done if a driver can call functions in application, or if driver has a way like “DeviceIoControl” to send any request up to application. But How can I do it???
>
> Thanks and regards
> Elton
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: SONG1118@2911.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
There are alternative methods to the standard IOCTL inverted call model
(mostly undocumented - APCs, LPCs, etc.), but nothing that is any
significant degree faster than the method you’ve outlined below. Every
one still requires a context switch from the driver thread to service
thread (assuming they are in two different processes), and the time
required to do this dominates the time it takes to call DeviceIoControl
(a relatively fast API).
However, there is a way to avoid a memory copy or additional memory
allocation when you want to share data with your service. You can use
the technique in the OSR article linked to below to map an already
allocated piece of kernel memory to your service’s address space.
Some references:
http://www.osr.com/ntinsider/2000/sharing_memory.htm
http://www.osr.com/ntinsider/2002/inverted/inverted.htm
http://www.osr.com/ntinsider/1998/apc.htm
http://www.windowsitlibrary.com/Content/356/08/1.html
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0799/nerd/nerd07
99.htm&nav=/msj/0799/newnav.htm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Li Dong
Sent: Thursday, March 06, 2003 11:20 PM
To: NT Developers Interest List
Subject: [ntdev] How to pass data from driver to Application
Hi all,
I recently write a virtual network card driver. And also, I
created an application to receive some sensative data
directly from driver by using DeviceIoControl).
What I did like this.
- Create an Event in my application and pass down event
handle to driver, then keep on waiting it. 2. Driver will set
event to wake up the application, when driver gets some data.
- Then application is waked up and call DeviceIoControl() to
send IRP to driver. 4. Driver copy the data to buffer and return.
This way works. But I don’t think it is good one, because it
takes a lot of time. Set event and application calling
DeviceIoControl, all these take a lot of time. I am thinking
why not let driver pass data directly to application. Is it
possible ??
I think this can be done if a driver can call functions in
application, or if driver has a way like “DeviceIoControl”
to send any request up to application. But How can I do it???
Thanks and regards
Elton
You are currently subscribed to ntdev as: xxxxx@nryan.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
There has already been a lot of discussions here about driver to userprogram communications.
From what I learned, I could conclude ( but I might be wrong ) that the method you use is still
one of the most dynamic favourable ones. You could optimize the transfer by using shared memory
between your driver and the user application instead of using the DeviceIOControl. Of course, you
have to use some coordination methods between the driver and the user-api when reading/writing the
memory and setting/accepting new events. When calling user-code from within a driver, you have to
pass the ring0 to ring3 boundery and take care about potentionally being paged out user-code.
I don’t think you will find “official” ways that allow you to do this.
Christiaan
----- Original Message -----
From: “Li Dong”
To: “NT Developers Interest List”
Sent: Friday, March 07, 2003 8:19 AM
Subject: [ntdev] How to pass data from driver to Application
> Hi all,
>
> I recently write a virtual network card driver. And also, I created an application to receive some sensative data directly from
driver by using DeviceIoControl).
>
> What I did like this.
>
> 1. Create an Event in my application and pass down event handle to driver, then keep on waiting it.
> 2. Driver will set event to wake up the application, when driver gets some data.
> 3. Then application is waked up and call DeviceIoControl() to send IRP to driver.
> 4. Driver copy the data to buffer and return.
>
> This way works. But I don’t think it is good one, because it takes a lot of time. Set event and application calling
DeviceIoControl, all these take a lot of time. I am thinking why not let driver pass data directly to application. Is it possible
??
>
> I think this can be done if a driver can call functions in application, or if driver has a way like “DeviceIoControl” to send any
request up to application. But How can I do it???
>
> Thanks and regards
> Elton
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
Thank you Nryan and Christiaan for so many information. It helps me a lot.
Regards
Elton
>> xxxxx@nryan.com 03/07/03 04:24pm >>>
There are alternative methods to the standard IOCTL inverted call model
(mostly undocumented - APCs, LPCs, etc.), but nothing that is any
significant degree faster than the method you’ve outlined below. Every
one still requires a context switch from the driver thread to service
thread (assuming they are in two different processes), and the time
required to do this dominates the time it takes to call DeviceIoControl
(a relatively fast API).
However, there is a way to avoid a memory copy or additional memory
allocation when you want to share data with your service. You can use
the technique in the OSR article linked to below to map an already
allocated piece of kernel memory to your service’s address space.
Some references:
http://www.osr.com/ntinsider/2000/sharing_memory.htm
http://www.osr.com/ntinsider/2002/inverted/inverted.htm
http://www.osr.com/ntinsider/1998/apc.htm
http://www.windowsitlibrary.com/Content/356/08/1.html
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0799/nerd/nerd07
99.htm&nav=/msj/0799/newnav.htm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Li Dong
Sent: Thursday, March 06, 2003 11:20 PM
To: NT Developers Interest List
Subject: [ntdev] How to pass data from driver to Application
Hi all,
I recently write a virtual network card driver. And also, I
created an application to receive some sensative data
directly from driver by using DeviceIoControl).
What I did like this.
- Create an Event in my application and pass down event
handle to driver, then keep on waiting it. 2. Driver will set
event to wake up the application, when driver gets some data.
- Then application is waked up and call DeviceIoControl() to
send IRP to driver. 4. Driver copy the data to buffer and return.
This way works. But I don’t think it is good one, because it
takes a lot of time. Set event and application calling
DeviceIoControl, all these take a lot of time. I am thinking
why not let driver pass data directly to application. Is it
possible ??
I think this can be done if a driver can call functions in
application, or if driver has a way like “DeviceIoControl”
to send any request up to application. But How can I do it???
Thanks and regards
Elton
You are currently subscribed to ntdev as: xxxxx@nryan.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@i2r.a-star.edu.sg
To unsubscribe send a blank email to xxxxx@lists.osr.com
Also, if you don’t want to fuss with an event, you could just block in
an ioctl. It would (theoretically) save a couple of cycles because the
event wake-up and subsequent ioctl wouldn’t have to happen. I think
Nicholas is still right about the context switch being the big time
sink, though. It’d be interesting to benchmark these methods, just to
confirm.
-sd
On Sun, 2003-03-09 at 21:22, Li Dong wrote:
Thank you Nryan and Christiaan for so many information. It helps me a lot.
Regards
Elton
>>> xxxxx@nryan.com 03/07/03 04:24pm >>>
There are alternative methods to the standard IOCTL inverted call model
(mostly undocumented - APCs, LPCs, etc.), but nothing that is any
significant degree faster than the method you’ve outlined below. Every
one still requires a context switch from the driver thread to service
thread (assuming they are in two different processes), and the time
required to do this dominates the time it takes to call DeviceIoControl
(a relatively fast API).
However, there is a way to avoid a memory copy or additional memory
allocation when you want to share data with your service. You can use
the technique in the OSR article linked to below to map an already
allocated piece of kernel memory to your service’s address space.
Some references:
http://www.osr.com/ntinsider/2000/sharing_memory.htm
http://www.osr.com/ntinsider/2002/inverted/inverted.htm
http://www.osr.com/ntinsider/1998/apc.htm
http://www.windowsitlibrary.com/Content/356/08/1.html
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0799/nerd/nerd07
99.htm&nav=/msj/0799/newnav.htm
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Li Dong
> Sent: Thursday, March 06, 2003 11:20 PM
> To: NT Developers Interest List
> Subject: [ntdev] How to pass data from driver to Application
>
>
> Hi all,
>
> I recently write a virtual network card driver. And also, I
> created an application to receive some sensative data
> directly from driver by using DeviceIoControl).
>
> What I did like this.
>
> 1. Create an Event in my application and pass down event
> handle to driver, then keep on waiting it. 2. Driver will set
> event to wake up the application, when driver gets some data.
> 3. Then application is waked up and call DeviceIoControl() to
> send IRP to driver. 4. Driver copy the data to buffer and return.
>
> This way works. But I don’t think it is good one, because it
> takes a lot of time. Set event and application calling
> DeviceIoControl, all these take a lot of time. I am thinking
> why not let driver pass data directly to application. Is it
> possible ??
>
> I think this can be done if a driver can call functions in
> application, or if driver has a way like “DeviceIoControl”
> to send any request up to application. But How can I do it???
>
> Thanks and regards
> Elton
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@nryan.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
You are currently subscribed to ntdev as: xxxxx@i2r.a-star.edu.sg
To unsubscribe send a blank email to xxxxx@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@positivenetworks.net
To unsubscribe send a blank email to xxxxx@lists.osr.com
–
Steve Dispensa
Chief Technology Officer
Positive Networks, Inc.
>3. Then application is waked up and call DeviceIoControl() to send
IRP to driver.
- Driver copy the data to buffer and return.
Forget the event, use only the IOCTL and send it from the app using
overlapped IO. It will be completed by the driver when the event will
occur.
Be sure you have proper cancellation logic in the driver in case if
the app will want to quit before the event occured.
Max