Event sharing between user mode and Kernel Mode

Hi,

How do we pass some data along with firing an event from kernel mode to user
mode.

I was thinking of using KeSetEvent, but there is provision to send some data
along with it.
I do not want to use an IOCTL at that time so as to get data from Kernel.
Please show me the way.

Thanks and Regards,
Shreshth

The easiest and best way to transact data between user and kernel modes is
via an IO request, whether IOCTL or Read/WriteFile, and about as fast as
you can get. Simply hang an IO request on the driver, who pends it until
it’s time to use it. When the driver completes it, hang another.

Gary G. Little


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Shreshth Luthra
Sent: Tuesday, June 06, 2006 8:47 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Event sharing between user mode and Kernel Mode

Hi,

How do we pass some data along with firing an event from kernel mode to
user mode.

I was thinking of using KeSetEvent, but there is provision to send some
data along with it.
I do not want to use an IOCTL at that time so as to get data from Kernel.
Please show me the way.

Thanks and Regards,
Shreshth — Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17 You are currently subscribed
to ntfsd as: xxxxx@seagate.com To unsubscribe send a blank email
to xxxxx@lists.osr.com

Hi Gary,

In my case, i am having a dynamic list (1 to as many as 100 entries) to be
sent to the user mode.
Which means that i will have to signal the event and then issue an IOCTL to
get the number of entries “n” from the driver and then another IOCTL, so as
to get each and every entry (“n” entries).

I want to do this in some better way.
Just think, in case we have some provision of sending data to UserMode along
with SetEvent, it will simply retrieve the dynamic list (one entry at a
time) and the user mode can process them.
I was thinking of dumping it in registry or so (and then user mode with
retrieve it from registry), but that too does not seem to be a good
approach.
About a month back, i had read some similar problem on ntfsd but could not
find that thread again.

Please suggest me what can be done in this case.

On 6/6/06, xxxxx@seagate.com wrote:
>
> The easiest and best way to transact data between user and kernel modes
> is via an IO request, whether IOCTL or Read/WriteFile, and about as fast as
> you can get. Simply hang an IO request on the driver, who pends it until
> it’s time to use it. When the driver completes it, hang another.
>
> Gary G. Little
> ------------------------------
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *Shreshth Luthra
> Sent: Tuesday, June 06, 2006 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Event sharing between user mode and Kernel Mode
>
>
>
> Hi,
>
> How do we pass some data along with firing an event from kernel mode to
> user mode.
>
> I was thinking of using KeSetEvent, but there is provision to send some
> data along with it.
> I do not want to use an IOCTL at that time so as to get data from Kernel.
> Please show me the way.
>
>
> Thanks and Regards,
> Shreshth — Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17 You are currently subscribed
> to ntfsd as: xxxxx@seagate.com To unsubscribe send a blank email
> to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
>
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

No, you are hung up on not using an IOCTL for an event, consider this simple
model:

a. Issue an IOCTL with a buffer of a size to hold a common number of
entries
b. IOCTL pends in the driver, the user mode program can wait on the
OVERLAPPED event or otherwise test it
c. Items come in, you finish the IOCTL filling in as many entries as
the buffer will hold and complete it.
d. Once the application gets the entries it resubmitts the IOCTL, if
their are entries present the IOCTL is immediately completed with the next
set of entries, if not it pends

Or better yet have multiple IOCTL’s and complete them as needed to get the
data

