Hello,
My app calls DeviceIoControl
, the driver marks the IRP as STATUS_PENDING
and copies the IRP pointer to a global variable.
if( g_notificationIrp == NULL )
{
IoMarkIrpPending(Irp);
g_notificationIrp = Irp;
return STATUS_PENDING;
}
The app waits for notification. When the driver wants to send the notification, it grabs the global IRP pointer, puts the data in it and completes it via IoCompleteRequest
.
if( g_notificationIrp != NULL )
{
RtlCopyBytes(g_notificationIrp->AssociatedIrp.SystemBuffer, ¬ificationData, sizeof(Notification_t));
g_notificationIrp->IoStatus.Information = sizeof(Notification_t);
g_notificationIrp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(g_notificationIrp, IO_NO_INCREMENT);
g_notificationIrp = NULL; // is this a problem?
}
The app receives the data and calls DeviceIoControl
again immediately to wait for the next notification.
Can I set my global IRP pointer to NULL right after calling IoCompleteRequest
, before my app calls DeviceIoControl
again? I am asking about the race condition here. Is it possible that setting the global IRP pointer to NULL happen after my app calls DeviceIoControl
?
P.S. I set my global IRP pointer to NULL using IoSetCancelRoutine
in case of cancellation.