ReactOS 0.4.16-dev-290-g89a3b8f
waitsup.c File Reference
#include "npfs.h"
Include dependency graph for waitsup.c:

Go to the source code of this file.

Macros

#define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_WAITSUP)
 

Functions

VOID NTAPI NpCancelWaitQueueIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI NpTimerDispatch (IN PKDPC Dpc, IN PVOID Context, IN PVOID Argument1, IN PVOID Argument2)
 
VOID NTAPI NpInitializeWaitQueue (IN PNP_WAIT_QUEUE WaitQueue)
 
static BOOLEAN NpEqualUnicodeString (IN PCUNICODE_STRING String1, IN PCUNICODE_STRING String2)
 
NTSTATUS NTAPI NpCancelWaiter (IN PNP_WAIT_QUEUE WaitQueue, IN PUNICODE_STRING PipePath, IN NTSTATUS Status, IN PLIST_ENTRY List)
 
NTSTATUS NTAPI NpAddWaiter (IN PNP_WAIT_QUEUE WaitQueue, IN LARGE_INTEGER WaitTime, IN PIRP Irp, IN PUNICODE_STRING AliasName)
 

Macro Definition Documentation

◆ NPFS_BUGCHECK_FILE_ID

#define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_WAITSUP)

Definition at line 14 of file waitsup.c.

Function Documentation

◆ NpAddWaiter()

NTSTATUS NTAPI NpAddWaiter ( IN PNP_WAIT_QUEUE  WaitQueue,
IN LARGE_INTEGER  WaitTime,
IN PIRP  Irp,
IN PUNICODE_STRING  AliasName 
)

Definition at line 221 of file waitsup.c.

225{
226 PIO_STACK_LOCATION IoStack;
229 PNP_WAIT_QUEUE_ENTRY WaitEntry;
232 ULONG i;
233
235
237 sizeof(*WaitEntry),
239 if (!WaitEntry)
240 {
242 }
243
244 KeInitializeDpc(&WaitEntry->Dpc, NpTimerDispatch, WaitEntry);
245 KeInitializeTimer(&WaitEntry->Timer);
246
247 if (AliasName)
248 {
249 WaitEntry->AliasName = *AliasName;
250 }
251 else
252 {
253 WaitEntry->AliasName.Length = 0;
254 WaitEntry->AliasName.Buffer = NULL;
255 }
256
257 WaitEntry->WaitQueue = WaitQueue;
258 WaitEntry->Irp = Irp;
259
260 WaitBuffer = Irp->AssociatedIrp.SystemBuffer;
261 if (WaitBuffer->TimeoutSpecified)
262 {
263 DueTime = WaitBuffer->Timeout;
264 }
265 else
266 {
267 DueTime = WaitTime;
268 }
269
270 for (i = 0; i < WaitBuffer->NameLength / sizeof(WCHAR); i++)
271 {
272 WaitBuffer->Name[i] = RtlUpcaseUnicodeChar(WaitBuffer->Name[i]);
273 }
274
275 Irp->Tail.Overlay.DriverContext[0] = WaitQueue;
276 Irp->Tail.Overlay.DriverContext[1] = WaitEntry;
277
278 KeAcquireSpinLock(&WaitQueue->WaitLock, &OldIrql);
279
281
282 if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
283 {
285 }
286 else
287 {
288 InsertTailList(&WaitQueue->WaitList, &Irp->Tail.Overlay.ListEntry);
289
292
293 WaitEntry->FileObject = IoStack->FileObject;
294 ObReferenceObject(WaitEntry->FileObject);
295
296 KeSetTimer(&WaitEntry->Timer, DueTime, &WaitEntry->Dpc);
297 WaitEntry = NULL;
298 }
299
300 KeReleaseSpinLock(&WaitQueue->WaitLock, OldIrql);
301 if (WaitEntry) ExFreePool(WaitEntry);
302
303 return Status;
304}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define NPFS_WRITE_BLOCK_TAG
Definition: npfs.h:64
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
IoMarkIrpPending(Irp)
IoSetCancelRoutine(Irp, CancelRoutine)
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:176
LARGE_INTEGER Timeout
Definition: winioctl.h:457
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
Definition: npfs.h:167
KDPC Dpc
Definition: npfs.h:169
PNP_WAIT_QUEUE WaitQueue
Definition: npfs.h:171
UNICODE_STRING AliasName
Definition: npfs.h:172
PIRP Irp
Definition: npfs.h:168
PFILE_OBJECT FileObject
Definition: npfs.h:173
KTIMER Timer
Definition: npfs.h:170
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
VOID NTAPI NpCancelWaitQueueIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: waitsup.c:20
VOID NTAPI NpTimerDispatch(IN PKDPC Dpc, IN PVOID Context, IN PVOID Argument1, IN PVOID Argument2)
Definition: waitsup.c:59
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
#define ExAllocatePoolWithQuotaTag(a, b, c)
Definition: exfuncs.h:530
#define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
#define ObReferenceObject
Definition: obfuncs.h:204
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by NpWaitForNamedPipe().