Using events is not going to make things faster, and it is going to make
things harder (such as what do you do if the application crashes how do you
detect and clean up things? Your idea of using the registry is really
wrong, there are many problems here, including that the application in the
end still has to notify the driver it got the data, unless you want to fill
the registry with old entries?


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

“Shreshth Luthra” wrote in message
news:xxxxx@ntfsd…
> Hi Gary,
>
> In my case, i am having a dynamic list (1 to as many as 100 entries) to be
> sent to the user mode.
> Which means that i will have to signal the event and then issue an IOCTL
> to
> get the number of entries “n” from the driver and then another IOCTL, so
> as
> to get each and every entry (“n” entries).
>
> I want to do this in some better way.
> Just think, in case we have some provision of sending data to UserMode
> along
> with SetEvent, it will simply retrieve the dynamic list (one entry at a
> time) and the user mode can process them.
> I was thinking of dumping it in registry or so (and then user mode with
> retrieve it from registry), but that too does not seem to be a good
> approach.
> About a month back, i had read some similar problem on ntfsd but could not
> find that thread again.
>
> Please suggest me what can be done in this case.
>
>
> On 6/6/06, xxxxx@seagate.com wrote:
>>
>> The easiest and best way to transact data between user and kernel modes
>> is via an IO request, whether IOCTL or Read/WriteFile, and about as fast
>> as
>> you can get. Simply hang an IO request on the driver, who pends it until
>> it’s time to use it. When the driver completes it, hang another.
>>
>> Gary G. Little
>> ------------------------------
>>
>> From: xxxxx@lists.osr.com [mailto:
>> xxxxx@lists.osr.com] *On Behalf Of *Shreshth Luthra
>> Sent: Tuesday, June 06, 2006 8:47 AM
>> To: Windows File Systems Devs Interest List
>> Subject: [ntfsd] Event sharing between user mode and Kernel Mode
>>
>>
>>
>> Hi,
>>
>> How do we pass some data along with firing an event from kernel mode to
>> user mode.
>>
>> I was thinking of using KeSetEvent, but there is provision to send some
>> data along with it.
>> I do not want to use an IOCTL at that time so as to get data from Kernel.
>> Please show me the way.
>>
>>
>> Thanks and Regards,
>> Shreshth — Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17 You are currently subscribed
>> to ntfsd as: xxxxx@seagate.com To unsubscribe send a blank email
>> to xxxxx@lists.osr.com
>>
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
>> ‘’
>>
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>

Have your user mode application open the device with
FILE_FLAG_OVERLAPPED.

Then have it issue an IOCTL with and OVERLAPPED structure
(and an EVENT in the structure.) Use a buffer that is
big enough to hold the ‘average’ number of entries.

The usermode application then waits on the event.

The driver will return STATUS_IO_PENDING when it receives the
IOCTL and put the IRP on a queue.

When the driver has some entries to send to user mode, it
removes the IRP from the queue, and fills it with as many
entries as will fit (reserving the first 8 bytes of the
buffer for a header.)

It then writes the total number of entries it has to
send in the first 4 bytes of the buffer and the number
of entries it was able to send in the second four bytes,
and completes the IRP. The driver will then need to
stash the remaining entries away someplace.

Completing the IRP will wake the user mode application up,
which will process the buffer, and if necessary, it will
queue another IOCTL to the driver to retrieve the remaining
entries.

The driver will then fill that buffer with the remaining entries,
and complete it.

Repeat for as long as usermode app will be processing entries
for the driver.

Thanks,

Joseph

Shreshth Luthra wrote:

Hi Gary,

In my case, i am having a dynamic list (1 to as many as 100 entries) to
be sent to the user mode.
Which means that i will have to signal the event and then issue an IOCTL
to get the number of entries “n” from the driver and then another IOCTL,
so as to get each and every entry (“n” entries).

I want to do this in some better way.
Just think, in case we have some provision of sending data to UserMode
along with SetEvent, it will simply retrieve the dynamic list (one entry
at a time) and the user mode can process them.
I was thinking of dumping it in registry or so (and then user mode with
retrieve it from registry), but that too does not seem to be a good
approach.
About a month back, i had read some similar problem on ntfsd but could
not find that thread again.

Please suggest me what can be done in this case.

On 6/6/06, *xxxxx@seagate.com
mailto:xxxxx* > mailto:xxxxx> wrote:
>
> The easiest and best way to transact data between user and kernel
> modes is via an IO request, whether IOCTL or Read/WriteFile, and
> about as fast as you can get. Simply hang an IO request on the
> driver, who pends it until it’s time to use it. When the driver
> completes it, hang another.
>
> Gary G. Little
>
> ------------------------------------------------------------------------
>
> From: xxxxx@lists.osr.com
> mailto:xxxxx [mailto:
> xxxxx@lists.osr.com
> mailto:xxxxx] *On Behalf Of *Shreshth
> Luthra
> Sent: Tuesday, June 06, 2006 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Event sharing between user mode and Kernel Mode
>
>
>
> Hi,
>
> How do we pass some data along with firing an event from kernel mode
> to user mode.
>
> I was thinking of using KeSetEvent, but there is provision to send
> some data along with it.
> I do not want to use an IOCTL at that time so as to get data from
> Kernel.
> Please show me the way.
>
>
> Thanks and Regards,
> Shreshth — Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17 You are currently
> subscribed to ntfsd as: xxxxx@seagate.com
> mailto:xxxxx To unsubscribe send a blank email
> to xxxxx@lists.osr.com
> mailto:xxxxx
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> mailto:xxxxx
>
>
> — Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17 You are currently subscribed
> to ntfsd as: xxxxx@vandyke.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

> a. Issue an IOCTL with a buffer of a size to hold a common number of

entries
> b. IOCTL pends in the driver, the user mode program can wait on the
OVERLAPPED event or otherwise test it

Thanks for your inputs Don. I got most of the things which you mean, but
still there are a few doubts related to a) n b)

