Hi all,

The DDK documetation says:

"If the value of Alertable is TRUE and one of the following conditions
is present, the thread will be alerted:

1, If the origin of the alert is an internal, undocumented kernel-mode
routine used to alert threads.

2, The origin of the alert is a user-mode APC, and the value of the
WaitMode parameter is UserMode.

In the first of these two cases, the thread's wait is satisfied with a
completion status of STATUS_ALERTED; in the second case, it is
satisfied with a completion status of STATUS_USER_APC."

However, the parameters passed into KeDelayExecutionThread doesn't
include any dispatcher object such as event, semaphore, mutex, etc. My
question is: By which dispatcher object does current sleeping thread
get alerted? Except by user APC.

Thanks in advance.

Re: When and how does KeDelayExecutionThread get alerted? by Tim

Tim
Wed Aug 29 01:17:34 CDT 2007

xmllmx <xmllmx@gmail.com> wrote:
>
>The DDK documetation says:
>
>"If the value of Alertable is TRUE and one of the following conditions
>is present, the thread will be alerted:
>
>1, If the origin of the alert is an internal, undocumented kernel-mode
>routine used to alert threads.
>
>2, The origin of the alert is a user-mode APC, and the value of the
>WaitMode parameter is UserMode.
>
>In the first of these two cases, the thread's wait is satisfied with a
>completion status of STATUS_ALERTED; in the second case, it is
>satisfied with a completion status of STATUS_USER_APC."
>
>However, the parameters passed into KeDelayExecutionThread doesn't
>include any dispatcher object such as event, semaphore, mutex, etc. My
>question is: By which dispatcher object does current sleeping thread
>get alerted?

Just like the documentation says: it gets alerted by having
KeDelayExecutionThread return one of those specific error codes instead of
STATUS_SUCCESS.

status = KeDelayExecutionThread( ... );
if( status == STATUS_USER_APC )
{
// Whoops, we were alerted by a user-mode APC.
}
else if( status == STATUS_ALERTED )
{
// Whoops, we were alerted by the mysterious internal kernel
// routine.
}

The vast majority of drivers don't need to worry about this.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Re: When and how does KeDelayExecutionThread get alerted? by Maxim

Maxim
Wed Aug 29 05:35:24 CDT 2007

KernelMode/Alertable = FALSE - wait cannot be interrupted
UserMode/Alertable = FALSE - wait can be interrupted only by the
termination of the process owning the thread.
KernelMode/Alertable = TRUE - don't know
UserMode/Alertable = TRUE - wait can be interrupted by the termination of
the process owning the thread, as also by a user APC.

The return values of "the wait was interrupted" are STATUS_ALERTED or
STATUS_USER_APC.

About the related topic of Ctrl-C: it works by CSRSS making a remote thread
inside the client process, and this injected thread calls the handler, the
default is ExitProcess.

About waits in synchronous IO calls: they are by default non-alertable,
thus, the IO wait can be interrupted only by process termination.

This is because Win32's CreateFile provides FILE_SYNCHRONOUS_IO_NONALERT to
ZwCreateFile. You can try calling ZwCreateFile with FILE_SYNCHRONOUS_IO_ALERT,
in which case theoretically the IO waits will be interruptable by APCs.

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

"xmllmx" <xmllmx@gmail.com> wrote in message
news:1188342965.566835.172820@x35g2000prf.googlegroups.com...
> Hi all,
>
> The DDK documetation says:
>
> "If the value of Alertable is TRUE and one of the following conditions
> is present, the thread will be alerted:
>
> 1, If the origin of the alert is an internal, undocumented kernel-mode
> routine used to alert threads.
>
> 2, The origin of the alert is a user-mode APC, and the value of the
> WaitMode parameter is UserMode.
>
> In the first of these two cases, the thread's wait is satisfied with a
> completion status of STATUS_ALERTED; in the second case, it is
> satisfied with a completion status of STATUS_USER_APC."
>
> However, the parameters passed into KeDelayExecutionThread doesn't
> include any dispatcher object such as event, semaphore, mutex, etc. My
> question is: By which dispatcher object does current sleeping thread
> get alerted? Except by user APC.
>
> Thanks in advance.
>