Hi all,
I want to notify the user mode application about the arrival of
interrupts…so I created an event and I am sending the event handle down
to the driver using an DeviceIoControl…there I get a kernel mode event
handle for the same using ObReferenceObjectByHandle(…,…,)…
Now I want to set the event in the DPC for the ISR to trigger the
WaitforSingleObject() in the User mode application. I understand that the
kernel mode event handle is in a paged pool, where as the DPC for isr is
at Dispatch level…
so I get a BSOD with IRQL_NOT_LESS_OR_EQUAL message…
but if i lock the variable representing the kernel mode event handle,
still i get the BSOD…
I am attaching the code for reference, please advice me where i am going
wrong…
struct{
…
…
…
PVOID gpEventObject;
…
…
…
}DeviceExtension,*pdx;
I want to make sure whether I am right in locking the pdx->gpEventObject
Please Note:-
When I set the event in any code at PASSIVE_LEVEL, there is no problem,
only when i set the event in the DPC, it gives the BSOD.
User Mode Creating event: -
UserEventHandle = CreateEvent(NULL, false, false, NULL);
//download event object to device driver
DeviceIoControl(HMdpc1,
IOCTL_REFERENCE_EVENT,
(LPVOID) UserEventHandle,
0,
NULL,
0,
&dwReturn,
NULL);
printf(“\nWaiting for Interrupt Event to occur\n”);
WaitForSingleObject(UserEventHandle,INFINITE);
MessageBox(“…”);
In the Kernel Mode Driver: -
#pragma code_seg(“page”)
NTSTATUS DispatchControl(PDEVICE_OBJECT fdo, PIRP Irp)
{
…
…
switch(code)
{
case IOCTL_REFERENCE_EVENT:
{
KdPrint((“Inside IOCTL_REFERENCE_EVENT”));
hEvent = (HANDLE) stack ->parameters.DeviceIoControl.Type3InputBuffer;
KdPrint((“the kernel mode hevent 0x%x”,hEvent));
status = STATUS_SUCCESS;
status = ObReferenceObjectByHandle(
hEvent,
GENERIC_ALL,
NULL,
KernelMode,
&pdx->gpEventObject,
&objHandleInfo);
if(status != STATUS_SUCCESS)
{
DbgPrint(“ObReferenceObjectByHandle failed! status = %x\n”, status);
break;
}
/**************Here I am locking the
“&pdx->gpEventObject”*******************/
KdPrint((“Locking the Event object which is inside Paged Code”));
pdx->hPageDataSection=MmLockPagableDataSection((PVOID) &pdx-
gpEventObject);
pdx->EventFlag=TRUE;
DbgPrint(“Referenct object sussfully!\n”);
In the DPC for ISR: -
#pragma LOCKEDCODE
VOID DpcForIsr(PKDPC Dpc, PDEVICE_OBJECT fdo, PIRP junk, PDEVICE_EXTENSION
pdx)
{ // DpcForIsr
KdPrint((“Entering DpcForISR Function”));
NTSTATUS status=STATUS_SUCCESS;
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
/*****here I am setting the Kernel mode Event Object*****************/
KeSetEvent((KEVENT*)pdx->gpEventObject,
0,
FALSE);
KdPrint((“KeSetEvent sussfully!\n”));
//Enable Pci interrupt
KdPrint((“Quitting DpcForISR Function”));
} // DpcForIsr
break;
}
In the StopDriver(): -
I am Unlocking the variable in the StopDriver function
KdPrint((“Unlocking the Kernel Event Object”));
MmUnlockPagableImageSection(pdx->hPageDataSection);
But here I got one more problem, when i uninstall it gives me
KMODE_EXECPTION_UNHANDLED,
so I would also like to know where I can again UNlock the locked data…
In anticipation of some suggestions…
thanx,
shiv