mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
Fix some cancellation race conditions.
svn path=/trunk/; revision=13851
This commit is contained in:
parent
fb22000d1c
commit
ca4d8c0923
2 changed files with 22 additions and 8 deletions
|
@ -54,10 +54,15 @@ NpfsFindListeningServerInstance(PNPFS_PIPE Pipe)
|
|||
while (CurrentEntry != &Pipe->WaiterListHead)
|
||||
{
|
||||
Waiter = CONTAINING_RECORD(CurrentEntry, NPFS_WAITER_ENTRY, Entry);
|
||||
if (Waiter->Fcb->PipeState == FILE_PIPE_LISTENING_STATE)
|
||||
if (Waiter->Fcb->PipeState == FILE_PIPE_LISTENING_STATE &&
|
||||
!Waiter->Irp->Cancel)
|
||||
{
|
||||
DPRINT("Server found! Fcb %p\n", Waiter->Fcb);
|
||||
return Waiter->Fcb;
|
||||
|
||||
if (IoSetCancelRoutine(Waiter->Irp, NULL) != NULL)
|
||||
{
|
||||
return Waiter->Fcb;
|
||||
}
|
||||
}
|
||||
|
||||
CurrentEntry = CurrentEntry->Flink;
|
||||
|
|
|
@ -25,18 +25,26 @@ NpfsListeningCancelRoutine(IN PDEVICE_OBJECT DeviceObject,
|
|||
PNPFS_WAITER_ENTRY Waiter;
|
||||
|
||||
DPRINT1("NpfsListeningCancelRoutine() called\n");
|
||||
|
||||
/* FIXME: Not tested. */
|
||||
|
||||
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
||||
|
||||
Waiter = Irp->Tail.Overlay.DriverContext[0];
|
||||
|
||||
KeLockMutex(&Waiter->Pipe->FcbListLock);
|
||||
RemoveEntryList(&Waiter->Entry);
|
||||
ExFreePool(Waiter);
|
||||
|
||||
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
||||
if (IoSetCancelRoutine(Waiter->Irp, NULL) == NULL)
|
||||
{
|
||||
KeUnlockMutex(&Waiter->Pipe->FcbListLock);
|
||||
return;
|
||||
}
|
||||
KeUnlockMutex(&Waiter->Pipe->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_CANCELLED;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
ExFreePool(Waiter);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +61,7 @@ NpfsAddListeningServerInstance(PIRP Irp,
|
|||
|
||||
Entry->Irp = Irp;
|
||||
Entry->Fcb = Fcb;
|
||||
InsertTailList(&Fcb->Pipe->WaiterListHead, &Entry->Entry);
|
||||
Entry->Pipe = Fcb->Pipe;
|
||||
|
||||
IoAcquireCancelSpinLock(&OldIrql);
|
||||
if (!Irp->Cancel)
|
||||
|
@ -61,14 +69,15 @@ NpfsAddListeningServerInstance(PIRP Irp,
|
|||
Irp->Tail.Overlay.DriverContext[0] = Entry;
|
||||
IoMarkIrpPending(Irp);
|
||||
IoSetCancelRoutine(Irp, NpfsListeningCancelRoutine);
|
||||
KeLockMutex(&Fcb->Pipe->FcbListLock);
|
||||
InsertTailList(&Fcb->Pipe->WaiterListHead, &Entry->Entry);
|
||||
KeUnlockMutex(&Fcb->Pipe->FcbListLock);
|
||||
IoReleaseCancelSpinLock(OldIrql);
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
/* IRP has already been cancelled */
|
||||
IoReleaseCancelSpinLock(OldIrql);
|
||||
|
||||
DPRINT1("FIXME: Remove waiter entry!\n");
|
||||
RemoveEntryList(&Entry->Entry);
|
||||
ExFreePool(Entry);
|
||||
|
||||
return STATUS_CANCELLED;
|
||||
|
|
Loading…
Reference in a new issue