KeReleaseSemaphore called in a DPC

Am I correct that this call is potentially dangerous to make within a DPC?
The DDK documentation states that the function can be called at IRQL <=
DISPATCH_LEVEL provided that the Wait parameter is set to FALSE. However it
also states that if the resulting value is greater than the limit of the
semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED, is raised. If
this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I would expect
that result to be a BSOD.

  • Steve -

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

When I first ran into this I concluded that semaphores are bad and evil in
nt and should be avoided at all costs :slight_smile: Of course the count ought never
get there, right?

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 10:27 AM
To: NT Developers Interest List
Subject: [ntdev] KeReleaseSemaphore called in a DPC

Am I correct that this call is potentially dangerous to make within a DPC?
The DDK documentation states that the function can be called at IRQL <=
DISPATCH_LEVEL provided that the Wait parameter is set to FALSE. However it
also states that if the resulting value is greater than the limit of the
semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED, is raised. If
this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I would expect
that result to be a BSOD.

  • Steve -

You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I’ll rephrase the question. Will exceptions cause a Bugcheck at Dispatch
if they are handled correctly? If not, then the answer to this is, catch
the exception.

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 10:27 AM
To: NT Developers Interest List
Subject: [ntdev] KeReleaseSemaphore called in a DPC

Am I correct that this call is potentially dangerous to make within a DPC?
The DDK documentation states that the function can be called at IRQL <=
DISPATCH_LEVEL provided that the Wait parameter is set to FALSE. However
it
also states that if the resulting value is greater than the limit of the
semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED, is raised.
If
this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I would expect
that result to be a BSOD.

  • Steve -

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I believe that exceptions will cause a bugcheck. ExRaiseStatus() is called
to generate an exception and the DDK states that you can only call this
function if running at IRQL PASSIVE_LEVEL I would conclude that exceptions
will cause a bugcheck.

  • Steve -

-----Original Message-----
From: Jason LaVoie [mailto:lavoie@us.ibm.com]
Sent: Thursday, December 20, 2001 11:22 AM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I’ll rephrase the question. Will exceptions cause a Bugcheck
at Dispatch
if they are handled correctly? If not, then the answer to
this is, catch
the exception.

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 10:27 AM
To: NT Developers Interest List
Subject: [ntdev] KeReleaseSemaphore called in a DPC

Am I correct that this call is potentially dangerous to make
within a DPC?
The DDK documentation states that the function can be called
at IRQL <=
DISPATCH_LEVEL provided that the Wait parameter is set to
FALSE. However
it
also states that if the resulting value is greater than the
limit of the
semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED,
is raised.
If
this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I
would expect
that result to be a BSOD.

  • Steve -

You are currently subscribed to ntdev as: xxxxx@cognex.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Well just to muddy the waters I think I’ll make the claim that exception
handling works at DISPATCH_LEVEL and in a dpc routine (both or either.) So,
while semaphores in nt are BAD EVIL-DOERS, and while one should actually
never exceed the release count barrier, one could put an exception handler
around the release and actually manage to not bugcheck in one’s dpc routine.

Anyone think otherwise?

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 11:59 AM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I believe that exceptions will cause a bugcheck. ExRaiseStatus() is called
to generate an exception and the DDK states that you can only call this
function if running at IRQL PASSIVE_LEVEL I would conclude that exceptions
will cause a bugcheck.

  • Steve -

-----Original Message-----
From: Jason LaVoie [mailto:lavoie@us.ibm.com]
Sent: Thursday, December 20, 2001 11:22 AM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I’ll rephrase the question. Will exceptions cause a Bugcheck
at Dispatch
if they are handled correctly? If not, then the answer to
this is, catch
the exception.

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 10:27 AM
To: NT Developers Interest List
Subject: [ntdev] KeReleaseSemaphore called in a DPC

Am I correct that this call is potentially dangerous to make
within a DPC?
The DDK documentation states that the function can be called
at IRQL <=
DISPATCH_LEVEL provided that the Wait parameter is set to
FALSE. However
it
also states that if the resulting value is greater than the
limit of the
semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED,
is raised.
If
this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I
would expect
that result to be a BSOD.

  • Steve -

You are currently subscribed to ntdev as: xxxxx@cognex.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I orignally thought that exception handling would work at DISPATCH_LEVEL but
I recently tracked a BSOD to a call to KeReleaseSemaphore(). The exception
code was STATUS_SEMAPHORE_COUNT_EXCEEDED. The KeReleaseSemaphore() was
surronded by a try/except handler. The stack trace showed that
ExRaiseStatus() was called prior to the blue screen.