◆ NpCancelWaiter()

NTSTATUS NTAPI NpCancelWaiter ( IN PNP_WAIT_QUEUE  WaitQueue,
IN PUNICODE_STRING  PipePath,
IN NTSTATUS  Status,
IN PLIST_ENTRY  List 
)

Definition at line 120 of file waitsup.c.

124{
125 UNICODE_STRING PipePathUpper;
128 PLIST_ENTRY NextEntry;
129 PNP_WAIT_QUEUE_ENTRY WaitEntry, Linkage;
130 PIRP WaitIrp;
132 UNICODE_STRING WaitName, PipeName;
133
134 Linkage = NULL;
135
137 PipePath->Length,
140
141 RtlInitEmptyUnicodeString(&PipePathUpper, Buffer, PipePath->Length);
142 RtlUpcaseUnicodeString(&PipePathUpper, PipePath, FALSE);
143
144 KeAcquireSpinLock(&WaitQueue->WaitLock, &OldIrql);
145
146 NextEntry = WaitQueue->WaitList.Flink;
147 while (NextEntry != &WaitQueue->WaitList)
148 {
149 WaitIrp = CONTAINING_RECORD(NextEntry, IRP, Tail.Overlay.ListEntry);
150 NextEntry = NextEntry->Flink;
151 WaitEntry = WaitIrp->Tail.Overlay.DriverContext[1];
152
153 if (WaitEntry->AliasName.Length)
154 {
155 ASSERT(FALSE);
156 /* We have an alias. Use that for comparison */
157 WaitName = WaitEntry->AliasName;
158 PipeName = PipePathUpper;
159 }
160 else
161 {
162 /* Use the name from the wait buffer to compare */
163 WaitBuffer = WaitIrp->AssociatedIrp.SystemBuffer;
164 WaitName.Buffer = WaitBuffer->Name;
165 WaitName.Length = WaitBuffer->NameLength;
166 WaitName.MaximumLength = WaitName.Length;
167
168 /* WaitName doesn't have a leading backslash,
169 * so skip the one in PipePathUpper for the comparison */
170 PipeName.Buffer = PipePathUpper.Buffer + 1;
171 PipeName.Length = PipePathUpper.Length - sizeof(WCHAR);
172 PipeName.MaximumLength = PipeName.Length;
173 }
174
175 /* Can't use RtlEqualUnicodeString with a spinlock held */
176 if (NpEqualUnicodeString(&WaitName, &PipeName))
177 {
178 /* Found a matching wait. Cancel it */
179 RemoveEntryList(&WaitIrp->Tail.Overlay.ListEntry);
180 if (KeCancelTimer(&WaitEntry->Timer))
181 {
182 WaitEntry->WaitQueue = (PNP_WAIT_QUEUE)Linkage;
183 Linkage = WaitEntry;
184 }
185 else
186 {
187 WaitEntry->Irp = NULL;
188 WaitIrp->Tail.Overlay.DriverContext[1] = NULL;
189 }
190
191 if (IoSetCancelRoutine(WaitIrp, NULL))
192 {
193 WaitIrp->IoStatus.Information = 0;
194 WaitIrp->IoStatus.Status = Status;
195 InsertTailList(List, &WaitIrp->Tail.Overlay.ListEntry);
196 }
197 else
198 {
199 WaitIrp->Tail.Overlay.DriverContext[1] = NULL;
200 }
201 }
202 }
203
204 KeReleaseSpinLock(&WaitQueue->WaitLock, OldIrql);
205
207
208 while (Linkage)
209 {
210 WaitEntry = Linkage;
211 Linkage = (PNP_WAIT_QUEUE_ENTRY)Linkage->WaitQueue;
213 ExFreePool(WaitEntry);
214 }
215
216 return STATUS_SUCCESS;
217}
Definition: bufpool.h:45
#define FALSE
Definition: types.h:117
#define NPFS_WAIT_BLOCK_TAG
Definition: npfs.h:63
struct _NP_WAIT_QUEUE_ENTRY * PNP_WAIT_QUEUE_ENTRY
struct _NP_WAIT_QUEUE * PNP_WAIT_QUEUE
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID SystemBuffer
union _IRP::@1581 AssociatedIrp
IO_STATUS_BLOCK IoStatus
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
USHORT MaximumLength
Definition: env_spec_w32.h:370
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static BOOLEAN NpEqualUnicodeString(IN PCUNICODE_STRING String1, IN PCUNICODE_STRING String2)
Definition: waitsup.c:104
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by NpCreateExistingNamedPipe(), NpDeleteFcb(), and NpSetListeningPipeState().

