Re: KeSetEvent and context switches

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi mate

I think you just took unwise approach......

Indeed, KeSetEvent() is not atomic - unless you have set Wait to TRUE,
dispatcher database spin lock gets released and IRQL gets below
DISPATCH_LEVEL, so that context switch may occur before KeSetEvent()
returns

It is
quite strange that it does not appear on XP and W2K.

I don't know if it may be related to the OS version - you have to
discover it via disassembly. Probably, on these systems KEVENT
structure does not get accessed
by KeSetEvent() after event gets signalled. Anyway, even this is the
case, you should not assume such behaviour. Furthermore, this bug has
much, much higher chance of revealing itself on SMP machine......

The bottom line - go and fix your code

Anton Bassov


Calin Iaru wrote:
Hi *,


I have a bug which seems to be related to context switches while doing a
KeSetEvent. So, the code looks like this - 2 threads, one signals the second,
and the second frees the event. It so happens that on Server 2003 x86, the
second thread creates a new structure on the old event, and this corrupts the
event's internal state on the first thread.
It seems that KeSetEvent is not atomic, and the DDK confirms it. It is
quite strange that it does not appear on XP and W2K.

Let me know your thoughts on this,
Calin

.



Relevant Pages

  • Re: KeSetEvent and context switches
    ... nature of this bug - either a resource leak or a context switch. ... have been a bad design to make the code "context switch dependent". ... It's a bit strange to have locks around KeSetEvent and ExFreePool. ...
    (microsoft.public.development.device.drivers)
  • Re: KeSetEvent and context switches
    ... switch bug that can harm KeSetEvent. ... It's a bit strange to have locks around KeSetEvent and ExFreePool. ... so that context switch may occur before KeSetEvent ...
    (microsoft.public.development.device.drivers)
  • Re: KeSetEvent and context switches
    ... Calin Iaru wrote: ... I have a bug which seems to be related to context switches while doing a KeSetEvent. ...
    (microsoft.public.development.device.drivers)