forked from reactos/reactos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irp cancel boilerplate.c
103 lines (68 loc) · 2.06 KB
/
irp cancel boilerplate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Boiler plate for irp cancelation, for irp queues you manage yourself
-Gunnar
*/
CancelRoutine(
DEV_OBJ Dev,
Irp
)
{
//don't need this since we have our own sync. protecting irp cancellation
IoReleaseCancelSpinLock(Irp->CancelIrql);
theLock = Irp->Tail.Overlay.DriverContext[3];
Lock(theLock);
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
Unlock(theLock);
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
QUEUE_BOLIERPLATE
{
Lock(theLock);
Irp->Tail.Overlay.DriverContext[3] = &theLock;
IoSetCancelRoutine(Irp, CancelRoutine);
if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
{
/*
Irp has already been cancelled (before we got to queue it),
and we got to remove the cancel routine before the canceler could,
so we cancel/complete the irp ourself.
*/
Unlock(theLock);
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return FALSE;
}
//else were ok
Irp->IoStatus.Status = STATUS_PENDING;
IoMarkIrpPending(Irp);
InsertTailList(Queue);
Unlock(theLock);
}
DEQUEUE_BOILERPLATE
{
Lock(theLock);
Irp = RemoveHeadList(Queue);
if (!IoSetCancelRoutine(Irp, NULL))
{
/*
Cancel routine WILL be called after we release the spinlock. It will try to remove
the irp from the list and cancel/complete this irp. Since we allready removed it,
make its ListEntry point to itself.
*/
InitializeListHead(&Irp->Tail.Overlay.ListEntry);
Unlock(theLock);
return;
}
/*
Cancel routine will NOT be called, canceled or not.
The Irp might have been canceled (Irp->Cancel flag set) but we don't care,
since we are to complete this Irp now anyways.
*/
Unlock(theLock);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}