KeReleaseSemaphore() calls ExRaiseStatus() but that routine is not supposed
to be called at an elevated IRQL. Is NT breaking it’s own rules?

On a slightly different note, why do you consider semaphores in NT “BAD
EVIL-DOERS”?

  • Steve -

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, December 20, 2001 1:03 PM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

Well just to muddy the waters I think I’ll make the claim
that exception
handling works at DISPATCH_LEVEL and in a dpc routine (both
or either.) So,
while semaphores in nt are BAD EVIL-DOERS, and while one
should actually
never exceed the release count barrier, one could put an
exception handler
around the release and actually manage to not bugcheck in
one’s dpc routine.

Anyone think otherwise?

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 11:59 AM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I believe that exceptions will cause a bugcheck.
ExRaiseStatus() is called
to generate an exception and the DDK states that you can only
call this
function if running at IRQL PASSIVE_LEVEL I would conclude
that exceptions
will cause a bugcheck.

  • Steve -

> -----Original Message-----
> From: Jason LaVoie [mailto:lavoie@us.ibm.com]
> Sent: Thursday, December 20, 2001 11:22 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC
>
>
>
> I’ll rephrase the question. Will exceptions cause a Bugcheck
> at Dispatch
> if they are handled correctly? If not, then the answer to
> this is, catch
> the exception.
>
>
> -----Original Message-----
> From: Steve Whitman [mailto:xxxxx@cognex.com]
> Sent: Thursday, December 20, 2001 10:27 AM
> To: NT Developers Interest List
> Subject: [ntdev] KeReleaseSemaphore called in a DPC
>
>
> Am I correct that this call is potentially dangerous to make
> within a DPC?
> The DDK documentation states that the function can be called
> at IRQL <=
> DISPATCH_LEVEL provided that the Wait parameter is set to
> FALSE. However
> it
> also states that if the resulting value is greater than the
> limit of the
> semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED,
> is raised.
> If
> this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I
> would expect
> that result to be a BSOD.
>
> - Steve -
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@cognex.com To
> unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@cognex.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Oh it was a feeble joke. My experience is that they do not really serve a
useful purpose in most cases, are prone to the extra release problem, and
are easily replaced by other mechanisms. That doesn’t mean that there aren’t
good uses for semaphores, just that most of the usage I’ve seen has been
wrong, buggy, and not needed.

What exactly was the bugcheck? I still think that raising a software
exception, in and of itself, need not cause a bugcheck at dispatch level.

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 2:34 PM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I orignally thought that exception handling would work at DISPATCH_LEVEL but
I recently tracked a BSOD to a call to KeReleaseSemaphore(). The exception
code was STATUS_SEMAPHORE_COUNT_EXCEEDED. The KeReleaseSemaphore() was
surronded by a try/except handler. The stack trace showed that
ExRaiseStatus() was called prior to the blue screen.

KeReleaseSemaphore() calls ExRaiseStatus() but that routine is not supposed
to be called at an elevated IRQL. Is NT breaking it’s own rules?

On a slightly different note, why do you consider semaphores in NT “BAD
EVIL-DOERS”?

  • Steve -

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, December 20, 2001 1:03 PM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

Well just to muddy the waters I think I’ll make the claim
that exception
handling works at DISPATCH_LEVEL and in a dpc routine (both
or either.) So,
while semaphores in nt are BAD EVIL-DOERS, and while one
should actually
never exceed the release count barrier, one could put an
exception handler
around the release and actually manage to not bugcheck in
one’s dpc routine.

Anyone think otherwise?

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 11:59 AM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I believe that exceptions will cause a bugcheck.
ExRaiseStatus() is called
to generate an exception and the DDK states that you can only
call this
function if running at IRQL PASSIVE_LEVEL I would conclude
that exceptions
will cause a bugcheck.

  • Steve -

> -----Original Message-----
> From: Jason LaVoie [mailto:lavoie@us.ibm.com]
> Sent: Thursday, December 20, 2001 11:22 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC
>
>
>
> I’ll rephrase the question. Will exceptions cause a Bugcheck at
> Dispatch if they are handled correctly? If not, then the answer to
> this is, catch
> the exception.
>
>
> -----Original Message-----
> From: Steve Whitman [mailto:xxxxx@cognex.com]
> Sent: Thursday, December 20, 2001 10:27 AM
> To: NT Developers Interest List
> Subject: [ntdev] KeReleaseSemaphore called in a DPC
>
>
> Am I correct that this call is potentially dangerous to make within
> a DPC? The DDK documentation states that the function can be called
> at IRQL <=
> DISPATCH_LEVEL provided that the Wait parameter is set to
> FALSE. However
> it
> also states that if the resulting value is greater than the
> limit of the
> semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED,
> is raised.
> If
> this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I
> would expect
> that result to be a BSOD.
>
> - Steve -
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@cognex.com To
> unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@cognex.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

