Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

KeWaitForSingleObject in Completion/Cancellation Routine

0 views
Skip to first unread message

Prakash Manannavar

unread,
Nov 19, 2009, 6:21:01 AM11/19/09
to
Hi all,


Is it a right thing to wait for an event with KeWaitForSingleObject in the
Completion/Cancellation Routine?

In DDK reference, it has been told that, caller for KeWaitForSingleObject
can run at IRQL <= DISPATCH_LEVEL. Even Cancell routines will run at IRQL <=
DISPATCH_LEVEL.
--
~~~~~
Prakash A Manannavar,
Bangalore/Bengaluru.

Scott Noone

unread,
Nov 19, 2009, 8:11:32 AM11/19/09
to
> Is it a right thing to wait for an event with KeWaitForSingleObject in the
> Completion/Cancellation Routine?

No, that is not a good idea. As you noted this may break the IRQL rules as
completion/cancel routines can be called at IRQL DISPATCH_LEVEL.

--
Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

"Prakash Manannavar" <PrakashM...@discussions.microsoft.com> wrote in
message news:8488E223-4807-4EA5...@microsoft.com...

Prakash Manannavar

unread,
Nov 20, 2009, 12:18:04 AM11/20/09
to
Thanks Scott,

I have some issues,

1. If waiting with KeWaitForSingleObejct at IRQL <= DISPATCH_LEVEL, Is there
any specific reason which has been supported by OS?

2. I read KeRaiseIrql and KeLowerIrql functions, As I read we can raise IRQL
first and then we can lower it to the previous level. Is there any functions
to lower the IRQL and then raise it to the previous level?

David Craig

unread,
Nov 20, 2009, 12:49:16 AM11/20/09
to
NO!!! That will/can cause priority inversion.

"Prakash Manannavar" <PrakashM...@discussions.microsoft.com> wrote in

message news:BAD738A5-ECE4-4D4B...@microsoft.com...

Tim Roberts

unread,
Nov 20, 2009, 1:59:19 AM11/20/09
to
Prakash Manannavar <PrakashM...@discussions.microsoft.com> wrote:
>
>2. I read KeRaiseIrql and KeLowerIrql functions, As I read we can raise IRQL
>first and then we can lower it to the previous level. Is there any functions
>to lower the IRQL and then raise it to the previous level?

Think about what you're asking. The reason you run at an increased IRQL is
to make sure your code can't be interrupted by lower level code. AS SOON
AS you lower your IRQL, your code will be interrupted by lower level code.

The RIGHT way do to this is to queue up a work item with IoQueueWorkItem.
The callback will be called at PASSIVE_LEVEL.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

eagersh

unread,
Nov 20, 2009, 12:48:36 PM11/20/09
to
On Nov 19, 11:59 pm, Tim Roberts <t...@probo.com> wrote:
> Prakash Manannavar <PrakashMananna...@discussions.microsoft.com> wrote:

> The RIGHT way do to this is to queue up a work item with IoQueueWorkItem.
> The callback will be called at PASSIVE_LEVEL.

I would like to add that OP could move his KeWaitForSingleObject into
work item or created system thread and synchronize the work item with
a drivers Completion/Cancellation Routine. It is little bit
complicated but it is safe for sure.

Igor Sharovar

Doron Holan [MSFT]

unread,
Nov 20, 2009, 6:42:22 PM11/20/09
to
lowering irql that you did not raise does not cause priority inversion. it
causes deadlocks and strange undiagnosible errors.

d

--

This posting is provided "AS IS" with no warranties, and confers no rights.


"David Craig" <dri...@noemail.noemail> wrote in message
news:OkgjzUaa...@TK2MSFTNGP06.phx.gbl...

Prakash Manannavar

unread,
Nov 24, 2009, 1:36:02 AM11/24/09
to
Thanks guys,

Now I have created WorkItem and queuing it.

In DDK it has been told that "caller of KeWaitForSingleObject can be run at
IRQL <= DISPATCH LEVEL"

I wanted to know that, is there any specific scenarios we can wait there??

David Craig

unread,
Nov 24, 2009, 2:19:52 AM11/24/09
to
I would take a class about driver development.

I would also use the WDK and not a DDK. Version 7.0.0 A.K.A. 7600.16385.0
is the most recent and supports back to XP.

The documentation describes how you can use KeWFSO. You can 'wait' at
DISPATCH_LEVEL or lower, however the 'wait' at DISPATCH_LEVEL must be zero,
which makes it a test and not a real wait. In the wrong context waiting at
APC_LEVEL can cause a deadlock, though that is usually only in the file
systems area.


"Prakash Manannavar" <PrakashM...@discussions.microsoft.com> wrote in

message news:D7855A81-20EA-4711...@microsoft.com...

0 new messages