ReactOS  0.4.14-dev-368-gfa26425
iocomp.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for iocomp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI IopUnloadSafeCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
VOID NTAPI IopFreeMiniPacket (PIOP_MINI_COMPLETION_PACKET Packet)
 
VOID NTAPI IopDeleteIoCompletion (PVOID ObjectBody)
 
NTSTATUS NTAPI IoSetIoCompletion (IN PVOID IoCompletion, IN PVOID KeyContext, IN PVOID ApcContext, IN NTSTATUS IoStatus, IN ULONG_PTR IoStatusInformation, IN BOOLEAN Quota)
 
NTSTATUS NTAPI IoSetCompletionRoutineEx (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PIO_COMPLETION_ROUTINE CompletionRoutine, IN PVOID Context, IN BOOLEAN InvokeOnSuccess, IN BOOLEAN InvokeOnError, IN BOOLEAN InvokeOnCancel)
 
NTSTATUS NTAPI NtCreateIoCompletion (OUT PHANDLE IoCompletionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG NumberOfConcurrentThreads)
 
NTSTATUS NTAPI NtOpenIoCompletion (OUT PHANDLE IoCompletionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
 
NTSTATUS NTAPI NtQueryIoCompletion (IN HANDLE IoCompletionHandle, IN IO_COMPLETION_INFORMATION_CLASS IoCompletionInformationClass, OUT PVOID IoCompletionInformation, IN ULONG IoCompletionInformationLength, OUT PULONG ResultLength OPTIONAL)
 
NTSTATUS NTAPI NtRemoveIoCompletion (IN HANDLE IoCompletionHandle, OUT PVOID *KeyContext, OUT PVOID *ApcContext, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER Timeout OPTIONAL)
 
NTSTATUS NTAPI NtSetIoCompletion (IN HANDLE IoCompletionPortHandle, IN PVOID CompletionKey, IN PVOID CompletionContext, IN NTSTATUS CompletionStatus, IN ULONG CompletionInformation)
 

Variables

POBJECT_TYPE IoCompletionType
 
GENERAL_LOOKASIDE IoCompletionPacketLookaside
 
GENERIC_MAPPING IopCompletionMapping
 
static const INFORMATION_CLASS_INFO IoCompletionInfoClass []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file iocomp.c.

Function Documentation

◆ IopDeleteIoCompletion()

VOID NTAPI IopDeleteIoCompletion ( PVOID  ObjectBody)

Definition at line 100 of file iocomp.c.

101 {
102  PKQUEUE Queue = ObjectBody;
103  PLIST_ENTRY FirstEntry;
104  PLIST_ENTRY CurrentEntry;
105  PIRP Irp;
107 
108  /* Rundown the Queue */
109  FirstEntry = KeRundownQueue(Queue);
110  if (FirstEntry)
111  {
112  /* Loop the packets */
113  CurrentEntry = FirstEntry;
114  do
115  {
116  /* Get the Packet */
117  Packet = CONTAINING_RECORD(CurrentEntry,
119  ListEntry);
120 
121  /* Go to next Entry */
122  CurrentEntry = CurrentEntry->Flink;
123 
124  /* Check if it's part of an IRP, or a separate packet */
125  if (Packet->PacketType == IopCompletionPacketIrp)
126  {
127  /* Get the IRP and free it */
128  Irp = CONTAINING_RECORD(Packet, IRP, Tail.Overlay.ListEntry);
129  IoFreeIrp(Irp);
130  }
131  else
132  {
133  /* Use common routine */
135  }
136  } while (FirstEntry != CurrentEntry);
137  }
138 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
_In_ PIRP Irp
Definition: csq.h:116
IRP
Definition: iotypes.h:2463
PLIST_ENTRY NTAPI KeRundownQueue(IN PKQUEUE Queue)
Definition: queue.c:438
VOID NTAPI IopFreeMiniPacket(PIOP_MINI_COMPLETION_PACKET Packet)
Definition: iocomp.c:63
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666

Referenced by IopCreateObjectTypes().

◆ IopFreeMiniPacket()

VOID NTAPI IopFreeMiniPacket ( PIOP_MINI_COMPLETION_PACKET  Packet)

Definition at line 63 of file iocomp.c.

64 {
65  PKPRCB Prcb = KeGetCurrentPrcb();
67 
68  /* Use the P List */
70  PPLookasideList[LookasideCompletionList].P;
71  List->L.TotalFrees++;
72 
73  /* Check if the Free was within the Depth or not */
74  if (ExQueryDepthSList(&List->L.ListHead) >= List->L.Depth)
75  {
76  /* Let the balancer know */
77  List->L.FreeMisses++;
78 
79  /* Use the L List */
81  PPLookasideList[LookasideCompletionList].L;
82  List->L.TotalFrees++;
83 
84  /* Check if the Free was within the Depth or not */
85  if (ExQueryDepthSList(&List->L.ListHead) >= List->L.Depth)
86  {
87  /* All lists failed, use the pool */
88  List->L.FreeMisses++;
90  return;
91  }
92  }
93 
94  /* The free was within dhe Depth */
96 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST * PNPAGED_LOOKASIDE_LIST
LIST_ENTRY List
Definition: psmgr.c:57
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define PSLIST_ENTRY
Definition: rtltypes.h:130
FORCEINLINE USHORT ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
Definition: exfuncs.h:153
NTKERNELAPI PSLIST_ENTRY FASTCALL InterlockedPushEntrySList(IN PSLIST_HEADER ListHead, IN PSLIST_ENTRY ListEntry)
Definition: interlocked.c:82
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IopDeleteIoCompletion(), and NtRemoveIoCompletion().

◆ IopUnloadSafeCompletion()

NTSTATUS NTAPI IopUnloadSafeCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 38 of file iocomp.c.

41 {
44 
45  /* Reference the device object */
46  ObReferenceObject(UnsafeContext->DeviceObject);
47 
48  /* Call the completion routine */
49  Status= UnsafeContext->CompletionRoutine(DeviceObject,
50  Irp,
51  UnsafeContext->Context);
52 
53  /* Dereference the device object */
54  ObDereferenceObject(UnsafeContext->DeviceObject);
55 
56  /* Free our context */
57  ExFreePool(UnsafeContext);
58  return Status;
59 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: io.h:300
PDEVICE_OBJECT DeviceObject
Definition: io.h:298
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ObReferenceObject
Definition: obfuncs.h:204
struct tagContext Context
Definition: acpixf.h:1030
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by IoSetCompletionRoutineEx().

◆ IoSetCompletionRoutineEx()

NTSTATUS NTAPI IoSetCompletionRoutineEx ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PIO_COMPLETION_ROUTINE  CompletionRoutine,
IN PVOID  Context,
IN BOOLEAN  InvokeOnSuccess,
IN BOOLEAN  InvokeOnError,
IN BOOLEAN  InvokeOnCancel 
)

Definition at line 220 of file iocomp.c.

227 {
229 
230  /* Allocate the context */
231  UnloadContext = ExAllocatePoolWithTag(NonPagedPool,
232  sizeof(*UnloadContext),
233  'sUoI');
234  if (!UnloadContext) return STATUS_INSUFFICIENT_RESOURCES;
235 
236  /* Set up the context */
237  UnloadContext->DeviceObject = DeviceObject;
238  UnloadContext->Context = Context;
239  UnloadContext->CompletionRoutine = CompletionRoutine;
240 
241  /* Now set the completion routine */
244  UnloadContext,
248  return STATUS_SUCCESS;
249 }
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_opt_ PVOID _In_ BOOLEAN _In_ BOOLEAN InvokeOnError
Definition: iofuncs.h:1935
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: io.h:300
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_opt_ PVOID _In_ BOOLEAN _In_ BOOLEAN _In_ BOOLEAN InvokeOnCancel
Definition: iofuncs.h:1935
PDEVICE_OBJECT DeviceObject
Definition: io.h:298
NTSTATUS NTAPI IopUnloadSafeCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: iocomp.c:38
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_opt_ PVOID _In_ BOOLEAN InvokeOnSuccess
Definition: iofuncs.h:1935
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct tagContext Context
Definition: acpixf.h:1030
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by IssueUniqueIdChangeNotifyWorker().

◆ IoSetIoCompletion()

NTSTATUS NTAPI IoSetIoCompletion ( IN PVOID  IoCompletion,
IN PVOID  KeyContext,
IN PVOID  ApcContext,
IN NTSTATUS  IoStatus,
IN ULONG_PTR  IoStatusInformation,
IN BOOLEAN  Quota 
)

Definition at line 147 of file iocomp.c.

153 {
154  PKQUEUE Queue = (PKQUEUE)IoCompletion;
156  PKPRCB Prcb = KeGetCurrentPrcb();
158 
159  /* Get the P List */
160  List = (PNPAGED_LOOKASIDE_LIST)Prcb->
161  PPLookasideList[LookasideCompletionList].P;
162 
163  /* Try to allocate the Packet */
164  List->L.TotalAllocates++;
165  Packet = (PVOID)InterlockedPopEntrySList(&List->L.ListHead);
166 
167  /* Check if that failed, use the L list if it did */
168  if (!Packet)
169  {
170  /* Let the balancer know */
171  List->L.AllocateMisses++;
172 
173  /* Get L List */
174  List = (PNPAGED_LOOKASIDE_LIST)Prcb->
175  PPLookasideList[LookasideCompletionList].L;
176 
177  /* Try to allocate the Packet */
178  List->L.TotalAllocates++;
179  Packet = (PVOID)InterlockedPopEntrySList(&List->L.ListHead);
180  }
181 
182  /* Still failed, use pool */
183  if (!Packet)
184  {
185  /* Let the balancer know */
186  List->L.AllocateMisses++;
187 
188  /* Allocate from Nonpaged Pool */
190  }
191 
192  /* Make sure we have one by now... */
193  if (Packet)
194  {
195  /* Set up the Packet */
196  Packet->PacketType = IopCompletionPacketMini;
197  Packet->KeyContext = KeyContext;
198  Packet->ApcContext = ApcContext;
199  Packet->IoStatus = IoStatus;
200  Packet->IoStatusInformation = IoStatusInformation;
201 
202  /* Insert the Queue */
203  KeInsertQueue(Queue, &Packet->ListEntry);
204  }
205  else
206  {
207  /* Out of memory, fail */
209  }
210 
211  /* Return Success */
212  return STATUS_SUCCESS;
213 }
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
PSLIST_ENTRY WINAPI InterlockedPopEntrySList(PSLIST_HEADER ListHead)
Definition: interlocked.c:55
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST * PNPAGED_LOOKASIDE_LIST
LIST_ENTRY List
Definition: psmgr.c:57
#define IOC_TAG
Definition: tag.h:56
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct _KQUEUE * PKQUEUE
LONG NTAPI KeInsertQueue(IN PKQUEUE Queue, IN PLIST_ENTRY Entry)
Definition: queue.c:198
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI IoCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
Definition: control.c:382

Referenced by IopDeviceFsIoControl(), NtLockFile(), and NtSetIoCompletion().

◆ NtCreateIoCompletion()

NTSTATUS NTAPI NtCreateIoCompletion ( OUT PHANDLE  IoCompletionHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN ULONG  NumberOfConcurrentThreads 
)

Definition at line 253 of file iocomp.c.

257 {
258  PKQUEUE Queue;
259  HANDLE hIoCompletionHandle;
262  PAGED_CODE();
263 
264  /* Check if this was a user-mode call */
265  if (PreviousMode != KernelMode)
266  {
267  /* Wrap probing in SEH */
268  _SEH2_TRY
269  {
270  /* Probe the handle */
271  ProbeForWriteHandle(IoCompletionHandle);
272  }
274  {
275  /* Return the exception code */
277  }
278  _SEH2_END;
279  }
280 
281  /* Create the Object */
285  PreviousMode,
286  NULL,
287  sizeof(KQUEUE),
288  0,
289  0,
290  (PVOID*)&Queue);
291  if (NT_SUCCESS(Status))
292  {
293  /* Initialize the Queue */
294  KeInitializeQueue(Queue, NumberOfConcurrentThreads);
295 
296  /* Insert it */
297  Status = ObInsertObject(Queue,
298  NULL,
300  0,
301  NULL,
302  &hIoCompletionHandle);
303  if (NT_SUCCESS(Status))
304  {
305  /* Protect writing the handle in SEH */
306  _SEH2_TRY
307  {
308  /* Write the handle back */
309  *IoCompletionHandle = hIoCompletionHandle;
310  }
312  {
313  /* Get the exception code */
315  }
316  _SEH2_END;
317  }
318  }
319 
320  /* Return Status */
321  return Status;
322 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
VOID NTAPI KeInitializeQueue(IN PKQUEUE Queue, IN ULONG Count OPTIONAL)
Definition: queue.c:148
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
POBJECT_TYPE IoCompletionType
Definition: iocomp.c:16

Referenced by CreateIoCompletionPort(), RtlpInitializeThreadPool(), and SockCreateOrReferenceAsyncThread().

◆ NtOpenIoCompletion()

NTSTATUS NTAPI NtOpenIoCompletion ( OUT PHANDLE  IoCompletionHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes 
)

Definition at line 326 of file iocomp.c.

329 {
331  HANDLE hIoCompletionHandle;
333  PAGED_CODE();
334 
335  /* Check if this was a user-mode call */
336  if (PreviousMode != KernelMode)
337  {
338  /* Wrap probing in SEH */
339  _SEH2_TRY
340  {
341  /* Probe the handle */
342  ProbeForWriteHandle(IoCompletionHandle);
343  }
345  {
346  /* Return the exception code */
348  }
349  _SEH2_END;
350  }
351 
352  /* Open the Object */
355  PreviousMode,
356  NULL,
358  NULL,
359  &hIoCompletionHandle);
360  if (NT_SUCCESS(Status))
361  {
362  /* Protect writing the handle in SEH */
363  _SEH2_TRY
364  {
365  /* Write the handle back */
366  *IoCompletionHandle = hIoCompletionHandle;
367  }
369  {
370  /* Get the exception code */
372  }
373  _SEH2_END;
374  }
375 
376  /* Return Status */
377  return Status;
378 }
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2529
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
POBJECT_TYPE IoCompletionType
Definition: iocomp.c:16

Referenced by NtOpenObject().

◆ NtQueryIoCompletion()

NTSTATUS NTAPI NtQueryIoCompletion ( IN HANDLE  IoCompletionHandle,
IN IO_COMPLETION_INFORMATION_CLASS  IoCompletionInformationClass,
OUT PVOID  IoCompletionInformation,
IN ULONG  IoCompletionInformationLength,
OUT PULONG ResultLength  OPTIONAL 
)

Definition at line 382 of file iocomp.c.

387 {
388  PKQUEUE Queue;
391  PAGED_CODE();
392 
393  /* Check buffers and parameters */
394  Status = DefaultQueryInfoBufferCheck(IoCompletionInformationClass,
396  sizeof(IoCompletionInfoClass) /
397  sizeof(IoCompletionInfoClass[0]),
398  IoCompletionInformation,
399  IoCompletionInformationLength,
400  ResultLength,
401  NULL,
402  PreviousMode);
403  if (!NT_SUCCESS(Status)) return Status;
404 
405  /* Get the Object */
406  Status = ObReferenceObjectByHandle(IoCompletionHandle,
409  PreviousMode,
410  (PVOID*)&Queue,
411  NULL);
412  if (NT_SUCCESS(Status))
413  {
414  /* Protect write in SEH */
415  _SEH2_TRY
416  {
417  /* Return Info */
418  ((PIO_COMPLETION_BASIC_INFORMATION)IoCompletionInformation)->
419  Depth = KeReadStateQueue(Queue);
420 
421  /* Return Result Length if needed */
422  if (ResultLength)
423  {
425  }
426  }
428  {
429  /* Get exception code */
431  }
432  _SEH2_END;
433 
434  /* Dereference the queue */
435  ObDereferenceObject(Queue);
436  }
437 
438  /* Return Status */
439  return Status;
440 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:656
LONG NTSTATUS
Definition: precomp.h:26
struct _IO_COMPLETION_BASIC_INFORMATION * PIO_COMPLETION_BASIC_INFORMATION
#define IO_COMPLETION_QUERY_STATE
Definition: iotypes.h:31
static const INFORMATION_CLASS_INFO IoCompletionInfoClass[]
Definition: iocomp.c:28
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
LONG NTAPI KeReadStateQueue(IN PKQUEUE Queue)
Definition: queue.c:226
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
static __inline NTSTATUS DefaultQueryInfoBufferCheck(ULONG Class, const INFORMATION_CLASS_INFO *ClassList, ULONG ClassListEntries, PVOID Buffer, ULONG BufferLength, PULONG ReturnLength, PULONG_PTR ReturnLengthPtr, KPROCESSOR_MODE PreviousMode)
Definition: probe.h:59
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
struct _IO_COMPLETION_BASIC_INFORMATION IO_COMPLETION_BASIC_INFORMATION
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
POBJECT_TYPE IoCompletionType
Definition: iocomp.c:16

◆ NtRemoveIoCompletion()

NTSTATUS NTAPI NtRemoveIoCompletion ( IN HANDLE  IoCompletionHandle,
OUT PVOID KeyContext,
OUT PVOID ApcContext,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN PLARGE_INTEGER Timeout  OPTIONAL 
)

Definition at line 444 of file iocomp.c.

449 {
450  LARGE_INTEGER SafeTimeout;
451  PKQUEUE Queue;
453  PLIST_ENTRY ListEntry;
456  PIRP Irp;
457  PVOID Apc, Key;
459  PAGED_CODE();
460 
461  /* Check if the call was from user mode */
462  if (PreviousMode != KernelMode)
463  {
464  /* Protect probes in SEH */
465  _SEH2_TRY
466  {
467  /* Probe the pointers */
468  ProbeForWritePointer(KeyContext);
470 
471  /* Probe the I/O Status Block */
473  if (Timeout)
474  {
475  /* Probe and capture the timeout */
476  SafeTimeout = ProbeForReadLargeInteger(Timeout);
477  Timeout = &SafeTimeout;
478  }
479  }
481  {
482  /* Return the exception code */
484  }
485  _SEH2_END;
486  }
487 
488  /* Open the Object */
489  Status = ObReferenceObjectByHandle(IoCompletionHandle,
492  PreviousMode,
493  (PVOID*)&Queue,
494  NULL);
495  if (NT_SUCCESS(Status))
496  {
497  /* Remove queue */
498  ListEntry = KeRemoveQueue(Queue, PreviousMode, Timeout);
499 
500  /* If we got a timeout or user_apc back, return the status */
501  if (((NTSTATUS)(ULONG_PTR)ListEntry == STATUS_TIMEOUT) ||
502  ((NTSTATUS)(ULONG_PTR)ListEntry == STATUS_USER_APC))
503  {
504  /* Set this as the status */
505  Status = (NTSTATUS)(ULONG_PTR)ListEntry;
506  }
507  else
508  {
509  /* Get the Packet Data */
510  Packet = CONTAINING_RECORD(ListEntry,
512  ListEntry);
513 
514  /* Check if this is piggybacked on an IRP */
515  if (Packet->PacketType == IopCompletionPacketIrp)
516  {
517  /* Get the IRP */
518  Irp = CONTAINING_RECORD(ListEntry,
519  IRP,
520  Tail.Overlay.ListEntry);
521 
522  /* Save values */
523  Key = Irp->Tail.CompletionKey;
524  Apc = Irp->Overlay.AsynchronousParameters.UserApcContext;
525  IoStatus = Irp->IoStatus;
526 
527  /* Free the IRP */
528  IoFreeIrp(Irp);
529  }
530  else
531  {
532  /* Save values */
533  Key = Packet->KeyContext;
534  Apc = Packet->ApcContext;
535  IoStatus.Status = Packet->IoStatus;
536  IoStatus.Information = Packet->IoStatusInformation;
537 
538  /* Free the packet */
540  }
541 
542  /* Enter SEH to write back the values */
543  _SEH2_TRY
544  {
545  /* Write the values to caller */
546  *ApcContext = Apc;
547  *KeyContext = Key;
549  }
551  {
552  /* Get the exception code */
554  }
555  _SEH2_END;
556  }
557 
558  /* Dereference the Object */
559  ObDereferenceObject(Queue);
560  }
561 
562  /* Return status */
563  return Status;
564 }
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define IO_COMPLETION_MODIFY_STATE
Definition: iotypes.h:33
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
IRP
Definition: iotypes.h:2463
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI IopFreeMiniPacket(PIOP_MINI_COMPLETION_PACKET Packet)
Definition: iocomp.c:63
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define NTSTATUS
Definition: precomp.h:20
PLIST_ENTRY NTAPI KeRemoveQueue(IN PKQUEUE Queue, IN KPROCESSOR_MODE WaitMode, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: queue.c:238
#define ProbeForWritePointer(Ptr)
Definition: probe.h:42
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define STATUS_USER_APC
Definition: ntstatus.h:78
_SEH2_END
Definition: create.c:4424
static ULONG Timeout
Definition: ping.c:61
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
POBJECT_TYPE IoCompletionType
Definition: iocomp.c:16

Referenced by GetQueuedCompletionStatus(), RtlpWorkerThreadProc(), and SockAsyncThread().

◆ NtSetIoCompletion()

NTSTATUS NTAPI NtSetIoCompletion ( IN HANDLE  IoCompletionPortHandle,
IN PVOID  CompletionKey,
IN PVOID  CompletionContext,
IN NTSTATUS  CompletionStatus,
IN ULONG  CompletionInformation 
)

Definition at line 568 of file iocomp.c.

573 {
575  PKQUEUE Queue;
576  PAGED_CODE();
577 
578  /* Get the Object */
579  Status = ObReferenceObjectByHandle(IoCompletionPortHandle,
583  (PVOID*)&Queue,
584  NULL);
585  if (NT_SUCCESS(Status))
586  {
587  /* Set the Completion */
588  Status = IoSetIoCompletion(Queue,
589  CompletionKey,
591  CompletionStatus,
592  CompletionInformation,
593  TRUE);
594 
595  /* Dereference the object */
596  ObDereferenceObject(Queue);
597  }
598 
599  /* Return status */
600  return Status;
601 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define IO_COMPLETION_MODIFY_STATE
Definition: iotypes.h:33
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
_Unreferenced_parameter_ PVOID * CompletionContext
Definition: cdprocs.h:1130
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IoSetIoCompletion(IN PVOID IoCompletion, IN PVOID KeyContext, IN PVOID ApcContext, IN NTSTATUS IoStatus, IN ULONG_PTR IoStatusInformation, IN BOOLEAN Quota)
Definition: iocomp.c:147
POBJECT_TYPE IoCompletionType
Definition: iocomp.c:16

Referenced by PostQueuedCompletionStatus(), RtlpQueueWorkerThread(), SockReenableAsyncSelectEvent(), and WSPAsyncSelect().

Variable Documentation

◆ IoCompletionInfoClass

const INFORMATION_CLASS_INFO IoCompletionInfoClass[]
static
Initial value:
=
{
ICI_SQ_SAME(sizeof(IO_COMPLETION_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY),
}
unsigned int ULONG
Definition: retypes.h:1

Definition at line 28 of file iocomp.c.

Referenced by NtQueryIoCompletion().

◆ IoCompletionPacketLookaside

GENERAL_LOOKASIDE IoCompletionPacketLookaside

Definition at line 18 of file iocomp.c.

Referenced by IopInitLookasideLists().

◆ IoCompletionType

◆ IopCompletionMapping

GENERIC_MAPPING IopCompletionMapping
Initial value:
=
{
}
#define IO_COMPLETION_ALL_ACCESS
Definition: file.c:72
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define IO_COMPLETION_MODIFY_STATE
Definition: iotypes.h:33
#define IO_COMPLETION_QUERY_STATE
Definition: iotypes.h:31
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define SYNCHRONIZE
Definition: nt_native.h:61

Definition at line 20 of file iocomp.c.

Referenced by IopCreateObjectTypes().