The bugcheck was KMODE_EXCEPTION_NOT_HANDLED. The exception code was
STATUS_SEMAPHORE_COUNT_EXCEEDED. The stack trace had the
KeReleaseSemaphore() call in it and the semaphore was already at the limit.

  • Steve -

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, December 20, 2001 2:45 PM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

Oh it was a feeble joke. My experience is that they do not
really serve a
useful purpose in most cases, are prone to the extra release
problem, and
are easily replaced by other mechanisms. That doesn’t mean
that there aren’t
good uses for semaphores, just that most of the usage I’ve
seen has been
wrong, buggy, and not needed.

What exactly was the bugcheck? I still think that raising a software
exception, in and of itself, need not cause a bugcheck at
dispatch level.

-----Original Message-----
From: Steve Whitman [mailto:xxxxx@cognex.com]
Sent: Thursday, December 20, 2001 2:34 PM
To: NT Developers Interest List
Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC

I orignally thought that exception handling would work at
DISPATCH_LEVEL but
I recently tracked a BSOD to a call to KeReleaseSemaphore().
The exception
code was STATUS_SEMAPHORE_COUNT_EXCEEDED. The
KeReleaseSemaphore() was
surronded by a try/except handler. The stack trace showed that
ExRaiseStatus() was called prior to the blue screen.

KeReleaseSemaphore() calls ExRaiseStatus() but that routine
is not supposed
to be called at an elevated IRQL. Is NT breaking it’s own rules?

On a slightly different note, why do you consider semaphores
in NT “BAD
EVIL-DOERS”?

  • Steve -

> -----Original Message-----
> From: Roddy, Mark [mailto:xxxxx@stratus.com]
> Sent: Thursday, December 20, 2001 1:03 PM
> To: NT Developers Interest List
> Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC
>
>
> Well just to muddy the waters I think I’ll make the claim
> that exception
> handling works at DISPATCH_LEVEL and in a dpc routine (both
> or either.) So,
> while semaphores in nt are BAD EVIL-DOERS, and while one
> should actually
> never exceed the release count barrier, one could put an
> exception handler
> around the release and actually manage to not bugcheck in
> one’s dpc routine.
>
> Anyone think otherwise?
>
> -----Original Message-----
> From: Steve Whitman [mailto:xxxxx@cognex.com]
> Sent: Thursday, December 20, 2001 11:59 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC
>
>
> I believe that exceptions will cause a bugcheck.
> ExRaiseStatus() is called
> to generate an exception and the DDK states that you can only
> call this
> function if running at IRQL PASSIVE_LEVEL I would conclude
> that exceptions
> will cause a bugcheck.
>
> - Steve -
>
> > -----Original Message-----
> > From: Jason LaVoie [mailto:lavoie@us.ibm.com]
> > Sent: Thursday, December 20, 2001 11:22 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: KeReleaseSemaphore called in a DPC
> >
> >
> >
> > I’ll rephrase the question. Will exceptions cause a Bugcheck at
> > Dispatch if they are handled correctly? If not, then the
answer to
> > this is, catch
> > the exception.
> >
> >
> > -----Original Message-----
> > From: Steve Whitman [mailto:xxxxx@cognex.com]
> > Sent: Thursday, December 20, 2001 10:27 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] KeReleaseSemaphore called in a DPC
> >
> >
> > Am I correct that this call is potentially dangerous to
make within
> > a DPC? The DDK documentation states that the function can
be called
> > at IRQL <=
> > DISPATCH_LEVEL provided that the Wait parameter is set to
> > FALSE. However
> > it
> > also states that if the resulting value is greater than the
> > limit of the
> > semaphore then an exception, STATUS_SEMAPHORE_COUNT_EXCEEDED,
> > is raised.
> > If
> > this occurs within a DPC (or when IRQL == DISPATCH_LEVEL) I
> > would expect
> > that result to be a BSOD.
> >
> > - Steve -
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@cognex.com To
> > unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
>
> —
> You are currently subscribed to ntdev as: xxxxx@stratus.com To
> unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
> —
> You are currently subscribed to ntdev as: xxxxx@cognex.com To
> unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@cognex.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> Oh it was a feeble joke. My experience is that they do not really serve a

useful purpose in most cases

I can say the same on KMUTEX - any need in recursive mutexes? Why non-recursive are bad?

Max


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com