Event reset

I am having trouble setting an event more than once. I use http://www.osronline.com/article.cfm?id=108 as a reference but can’t seem to reuse the event.

My steps:

App-----
SharedEvent = CreateEvent(NULL, TRUE, FALSE, “SharedEvent”);
if (SharedEvent == NULL)
return 1;

if (!DeviceIoControl(DeviceDriver,
IOCTL_OPEN_EVENT,
NULL, 0,
NULL, 0,
&bytesReturned,
NULL))
return 1;

Driver----
HANDLE SharedEventHandle = NULL;
PKEVENT SharedEvent = NULL;
RtlInitUnicodeString(&EventName, L"\BaseNamedObjects\SharedEvent");
SharedEvent = IoCreateNotificationEvent(&EventName, &SharedEventHandle);
if (SharedEvent != NULL)
n ObReferenceObject(SharedEvent);

After this setup I have my app send an instruction to cause an interrupt in the driver which will then call.

KeSetEvent(SharedEvent, 0, FALSE);

Meanwhile the app:
App----
WaitStatus = WaitForSingleObject(SharedEvent, 5000);
if (WaitStatus != WAIT_OBJECT_0)
return error;
else
ResetEvent(SharedEvent)

This seems to work just fine the first time but if I generate a second interrupt, WaitForSingleObject times out every time.

Is there anything here that I’m neglecting to do or doing incorrectly?

> Is there anything here that I’m neglecting to do or doing incorrectly?

Well, I think it would be better to ask us whether you do anything correctly here…

Anton Bassov

Hi

I’m suprised that this works at all since the driver code creates the
event in global namespace but the application is creating the event in
the session local namespace. Unless the application is running as a
system service, i.e. in session zero, they are not sharing the same event.

An app running as ordinary user cannot create objects in the global
namespace but it can access already created objects. To do that the app
should prepend "Global" to the name. In your case, you should let the
driver create the event in the global namespace first and then “create”
the event in the app with "Global" prepended to the name.

Good luck!

/Robert

xxxxx@gmail.com wrote:

I am having trouble setting an event more than once. I use http://www.osronline.com/article.cfm?id=108 as a reference but can’t seem to reuse the event.

My steps:

App-----
SharedEvent = CreateEvent(NULL, TRUE, FALSE, “SharedEvent”);
if (SharedEvent == NULL)
return 1;

if (!DeviceIoControl(DeviceDriver,
IOCTL_OPEN_EVENT,
NULL, 0,
NULL, 0,
&bytesReturned,
NULL))
return 1;

Driver----
HANDLE SharedEventHandle = NULL;
PKEVENT SharedEvent = NULL;
RtlInitUnicodeString(&EventName, L"\BaseNamedObjects\SharedEvent");
SharedEvent = IoCreateNotificationEvent(&EventName, &SharedEventHandle);
if (SharedEvent != NULL)
n ObReferenceObject(SharedEvent);

After this setup I have my app send an instruction to cause an interrupt in the driver which will then call.

KeSetEvent(SharedEvent, 0, FALSE);

Meanwhile the app:
App----
WaitStatus = WaitForSingleObject(SharedEvent, 5000);
if (WaitStatus != WAIT_OBJECT_0)
return error;
else
ResetEvent(SharedEvent)

This seems to work just fine the first time but if I generate a second interrupt, WaitForSingleObject times out every time.

Is there anything here that I’m neglecting to do or doing incorrectly?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

95% of this code comes from the OSR example so I assume it is correct. Your comment is not helpful.

I’ll give your idea about adding Global a try. This code is basically cut and paste from the article I mentioned in my original post. The only addition I made was the resetevent( ) call. Surprised it wouldn’t work as written.

What OS are you running on?

I should have mentioned that on XP everything is usually running in
session zero. The other sessions come in play when you use fast user
switching or logon to a terminal server. What I tried to explain applies
to Vista and later.

/Robert

xxxxx@gmail.com wrote:

I’ll give your idea about adding Global a try. This code is basically cut and paste from the article I mentioned in my original post. The only addition I made was the resetevent( ) call. Surprised it wouldn’t work as written.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Have you noticed that the article is almost 8 years old? Things changed
since then. In addition, read carefully the part about passing and
referencing the event handle instead of using name. If you have a
tightly coupled driver and app, it can be better way. The article seems
to discourage this technique but not generally and it can work better
for you.

Last but not least: ask yourself if you really want to share event?
Wouldn’t inverted call model work better for your purposes? It mostly
does unless the only thing you want is to inform an app about some event
which is unlikely. If the event is tied with data app has to read,
inverted call model is better.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Wednesday, June 09, 2010 1:03 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Event reset

I’ll give your idea about adding Global a try. This code is
basically cut and paste from the article I mentioned in my
original post. The only addition I made was the resetevent(
) call. Surprised it wouldn’t work as written.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer

I’m testing on XP but I need it to work on Vista and later too.

Despite the articles age I could find nothing more up to date. I previously tried passing the handle but since the article discouraged it, as you mentioned, I tried this method. It seemed simpler too. With Robert’s warnings I think I ought to go back to passing the handle.

I’m unfamiliar with the inverted call model and will look into this. Any suggestions on where to find good information on this? The event in this case is indeed an indicator of data that can now be read.

Thanks.

Inverted call model is discussed in this periodically at least once per
month. Try to seach list archives. In addition, WDK samples and also OSR
web: http://www.osronline.com/article.cfm?id=94 which is the first
Google hit.

And please. Don’t blindly copy&&paste the code. Try to understand it at
first. I’m saying this because your decision about using named event
instead of handle seems to be based on first impression instead of real
understanding.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Wednesday, June 09, 2010 1:47 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Event reset

I’m testing on XP but I need it to work on Vista and later too.

Despite the articles age I could find nothing more up to
date. I previously tried passing the handle but since the
article discouraged it, as you mentioned, I tried this
method. It seemed simpler too. With Robert’s warnings I
think I ought to go back to passing the handle.

I’m unfamiliar with the inverted call model and will look
into this. Any suggestions on where to find good information
on this? The event in this case is indeed an indicator of
data that can now be read.

Thanks.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer

>Robert’s warnings I think I ought to go back to passing the handle.

Yes, I would say passing the handle is better.

I’m unfamiliar with the inverted call model and will look into this.

Call the IOCTL, it will be pended in the driver, and completed when something occurs.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> This seems to work just fine the first time but if I generate a second interrupt, WaitForSingleObject

times out every time.

Then your naming is OK, and you have a race condition. Try to re-read the code thoroughly to catch it.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

have you read the comments to http://www.osronline.com/article.cfm?id=108 ?

I did read the comments but found nothing helpful. There was a useful question but no answer.