◆ NpCancelWaitQueueIrp()

VOID NTAPI NpCancelWaitQueueIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 20 of file waitsup.c.

22{
24 PNP_WAIT_QUEUE_ENTRY WaitEntry;
25 PNP_WAIT_QUEUE WaitQueue;
26
27 IoReleaseCancelSpinLock(Irp->CancelIrql);
28
29 WaitQueue = Irp->Tail.Overlay.DriverContext[0];
30
31 KeAcquireSpinLock(&WaitQueue->WaitLock, &OldIrql);
32
33 WaitEntry = Irp->Tail.Overlay.DriverContext[1];
34 if (WaitEntry)
35 {
36 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
37 if (!KeCancelTimer(&WaitEntry->Timer))
38 {
39 WaitEntry->Irp = NULL;
40 WaitEntry = NULL;
41 }
42 }
43
45
46 if (WaitEntry)
47 {
49 ExFreePool(WaitEntry);
50 }
51
52 Irp->IoStatus.Information = 0;
53 Irp->IoStatus.Status = STATUS_CANCELLED;
55}
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
KSPIN_LOCK WaitLock
Definition: npfs.h:162
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:604

Referenced by NpAddWaiter().

◆ NpEqualUnicodeString()

static BOOLEAN NpEqualUnicodeString ( IN PCUNICODE_STRING  String1,
IN PCUNICODE_STRING  String2 
)
static

Definition at line 104 of file waitsup.c.

106{
107 SIZE_T EqualLength;
108
109 if (String1->Length != String2->Length)
110 return FALSE;
111
112 EqualLength = RtlCompareMemory(String1->Buffer,
113 String2->Buffer,
114 String1->Length);
115 return EqualLength == String1->Length;
116}
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
_In_ const STRING * String2
Definition: rtlfuncs.h:2369
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by NpCancelWaiter().

◆ NpInitializeWaitQueue()

VOID NTAPI NpInitializeWaitQueue ( IN PNP_WAIT_QUEUE  WaitQueue)

Definition at line 96 of file waitsup.c.

97{
98 InitializeListHead(&WaitQueue->WaitList);
99 KeInitializeSpinLock(&WaitQueue->WaitLock);
100}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604

Referenced by NpInitializeVcb().

◆ NpTimerDispatch()

VOID NTAPI NpTimerDispatch ( IN PKDPC  Dpc,
IN PVOID  Context,
IN PVOID  Argument1,
IN PVOID  Argument2 
)

Definition at line 59 of file waitsup.c.

63{
64 PIRP Irp;
66 PNP_WAIT_QUEUE_ENTRY WaitEntry = Context;
67
69
70 Irp = WaitEntry->Irp;
71 if (Irp)
72 {
73 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
74
76 {
77 Irp->Tail.Overlay.DriverContext[1] = NULL;
78 Irp = NULL;
79 }
80 }
81
83
84 if (Irp)
85 {
86 Irp->IoStatus.Status = STATUS_IO_TIMEOUT;
88 }
89
91 ExFreePool(WaitEntry);
92}
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163

Referenced by NpAddWaiter().