How can I Alert a event?

I Initialize a event and thread in ToasterEvtDeviceAdd, and wait the event by calling KeWaitForSingleObject in the thread function, I set the Parameter Alertable to TRUE. But I don’t know how to Alert the event.(I type the “ctrl+c”, but the " if(status == STATUS_ALERTED)" can not reached).

/*********************************************************
KSTART_ROUTINE CsampPollingThread;

VOID
CsampPollingThread(
__in PVOID Context
)
{
PDEVICE_EXTENSION devExt = NULL;
NTSTATUS status = STATUS_SUCCESS;

devExt = (PDEVICE_EXTENSION)Context;

status = KeWaitForSingleObject(&devExt->event,Executive,UserMode,TRUE,NULL);
if(status == STATUS_ALERTED) // Can’t reach here
{
KdPrint( (“KeWaitForSingleObject Exit with status code 0x%x\n”, status));
}
}

NTSTATUS
ToasterEvtDeviceAdd(
IN WDFDRIVER Driver,
IN PWDFDEVICE_INIT DeviceInit
)
{…

devExt = DRE_ctrlGetDeviceContext(hDevice);
if(devExt == NULL)
{
KdPrint( (“DRE_ctrlGetDeviceContext failed”));
return status;
}
KeInitializeEvent(&devExt->event,NotificationEvent,FALSE);
InitializeObjectAttributes(&threadAttr, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
status = PsCreateSystemThread(&devExt->threadHandle,
THREAD_ALL_ACCESS,&threadAttr, NULL, &devExt->client,
CsampPollingThread,devExt);

}
/*************************************************************

It is not event but thread who gets alerted. I happens when waiting thread receives an APC, for example, when IO gets completed. In general, APCs are totally undocumented - you are not going to find any mentioning of KeInitializeApc.and KeInsertQueueApc anywhere in documentation, although code samples
that use them directly an be found on the web. Anyway, why such obsession with STATUS_ALERTED???

Anton Bassov

You don’t want a usermode/alertable wait for your own thread. You want kernelmode/non alertable. Why do you think you need usermode/alertable?

d

dent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@yahoo.com.cn
Sent: July 26, 2010 7:21 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How can I Alert a event?

I Initialize a event and thread in ToasterEvtDeviceAdd, and wait the event by calling KeWaitForSingleObject in the thread function, I set the Parameter Alertable to TRUE. But I don’t know how to Alert the event.(I type the “ctrl+c”, but the " if(status == STATUS_ALERTED)" can not reached).

/
KSTART_ROUTINE CsampPollingThread;

VOID
CsampPollingThread(
__in PVOID Context
)
{
PDEVICE_EXTENSION devExt = NULL;
NTSTATUS status = STATUS_SUCCESS;

devExt = (PDEVICE_EXTENSION)Context;

status = KeWaitForSingleObject(&devExt->event,Executive,UserMode,TRUE,NULL);
if(status == STATUS_ALERTED) // Can’t reach here
{
KdPrint( (“KeWaitForSingleObject Exit with status code 0x%x\n”, status));
}
}

NTSTATUS
ToasterEvtDeviceAdd(
IN WDFDRIVER Driver,
IN PWDFDEVICE_INIT DeviceInit
)
{…

devExt = DRE_ctrlGetDeviceContext(hDevice);
if(devExt == NULL)
{
KdPrint( (“DRE_ctrlGetDeviceContext failed”));
return status;
}
KeInitializeEvent(&devExt->event,NotificationEvent,FALSE);
InitializeObjectAttributes(&threadAttr, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
status = PsCreateSystemThread(&devExt->threadHandle,
THREAD_ALL_ACCESS,&threadAttr, NULL, &devExt->client,
CsampPollingThread,devExt);

}
/
****


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 Initialize a event and thread in ToasterEvtDeviceAdd, and wait the event by calling

KeWaitForSingleObject in the thread function, I set the Parameter Alertable to TRUE. But I don’t know
how to Alert the event.

Forget this undocumented mechanism never intented for use outside MS, and just signal the event.


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

>example, when IO gets completed. In general, APCs are totally undocumented

Correct, because the proper way to generate an APC is to pend the IRP using Read/WriteFileEx, and for the driver to complete it.

Windows does not assume that the kmode driver can send an APC to the user-mode process on its (driver’s) own will, without receiving the process’s permission to do so before. And yes, this “permission” should be in the form of the IRP pended.

Too bad there is no DeviceIoControlEx, but you can handicraft the replacement using NtDeviceIoControlFile and RtlNtStatusToDosError. Also undocumented, but lesser evil then handicrafting the whole APC.


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