Here do you mean that, even before i start getting entries in list, i should
issue an ioctl for reading the values (in such a case, the IOCTL will remain
pending till the time it gets entries and returns) or i should better issue
it as soon as the driver signal that “Hey User app: I am having entries,
issue the IOCTL to read these entries”.

There could be another approach in which instead of having an event, i keep
on pinging the driver with IOCTL so as to check if it is having any entries.

Or better yet have multiple IOCTL’s and complete them as needed to get the
data

Here do you mean to say that i issue mutiple calls to the same IOCTL at the
same time so as to get the dynamic list. Timely, as and when i will get
entries, these IOCTLs will return.
I am sorry, but could you please explain me that how can i have so many
IOCTLS pending all the time. Won’t it induce overhead on the system. Is
there any article on OSR which speaks about how to implement it.

Thanks and Regards,
Shreshth

On 6/6/06, Don Burn wrote:
>
> No, you are hung up on not using an IOCTL for an event, consider this
> simple
> model:
>
> a. Issue an IOCTL with a buffer of a size to hold a common number
> of
> entries
> b. IOCTL pends in the driver, the user mode program can wait on the
> OVERLAPPED event or otherwise test it
> c. Items come in, you finish the IOCTL filling in as many entries as
> the buffer will hold and complete it.
> d. Once the application gets the entries it resubmitts the IOCTL, if
> their are entries present the IOCTL is immediately completed with the next
> set of entries, if not it pends
>
> Or better yet have multiple IOCTL’s and complete them as needed to get the
> data
>
> Using events is not going to make things faster, and it is going to make
> things harder (such as what do you do if the application crashes how do
> you
> detect and clean up things? Your idea of using the registry is really
> wrong, there are many problems here, including that the application in the
> end still has to notify the driver it got the data, unless you want to
> fill
> the registry with old entries?
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> http://www.windrvr.com
> Remove StopSpam from the email to reply
>
>
>
>
> “Shreshth Luthra” wrote in message
> news:xxxxx@ntfsd…
> > Hi Gary,
> >
> > In my case, i am having a dynamic list (1 to as many as 100 entries) to
> be
> > sent to the user mode.
> > Which means that i will have to signal the event and then issue an IOCTL
> > to
> > get the number of entries “n” from the driver and then another IOCTL, so
> > as
> > to get each and every entry (“n” entries).
> >
> > I want to do this in some better way.
> > Just think, in case we have some provision of sending data to UserMode
> > along
> > with SetEvent, it will simply retrieve the dynamic list (one entry at a
> > time) and the user mode can process them.
> > I was thinking of dumping it in registry or so (and then user mode with
> > retrieve it from registry), but that too does not seem to be a good
> > approach.
> > About a month back, i had read some similar problem on ntfsd but could
> not
> > find that thread again.
> >
> > Please suggest me what can be done in this case.
> >
> >
> > On 6/6/06, xxxxx@seagate.com wrote:
> >>
> >> The easiest and best way to transact data between user and kernel
> modes
> >> is via an IO request, whether IOCTL or Read/WriteFile, and about as
> fast
> >> as
> >> you can get. Simply hang an IO request on the driver, who pends it
> until
> >> it’s time to use it. When the driver completes it, hang another.
> >>
> >> Gary G. Little
> >> ------------------------------
> >>
> >> From: xxxxx@lists.osr.com [mailto:
> >> xxxxx@lists.osr.com] *On Behalf Of *Shreshth Luthra
> >> Sent: Tuesday, June 06, 2006 8:47 AM
> >> To: Windows File Systems Devs Interest List
> >> Subject: [ntfsd] Event sharing between user mode and Kernel Mode
> >>
> >>
> >>
> >> Hi,
> >>
> >> How do we pass some data along with firing an event from kernel mode to
> >> user mode.
> >>
> >> I was thinking of using KeSetEvent, but there is provision to send some
> >> data along with it.
> >> I do not want to use an IOCTL at that time so as to get data from
> Kernel.
> >> Please show me the way.
> >>
> >>
> >> Thanks and Regards,
> >> Shreshth — Questions? First check the IFS FAQ at
> >> https://www.osronline.com/article.cfm?id=17 You are currently
> subscribed
> >> to ntfsd as: xxxxx@seagate.com To unsubscribe send a blank
> email
> >> to xxxxx@lists.osr.com
> >>
> >>
> >> —
> >> Questions? First check the IFS FAQ at
> >> https://www.osronline.com/article.cfm?id=17
> >>
> >> You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
> >> ‘’
> >>
> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
> >>
> >
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

You issue one or more IOCTL’s with OVERLAPPED I/O as soon as your
application starts. Have the driver pend these requests (use IO_CSQ see
IoCsqInitializeEx) and then when data comes available you complete the
request. The OVERLAPPED I/O provides an event signalling mechanism for
you. The overhead of a bunch of IOCTL’s is small (unless you have huge
buffers with these).

The basic concept of all this is well explained in the article
http://www.osronline.com/article.cfm?id=94 That article was written before
cancel safe queues, so look at the src\general\cancel sample from the DDK on
a better way to pend the requests.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

“Shreshth Luthra” wrote in message
news:xxxxx@ntfsd…
>> a. Issue an IOCTL with a buffer of a size to hold a common number
>> of
>>entries
> > b. IOCTL pends in the driver, the user mode program can wait on the
>>OVERLAPPED event or otherwise test it
>
> Thanks for your inputs Don. I got most of the things which you mean, but
> still there are a few doubts related to a) n b)
>
>
> Here do you mean that, even before i start getting entries in list, i
> should
> issue an ioctl for reading the values (in such a case, the IOCTL will
> remain
> pending till the time it gets entries and returns) or i should better
> issue
> it as soon as the driver signal that “Hey User app: I am having entries,
> issue the IOCTL to read these entries”.
>
> There could be another approach in which instead of having an event, i
> keep
> on pinging the driver with IOCTL so as to check if it is having any
> entries.
>
>
>> Or better yet have multiple IOCTL’s and complete them as needed to get
>> the
>> data
>
> Here do you mean to say that i issue mutiple calls to the same IOCTL at
> the
> same time so as to get the dynamic list. Timely, as and when i will get
> entries, these IOCTLs will return.
> I am sorry, but could you please explain me that how can i have so many
> IOCTLS pending all the time. Won’t it induce overhead on the system. Is
> there any article on OSR which speaks about how to implement it.
>
> Thanks and Regards,
> Shreshth
>
>
>
> On 6/6/06, Don Burn wrote:
>>
>> No, you are hung up on not using an IOCTL for an event, consider this
>> simple
>> model:
>>
>> a. Issue an IOCTL with a buffer of a size to hold a common number
>> of
>> entries
>> b. IOCTL pends in the driver, the user mode program can wait on the
>> OVERLAPPED event or otherwise test it
>> c. Items come in, you finish the IOCTL filling in as many entries
>> as
>> the buffer will hold and complete it.
>> d. Once the application gets the entries it resubmitts the IOCTL,
>> if
>> their are entries present the IOCTL is immediately completed with the
>> next
>> set of entries, if not it pends
>>
>> Or better yet have multiple IOCTL’s and complete them as needed to get
>> the
>> data
>>
>> Using events is not going to make things faster, and it is going to make
>> things harder (such as what do you do if the application crashes how do
>> you
>> detect and clean up things? Your idea of using the registry is really
>> wrong, there are many problems here, including that the application in
>> the
>> end still has to notify the driver it got the data, unless you want to
>> fill
>> the registry with old entries?
>>
>>
>> –
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> http://www.windrvr.com
>> Remove StopSpam from the email to reply
>>
>>
>>
>>
>> “Shreshth Luthra” wrote in message
>> news:xxxxx@ntfsd…
>> > Hi Gary,
>> >
>> > In my case, i am having a dynamic list (1 to as many as 100 entries) to
>> be
>> > sent to the user mode.
>> > Which means that i will have to signal the event and then issue an
>> > IOCTL
>> > to
>> > get the number of entries “n” from the driver and then another IOCTL,
>> > so
>> > as
>> > to get each and every entry (“n” entries).
>> >
>> > I want to do this in some better way.
>> > Just think, in case we have some provision of sending data to UserMode
>> > along
>> > with SetEvent, it will simply retrieve the dynamic list (one entry at a
>> > time) and the user mode can process them.
>> > I was thinking of dumping it in registry or so (and then user mode with
>> > retrieve it from registry), but that too does not seem to be a good
>> > approach.
>> > About a month back, i had read some similar problem on ntfsd but could
>> not
>> > find that thread again.
>> >
>> > Please suggest me what can be done in this case.
>> >
>> >
>> > On 6/6/06, xxxxx@seagate.com wrote:
>> >>
>> >> The easiest and best way to transact data between user and kernel
>> modes
>> >> is via an IO request, whether IOCTL or Read/WriteFile, and about as
>> fast
>> >> as
>> >> you can get. Simply hang an IO request on the driver, who pends it
>> until
>> >> it’s time to use it. When the driver completes it, hang another.
>> >>
>> >> Gary G. Little
>> >> ------------------------------
>> >>
>> >> From: xxxxx@lists.osr.com [mailto:
>> >> xxxxx@lists.osr.com] *On Behalf Of *Shreshth Luthra
>> >> Sent: Tuesday, June 06, 2006 8:47 AM
>> >> To: Windows File Systems Devs Interest List
>> >> Subject: [ntfsd] Event sharing between user mode and Kernel Mode
>> >>
>> >>
>> >>
>> >> Hi,
>> >>
>> >> How do we pass some data along with firing an event from kernel mode
>> >> to
>> >> user mode.
>> >>
>> >> I was thinking of using KeSetEvent, but there is provision to send
>> >> some
>> >> data along with it.
>> >> I do not want to use an IOCTL at that time so as to get data from
>> Kernel.
>> >> Please show me the way.
>> >>
>> >>
>> >> Thanks and Regards,
>> >> Shreshth — Questions? First check the IFS FAQ at
>> >> https://www.osronline.com/article.cfm?id=17 You are currently
>> subscribed
>> >> to ntfsd as: xxxxx@seagate.com To unsubscribe send a blank
>> email
>> >> to xxxxx@lists.osr.com
>> >>
>> >>
>> >> —
>> >> Questions? First check the IFS FAQ at
>> >> https://www.osronline.com/article.cfm?id=17
>> >>
>> >> You are currently subscribed to ntfsd as: unknown lmsubst tag
>> >> argument:
>> >> ‘’
>> >>
>> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
>> >>
>> >
>>
>>
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@gmail.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>

> I am sorry, but could you please explain me that how can i have so many

IOCTLS pending all the time. Won’t it induce overhead on the system. Is

Surely by far lesser overhead then even 1 long registry value.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com