2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/io/iomgr/irp.c
5 * PURPOSE: IRP Handling Functions
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
8 * Filip Navara (navaraf@reactos.org)
11 /* INCLUDES ****************************************************************/
17 /* Undefine some macros we implement here */
19 #undef IoCompleteRequest
21 /* PRIVATE FUNCTIONS ********************************************************/
25 IopFreeIrpKernelApc(IN PKAPC Apc
,
26 IN PKNORMAL_ROUTINE
*NormalRoutine
,
27 IN PVOID
*NormalContext
,
28 IN PVOID
*SystemArgument1
,
29 IN PVOID
*SystemArgument2
)
32 IoFreeIrp(CONTAINING_RECORD(Apc
, IRP
, Tail
.Apc
));
37 IopAbortIrpKernelApc(IN PKAPC Apc
)
40 IoFreeIrp(CONTAINING_RECORD(Apc
, IRP
, Tail
.Apc
));
45 IopCleanupFailedIrp(IN PFILE_OBJECT FileObject
,
46 IN PKEVENT EventObject OPTIONAL
,
47 IN PVOID Buffer OPTIONAL
)
51 /* Dereference the event */
52 if (EventObject
) ObDereferenceObject(EventObject
);
54 /* Free a buffer, if any */
55 if (Buffer
) ExFreePool(Buffer
);
57 /* If this was a file opened for synch I/O, then unlock it */
58 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
) IopUnlockFileObject(FileObject
);
60 /* Now dereference it and return */
61 ObDereferenceObject(FileObject
);
62 return STATUS_INSUFFICIENT_RESOURCES
;
67 IopAbortInterruptedIrp(IN PKEVENT EventObject
,
75 /* Raise IRQL to APC */
76 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
78 /* Check if nobody completed it yet */
79 if (!KeReadStateEvent(EventObject
))
81 /* First, cancel it */
82 CancelResult
= IoCancelIrp(Irp
);
85 /* Check if we cancelled it */
88 /* Wait for the IRP to be cancelled */
89 Wait
.QuadPart
= -100000;
90 while (!KeReadStateEvent(EventObject
))
92 /* Delay indefintely */
93 KeDelayExecutionThread(KernelMode
, FALSE
, &Wait
);
98 /* No cancellation done, so wait for the I/O system to kill it */
99 KeWaitForSingleObject(EventObject
,
108 /* We got preempted, so give up */
109 KeLowerIrql(OldIrql
);
115 IopRemoveThreadIrp(VOID
)
120 PLIST_ENTRY IrpEntry
;
121 PIO_ERROR_LOG_PACKET ErrorLogEntry
;
122 PDEVICE_OBJECT DeviceObject
= NULL
;
123 PIO_STACK_LOCATION IoStackLocation
;
125 /* First, raise to APC to protect IrpList */
126 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
128 /* Get the Thread and check the list */
129 IrpThread
= PsGetCurrentThread();
130 if (IsListEmpty(&IrpThread
->IrpList
))
132 /* It got completed now, so quit */
133 KeLowerIrql(OldIrql
);
137 /* Get the misbehaving IRP */
138 IrpEntry
= IrpThread
->IrpList
.Flink
;
139 DeadIrp
= CONTAINING_RECORD(IrpEntry
, IRP
, ThreadListEntry
);
140 IOTRACE(IO_IRP_DEBUG
,
141 "%s - Deassociating IRP %p for %p\n",
146 /* Don't cancel the IRP if it's already been completed far */
147 if (DeadIrp
->CurrentLocation
== (DeadIrp
->StackCount
+ 2))
150 KeLowerIrql(OldIrql
);
154 /* Disown the IRP! */
155 DeadIrp
->Tail
.Overlay
.Thread
= NULL
;
156 RemoveHeadList(&IrpThread
->IrpList
);
157 InitializeListHead(&DeadIrp
->ThreadListEntry
);
159 /* Get the stack location and check if it's valid */
160 IoStackLocation
= IoGetCurrentIrpStackLocation(DeadIrp
);
161 if (DeadIrp
->CurrentLocation
<= DeadIrp
->StackCount
)
163 /* Get the device object */
164 DeviceObject
= IoStackLocation
->DeviceObject
;
167 /* Lower IRQL now, since we have the pointers we need */
168 KeLowerIrql(OldIrql
);
170 /* Check if we can send an Error Log Entry*/
173 /* Allocate an entry */
174 ErrorLogEntry
= IoAllocateErrorLogEntry(DeviceObject
,
175 sizeof(IO_ERROR_LOG_PACKET
));
178 /* Write the entry */
179 ErrorLogEntry
->ErrorCode
= 0xBAADF00D; /* FIXME */
180 IoWriteErrorLogEntry(ErrorLogEntry
);
187 IopCleanupIrp(IN PIRP Irp
,
188 IN PFILE_OBJECT FileObject
)
191 IOTRACE(IO_IRP_DEBUG
,
192 "%s - Cleaning IRP %p for %p\n",
197 /* Check if there's an MDL */
198 while ((Mdl
= Irp
->MdlAddress
))
200 /* Clear all of them */
201 Irp
->MdlAddress
= Mdl
->Next
;
205 /* Check if the IRP has system buffer */
206 if (Irp
->Flags
& IRP_DEALLOCATE_BUFFER
)
208 /* Free the buffer */
209 ExFreePoolWithTag(Irp
->AssociatedIrp
.SystemBuffer
, TAG_SYS_BUF
);
212 /* Check if this IRP has a user event, a file object, and is async */
213 if ((Irp
->UserEvent
) &&
214 !(Irp
->Flags
& IRP_SYNCHRONOUS_API
) &&
217 /* Dereference the User Event */
218 ObDereferenceObject(Irp
->UserEvent
);
221 /* Check if we have a file object and this isn't a create operation */
222 if ((FileObject
) && !(Irp
->Flags
& IRP_CREATE_OPERATION
))
224 /* Dereference the file object */
225 ObDereferenceObject(FileObject
);
234 IopCompleteRequest(IN PKAPC Apc
,
235 IN PKNORMAL_ROUTINE
* NormalRoutine
,
236 IN PVOID
* NormalContext
,
237 IN PVOID
* SystemArgument1
,
238 IN PVOID
* SystemArgument2
)
240 PFILE_OBJECT FileObject
;
243 PVOID Port
= NULL
, Key
= NULL
;
244 BOOLEAN SignaledCreateRequest
= FALSE
;
246 /* Get data from the APC */
247 FileObject
= (PFILE_OBJECT
)*SystemArgument1
;
248 Irp
= CONTAINING_RECORD(Apc
, IRP
, Tail
.Apc
);
249 IOTRACE(IO_IRP_DEBUG
,
250 "%s - Completing IRP %p for %p\n",
256 ASSERT(Irp
->IoStatus
.Status
!= (NTSTATUS
)0xFFFFFFFF);
258 /* Check if we have a file object */
259 if (*SystemArgument2
)
261 /* Check if we're reparsing */
262 if ((Irp
->IoStatus
.Status
== STATUS_REPARSE
) &&
263 (Irp
->IoStatus
.Information
== IO_REPARSE_TAG_MOUNT_POINT
))
265 /* We should never get this yet */
266 DPRINT1("Reparse support not yet present!\n");
271 /* Handle Buffered case first */
272 if (Irp
->Flags
& IRP_BUFFERED_IO
)
274 /* Check if we have an input buffer and if we succeeded */
275 if ((Irp
->Flags
& IRP_INPUT_OPERATION
) &&
276 (Irp
->IoStatus
.Status
!= STATUS_VERIFY_REQUIRED
) &&
277 !(NT_ERROR(Irp
->IoStatus
.Status
)))
279 /* Copy the buffer back to the user */
280 RtlCopyMemory(Irp
->UserBuffer
,
281 Irp
->AssociatedIrp
.SystemBuffer
,
282 Irp
->IoStatus
.Information
);
285 /* Also check if we should de-allocate it */
286 if (Irp
->Flags
& IRP_DEALLOCATE_BUFFER
)
289 ExFreePool(Irp
->AssociatedIrp
.SystemBuffer
);
293 /* Now we got rid of these two... */
294 Irp
->Flags
&= ~(IRP_BUFFERED_IO
| IRP_DEALLOCATE_BUFFER
);
296 /* Check if there's an MDL */
297 for (Mdl
= Irp
->MdlAddress
; Mdl
; Mdl
= NextMdl
)
305 Irp
->MdlAddress
= NULL
;
308 * Check if either the request was completed without any errors
309 * (but warnings are OK!), or if it was completed with an error, but
310 * did return from a pending I/O Operation and is not synchronous.
312 if (!(NT_ERROR(Irp
->IoStatus
.Status
)) ||
313 (NT_ERROR(Irp
->IoStatus
.Status
) &&
314 (Irp
->PendingReturned
) &&
315 !(IsIrpSynchronous(Irp
, FileObject
))))
317 /* Get any information we need from the FO before we kill it */
318 if ((FileObject
) && (FileObject
->CompletionContext
))
320 /* Save Completion Data */
321 Port
= FileObject
->CompletionContext
->Port
;
322 Key
= FileObject
->CompletionContext
->Key
;
325 /* Use SEH to make sure we don't write somewhere invalid */
328 /* Save the IOSB Information */
329 *Irp
->UserIosb
= Irp
->IoStatus
;
331 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
333 /* Ignore any error */
337 /* Check if we have an event or a file object */
340 /* At the very least, this is a PKEVENT, so signal it always */
341 KeSetEvent(Irp
->UserEvent
, 0, FALSE
);
343 /* Check if we also have a File Object */
346 /* Check if this is an Asynch API */
347 if (!(Irp
->Flags
& IRP_SYNCHRONOUS_API
))
349 /* Dereference the event */
350 ObDereferenceObject(Irp
->UserEvent
);
354 * Now, if this is a Synch I/O File Object, then this event is
355 * NOT an actual Executive Event, so we won't dereference it,
356 * and instead, we will signal the File Object
358 if ((FileObject
->Flags
& FO_SYNCHRONOUS_IO
) &&
359 !(Irp
->Flags
& IRP_OB_QUERY_NAME
))
361 /* Signal the file object and set the status */
362 KeSetEvent(&FileObject
->Event
, 0, FALSE
);
363 FileObject
->FinalStatus
= Irp
->IoStatus
.Status
;
367 * This could also be a create operation, in which case we want
368 * to make sure there's no APC fired.
370 if (Irp
->Flags
& IRP_CREATE_OPERATION
)
372 /* Clear the APC Routine and remember this */
373 Irp
->Overlay
.AsynchronousParameters
.UserApcRoutine
= NULL
;
374 SignaledCreateRequest
= TRUE
;
380 /* Signal the file object and set the status */
381 KeSetEvent(&FileObject
->Event
, 0, FALSE
);
382 FileObject
->FinalStatus
= Irp
->IoStatus
.Status
;
385 * This could also be a create operation, in which case we want
386 * to make sure there's no APC fired.
388 if (Irp
->Flags
& IRP_CREATE_OPERATION
)
390 /* Clear the APC Routine and remember this */
391 Irp
->Overlay
.AsynchronousParameters
.UserApcRoutine
= NULL
;
392 SignaledCreateRequest
= TRUE
;
396 /* Update transfer count for everything but create operation */
397 if (!(Irp
->Flags
& IRP_CREATE_OPERATION
))
399 if (Irp
->Flags
& IRP_WRITE_OPERATION
)
401 /* Update write transfer count */
402 IopUpdateTransferCount(IopWriteTransfer
,
403 (ULONG
)Irp
->IoStatus
.Information
);
405 else if (Irp
->Flags
& IRP_READ_OPERATION
)
407 /* Update read transfer count */
408 IopUpdateTransferCount(IopReadTransfer
,
409 (ULONG
)Irp
->IoStatus
.Information
);
413 /* Update other transfer count */
414 IopUpdateTransferCount(IopOtherTransfer
,
415 (ULONG
)Irp
->IoStatus
.Information
);
419 /* Now that we've signaled the events, de-associate the IRP */
420 IopUnQueueIrpFromThread(Irp
);
422 /* Now check if a User APC Routine was requested */
423 if (Irp
->Overlay
.AsynchronousParameters
.UserApcRoutine
)
426 KeInitializeApc(&Irp
->Tail
.Apc
,
427 KeGetCurrentThread(),
428 CurrentApcEnvironment
,
430 IopAbortIrpKernelApc
,
431 (PKNORMAL_ROUTINE
)Irp
->
432 Overlay
.AsynchronousParameters
.UserApcRoutine
,
435 Overlay
.AsynchronousParameters
.UserApcContext
);
438 KeInsertQueueApc(&Irp
->Tail
.Apc
, Irp
->UserIosb
, NULL
, 2);
441 (Irp
->Overlay
.AsynchronousParameters
.UserApcContext
))
443 /* We have an I/O Completion setup... create the special Overlay */
444 Irp
->Tail
.CompletionKey
= Key
;
445 Irp
->Tail
.Overlay
.PacketType
= IopCompletionPacketIrp
;
446 KeInsertQueue(Port
, &Irp
->Tail
.Overlay
.ListEntry
);
450 /* Free the IRP since we don't need it anymore */
454 /* Check if we have a file object that wasn't part of a create */
455 if ((FileObject
) && !(SignaledCreateRequest
))
457 /* Dereference it, since it's not needed anymore either */
458 ObDereferenceObjectDeferDelete(FileObject
);
464 * Either we didn't return from the request, or we did return but this
465 * request was synchronous.
467 if ((Irp
->PendingReturned
) && (FileObject
))
469 /* So we did return with a synch operation, was it the IRP? */
470 if (Irp
->Flags
& IRP_SYNCHRONOUS_API
)
472 /* Yes, this IRP was synchronous, so return the I/O Status */
473 *Irp
->UserIosb
= Irp
->IoStatus
;
475 /* Now check if the user gave an event */
479 KeSetEvent(Irp
->UserEvent
, 0, FALSE
);
483 /* No event was given, so signal the FO instead */
484 KeSetEvent(&FileObject
->Event
, 0, FALSE
);
490 * It's not the IRP that was synchronous, it was the FO
491 * that was opened this way. Signal its event.
493 FileObject
->FinalStatus
= Irp
->IoStatus
.Status
;
494 KeSetEvent(&FileObject
->Event
, 0, FALSE
);
498 /* Now that we got here, we do this for incomplete I/Os as well */
499 if ((FileObject
) && !(Irp
->Flags
& IRP_CREATE_OPERATION
))
501 /* Dereference the File Object unless this was a create */
502 ObDereferenceObjectDeferDelete(FileObject
);
506 * Check if this was an Executive Event (remember that we know this
507 * by checking if the IRP is synchronous)
509 if ((Irp
->UserEvent
) &&
511 !(Irp
->Flags
& IRP_SYNCHRONOUS_API
))
513 /* This isn't a PKEVENT, so dereference it */
514 ObDereferenceObject(Irp
->UserEvent
);
517 /* Now that we've signaled the events, de-associate the IRP */
518 IopUnQueueIrpFromThread(Irp
);
520 /* Free the IRP as well */
525 /* FUNCTIONS *****************************************************************/
532 IoAllocateIrp(IN CCHAR StackSize
,
533 IN BOOLEAN ChargeQuota
)
536 USHORT Size
= IoSizeOfIrp(StackSize
);
539 PNPAGED_LOOKASIDE_LIST List
= NULL
;
540 PP_NPAGED_LOOKASIDE_NUMBER ListType
= LookasideSmallIrpList
;
542 /* Set Charge Quota Flag */
543 if (ChargeQuota
) Flags
|= IRP_QUOTA_CHARGED
;
545 /* FIXME: Implement Lookaside Floats */
547 /* Figure out which Lookaside List to use */
548 if ((StackSize
<= 8) && (ChargeQuota
== FALSE
))
550 /* Set Fixed Size Flag */
551 Flags
= IRP_ALLOCATED_FIXED_SIZE
;
553 /* See if we should use big list */
556 Size
= IoSizeOfIrp(8);
557 ListType
= LookasideLargeIrpList
;
561 Prcb
= KeGetCurrentPrcb();
563 /* Get the P List First */
564 List
= (PNPAGED_LOOKASIDE_LIST
)Prcb
->PPLookasideList
[ListType
].P
;
566 /* Attempt allocation */
567 List
->L
.TotalAllocates
++;
568 Irp
= (PIRP
)InterlockedPopEntrySList(&List
->L
.ListHead
);
570 /* Check if the P List failed */
573 /* Let the balancer know */
574 List
->L
.AllocateMisses
++;
577 List
= (PNPAGED_LOOKASIDE_LIST
)Prcb
->PPLookasideList
[ListType
].L
;
578 List
->L
.TotalAllocates
++;
579 Irp
= (PIRP
)InterlockedPopEntrySList(&List
->L
.ListHead
);
583 /* Check if we have to use the pool */
586 /* Did we try lookaside and fail? */
587 if (Flags
& IRP_ALLOCATED_FIXED_SIZE
) List
->L
.AllocateMisses
++;
589 /* Check if we should charge quota */
592 /* Irp = ExAllocatePoolWithQuotaTag(NonPagedPool, Size, TAG_IRP); */
594 Irp
= ExAllocatePoolWithTag(NonPagedPool
, Size
, TAG_IRP
);
598 /* Allocate the IRP With no Quota charge */
599 Irp
= ExAllocatePoolWithTag(NonPagedPool
, Size
, TAG_IRP
);
602 /* Make sure it was sucessful */
603 if (!Irp
) return(NULL
);
607 /* In this case there is no charge quota */
608 Flags
&= ~IRP_QUOTA_CHARGED
;
611 /* Now Initialize it */
612 IoInitializeIrp(Irp
, Size
, StackSize
);
614 /* Set the Allocation Flags */
615 Irp
->AllocationFlags
= Flags
;
618 IOTRACE(IO_IRP_DEBUG
,
619 "%s - Allocated IRP %p with allocation flags %lx\n",
631 IoBuildAsynchronousFsdRequest(IN ULONG MajorFunction
,
632 IN PDEVICE_OBJECT DeviceObject
,
635 IN PLARGE_INTEGER StartingOffset
,
636 IN PIO_STATUS_BLOCK IoStatusBlock
)
639 PIO_STACK_LOCATION StackPtr
;
642 Irp
= IoAllocateIrp(DeviceObject
->StackSize
, FALSE
);
643 if (!Irp
) return NULL
;
646 StackPtr
= IoGetNextIrpStackLocation(Irp
);
648 /* Write the Major function and then deal with it */
649 StackPtr
->MajorFunction
= (UCHAR
)MajorFunction
;
651 /* Do not handle the following here */
652 if ((MajorFunction
!= IRP_MJ_FLUSH_BUFFERS
) &&
653 (MajorFunction
!= IRP_MJ_SHUTDOWN
) &&
654 (MajorFunction
!= IRP_MJ_PNP
) &&
655 (MajorFunction
!= IRP_MJ_POWER
))
657 /* Check if this is Buffered IO */
658 if (DeviceObject
->Flags
& DO_BUFFERED_IO
)
660 /* Allocate the System Buffer */
661 Irp
->AssociatedIrp
.SystemBuffer
=
662 ExAllocatePoolWithTag(NonPagedPool
, Length
, TAG_SYS_BUF
);
663 if (!Irp
->AssociatedIrp
.SystemBuffer
)
665 /* Free the IRP and fail */
671 Irp
->Flags
= IRP_BUFFERED_IO
| IRP_DEALLOCATE_BUFFER
;
673 /* Handle special IRP_MJ_WRITE Case */
674 if (MajorFunction
== IRP_MJ_WRITE
)
676 /* Copy the buffer data */
677 RtlCopyMemory(Irp
->AssociatedIrp
.SystemBuffer
, Buffer
, Length
);
681 /* Set the Input Operation flag and set this as a User Buffer */
682 Irp
->Flags
|= IRP_INPUT_OPERATION
;
683 Irp
->UserBuffer
= Buffer
;
686 else if (DeviceObject
->Flags
& DO_DIRECT_IO
)
688 /* Use an MDL for Direct I/O */
689 Irp
->MdlAddress
= IoAllocateMdl(Buffer
,
694 if (!Irp
->MdlAddress
)
696 /* Free the IRP and fail */
705 MmProbeAndLockPages(Irp
->MdlAddress
,
707 MajorFunction
== IRP_MJ_READ
?
708 IoWriteAccess
: IoReadAccess
);
710 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
712 /* Free the IRP and its MDL */
713 IoFreeMdl(Irp
->MdlAddress
);
717 _SEH2_YIELD(return NULL
);
723 /* Neither, use the buffer */
724 Irp
->UserBuffer
= Buffer
;
727 /* Check if this is a read */
728 if (MajorFunction
== IRP_MJ_READ
)
730 /* Set the parameters for a read */
731 StackPtr
->Parameters
.Read
.Length
= Length
;
732 StackPtr
->Parameters
.Read
.ByteOffset
= *StartingOffset
;
734 else if (MajorFunction
== IRP_MJ_WRITE
)
736 /* Otherwise, set write parameters */
737 StackPtr
->Parameters
.Write
.Length
= Length
;
738 StackPtr
->Parameters
.Write
.ByteOffset
= *StartingOffset
;
742 /* Set the Current Thread and IOSB */
743 Irp
->UserIosb
= IoStatusBlock
;
744 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
747 IOTRACE(IO_IRP_DEBUG
,
748 "%s - Built IRP %p with Major, Buffer, DO %lx %p %p\n",
762 IoBuildDeviceIoControlRequest(IN ULONG IoControlCode
,
763 IN PDEVICE_OBJECT DeviceObject
,
764 IN PVOID InputBuffer
,
765 IN ULONG InputBufferLength
,
766 IN PVOID OutputBuffer
,
767 IN ULONG OutputBufferLength
,
768 IN BOOLEAN InternalDeviceIoControl
,
770 IN PIO_STATUS_BLOCK IoStatusBlock
)
773 PIO_STACK_LOCATION StackPtr
;
777 Irp
= IoAllocateIrp(DeviceObject
->StackSize
, FALSE
);
778 if (!Irp
) return NULL
;
781 StackPtr
= IoGetNextIrpStackLocation(Irp
);
783 /* Set the DevCtl Type */
784 StackPtr
->MajorFunction
= InternalDeviceIoControl
?
785 IRP_MJ_INTERNAL_DEVICE_CONTROL
:
786 IRP_MJ_DEVICE_CONTROL
;
788 /* Set the IOCTL Data */
789 StackPtr
->Parameters
.DeviceIoControl
.IoControlCode
= IoControlCode
;
790 StackPtr
->Parameters
.DeviceIoControl
.InputBufferLength
= InputBufferLength
;
791 StackPtr
->Parameters
.DeviceIoControl
.OutputBufferLength
=
794 /* Handle the Methods */
795 switch (IO_METHOD_FROM_CTL_CODE(IoControlCode
))
798 case METHOD_BUFFERED
:
800 /* Select the right Buffer Length */
801 BufferLength
= InputBufferLength
> OutputBufferLength
?
802 InputBufferLength
: OutputBufferLength
;
804 /* Make sure there is one */
807 /* Allocate the System Buffer */
808 Irp
->AssociatedIrp
.SystemBuffer
=
809 ExAllocatePoolWithTag(NonPagedPool
,
812 if (!Irp
->AssociatedIrp
.SystemBuffer
)
814 /* Free the IRP and fail */
819 /* Check if we got a buffer */
822 /* Copy into the System Buffer */
823 RtlCopyMemory(Irp
->AssociatedIrp
.SystemBuffer
,
828 /* Write the flags */
829 Irp
->Flags
= IRP_BUFFERED_IO
| IRP_DEALLOCATE_BUFFER
;
830 if (OutputBuffer
) Irp
->Flags
|= IRP_INPUT_OPERATION
;
832 /* Save the Buffer */
833 Irp
->UserBuffer
= OutputBuffer
;
837 /* Clear the Flags and Buffer */
839 Irp
->UserBuffer
= NULL
;
844 case METHOD_IN_DIRECT
:
845 case METHOD_OUT_DIRECT
:
847 /* Check if we got an input buffer */
850 /* Allocate the System Buffer */
851 Irp
->AssociatedIrp
.SystemBuffer
=
852 ExAllocatePoolWithTag(NonPagedPool
,
855 if (!Irp
->AssociatedIrp
.SystemBuffer
)
857 /* Free the IRP and fail */
862 /* Copy into the System Buffer */
863 RtlCopyMemory(Irp
->AssociatedIrp
.SystemBuffer
,
867 /* Write the flags */
868 Irp
->Flags
= IRP_BUFFERED_IO
| IRP_DEALLOCATE_BUFFER
;
872 /* Clear the flags */
876 /* Check if we got an output buffer */
879 /* Allocate the System Buffer */
880 Irp
->MdlAddress
= IoAllocateMdl(OutputBuffer
,
885 if (!Irp
->MdlAddress
)
887 /* Free the IRP and fail */
896 MmProbeAndLockPages(Irp
->MdlAddress
,
898 IO_METHOD_FROM_CTL_CODE(IoControlCode
) ==
900 IoReadAccess
: IoWriteAccess
);
902 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
905 IoFreeMdl(Irp
->MdlAddress
);
907 /* Free the input buffer and IRP */
908 if (InputBuffer
) ExFreePool(Irp
->AssociatedIrp
.SystemBuffer
);
912 _SEH2_YIELD(return NULL
);
920 /* Just save the Buffer */
921 Irp
->UserBuffer
= OutputBuffer
;
922 StackPtr
->Parameters
.DeviceIoControl
.Type3InputBuffer
= InputBuffer
;
925 /* Now write the Event and IoSB */
926 Irp
->UserIosb
= IoStatusBlock
;
927 Irp
->UserEvent
= Event
;
929 /* Sync IRPs are queued to requestor thread's irp cancel/cleanup list */
930 Irp
->Tail
.Overlay
.Thread
= PsGetCurrentThread();
931 IoQueueThreadIrp(Irp
);
934 IOTRACE(IO_IRP_DEBUG
,
935 "%s - Built IRP %p with IOCTL, Buffers, DO %lx %p %p %p\n",
950 IoBuildSynchronousFsdRequest(IN ULONG MajorFunction
,
951 IN PDEVICE_OBJECT DeviceObject
,
954 IN PLARGE_INTEGER StartingOffset
,
956 IN PIO_STATUS_BLOCK IoStatusBlock
)
960 /* Do the big work to set up the IRP */
961 Irp
= IoBuildAsynchronousFsdRequest(MajorFunction
,
967 if (!Irp
) return NULL
;
969 /* Set the Event which makes it Syncronous */
970 Irp
->UserEvent
= Event
;
972 /* Sync IRPs are queued to requestor thread's irp cancel/cleanup list */
973 IoQueueThreadIrp(Irp
);
982 IoCancelIrp(IN PIRP Irp
)
986 PDRIVER_CANCEL CancelRoutine
;
987 IOTRACE(IO_IRP_DEBUG
,
988 "%s - Canceling IRP %p\n",
991 ASSERT(Irp
->Type
== IO_TYPE_IRP
);
992 IrqlAtEntry
= KeGetCurrentIrql();
994 /* Acquire the cancel lock and cancel the IRP */
995 IoAcquireCancelSpinLock(&OldIrql
);
998 /* Clear the cancel routine and get the old one */
999 CancelRoutine
= (PVOID
)IoSetCancelRoutine(Irp
, NULL
);
1002 /* We had a routine, make sure the IRP isn't completed */
1003 if (Irp
->CurrentLocation
> (Irp
->StackCount
+ 1))
1005 /* It is, bugcheck */
1006 KeBugCheckEx(CANCEL_STATE_IN_COMPLETED_IRP
,
1013 /* Set the cancel IRQL And call the routine */
1014 Irp
->CancelIrql
= OldIrql
;
1015 CancelRoutine(IoGetCurrentIrpStackLocation(Irp
)->DeviceObject
, Irp
);
1016 ASSERT(IrqlAtEntry
== KeGetCurrentIrql());
1020 /* Otherwise, release the cancel lock and fail */
1021 IoReleaseCancelSpinLock(OldIrql
);
1030 IoCancelThreadIo(IN PETHREAD Thread
)
1033 ULONG Retries
= 3000;
1034 LARGE_INTEGER Interval
;
1035 PLIST_ENTRY ListHead
, NextEntry
;
1037 IOTRACE(IO_IRP_DEBUG
,
1038 "%s - Canceling IRPs for Thread %p\n",
1042 /* Raise to APC to protect the IrpList */
1043 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
1045 /* Start by cancelling all the IRPs in the current thread queue. */
1046 ListHead
= &Thread
->IrpList
;
1047 NextEntry
= ListHead
->Flink
;
1048 while (ListHead
!= NextEntry
)
1051 Irp
= CONTAINING_RECORD(NextEntry
, IRP
, ThreadListEntry
);
1056 /* Move to the next entry */
1057 NextEntry
= NextEntry
->Flink
;
1060 /* Wait 100 milliseconds */
1061 Interval
.QuadPart
= -1000000;
1063 /* Wait till all the IRPs are completed or cancelled. */
1064 while (!IsListEmpty(&Thread
->IrpList
))
1066 /* Now we can lower */
1067 KeLowerIrql(OldIrql
);
1069 /* Wait a short while and then look if all our IRPs were completed. */
1070 KeDelayExecutionThread(KernelMode
, FALSE
, &Interval
);
1073 * Don't stay here forever if some broken driver doesn't complete
1078 /* Print out a message and remove the IRP */
1079 DPRINT1("Broken driver did not complete!\n");
1080 IopRemoveThreadIrp();
1083 /* Raise the IRQL Again */
1084 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
1087 /* We're done, lower the IRQL */
1088 KeLowerIrql(OldIrql
);
1096 IoCallDriver(IN PDEVICE_OBJECT DeviceObject
,
1100 return IofCallDriver(DeviceObject
, Irp
);
1108 IoCompleteRequest(IN PIRP Irp
,
1109 IN CCHAR PriorityBoost
)
1111 /* Call the fastcall */
1112 IofCompleteRequest(Irp
, PriorityBoost
);
1120 IoEnqueueIrp(IN PIRP Irp
)
1122 /* This is the same as calling IoQueueThreadIrp */
1123 IoQueueThreadIrp(Irp
);
1131 IofCallDriver(IN PDEVICE_OBJECT DeviceObject
,
1134 PDRIVER_OBJECT DriverObject
;
1135 PIO_STACK_LOCATION StackPtr
;
1137 /* Make sure this is a valid IRP */
1138 ASSERT(Irp
->Type
== IO_TYPE_IRP
);
1140 /* Get the Driver Object */
1141 DriverObject
= DeviceObject
->DriverObject
;
1143 /* Decrease the current location and check if */
1144 Irp
->CurrentLocation
--;
1145 if (Irp
->CurrentLocation
<= 0)
1147 /* This IRP ran out of stack, bugcheck */
1148 KeBugCheckEx(NO_MORE_IRP_STACK_LOCATIONS
, (ULONG_PTR
)Irp
, 0, 0, 0);
1151 /* Now update the stack location */
1152 StackPtr
= IoGetNextIrpStackLocation(Irp
);
1153 Irp
->Tail
.Overlay
.CurrentStackLocation
= StackPtr
;
1155 /* Get the Device Object */
1156 StackPtr
->DeviceObject
= DeviceObject
;
1159 return DriverObject
->MajorFunction
[StackPtr
->MajorFunction
](DeviceObject
,
1165 IopClearStackLocation(IN PIO_STACK_LOCATION IoStackLocation
)
1167 IoStackLocation
->MinorFunction
= 0;
1168 IoStackLocation
->Flags
= 0;
1169 IoStackLocation
->Control
&= SL_ERROR_RETURNED
;
1170 IoStackLocation
->Parameters
.Others
.Argument1
= 0;
1171 IoStackLocation
->Parameters
.Others
.Argument2
= 0;
1172 IoStackLocation
->Parameters
.Others
.Argument3
= 0;
1173 IoStackLocation
->FileObject
= NULL
;
1181 IofCompleteRequest(IN PIRP Irp
,
1182 IN CCHAR PriorityBoost
)
1184 PIO_STACK_LOCATION StackPtr
, LastStackPtr
;
1185 PDEVICE_OBJECT DeviceObject
;
1186 PFILE_OBJECT FileObject
;
1193 NTSTATUS ErrorCode
= STATUS_SUCCESS
;
1194 IOTRACE(IO_IRP_DEBUG
,
1195 "%s - Completing IRP %p\n",
1199 /* Make sure this IRP isn't getting completed twice or is invalid */
1200 if ((Irp
->CurrentLocation
) > (Irp
->StackCount
+ 1))
1203 KeBugCheckEx(MULTIPLE_IRP_COMPLETE_REQUESTS
, (ULONG_PTR
)Irp
, 0, 0, 0);
1206 /* Some sanity checks */
1207 ASSERT(Irp
->Type
== IO_TYPE_IRP
);
1208 ASSERT(!Irp
->CancelRoutine
);
1209 ASSERT(Irp
->IoStatus
.Status
!= STATUS_PENDING
);
1210 ASSERT(Irp
->IoStatus
.Status
!= (NTSTATUS
)0xFFFFFFFF);
1212 /* Get the last stack */
1213 LastStackPtr
= (PIO_STACK_LOCATION
)(Irp
+ 1);
1214 if (LastStackPtr
->Control
& SL_ERROR_RETURNED
)
1216 /* Get the error code */
1217 ErrorCode
= PtrToUlong(LastStackPtr
->Parameters
.Others
.Argument4
);
1220 /* Get the Current Stack */
1221 StackPtr
= IoGetCurrentIrpStackLocation(Irp
);
1223 /* Loop the Stacks and complete the IRPs */
1226 /* Skip current stack location */
1227 IoSkipCurrentIrpStackLocation(Irp
);
1229 /* Set Pending Returned */
1230 Irp
->PendingReturned
= StackPtr
->Control
& SL_PENDING_RETURNED
;
1232 /* Check if we failed */
1233 if (!NT_SUCCESS(Irp
->IoStatus
.Status
))
1235 /* Check if it was changed by a completion routine */
1236 if (Irp
->IoStatus
.Status
!= ErrorCode
)
1238 /* Update the error for the current stack */
1239 ErrorCode
= Irp
->IoStatus
.Status
;
1240 StackPtr
->Control
|= SL_ERROR_RETURNED
;
1241 LastStackPtr
->Parameters
.Others
.Argument4
= UlongToPtr(ErrorCode
);
1242 LastStackPtr
->Control
|= SL_ERROR_RETURNED
;
1246 /* Check if there is a Completion Routine to Call */
1247 if ((NT_SUCCESS(Irp
->IoStatus
.Status
) &&
1248 (StackPtr
->Control
& SL_INVOKE_ON_SUCCESS
)) ||
1249 (!NT_SUCCESS(Irp
->IoStatus
.Status
) &&
1250 (StackPtr
->Control
& SL_INVOKE_ON_ERROR
)) ||
1252 (StackPtr
->Control
& SL_INVOKE_ON_CANCEL
)))
1254 /* Clear the stack location */
1255 IopClearStackLocation(StackPtr
);
1257 /* Check for highest-level device completion routines */
1258 if (Irp
->CurrentLocation
== (Irp
->StackCount
+ 1))
1260 /* Clear the DO, since the current stack location is invalid */
1261 DeviceObject
= NULL
;
1265 /* Otherwise, return the real one */
1266 DeviceObject
= IoGetCurrentIrpStackLocation(Irp
)->DeviceObject
;
1269 /* Call the completion routine */
1270 Status
= StackPtr
->CompletionRoutine(DeviceObject
,
1274 /* Don't touch the Packet in this case, since it might be gone! */
1275 if (Status
== STATUS_MORE_PROCESSING_REQUIRED
) return;
1279 /* Otherwise, check if this is a completed IRP */
1280 if ((Irp
->CurrentLocation
<= Irp
->StackCount
) &&
1281 (Irp
->PendingReturned
))
1283 /* Mark it as pending */
1284 IoMarkIrpPending(Irp
);
1287 /* Clear the stack location */
1288 IopClearStackLocation(StackPtr
);
1291 /* Move pointer to next stack location */
1293 } while (Irp
->CurrentLocation
<= Irp
->StackCount
);
1295 /* Check if the IRP is an associated IRP */
1296 if (Irp
->Flags
& IRP_ASSOCIATED_IRP
)
1298 /* Get the master IRP and count */
1299 MasterIrp
= Irp
->AssociatedIrp
.MasterIrp
;
1300 MasterCount
= InterlockedDecrement(&MasterIrp
->AssociatedIrp
.IrpCount
);
1303 for (Mdl
= Irp
->MdlAddress
; Mdl
; Mdl
= NextMdl
)
1305 /* Go to the next one */
1306 NextMdl
= Mdl
->Next
;
1310 /* Free the IRP itself */
1313 /* Complete the Master IRP */
1314 if (!MasterCount
) IofCompleteRequest(MasterIrp
, PriorityBoost
);
1318 /* We don't support this yet */
1319 ASSERT(Irp
->IoStatus
.Status
!= STATUS_REPARSE
);
1321 /* Check if we have an auxiliary buffer */
1322 if (Irp
->Tail
.Overlay
.AuxiliaryBuffer
)
1325 ExFreePool(Irp
->Tail
.Overlay
.AuxiliaryBuffer
);
1326 Irp
->Tail
.Overlay
.AuxiliaryBuffer
= NULL
;
1329 /* Check if this is a Paging I/O or Close Operation */
1330 if (Irp
->Flags
& (IRP_PAGING_IO
| IRP_CLOSE_OPERATION
))
1332 /* Handle a Close Operation or Sync Paging I/O */
1333 if (Irp
->Flags
& (IRP_SYNCHRONOUS_PAGING_IO
| IRP_CLOSE_OPERATION
))
1335 /* Set the I/O Status and Signal the Event */
1336 Flags
= Irp
->Flags
& (IRP_SYNCHRONOUS_PAGING_IO
| IRP_PAGING_IO
);
1337 *Irp
->UserIosb
= Irp
->IoStatus
;
1338 KeSetEvent(Irp
->UserEvent
, PriorityBoost
, FALSE
);
1340 /* Free the IRP for a Paging I/O Only, Close is handled by us */
1341 if (Flags
) IoFreeIrp(Irp
);
1347 KeInitializeApc(&Irp
->Tail
.Apc
1348 &Irp
->Tail
.Overlay
.Thread
->Tcb
,
1349 Irp
->ApcEnvironment
,
1350 IopCompletePageWrite
,
1355 KeInsertQueueApc(&Irp
->Tail
.Apc
,
1360 /* Not implemented yet. */
1361 DPRINT1("Not supported!\n");
1366 /* Get out of here */
1370 /* Unlock MDL Pages, page 167. */
1371 Mdl
= Irp
->MdlAddress
;
1378 /* Check if we should exit because of a Deferred I/O (page 168) */
1379 if ((Irp
->Flags
& IRP_DEFER_IO_COMPLETION
) && !(Irp
->PendingReturned
))
1382 * Return without queuing the completion APC, since the caller will
1383 * take care of doing its own optimized completion at PASSIVE_LEVEL.
1388 /* Get the thread and file object */
1389 Thread
= Irp
->Tail
.Overlay
.Thread
;
1390 FileObject
= Irp
->Tail
.Overlay
.OriginalFileObject
;
1392 /* Make sure the IRP isn't canceled */
1395 /* Initialize the APC */
1396 KeInitializeApc(&Irp
->Tail
.Apc
,
1398 Irp
->ApcEnvironment
,
1406 KeInsertQueueApc(&Irp
->Tail
.Apc
,
1408 NULL
, /* This is used for REPARSE stuff */
1413 /* The IRP just got canceled... does a thread still own it? */
1414 Thread
= Irp
->Tail
.Overlay
.Thread
;
1417 /* Yes! There is still hope! Initialize the APC */
1418 KeInitializeApc(&Irp
->Tail
.Apc
,
1420 Irp
->ApcEnvironment
,
1428 KeInsertQueueApc(&Irp
->Tail
.Apc
,
1430 NULL
, /* This is used for REPARSE stuff */
1435 /* Nothing left for us to do, kill it */
1436 ASSERT(Irp
->Cancel
);
1437 IopCleanupIrp(Irp
, FileObject
);
1444 IopSynchronousCompletion(IN PDEVICE_OBJECT DeviceObject
,
1448 if (Irp
->PendingReturned
)
1449 KeSetEvent((PKEVENT
)Context
, IO_NO_INCREMENT
, FALSE
);
1450 return STATUS_MORE_PROCESSING_REQUIRED
;
1458 IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject
,
1464 /* Check if next stack location is available */
1465 if (Irp
->CurrentLocation
< Irp
->StackCount
)
1467 /* No more stack location */
1471 /* Initialize event */
1472 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
1474 /* Copy stack location for next driver */
1475 IoCopyCurrentIrpStackLocationToNext(Irp
);
1477 /* Set a completion routine, which will signal the event */
1478 IoSetCompletionRoutine(Irp
, IopSynchronousCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
1480 /* Call next driver */
1481 Status
= IoCallDriver(DeviceObject
, Irp
);
1483 /* Check if irp is pending */
1484 if (Status
== STATUS_PENDING
)
1486 /* Yes, wait for its completion */
1487 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
1490 /* Return success */
1499 IoFreeIrp(IN PIRP Irp
)
1501 PNPAGED_LOOKASIDE_LIST List
;
1502 PP_NPAGED_LOOKASIDE_NUMBER ListType
= LookasideSmallIrpList
;
1504 IOTRACE(IO_IRP_DEBUG
,
1505 "%s - Freeing IRPs %p\n",
1509 /* Make sure the Thread IRP list is empty and that it OK to free it */
1510 ASSERT(Irp
->Type
== IO_TYPE_IRP
);
1511 ASSERT(IsListEmpty(&Irp
->ThreadListEntry
));
1512 ASSERT(Irp
->CurrentLocation
>= Irp
->StackCount
);
1514 /* If this was a pool alloc, free it with the pool */
1515 if (!(Irp
->AllocationFlags
& IRP_ALLOCATED_FIXED_SIZE
))
1518 ExFreePoolWithTag(Irp
, TAG_IRP
);
1522 /* Check if this was a Big IRP */
1523 if (Irp
->StackCount
!= 1) ListType
= LookasideLargeIrpList
;
1526 Prcb
= KeGetCurrentPrcb();
1528 /* Use the P List */
1529 List
= (PNPAGED_LOOKASIDE_LIST
)Prcb
->PPLookasideList
[ListType
].P
;
1530 List
->L
.TotalFrees
++;
1532 /* Check if the Free was within the Depth or not */
1533 if (ExQueryDepthSList(&List
->L
.ListHead
) >= List
->L
.Depth
)
1535 /* Let the balancer know */
1536 List
->L
.FreeMisses
++;
1538 /* Use the L List */
1539 List
= (PNPAGED_LOOKASIDE_LIST
)Prcb
->PPLookasideList
[ListType
].L
;
1540 List
->L
.TotalFrees
++;
1542 /* Check if the Free was within the Depth or not */
1543 if (ExQueryDepthSList(&List
->L
.ListHead
) >= List
->L
.Depth
)
1545 /* All lists failed, use the pool */
1546 List
->L
.FreeMisses
++;
1547 ExFreePoolWithTag(Irp
, TAG_IRP
);
1552 /* The free was within the Depth */
1555 InterlockedPushEntrySList(&List
->L
.ListHead
,
1566 IoGetPagingIoPriority(IN PIRP Irp
)
1568 IO_PAGING_PRIORITY Priority
;
1574 /* Check what priority it has */
1575 if (Flags
& 0x8000) // FIXME: Undocumented flag
1578 Priority
= IoPagingPriorityHigh
;
1580 else if (Flags
& IRP_PAGING_IO
)
1582 /* Normal priority */
1583 Priority
= IoPagingPriorityNormal
;
1587 /* Invalid -- not a paging IRP */
1588 Priority
= IoPagingPriorityInvalid
;
1591 /* Return the priority */
1600 IoGetRequestorProcess(IN PIRP Irp
)
1602 /* Return the requestor process */
1603 return Irp
->Tail
.Overlay
.Thread
->ThreadsProcess
;
1611 IoGetRequestorProcessId(IN PIRP Irp
)
1613 /* Return the requestor process' id */
1614 return PtrToUlong(IoGetRequestorProcess(Irp
)->UniqueProcessId
);
1622 IoGetRequestorSessionId(IN PIRP Irp
,
1623 OUT PULONG pSessionId
)
1625 /* Return the session */
1626 *pSessionId
= (ULONG_PTR
)IoGetRequestorProcess(Irp
)->Session
;
1627 return STATUS_SUCCESS
;
1635 IoGetTopLevelIrp(VOID
)
1637 /* Return the IRP */
1638 return (PIRP
)PsGetCurrentThread()->TopLevelIrp
;
1646 IoInitializeIrp(IN PIRP Irp
,
1647 IN USHORT PacketSize
,
1651 IOTRACE(IO_IRP_DEBUG
,
1652 "%s - Initializing IRP %p\n",
1655 RtlZeroMemory(Irp
, PacketSize
);
1657 /* Set the Header and other data */
1658 Irp
->Type
= IO_TYPE_IRP
;
1659 Irp
->Size
= PacketSize
;
1660 Irp
->StackCount
= StackSize
;
1661 Irp
->CurrentLocation
= StackSize
+ 1;
1662 Irp
->ApcEnvironment
= KeGetCurrentThread()->ApcStateIndex
;
1663 Irp
->Tail
.Overlay
.CurrentStackLocation
= (PIO_STACK_LOCATION
)(Irp
+ 1) + StackSize
;
1665 /* Initialize the Thread List */
1666 InitializeListHead(&Irp
->ThreadListEntry
);
1674 IoIsOperationSynchronous(IN PIRP Irp
)
1676 /* Check the flags */
1677 if (!(Irp
->Flags
& (IRP_PAGING_IO
| IRP_SYNCHRONOUS_PAGING_IO
)) &&
1678 ((Irp
->Flags
& IRP_SYNCHRONOUS_PAGING_IO
) ||
1679 (Irp
->Flags
& IRP_SYNCHRONOUS_API
) ||
1680 (IoGetCurrentIrpStackLocation(Irp
)->FileObject
->Flags
&
1681 FO_SYNCHRONOUS_IO
)))
1683 /* Synch API or Paging I/O is OK, as is Sync File I/O */
1687 /* Otherwise, it is an asynchronous operation. */
1696 IoIsValidNameGraftingBuffer(IN PIRP Irp
,
1697 IN PREPARSE_DATA_BUFFER ReparseBuffer
)
1708 IoMakeAssociatedIrp(IN PIRP Irp
,
1712 IOTRACE(IO_IRP_DEBUG
,
1713 "%s - Associating IRP %p\n",
1717 /* Allocate the IRP */
1718 AssocIrp
= IoAllocateIrp(StackSize
, FALSE
);
1719 if (!AssocIrp
) return NULL
;
1722 AssocIrp
->Flags
|= IRP_ASSOCIATED_IRP
;
1724 /* Set the Thread */
1725 AssocIrp
->Tail
.Overlay
.Thread
= Irp
->Tail
.Overlay
.Thread
;
1727 /* Associate them */
1728 AssocIrp
->AssociatedIrp
.MasterIrp
= Irp
;
1737 IoQueueThreadIrp(IN PIRP Irp
)
1739 IOTRACE(IO_IRP_DEBUG
,
1740 "%s - Queueing IRP %p\n",
1744 /* Use our inlined routine */
1745 IopQueueIrpToThread(Irp
);
1750 * Reference: Chris Cant's "Writing WDM Device Drivers"
1754 IoReuseIrp(IN OUT PIRP Irp
,
1757 UCHAR AllocationFlags
;
1758 IOTRACE(IO_IRP_DEBUG
,
1759 "%s - Reusing IRP %p\n",
1763 /* Make sure it's OK to reuse it */
1764 ASSERT(!Irp
->CancelRoutine
);
1765 ASSERT(IsListEmpty(&Irp
->ThreadListEntry
));
1767 /* Get the old flags */
1768 AllocationFlags
= Irp
->AllocationFlags
;
1770 /* Reinitialize the IRP */
1771 IoInitializeIrp(Irp
, Irp
->Size
, Irp
->StackCount
);
1773 /* Duplicate the data */
1774 Irp
->IoStatus
.Status
= Status
;
1775 Irp
->AllocationFlags
= AllocationFlags
;
1783 IoSetTopLevelIrp(IN PIRP Irp
)
1786 PsGetCurrentThread()->TopLevelIrp
= (ULONG_PTR
)Irp
;