ReactOS  0.4.13-dev-563-g0561610
irp.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/ksfilter/ks/factory.c
5  * PURPOSE: KS Allocator functions
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "precomp.h"
10 
11 #include <ntifs.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /*
17  @implemented
18 */
21 NTAPI
24  IN PIRP Irp)
25 {
26  PKSOBJECT_CREATE_ITEM CreateItem;
27  PIO_STACK_LOCATION IoStack;
29  ULONG Length;
30 
31  /* get current irp stack */
33 
34  /* get create item */
35  CreateItem = KSCREATE_ITEM_IRP_STORAGE(Irp);
36 
37  if (!CreateItem || !CreateItem->SecurityDescriptor)
38  {
39  /* no create item */
40  Irp->IoStatus.Status = STATUS_NO_SECURITY_ON_OBJECT;
43  }
44 
45 
46  /* get input length */
47  Length = IoStack->Parameters.QuerySecurity.Length;
48 
49  /* clone the security descriptor */
50  Status = SeQuerySecurityDescriptorInfo(&IoStack->Parameters.QuerySecurity.SecurityInformation, (PSECURITY_DESCRIPTOR)Irp->UserBuffer, &Length, &CreateItem->SecurityDescriptor);
51 
52  DPRINT("SeQuerySecurityDescriptorInfo Status %x\n", Status);
53  /* store result */
54  Irp->IoStatus.Status = Status;
55  Irp->IoStatus.Information = Length;
56 
58  return Status;
59 }
60 
61 /*
62  @implemented
63 */
66 NTAPI
69  IN PIRP Irp)
70 {
71  PKSOBJECT_CREATE_ITEM CreateItem;
72  PIO_STACK_LOCATION IoStack;
76 
77  /* get current irp stack */
79 
80  /* get create item */
81  CreateItem = KSCREATE_ITEM_IRP_STORAGE(Irp);
82 
83  if (!CreateItem || !CreateItem->SecurityDescriptor)
84  {
85  /* no create item */
86  Irp->IoStatus.Status = STATUS_NO_SECURITY_ON_OBJECT;
89  }
90 
91  /* backup old descriptor */
92  Descriptor = CreateItem->SecurityDescriptor;
93 
94  /* get generic mapping */
96 
97  /* change security descriptor */
99  &IoStack->Parameters.SetSecurity.SecurityInformation,
100  IoStack->Parameters.SetSecurity.SecurityDescriptor,
101  &CreateItem->SecurityDescriptor,
102  NonPagedPool,
103  Mapping);
104 
105  if (NT_SUCCESS(Status))
106  {
107  /* free old descriptor */
109 
110  /* mark create item as changed */
111  CreateItem->Flags |= KSCREATE_ITEM_SECURITYCHANGED;
112  }
113 
114  /* store result */
115  Irp->IoStatus.Status = Status;
117 
118  return Status;
119 }
120 
121 /*
122  @unimplemented
123 */
124 KSDDKAPI
125 NTSTATUS
126 NTAPI
128  IN PIRP Irp,
129  IN PFNKSHANDLER Handler)
130 {
132  return STATUS_UNSUCCESSFUL;
133 }
134 
135 
136 /*
137  @implemented
138 */
139 KSDDKAPI
140 NTSTATUS
141 NTAPI
145  IN PVOID PortContext OPTIONAL,
147  OUT PVOID Buffer,
148  IN ULONG Length,
150  IN KPROCESSOR_MODE RequestorMode)
151 {
153  PIRP Irp;
155  BOOLEAN Result;
156  KEVENT LocalEvent;
157 
158  if (Event)
159  {
160  /* make sure event is reset */
162  }
163 
164  if (RequestorMode == UserMode)
165  {
166  /* probe the user buffer */
167  _SEH2_TRY
168  {
169  ProbeForWrite(Buffer, Length, sizeof(UCHAR));
171  }
173  {
174  /* Exception, get the error code */
176  }
177  _SEH2_END;
178 
179  if (!NT_SUCCESS(Status))
180  {
181  DPRINT1("Invalid user buffer provided\n");
182  return Status;
183  }
184  }
185 
186  /* get corresponding device object */
188 
189  /* fast-io read is only available for kernel mode clients */
190  if (RequestorMode == KernelMode && ExGetPreviousMode() == KernelMode &&
191  DeviceObject->DriverObject->FastIoDispatch->FastIoRead)
192  {
193  /* call fast io write */
194  Result = DeviceObject->DriverObject->FastIoDispatch->FastIoRead(FileObject, &FileObject->CurrentByteOffset, Length, TRUE, Key, Buffer, IoStatusBlock, DeviceObject);
195 
197  {
198  /* request was handled and succeeded */
199  return STATUS_SUCCESS;
200  }
201  }
202 
203  /* do the slow way */
204  if (!Event)
205  {
206  /* initialize temp event */
208  Event = &LocalEvent;
209  }
210 
211  /* build the irp packet */
213  if (!Irp)
214  {
215  /* not enough resources */
217  }
218 
219  /* send the packet */
221 
222  if (Status == STATUS_PENDING)
223  {
224  /* operation is pending, is sync file object */
225  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
226  {
227  /* it is so wait */
228  KeWaitForSingleObject(Event, Executive, RequestorMode, FALSE, NULL);
230  }
231  }
232  /* return result */
233  return Status;
234 }
235 
236 /*
237  @implemented
238 */
239 KSDDKAPI
240 NTSTATUS
241 NTAPI
245  IN PVOID PortContext OPTIONAL,
247  IN PVOID Buffer,
248  IN ULONG Length,
250  IN KPROCESSOR_MODE RequestorMode)
251 {
253  PIRP Irp;
255  BOOLEAN Result;
256  KEVENT LocalEvent;
257 
258  if (Event)
259  {
260  /* make sure event is reset */
262  }
263 
264  if (RequestorMode == UserMode)
265  {
266  /* probe the user buffer */
267  _SEH2_TRY
268  {
269  ProbeForRead(Buffer, Length, sizeof(UCHAR));
271  }
273  {
274  /* Exception, get the error code */
276  }
277  _SEH2_END;
278 
279  if (!NT_SUCCESS(Status))
280  {
281  DPRINT1("Invalid user buffer provided\n");
282  return Status;
283  }
284  }
285 
286  /* get corresponding device object */
288 
289  /* fast-io write is only available for kernel mode clients */
290  if (RequestorMode == KernelMode && ExGetPreviousMode() == KernelMode &&
291  DeviceObject->DriverObject->FastIoDispatch->FastIoWrite)
292  {
293  /* call fast io write */
294  Result = DeviceObject->DriverObject->FastIoDispatch->FastIoWrite(FileObject, &FileObject->CurrentByteOffset, Length, TRUE, Key, Buffer, IoStatusBlock, DeviceObject);
295 
297  {
298  /* request was handled and succeeded */
299  return STATUS_SUCCESS;
300  }
301  }
302 
303  /* do the slow way */
304  if (!Event)
305  {
306  /* initialize temp event */
308  Event = &LocalEvent;
309  }
310 
311  /* build the irp packet */
313  if (!Irp)
314  {
315  /* not enough resources */
317  }
318 
319  /* send the packet */
321 
322  if (Status == STATUS_PENDING)
323  {
324  /* operation is pending, is sync file object */
325  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
326  {
327  /* it is so wait */
328  KeWaitForSingleObject(Event, Executive, RequestorMode, FALSE, NULL);
330  }
331  }
332  /* return result */
333  return Status;
334 }
335 
336 /*
337  @implemented
338 */
339 KSDDKAPI
340 NTSTATUS
341 NTAPI
345  IN ULONG Length,
347 {
350  PIRP Irp;
351  PIO_STACK_LOCATION IoStack;
353  KEVENT Event;
355  IO_STATUS_BLOCK StatusBlock;
357 
358  /* get related file object */
360 
361  /* get fast i/o table */
362  FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
363 
364  /* is there a fast table */
365  if (FastIoDispatch)
366  {
367  /* check the class */
369  {
370  /* use FastIoQueryBasicInfo routine */
372  {
374  }
375  }
377  {
378  /* use FastIoQueryBasicInfo routine */
380  {
382  }
383  }
384  }
385  /* clear event */
386  KeClearEvent(&FileObject->Event);
387 
388  /* initialize event */
390 
391  /* set offset to zero */
392  Offset.QuadPart = 0L;
393 
394  /* build the request */
396 
397  if (!Irp)
399 
400  /* get next stack location */
401  IoStack = IoGetNextIrpStackLocation(Irp);
402 
403  /* setup parameters */
404  IoStack->Parameters.QueryFile.FileInformationClass = FileInformationClass;
405  IoStack->Parameters.QueryFile.Length = Length;
406  Irp->AssociatedIrp.SystemBuffer = FileInformation;
407 
408 
409  /* call the driver */
411 
412  if (Status == STATUS_PENDING)
413  {
414  /* wait for the operation to complete */
416 
417  /* is object sync */
418  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
419  Status = FileObject->FinalStatus;
420  else
421  Status = StatusBlock.Status;
422  }
423 
424  /* done */
425  return Status;
426 }
427 
428 /*
429  @implemented
430 */
431 KSDDKAPI
432 NTSTATUS
433 NTAPI
437  IN ULONG Length,
439 {
440  PIO_STACK_LOCATION IoStack;
442  PIRP Irp;
443  PVOID Buffer;
444  KEVENT Event;
448 
449  /* get related device object */
451 
452  /* copy file information */
454  if (!Buffer)
456 
457  _SEH2_TRY
458  {
459  ProbeForRead(Buffer, Length, sizeof(UCHAR));
462  }
464  {
465  /* Exception, get the error code */
467  }
468  _SEH2_END;
469 
470  if (!NT_SUCCESS(Status))
471  {
472  /* invalid user buffer */
473  FreeItem(Buffer);
474  return Status;
475  }
476 
477  /* initialize the event */
479 
480  /* zero offset */
481  Offset.QuadPart = 0LL;
482 
483  /* build the irp */
485 
486  if (!Irp)
487  {
488  /* failed to allocate irp */
489  FreeItem(Buffer);
491  }
492 
493  /* get next stack location */
494  IoStack = IoGetNextIrpStackLocation(Irp);
495 
496  /* set irp parameters */
497  IoStack->Parameters.SetFile.FileInformationClass = FileInformationClass;
498  IoStack->Parameters.SetFile.Length = Length;
499  IoStack->Parameters.SetFile.FileObject = FileObject;
500  Irp->AssociatedIrp.SystemBuffer = Buffer;
501  Irp->UserBuffer = FileInformation;
502 
503  /* dispatch the irp */
505 
506  if (Status == STATUS_PENDING)
507  {
508  /* wait untill the operation has completed */
510  /* is a sync file object */
511  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
512  Status = FileObject->FinalStatus;
513  else
514  Status = IoStatus.Status;
515  }
516  /* done */
517  return Status;
518 }
519 
520 /*
521  @implemented
522 */
523 KSDDKAPI
524 NTSTATUS
525 NTAPI
529  IN PVOID PortContext OPTIONAL,
532  IN KSCOMPLETION_INVOCATION CompletionInvocationFlags OPTIONAL,
534  IN OUT PVOID StreamHeaders,
535  IN ULONG Length,
536  IN ULONG Flags,
537  IN KPROCESSOR_MODE RequestorMode)
538 {
539  PIRP Irp;
540  PIO_STACK_LOCATION IoStack;
544  PKSIOBJECT_HEADER ObjectHeader;
545  BOOLEAN Ret;
546 
547  /* get related device object */
549  /* sanity check */
551 
552  /* is there a event provided */
553  if (Event)
554  {
555  /* reset event */
557  }
558 
559  if (RequestorMode || ExGetPreviousMode() == KernelMode)
560  {
561  /* requestor is from kernel land */
562  ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
563 
564  if (ObjectHeader)
565  {
566  /* there is a object header */
567  if (Flags == KSSTREAM_READ)
568  {
569  /* is fast read supported */
570  if (ObjectHeader->DispatchTable.FastRead)
571  {
572  /* call fast read dispatch routine */
573  Ret = ObjectHeader->DispatchTable.FastRead(FileObject, NULL, Length, FALSE, 0, StreamHeaders, IoStatusBlock, DeviceObject);
574 
575  if (Ret)
576  {
577  /* the request was handled */
578  return IoStatusBlock->Status;
579  }
580  }
581  }
582  else if (Flags == KSSTREAM_WRITE)
583  {
584  /* is fast write supported */
585  if (ObjectHeader->DispatchTable.FastWrite)
586  {
587  /* call fast write dispatch routine */
588  Ret = ObjectHeader->DispatchTable.FastWrite(FileObject, NULL, Length, FALSE, 0, StreamHeaders, IoStatusBlock, DeviceObject);
589 
590  if (Ret)
591  {
592  /* the request was handled */
593  return IoStatusBlock->Status;
594  }
595  }
596  }
597  }
598  }
599 
600  /* clear file object event */
601  KeClearEvent(&FileObject->Event);
602 
603  /* set the offset to zero */
604  Offset.QuadPart = 0LL;
605 
606  /* now build the irp */
608  DeviceObject, (PVOID)StreamHeaders, Length, &Offset, Event, IoStatusBlock);
609  if (!Irp)
610  {
611  /* not enough memory */
613  }
614 
615  /* setup irp parameters */
616  Irp->RequestorMode = RequestorMode;
617  Irp->Overlay.AsynchronousParameters.UserApcContext = PortContext;
618  Irp->Tail.Overlay.OriginalFileObject = FileObject;
619  Irp->UserBuffer = StreamHeaders;
620 
621  /* get next irp stack location */
622  IoStack = IoGetNextIrpStackLocation(Irp);
623  /* setup stack parameters */
624  IoStack->FileObject = FileObject;
625  IoStack->Parameters.DeviceIoControl.InputBufferLength = Length;
626  IoStack->Parameters.DeviceIoControl.Type3InputBuffer = StreamHeaders;
627  IoStack->Parameters.DeviceIoControl.IoControlCode = (Flags == KSSTREAM_READ ? IOCTL_KS_READ_STREAM : IOCTL_KS_WRITE_STREAM);
628 
629  if (CompletionRoutine)
630  {
631  /* setup completion routine for async processing */
632  IoSetCompletionRoutine(Irp, CompletionRoutine, CompletionContext, (CompletionInvocationFlags & KsInvokeOnSuccess), (CompletionInvocationFlags & KsInvokeOnError), (CompletionInvocationFlags & KsInvokeOnCancel));
633  }
634 
635  /* now call the driver */
637  /* done */
638  return Status;
639 }
640 
641 /*
642  @implemented
643 */
644 KSDDKAPI
645 NTSTATUS
646 NTAPI
648  IN PIRP Irp,
649  IN ULONG ProbeFlags,
650  IN ULONG HeaderSize)
651 {
652  PMDL Mdl;
653  PVOID Buffer;
656  PKSSTREAM_HEADER StreamHeader;
657  PIO_STACK_LOCATION IoStack;
658  ULONG Length;
659  //BOOLEAN AllocateMdl = FALSE;
660 
661  /* get current irp stack */
663 
664  Length = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
665 
666  if (Irp->RequestorMode == KernelMode || Irp->AssociatedIrp.SystemBuffer)
667  {
668  if (Irp->RequestorMode == KernelMode)
669  {
670  /* no need to allocate stream header */
671  Irp->AssociatedIrp.SystemBuffer = Irp->UserBuffer;
672  }
673 AllocMdl:
674  /* check if alloc mdl flag is passed */
675  if (!(ProbeFlags & KSPROBE_ALLOCATEMDL))
676  {
677  /* nothing more to do */
678  return STATUS_SUCCESS;
679  }
680  if (Irp->MdlAddress)
681  {
682 ProbeMdl:
683  if (ProbeFlags & KSPROBE_PROBEANDLOCK)
684  {
685  if (Irp->MdlAddress->MdlFlags & (MDL_PAGES_LOCKED | MDL_SOURCE_IS_NONPAGED_POOL))
686  {
687  if (ProbeFlags & KSPROBE_SYSTEMADDRESS)
688  {
689  _SEH2_TRY
690  {
691  /* loop through all mdls and probe them */
692  Mdl = Irp->MdlAddress;
693  do
694  {
695  /* the mapping can fail */
696  Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
697 
699  {
700  /* no need to probe these pages */
701  Buffer = Mdl->MappedSystemVa;
702  }
703  else
704  {
705  /* probe that mdl */
707  }
708 
709  /* check if the mapping succeeded */
710  if (!Buffer)
711  {
712  /* raise exception we'll catch */
714  }
715 
716  /* iterate to next mdl */
717  Mdl = Mdl->Next;
718 
719  }while(Mdl);
720  }
722  {
723  /* Exception, get the error code */
725  } _SEH2_END;
726  }
727  }
728  else
729  {
730  _SEH2_TRY
731  {
732  /* loop through all mdls and probe them */
733  Mdl = Irp->MdlAddress;
734 
735  /* determine operation */
736  if (!(ProbeFlags & KSPROBE_STREAMWRITE) || (ProbeFlags & KSPROBE_MODIFY))
737  {
738  /* operation is read / modify stream, need write access */
740  }
741  else
742  {
743  /* operation is write to device, so we need read access */
745  }
746 
747  do
748  {
749  /* probe the pages */
750  MmProbeAndLockPages(Mdl, Irp->RequestorMode, Operation);
751 
752  if (ProbeFlags & KSPROBE_SYSTEMADDRESS)
753  {
754  /* the mapping can fail */
755  Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
756 
758  {
759  /* no need to probe these pages */
760  Buffer = Mdl->MappedSystemVa;
761  }
762  else
763  {
764  /* probe that mdl */
766  }
767 
768  /* check if the mapping succeeded */
769  if (!Buffer)
770  {
771  /* raise exception we'll catch */
773  }
774  }
775 
776  /* iterate to next mdl */
777  Mdl = Mdl->Next;
778 
779  }while(Mdl);
780  }
782  {
783  /* Exception, get the error code */
785  } _SEH2_END;
786  }
787  }
788  return Status;
789  }
790 
791  /* check all stream headers */
792  StreamHeader = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;
793  ASSERT(StreamHeader);
794  _SEH2_TRY
795  {
796  do
797  {
798  if (HeaderSize)
799  {
800  /* does the supplied header size match stream header size and no type changed */
801  if (StreamHeader->Size != HeaderSize && !(StreamHeader->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_TYPECHANGED))
802  {
803  /* invalid stream header */
805  }
806  }
807  else
808  {
809  /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
810  if (StreamHeader->Size < sizeof(KSSTREAM_HEADER) || (StreamHeader->Size & 7))
811  {
812  /* invalid stream header */
814  }
815  }
816 
818  {
819  /* length is too short */
821  }
822 
823  if (ProbeFlags & KSPROBE_STREAMWRITE)
824  {
825  if (StreamHeader->DataUsed > StreamHeader->FrameExtent)
826  {
827  /* frame extend can never be smaller */
829  }
830 
831  /* is this stream change packet */
833  {
834  if (Length != sizeof(KSSTREAM_HEADER) || (PVOID)StreamHeader != Irp->AssociatedIrp.SystemBuffer)
835  {
836  /* stream changed - must be send in a single packet */
838  }
839 
840  if (!(ProbeFlags & KSPROBE_ALLOWFORMATCHANGE))
841  {
842  /* caller does not permit format changes */
844  }
845 
846  if (StreamHeader->FrameExtent)
847  {
848  /* allocate an mdl */
849  Mdl = IoAllocateMdl(StreamHeader->Data, StreamHeader->FrameExtent, FALSE, TRUE, Irp);
850 
851  if (!Mdl)
852  {
853  /* not enough memory */
855  }
856 
857  /* break-out to probe for the irp */
858  break;
859  }
860  }
861  }
862  else
863  {
864  if (StreamHeader->DataUsed)
865  {
866  /* DataUsed must be zero for stream read operation */
868  }
869 
870  if (StreamHeader->OptionsFlags)
871  {
872  /* no flags supported for reading */
874  }
875  }
876 
877  if (StreamHeader->FrameExtent)
878  {
879  /* allocate an mdl */
880  ASSERT(Irp->MdlAddress == NULL);
881  Mdl = IoAllocateMdl(StreamHeader->Data, StreamHeader->FrameExtent, FALSE, TRUE, Irp);
882  if (!Mdl)
883  {
884  /* not enough memory */
886  }
887  }
888 
889  /* move to next stream header */
890  Length -= StreamHeader->Size;
891  StreamHeader = (PKSSTREAM_HEADER)((ULONG_PTR)StreamHeader + StreamHeader->Size);
892  }while(Length);
893  }
895  {
896  /* Exception, get the error code */
898  }_SEH2_END;
899 
900  /* now probe the allocated mdl's */
901  if (!NT_SUCCESS(Status))
902  {
903  DPRINT("Status %x\n", Status);
904  return Status;
905  }
906  else
907  goto ProbeMdl;
908  }
909 
910  /* probe user mode buffers */
911  if (Length && ( (!HeaderSize) || (Length % HeaderSize == 0) || ((ProbeFlags & KSPROBE_ALLOWFORMATCHANGE) && (Length == sizeof(KSSTREAM_HEADER))) ) )
912  {
913  /* allocate stream header buffer */
914  Irp->AssociatedIrp.SystemBuffer = AllocateItem(NonPagedPool, Length);
915 
916  if (!Irp->AssociatedIrp.SystemBuffer)
917  {
918  /* no memory */
920  }
921 
922  /* mark irp as buffered so that changes the stream headers are propagated back */
924 
925  _SEH2_TRY
926  {
927  if (ProbeFlags & KSPROBE_STREAMWRITE)
928  {
929  if (ProbeFlags & KSPROBE_MODIFY)
930  ProbeForWrite(Irp->UserBuffer, Length, sizeof(UCHAR));
931  else
932  ProbeForRead(Irp->UserBuffer, Length, sizeof(UCHAR));
933  }
934  else
935  {
936  /* stream reads means writing */
937  ProbeForWrite(Irp->UserBuffer, Length, sizeof(UCHAR));
938 
939  /* set input operation flags */
940  Irp->Flags |= IRP_INPUT_OPERATION;
941  }
942 
943  /* copy stream buffer */
944  RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer, Irp->UserBuffer, Length);
945  }
947  {
948  /* Exception, get the error code */
950  }_SEH2_END;
951 
952  if (!NT_SUCCESS(Status))
953  {
954  /* failed */
955  return Status;
956  }
957 
958  if (ProbeFlags & KSPROBE_ALLOCATEMDL)
959  {
960  /* alloc mdls */
961  goto AllocMdl;
962  }
963 
964  /* check all stream headers */
965  StreamHeader = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;
966 
967  _SEH2_TRY
968  {
969  do
970  {
971  if (HeaderSize)
972  {
973  /* does the supplied header size match stream header size and no type changed */
974  if (StreamHeader->Size != HeaderSize && !(StreamHeader->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_TYPECHANGED))
975  {
976  /* invalid stream header */
978  }
979  }
980  else
981  {
982  /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
983  if (StreamHeader->Size < sizeof(KSSTREAM_HEADER) || (StreamHeader->Size & 7))
984  {
985  /* invalid stream header */
987  }
988  }
989 
991  {
992  /* length is too short */
994  }
995 
996  if (ProbeFlags & KSPROBE_STREAMWRITE)
997  {
998  if (StreamHeader->DataUsed > StreamHeader->FrameExtent)
999  {
1000  /* frame extend can never be smaller */
1002  }
1003 
1004  /* is this stream change packet */
1006  {
1007  if (Length != sizeof(KSSTREAM_HEADER) || (PVOID)StreamHeader != Irp->AssociatedIrp.SystemBuffer)
1008  {
1009  /* stream changed - must be send in a single packet */
1011  }
1012 
1013  if (!(ProbeFlags & KSPROBE_ALLOWFORMATCHANGE))
1014  {
1015  /* caller does not permit format changes */
1017  }
1018 
1019  if (StreamHeader->FrameExtent)
1020  {
1021  /* allocate an mdl */
1022  Mdl = IoAllocateMdl(StreamHeader->Data, StreamHeader->FrameExtent, FALSE, TRUE, Irp);
1023 
1024  if (!Mdl)
1025  {
1026  /* not enough memory */
1028  }
1029 
1030  /* break out to probe for the irp */
1031  //AllocateMdl = TRUE;
1032  break;
1033  }
1034  }
1035  }
1036  else
1037  {
1038  if (StreamHeader->DataUsed)
1039  {
1040  /* DataUsed must be zero for stream read operation */
1042  }
1043 
1044  if (StreamHeader->OptionsFlags)
1045  {
1046  /* no flags supported for reading */
1048  }
1049  }
1050 
1051  /* move to next stream header */
1052  Length -= StreamHeader->Size;
1053  StreamHeader = (PKSSTREAM_HEADER)((ULONG_PTR)StreamHeader + StreamHeader->Size);
1054  }while(Length);
1055 
1057  {
1058  /* Exception, get the error code */
1060  }_SEH2_END;
1061 
1062  /* now probe the allocated mdl's */
1063  if (NT_SUCCESS(Status))
1064  goto AllocMdl;
1065  else
1066  return Status;
1067  }
1068 
1070 }
1071 
1072 /*
1073  @implemented
1074 */
1075 KSDDKAPI
1076 NTSTATUS
1077 NTAPI
1079  IN PIRP Irp,
1080  IN ULONG ExtraSize,
1081  OUT PVOID* ExtraBuffer)
1082 {
1083  PIO_STACK_LOCATION IoStack;
1084  ULONG Count, Index;
1085  PUCHAR Buffer, BufferOrg;
1088 
1089  /* get current irp stack */
1090  IoStack = IoGetCurrentIrpStackLocation(Irp);
1091 
1092  /* sanity check */
1093  ASSERT(IoStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(KSSTREAM_HEADER));
1094 
1095  /* get total length */
1096  Count = IoStack->Parameters.DeviceIoControl.InputBufferLength / sizeof(KSSTREAM_HEADER);
1097 
1098  /* allocate buffer */
1099  Buffer = BufferOrg = AllocateItem(NonPagedPool, Count * (sizeof(KSSTREAM_HEADER) + ExtraSize));
1100  if (!Buffer)
1102 
1103  _SEH2_TRY
1104  {
1105  /* get input buffer */
1106  Header = (PKSSTREAM_HEADER)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
1107  for(Index = 0; Index < Count; Index++)
1108  {
1109  /* copy stream header */
1111 
1112  /* move to next header */
1113  Header++;
1114  /* increment output buffer offset */
1115  Buffer += sizeof(KSSTREAM_HEADER) + ExtraSize;
1116  }
1117  }
1119  {
1120  /* Exception, get the error code */
1122  }
1123  _SEH2_END;
1124 
1125  if (!NT_SUCCESS(Status))
1126  {
1127  /* free buffer on exception */
1128  FreeItem(Buffer);
1129  return Status;
1130  }
1131 
1132  /* store result */
1133  *ExtraBuffer = BufferOrg;
1134 
1135  /* done */
1136  return STATUS_SUCCESS;
1137 }
1138 
1139 /*
1140  @implemented
1141 */
1142 KSDDKAPI
1143 VOID
1144 NTAPI
1147 {
1148 }
1149 
1150 /*
1151  @implemented
1152 */
1153 KSDDKAPI
1154 NTSTATUS
1155 NTAPI
1158  IN PIRP Irp)
1159 {
1160  Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
1162 
1164 }
1165 
1166 /*
1167  @implemented
1168 */
1169 KSDDKAPI
1170 NTSTATUS
1171 NTAPI
1174  IN PIRP Irp)
1175 {
1176  PIO_STACK_LOCATION IoStack;
1177  NTSTATUS Status;
1178 
1179  /* get current irp stack */
1180  IoStack = IoGetCurrentIrpStackLocation(Irp);
1181 
1182  if (IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY &&
1183  IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_METHOD &&
1184  IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_ENABLE_EVENT &&
1185  IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_DISABLE_EVENT)
1186  {
1187  if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_KS_RESET_STATE)
1188  {
1189  /* fake success */
1191  }
1192  else
1193  {
1194  /* request unsupported */
1196  }
1197  }
1198  else
1199  {
1200  /* property / method / event not found */
1202  }
1203 
1204  /* complete request */
1205  Irp->IoStatus.Status = Status;
1207 
1208 
1209  return Status;
1210 }
1211 
1212 /*
1213  @implemented
1214 */
1215 KSDDKAPI
1216 BOOLEAN
1217 NTAPI
1220  IN BOOLEAN Wait,
1228 {
1229  return FALSE;
1230 }
1231 
1232 /*
1233  @implemented
1234 */
1235 KSDDKAPI
1236 BOOLEAN
1237 NTAPI
1241  IN ULONG Length,
1242  IN BOOLEAN Wait,
1243  IN ULONG LockKey,
1244  OUT PVOID Buffer,
1247 {
1248  return FALSE;
1249 }
1250 
1251 
1252 /*
1253  @implemented
1254 */
1255 KSDDKAPI
1256 VOID
1257 NTAPI
1259  IN OUT PLIST_ENTRY QueueHead,
1261 {
1262  PDRIVER_CANCEL OldDriverCancel;
1263  PIO_STACK_LOCATION IoStack;
1265  PLIST_ENTRY NextEntry;
1266  PIRP Irp;
1267  KIRQL OldLevel;
1268 
1269  /* acquire spinlock */
1270  KeAcquireSpinLock(SpinLock, &OldLevel);
1271  /* point to first entry */
1272  Entry = QueueHead->Flink;
1273  /* loop all items */
1274  while(Entry != QueueHead)
1275  {
1276  /* get irp offset */
1277  Irp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
1278 
1279  /* get next entry */
1280  NextEntry = Entry->Flink;
1281 
1282  /* set cancelled bit */
1283  Irp->Cancel = TRUE;
1284 
1285  /* now set the cancel routine */
1286  OldDriverCancel = IoSetCancelRoutine(Irp, NULL);
1287  if (OldDriverCancel)
1288  {
1289  /* this irp hasnt been yet used, so free to cancel */
1290  KeReleaseSpinLock(SpinLock, OldLevel);
1291 
1292  /* get current irp stack */
1293  IoStack = IoGetCurrentIrpStackLocation(Irp);
1294 
1295  /* acquire cancel spinlock */
1296  IoAcquireCancelSpinLock(&Irp->CancelIrql);
1297 
1298  /* call provided cancel routine */
1299  OldDriverCancel(IoStack->DeviceObject, Irp);
1300 
1301  /* re-acquire spinlock */
1302  KeAcquireSpinLock(SpinLock, &OldLevel);
1303  }
1304 
1305  /* move on to next entry */
1306  Entry = NextEntry;
1307  }
1308 
1309  /* the irp has already been canceled */
1310  KeReleaseSpinLock(SpinLock, OldLevel);
1311 
1312 }
1313 
1314 /*
1315  @implemented
1316 */
1317 KSDDKAPI
1318 VOID
1319 NTAPI
1321  IN PIRP Irp,
1322  IN PDRIVER_CANCEL DriverCancel OPTIONAL)
1323 {
1325  PDRIVER_CANCEL OldDriverCancel;
1326  PIO_STACK_LOCATION IoStack;
1327  KIRQL OldLevel;
1328 
1329  /* check for required parameters */
1330  if (!Irp)
1331  return;
1332 
1333  if (!DriverCancel)
1334  {
1335  /* default to KsCancelRoutine */
1336  DriverCancel = KsCancelRoutine;
1337  }
1338 
1339  /* get current irp stack */
1340  IoStack = IoGetCurrentIrpStackLocation(Irp);
1341 
1342  /* get internal queue lock */
1343  SpinLock = KSQUEUE_SPINLOCK_IRP_STORAGE(Irp);
1344 
1345  /* acquire spinlock */
1346  KeAcquireSpinLock(SpinLock, &OldLevel);
1347 
1348  /* now set the cancel routine */
1349  OldDriverCancel = IoSetCancelRoutine(Irp, DriverCancel);
1350 
1351  if (Irp->Cancel && OldDriverCancel == NULL)
1352  {
1353  /* the irp has already been canceled */
1354  KeReleaseSpinLock(SpinLock, OldLevel);
1355 
1356  /* cancel routine requires that cancel spinlock is held */
1357  IoAcquireCancelSpinLock(&Irp->CancelIrql);
1358 
1359  /* cancel irp */
1360  DriverCancel(IoStack->DeviceObject, Irp);
1361  }
1362  else
1363  {
1364  /* done */
1365  KeReleaseSpinLock(SpinLock, OldLevel);
1366  }
1367 }
1368 
1369 /*
1370  @implemented
1371 */
1372 KSDDKAPI
1373 PIRP
1374 NTAPI
1376  IN OUT PLIST_ENTRY QueueHead,
1378  IN KSLIST_ENTRY_LOCATION ListLocation,
1379  IN KSIRP_REMOVAL_OPERATION RemovalOperation)
1380 {
1381  PIRP Irp;
1382  PLIST_ENTRY CurEntry;
1383  KIRQL OldIrql;
1384 
1385  DPRINT("KsRemoveIrpFromCancelableQueue ListHead %p SpinLock %p ListLocation %x RemovalOperation %x\n", QueueHead, SpinLock, ListLocation, RemovalOperation);
1386 
1387  /* check parameters */
1388  if (!QueueHead || !SpinLock)
1389  return NULL;
1390 
1391  /* check if parameter ListLocation is valid */
1392  if (ListLocation != KsListEntryTail && ListLocation != KsListEntryHead)
1393  return NULL;
1394 
1395  /* acquire list lock */
1397 
1398  /* point to queue head */
1399  CurEntry = QueueHead;
1400 
1401  do
1402  {
1403  /* reset irp to null */
1404  Irp = NULL;
1405 
1406  /* iterate to next entry */
1407  if (ListLocation == KsListEntryHead)
1408  CurEntry = CurEntry->Flink;
1409  else
1410  CurEntry = CurEntry->Blink;
1411 
1412  /* is the end of list reached */
1413  if (CurEntry == QueueHead)
1414  {
1415  /* reached end of list */
1416  break;
1417  }
1418 
1419  /* get irp offset */
1420  Irp = (PIRP)CONTAINING_RECORD(CurEntry, IRP, Tail.Overlay.ListEntry);
1421 
1422  if (Irp->Cancel)
1423  {
1424  /* irp has been canceled */
1425  break;
1426  }
1427 
1428  if (Irp->CancelRoutine)
1429  {
1430  /* remove cancel routine */
1431  Irp->CancelRoutine = NULL;
1432 
1433  if (RemovalOperation == KsAcquireAndRemove || RemovalOperation == KsAcquireAndRemoveOnlySingleItem)
1434  {
1435  /* remove irp from list */
1436  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1437  }
1438 
1439  if (RemovalOperation == KsAcquireAndRemoveOnlySingleItem || RemovalOperation == KsAcquireOnlySingleItem)
1440  break;
1441  }
1442 
1443  }while(TRUE);
1444 
1445  /* release lock */
1447 
1448  if (!Irp || Irp->CancelRoutine == NULL)
1449  {
1450  /* either an irp has been acquired or nothing found */
1451  return Irp;
1452  }
1453 
1454  /* time to remove the canceled irp */
1456  /* acquire list lock */
1458 
1459  if (RemovalOperation == KsAcquireAndRemove || RemovalOperation == KsAcquireAndRemoveOnlySingleItem)
1460  {
1461  /* remove it */
1462  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1463  }
1464 
1465  /* release list lock */
1467 
1468  /* release cancel spinlock */
1470  /* no non canceled irp has been found */
1471  return NULL;
1472 }
1473 
1474 /*
1475  @implemented
1476 */
1477 KSDDKAPI
1478 NTSTATUS
1479 NTAPI
1482  IN PKSPIN_LOCK SourceLock,
1483  IN OUT PLIST_ENTRY DestinationList,
1484  IN PKSPIN_LOCK DestinationLock OPTIONAL,
1485  IN KSLIST_ENTRY_LOCATION ListLocation,
1486  IN PFNKSIRPLISTCALLBACK ListCallback,
1487  IN PVOID Context)
1488 {
1489  KIRQL OldLevel;
1490  PLIST_ENTRY SrcEntry;
1491  PIRP Irp;
1493 
1494  if (!DestinationLock)
1495  {
1496  /* no destination lock just acquire the source lock */
1497  KeAcquireSpinLock(SourceLock, &OldLevel);
1498  }
1499  else
1500  {
1501  /* acquire cancel spinlock */
1502  IoAcquireCancelSpinLock(&OldLevel);
1503 
1504  /* now acquire source lock */
1505  KeAcquireSpinLockAtDpcLevel(SourceLock);
1506 
1507  /* now acquire destination lock */
1508  KeAcquireSpinLockAtDpcLevel(DestinationLock);
1509  }
1510 
1511  /* point to list head */
1512  SrcEntry = SourceList;
1513 
1514  /* now move all irps */
1515  while(TRUE)
1516  {
1517  if (ListLocation == KsListEntryTail)
1518  {
1519  /* move queue downwards */
1520  SrcEntry = SrcEntry->Flink;
1521  }
1522  else
1523  {
1524  /* move queue upwards */
1525  SrcEntry = SrcEntry->Blink;
1526  }
1527 
1528  if (SrcEntry == SourceList)
1529  {
1530  /* eof list reached */
1531  break;
1532  }
1533 
1534  /* get irp offset */
1535  Irp = (PIRP)CONTAINING_RECORD(SrcEntry, IRP, Tail.Overlay.ListEntry);
1536 
1537  /* now check if irp can be moved */
1538  Status = ListCallback(Irp, Context);
1539 
1540  /* check if irp can be moved */
1541  if (Status == STATUS_SUCCESS)
1542  {
1543  /* remove irp from src list */
1544  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1545 
1546  if (ListLocation == KsListEntryTail)
1547  {
1548  /* insert irp end of list */
1549  InsertTailList(DestinationList, &Irp->Tail.Overlay.ListEntry);
1550  }
1551  else
1552  {
1553  /* insert irp head of list */
1554  InsertHeadList(DestinationList, &Irp->Tail.Overlay.ListEntry);
1555  }
1556 
1557  /* do we need to update the irp lock */
1558  if (DestinationLock)
1559  {
1560  /* update irp lock */
1561  KSQUEUE_SPINLOCK_IRP_STORAGE(Irp) = DestinationLock;
1562  }
1563  }
1564  else
1565  {
1566  if (Status != STATUS_NO_MATCH)
1567  {
1568  /* callback decided to stop enumeration */
1569  break;
1570  }
1571 
1572  /* reset return value */
1574  }
1575  }
1576 
1577  if (!DestinationLock)
1578  {
1579  /* release source lock */
1580  KeReleaseSpinLock(SourceLock, OldLevel);
1581  }
1582  else
1583  {
1584  /* now release destination lock */
1585  KeReleaseSpinLockFromDpcLevel(DestinationLock);
1586 
1587  /* now release source lock */
1588  KeReleaseSpinLockFromDpcLevel(SourceLock);
1589 
1590 
1591  /* now release cancel spinlock */
1592  IoReleaseCancelSpinLock(OldLevel);
1593  }
1594 
1595  /* done */
1596  return Status;
1597 }
1598 
1599 /*
1600  @implemented
1601 */
1602 KSDDKAPI
1603 VOID
1604 NTAPI
1606  IN PIRP Irp)
1607 {
1609  KIRQL OldLevel;
1610 
1611  DPRINT("KsRemoveSpecificIrpFromCancelableQueue %p\n", Irp);
1612 
1613  /* get internal queue lock */
1614  SpinLock = KSQUEUE_SPINLOCK_IRP_STORAGE(Irp);
1615 
1616  /* acquire spinlock */
1617  KeAcquireSpinLock(SpinLock, &OldLevel);
1618 
1619  /* remove the irp from the list */
1620  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1621 
1622  /* release spinlock */
1623  KeReleaseSpinLock(SpinLock, OldLevel);
1624 }
1625 
1626 
1627 /*
1628  @implemented
1629 */
1630 KSDDKAPI
1631 VOID
1632 NTAPI
1634  IN OUT PLIST_ENTRY QueueHead,
1636  IN PIRP Irp,
1637  IN KSLIST_ENTRY_LOCATION ListLocation,
1638  IN PDRIVER_CANCEL DriverCancel OPTIONAL)
1639 {
1640  PDRIVER_CANCEL OldDriverCancel;
1641  PIO_STACK_LOCATION IoStack;
1642  KIRQL OldLevel;
1643 
1644  /* check for required parameters */
1645  if (!QueueHead || !SpinLock || !Irp)
1646  return;
1647 
1648  /* get current irp stack */
1649  IoStack = IoGetCurrentIrpStackLocation(Irp);
1650 
1651  DPRINT("KsAddIrpToCancelableQueue QueueHead %p SpinLock %p Irp %p ListLocation %x DriverCancel %p\n", QueueHead, SpinLock, Irp, ListLocation, DriverCancel);
1652 
1653  // HACK for ms portcls
1654  if (IoStack->MajorFunction == IRP_MJ_CREATE)
1655  {
1656  // complete the request
1657  DPRINT1("MS HACK\n");
1658  Irp->IoStatus.Status = STATUS_SUCCESS;
1660 
1661  return;
1662  }
1663 
1664 
1665  if (!DriverCancel)
1666  {
1667  /* default to KsCancelRoutine */
1668  DriverCancel = KsCancelRoutine;
1669  }
1670 
1671 
1672  /* acquire spinlock */
1673  KeAcquireSpinLock(SpinLock, &OldLevel);
1674 
1675  if (ListLocation == KsListEntryTail)
1676  {
1677  /* insert irp to tail of list */
1678  InsertTailList(QueueHead, &Irp->Tail.Overlay.ListEntry);
1679  }
1680  else
1681  {
1682  /* insert irp to head of list */
1683  InsertHeadList(QueueHead, &Irp->Tail.Overlay.ListEntry);
1684  }
1685 
1686  /* store internal queue lock */
1687  KSQUEUE_SPINLOCK_IRP_STORAGE(Irp) = SpinLock;
1688 
1689  /* now set the cancel routine */
1690  OldDriverCancel = IoSetCancelRoutine(Irp, DriverCancel);
1691 
1692  if (Irp->Cancel && OldDriverCancel == NULL)
1693  {
1694  /* the irp has already been canceled */
1695  KeReleaseSpinLock(SpinLock, OldLevel);
1696 
1697  /* cancel routine requires that cancel spinlock is held */
1698  IoAcquireCancelSpinLock(&Irp->CancelIrql);
1699 
1700  /* cancel irp */
1701  DriverCancel(IoStack->DeviceObject, Irp);
1702  }
1703  else
1704  {
1705  /* done */
1706  KeReleaseSpinLock(SpinLock, OldLevel);
1707  }
1708 }
1709 
1710 /*
1711  @implemented
1712 */
1713 KSDDKAPI
1714 VOID
1715 NTAPI
1718  IN PIRP Irp)
1719 {
1721 
1722  /* get internal queue lock */
1723  SpinLock = KSQUEUE_SPINLOCK_IRP_STORAGE(Irp);
1724 
1725  /* acquire spinlock */
1727 
1728  /* sanity check */
1730 
1731  /* release cancel spinlock */
1732  IoReleaseCancelSpinLock(Irp->CancelIrql);
1733 
1734  /* remove the irp from the list */
1735  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1736 
1737  /* release spinlock */
1738  KeReleaseSpinLock(SpinLock, Irp->CancelIrql);
1739 
1740  /* has the irp already been canceled */
1741  if (Irp->IoStatus.Status != STATUS_CANCELLED)
1742  {
1743  /* let's complete it */
1744  Irp->IoStatus.Status = STATUS_CANCELLED;
1746  }
1747 }
1748 
1749 NTSTATUS
1751  PLIST_ENTRY ListHead,
1753  OUT PCREATE_ITEM_ENTRY *OutCreateItem)
1754 {
1756  PCREATE_ITEM_ENTRY CreateItemEntry;
1757  UNICODE_STRING RefString;
1758  LPWSTR pStr;
1759  ULONG Count;
1760 
1761  /* Copy the input string */
1762  RefString = *String;
1763 
1764  /* Check if the string starts with a backslash */
1765  if (String->Buffer[0] == L'\\')
1766  {
1767  /* Skip backslash */
1768  RefString.Buffer++;
1769  RefString.Length -= sizeof(WCHAR);
1770  }
1771  else
1772  {
1773  /* get terminator */
1774  pStr = String->Buffer;
1775  Count = String->Length / sizeof(WCHAR);
1776  while ((Count > 0) && (*pStr != L'\\'))
1777  {
1778  pStr++;
1779  Count--;
1780  }
1781 
1782  /* sanity check */
1783  ASSERT(Count != 0);
1784 
1785  // request is for pin / node / allocator
1786  RefString.Length = (USHORT)((PCHAR)pStr - (PCHAR)String->Buffer);
1787  }
1788 
1789  /* point to first entry */
1790  Entry = ListHead->Flink;
1791 
1792  /* loop all device items */
1793  while (Entry != ListHead)
1794  {
1795  /* get create item entry */
1796  CreateItemEntry = (PCREATE_ITEM_ENTRY)CONTAINING_RECORD(Entry,
1798  Entry);
1799 
1800  ASSERT(CreateItemEntry->CreateItem);
1801 
1802  if(CreateItemEntry->CreateItem->Flags & KSCREATE_ITEM_WILDCARD)
1803  {
1804  /* create item is default */
1805  *OutCreateItem = CreateItemEntry;
1806  return STATUS_SUCCESS;
1807  }
1808 
1809  if (!CreateItemEntry->CreateItem->Create)
1810  {
1811  /* skip free create item */
1812  Entry = Entry->Flink;
1813  continue;
1814  }
1815 
1816  DPRINT("CreateItem %S Length %u Request %wZ %u\n",
1817  CreateItemEntry->CreateItem->ObjectClass.Buffer,
1818  CreateItemEntry->CreateItem->ObjectClass.Length,
1819  &RefString,
1820  RefString.Length);
1821 
1822  if (CreateItemEntry->CreateItem->ObjectClass.Length > RefString.Length)
1823  {
1824  /* create item doesnt match in length */
1825  Entry = Entry->Flink;
1826  continue;
1827  }
1828 
1829  /* now check if the object class is the same */
1830  if (!RtlCompareUnicodeString(&CreateItemEntry->CreateItem->ObjectClass,
1831  &RefString,
1832  TRUE))
1833  {
1834  /* found matching create item */
1835  *OutCreateItem = CreateItemEntry;
1836  return STATUS_SUCCESS;
1837  }
1838  /* iterate to next */
1839  Entry = Entry->Flink;
1840  }
1841 
1842  return STATUS_NOT_FOUND;
1843 }
1844 
1845 NTSTATUS
1846 NTAPI
1849  IN PIRP Irp)
1850 {
1851  PCREATE_ITEM_ENTRY CreateItemEntry;
1852  PIO_STACK_LOCATION IoStack;
1853  PDEVICE_EXTENSION DeviceExtension;
1854  PKSIDEVICE_HEADER DeviceHeader;
1855  PKSIOBJECT_HEADER ObjectHeader;
1856  NTSTATUS Status;
1857 
1858  DPRINT("KS / CREATE\n");
1859 
1860  /* get current stack location */
1861  IoStack = IoGetCurrentIrpStackLocation(Irp);
1862  /* get device extension */
1863  DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
1864  /* get device header */
1865  DeviceHeader = DeviceExtension->DeviceHeader;
1866 
1867 
1868  if (IoStack->FileObject->FileName.Buffer == NULL)
1869  {
1870  /* FIXME Pnp-Issue */
1871  DPRINT("Using reference string hack\n");
1872  Irp->IoStatus.Information = 0;
1873  /* set return status */
1874  Irp->IoStatus.Status = STATUS_SUCCESS;
1876  return STATUS_SUCCESS;
1877  }
1878 
1879  if (IoStack->FileObject->RelatedFileObject != NULL)
1880  {
1881  /* request is to instantiate a pin / node / clock / allocator */
1882  ObjectHeader = (PKSIOBJECT_HEADER)IoStack->FileObject->RelatedFileObject->FsContext2;
1883 
1884  /* sanity check */
1885  ASSERT(ObjectHeader);
1886 
1887  /* find a matching a create item */
1888  Status = FindMatchingCreateItem(&ObjectHeader->ItemList,
1889  &IoStack->FileObject->FileName,
1890  &CreateItemEntry);
1891  }
1892  else
1893  {
1894  /* request to create a filter */
1895  Status = FindMatchingCreateItem(&DeviceHeader->ItemList,
1896  &IoStack->FileObject->FileName,
1897  &CreateItemEntry);
1898  }
1899 
1900  if (NT_SUCCESS(Status))
1901  {
1902  /* set object create item */
1903  KSCREATE_ITEM_IRP_STORAGE(Irp) = CreateItemEntry->CreateItem;
1904 
1905  /* call create function */
1906  Status = CreateItemEntry->CreateItem->Create(DeviceObject, Irp);
1907 
1908  if (NT_SUCCESS(Status))
1909  {
1910  /* increment create item reference count */
1911  InterlockedIncrement(&CreateItemEntry->ReferenceCount);
1912  }
1913  return Status;
1914  }
1915 
1916  Irp->IoStatus.Information = 0;
1917  /* set return status */
1918  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
1920  return STATUS_UNSUCCESSFUL;
1921 }
1922 
1923 NTSTATUS
1924 NTAPI
1927  IN PIRP Irp)
1928 {
1929  PIO_STACK_LOCATION IoStack;
1930  //PDEVICE_EXTENSION DeviceExtension;
1931  PKSIOBJECT_HEADER ObjectHeader;
1932  //PKSIDEVICE_HEADER DeviceHeader;
1934  NTSTATUS Status;
1935 
1936  /* get current stack location */
1937  IoStack = IoGetCurrentIrpStackLocation(Irp);
1938 
1939  /* get device extension */
1940  //DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
1941  /* get device header */
1942  //DeviceHeader = DeviceExtension->DeviceHeader;
1943 
1944  ASSERT(IoStack->FileObject);
1945 
1946  /* get object header */
1947  ObjectHeader = (PKSIOBJECT_HEADER) IoStack->FileObject->FsContext2;
1948 
1949  if (!ObjectHeader)
1950  {
1951  /* FIXME Pnp-Issue*/
1952  Irp->IoStatus.Status = STATUS_SUCCESS;
1953  Irp->IoStatus.Information = 0;
1954  /* complete and forget */
1956  return STATUS_SUCCESS;
1957  }
1958 
1959  /* sanity check */
1960  ASSERT(ObjectHeader);
1961  /* store create item */
1962  //KSCREATE_ITEM_IRP_STORAGE(Irp) = (PKSOBJECT_CREATE_ITEM)0x12345678; //ObjectHeader->CreateItem;
1963 
1964  /* retrieve matching dispatch function */
1965  switch(IoStack->MajorFunction)
1966  {
1967  case IRP_MJ_CLOSE:
1968  Dispatch = ObjectHeader->DispatchTable.Close;
1969  break;
1970  case IRP_MJ_DEVICE_CONTROL:
1971  Dispatch = ObjectHeader->DispatchTable.DeviceIoControl;
1972  break;
1973  case IRP_MJ_READ:
1974  Dispatch = ObjectHeader->DispatchTable.Read;
1975  break;
1976  case IRP_MJ_WRITE:
1977  Dispatch = ObjectHeader->DispatchTable.Write;
1978  break;
1979  case IRP_MJ_FLUSH_BUFFERS :
1980  Dispatch = ObjectHeader->DispatchTable.Flush;
1981  break;
1982  case IRP_MJ_QUERY_SECURITY:
1983  Dispatch = ObjectHeader->DispatchTable.QuerySecurity;
1984  break;
1985  case IRP_MJ_SET_SECURITY:
1986  Dispatch = ObjectHeader->DispatchTable.SetSecurity;
1987  break;
1988  case IRP_MJ_PNP:
1990  break;
1991  default:
1992  Dispatch = NULL;
1993  }
1994 
1995  /* is the request supported */
1996  if (Dispatch)
1997  {
1998  /* now call the dispatch function */
2000  }
2001  else
2002  {
2003  /* not supported request */
2005  }
2006 
2007  /* done */
2008  return Status;
2009 }
2010 
2011 /*
2012  @implemented
2013 */
2014 KSDDKAPI
2015 NTSTATUS
2016 NTAPI
2019  IN ULONG MajorFunction)
2020 {
2021  DPRINT("KsSetMajorFunctionHandler Function %x\n", MajorFunction);
2022 
2023  switch ( MajorFunction )
2024  {
2025  case IRP_MJ_CREATE:
2026  DriverObject->MajorFunction[MajorFunction] = KspCreate;
2027  break;
2028  case IRP_MJ_DEVICE_CONTROL:
2029  case IRP_MJ_CLOSE:
2030  case IRP_MJ_READ:
2031  case IRP_MJ_WRITE:
2032  case IRP_MJ_FLUSH_BUFFERS :
2033  case IRP_MJ_QUERY_SECURITY:
2034  case IRP_MJ_SET_SECURITY:
2035  DriverObject->MajorFunction[MajorFunction] = KspDispatchIrp;
2036  break;
2037  default:
2038  DPRINT1("NotSupported %x\n", MajorFunction);
2039  return STATUS_INVALID_PARAMETER;
2040  };
2041 
2042  return STATUS_SUCCESS;
2043 }
2044 
2045 /*
2046  @implemented
2047 */
2048 KSDDKAPI
2049 NTSTATUS
2050 NTAPI
2053  IN PIRP Irp)
2054 {
2055  PIO_STACK_LOCATION IoStack;
2056  PKSIDEVICE_HEADER DeviceHeader;
2057  PDEVICE_EXTENSION DeviceExtension;
2058 
2059  DPRINT("KsDispatchIrp DeviceObject %p Irp %p\n", DeviceObject, Irp);
2060 
2061  /* get device extension */
2062  DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
2063 
2064  /* get device header */
2065  DeviceHeader = DeviceExtension->DeviceHeader;
2066 
2067 
2068  /* get current irp stack */
2069  IoStack = IoGetCurrentIrpStackLocation(Irp);
2070 
2071  if (IoStack->MajorFunction <= IRP_MJ_DEVICE_CONTROL)
2072  {
2073  if (IoStack->MajorFunction == IRP_MJ_CREATE)
2074  {
2075  /* check internal type */
2076  if (DeviceHeader->BasicHeader.OuterUnknown) /* FIXME improve check */
2077  {
2078  /* AVStream client */
2080  }
2081  else
2082  {
2083  /* external client (portcls) */
2084  return KspCreate(DeviceObject, Irp);
2085  }
2086  }
2087 
2088  switch (IoStack->MajorFunction)
2089  {
2090  case IRP_MJ_CLOSE:
2091  case IRP_MJ_READ:
2092  case IRP_MJ_WRITE:
2093  case IRP_MJ_FLUSH_BUFFERS:
2094  case IRP_MJ_QUERY_SECURITY:
2095  case IRP_MJ_SET_SECURITY:
2096  case IRP_MJ_PNP:
2097  case IRP_MJ_DEVICE_CONTROL:
2098  return KspDispatchIrp(DeviceObject, Irp);
2099  default:
2101  }
2102  }
2103 
2104  /* dispatch power */
2105  if (IoStack->MajorFunction == IRP_MJ_POWER)
2106  {
2107  /* check internal type */
2108  if (DeviceHeader->BasicHeader.OuterUnknown) /* FIXME improve check */
2109  {
2110  /* AVStream client */
2111  return IKsDevice_Power(DeviceObject, Irp);
2112  }
2113  else
2114  {
2115  /* external client (portcls) */
2117  }
2118  }
2119  else if (IoStack->MajorFunction == IRP_MJ_PNP) /* dispatch pnp */
2120  {
2121  /* check internal type */
2122  if (DeviceHeader->BasicHeader.OuterUnknown) /* FIXME improve check */
2123  {
2124  /* AVStream client */
2125  return IKsDevice_Pnp(DeviceObject, Irp);
2126  }
2127  else
2128  {
2129  /* external client (portcls) */
2131  }
2132  }
2133  else if (IoStack->MajorFunction == IRP_MJ_SYSTEM_CONTROL)
2134  {
2135  /* forward irp */
2137  }
2138  else
2139  {
2140  /* not supported */
2142  }
2143 }
2144 
2145 /*
2146  @unimplemented
2147 */
2148 KSDDKAPI
2149 ULONG
2150 NTAPI
2152  IN PIRP Irp)
2153 {
2154  UNIMPLEMENTED;
2155  return KSFILTER_NODE;
2156 }
2157 
PGENERIC_MAPPING NTAPI IoGetFileObjectGenericMapping(VOID)
Definition: file.c:3266
KSDDKAPI NTSTATUS NTAPI KsDefaultDeviceIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1172
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
signed char * PCHAR
Definition: retypes.h:7
KSDDKAPI NTSTATUS NTAPI KsDefaultDispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:166
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
NTSTATUS NTAPI IKsDevice_Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:406
KSDDKAPI NTSTATUS NTAPI KsDefaultDispatchPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:110
#define IN
Definition: typedefs.h:38
DRIVER_CANCEL * PDRIVER_CANCEL
Definition: iotypes.h:2404
#define IOCTL_KS_WRITE_STREAM
Definition: ks.h:157
#define TRUE
Definition: types.h:120
KSDDKAPI NTSTATUS NTAPI KsDispatchSetSecurity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:67
NTKERNELAPI NTSTATUS NTAPI SeSetSecurityDescriptorInfo(_In_opt_ PVOID Object, _In_ PSECURITY_INFORMATION SecurityInformation, _In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor, _In_ POOL_TYPE PoolType, _In_ PGENERIC_MAPPING GenericMapping)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define LL
Definition: tui.h:72
#define IOCTL_KS_DISABLE_EVENT
Definition: ks.h:127
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
KSDDKAPI NTSTATUS NTAPI KsDispatchIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:2051
KSDDKAPI NTSTATUS NTAPI KsDispatchQuerySecurity(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:22
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_FLUSH_BUFFERS
struct _Entry Entry
Definition: kefuncs.h:640
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
NTSTATUS NTAPI IKsDevice_Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:574
_In_ IN_ADDR _In_ IN_ADDR _Out_ MULTICAST_MODE_TYPE _Inout_ ULONG _Out_writes_ SourceCount IN_ADDR * SourceList
Definition: ws2tcpip.h:622
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define IOCTL_KS_READ_STREAM
Definition: ks.h:164
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
#define IRP_MJ_SET_SECURITY
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
unsigned char * PUCHAR
Definition: retypes.h:3
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
KSDDKAPI NTSTATUS NTAPI KsProbeStreamIrp(IN PIRP Irp, IN ULONG ProbeFlags, IN ULONG HeaderSize)
Definition: irp.c:647
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
KSDDKAPI NTSTATUS NTAPI KsReadFile(IN PFILE_OBJECT FileObject, IN PKEVENT Event OPTIONAL, IN PVOID PortContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG Length, IN ULONG Key OPTIONAL, IN KPROCESSOR_MODE RequestorMode)
Definition: irp.c:142
LONG NTSTATUS
Definition: precomp.h:26
KSDDKAPI VOID NTAPI KsNullDriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: irp.c:1145
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
KSDDKAPI BOOLEAN NTAPI KsDispatchFastIoDeviceControlFailure(IN PFILE_OBJECT FileObject, IN BOOLEAN Wait, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength, IN ULONG IoControlCode, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: irp.c:1218
#define ExRaiseStatus
Definition: ntoskrnl.h:95
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI KspCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1847
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2982
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
static WCHAR String[]
Definition: stringtable.c:55
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1538
IRP
Definition: iotypes.h:2462
#define InsertTailList(ListHead, Entry)
struct KSSTREAM_HEADER * PKSSTREAM_HEADER
IoSetCancelRoutine(Irp, CancelRoutine)
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
KSDDKAPI NTSTATUS NTAPI KsDispatchSpecificMethod(IN PIRP Irp, IN PFNKSHANDLER Handler)
Definition: irp.c:127
#define KSDDKAPI
Definition: ks.h:40
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
PVOID NTAPI MmMapLockedPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode)
Definition: mdlsup.c:822
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler(IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
Definition: irp.c:2017
#define IOCTL_KS_RESET_STATE
Definition: ks.h:171
_SEH2_TRY
Definition: create.c:4250
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
KSDDKAPI PIRP NTAPI KsRemoveIrpFromCancelableQueue(IN OUT PLIST_ENTRY QueueHead, IN PKSPIN_LOCK SpinLock, IN KSLIST_ENTRY_LOCATION ListLocation, IN KSIRP_REMOVAL_OPERATION RemovalOperation)
Definition: irp.c:1375
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1732
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
Definition: kstypes.h:45
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: Header.h:8
KSDDKAPI VOID NTAPI KsCancelIo(IN OUT PLIST_ENTRY QueueHead, IN PKSPIN_LOCK SpinLock)
Definition: irp.c:1258
PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo
Definition: iotypes.h:1693
KSDDKAPI VOID NTAPI KsCancelRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1716
ULONG OptionsFlags
Definition: ks.h:2772
_Unreferenced_parameter_ PVOID * CompletionContext
Definition: cdprocs.h:1130
KSDDKAPI NTSTATUS NTAPI KsWriteFile(IN PFILE_OBJECT FileObject, IN PKEVENT Event OPTIONAL, IN PVOID PortContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID Buffer, IN ULONG Length, IN ULONG Key OPTIONAL, IN KPROCESSOR_MODE RequestorMode)
Definition: irp.c:242
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
#define KSFILTER_NODE
Definition: ks.h:44
PKSOBJECT_CREATE_ITEM CreateItem
Definition: kstypes.h:48
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define MDL_MAPPING_CAN_FAIL
Definition: mmtypes.h:31
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
KSDDKAPI ULONG NTAPI KsGetNodeIdFromIrp(IN PIRP Irp)
Definition: irp.c:2151
Definition: bufpool.h:45
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
struct CREATE_ITEM_ENTRY * PCREATE_ITEM_ENTRY
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IOCTL_KS_METHOD
Definition: ks.h:142
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
#define PCHAR
Definition: match.c:90
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:636
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2650
KSIRP_REMOVAL_OPERATION
Definition: ks.h:1302
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define STATUS_NOT_FOUND
Definition: shellext.h:67
KSDDKAPI NTSTATUS NTAPI KsQueryInformationFile(IN PFILE_OBJECT FileObject, OUT PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
Definition: irp.c:342
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1156
#define KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
Definition: ks.h:2781
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
ULONG FrameExtent
Definition: ks.h:2769
static const UCHAR Index[8]
Definition: usbohci.c:18
KSDISPATCH_TABLE DispatchTable
Definition: kstypes.h:22
KSCOMPLETION_INVOCATION
Definition: ks.h:1309
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2866
PVOID Data
Definition: ks.h:2771
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_NO_SECURITY_ON_OBJECT
Definition: ntstatus.h:437
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1954
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
KSDDKAPI NTSTATUS NTAPI KsSetInformationFile(IN PFILE_OBJECT FileObject, IN PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
Definition: irp.c:434
KSDDKAPI VOID NTAPI KsReleaseIrpOnCancelableQueue(IN PIRP Irp, IN PDRIVER_CANCEL DriverCancel OPTIONAL)
Definition: irp.c:1320
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
KSBASIC_HEADER BasicHeader
Definition: kstypes.h:87
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
static const WCHAR L[]
Definition: oid.c:1250
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define IOCTL_KS_ENABLE_EVENT
Definition: ks.h:134
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LIST_ENTRY ItemList
Definition: kstypes.h:26
Definition: typedefs.h:117
ULONG DataUsed
Definition: ks.h:2770
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:656
#define IRP_MJ_SYSTEM_CONTROL
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
#define STATUS_PROPSET_NOT_FOUND
Definition: ntstatus.h:678
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG Size
Definition: ks.h:2765
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH * Dispatch
Definition: wsk.h:182
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2153
_SEH2_END
Definition: create.c:4424
#define IRP_INPUT_OPERATION
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define IRP_BUFFERED_IO
#define InterlockedIncrement
Definition: armddk.h:53
KSDDKAPI NTSTATUS NTAPI KsDefaultForwardIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:227
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
enum _LOCK_OPERATION LOCK_OPERATION
KSDDKAPI BOOLEAN NTAPI KsDispatchFastReadFailure(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: irp.c:1238
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS NTAPI KspDispatchIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1925
KSDDKAPI NTSTATUS NTAPI KsMoveIrpsOnCancelableQueue(IN OUT PLIST_ENTRY SourceList, IN PKSPIN_LOCK SourceLock, IN OUT PLIST_ENTRY DestinationList, IN PKSPIN_LOCK DestinationLock OPTIONAL, IN KSLIST_ENTRY_LOCATION ListLocation, IN PFNKSIRPLISTCALLBACK ListCallback, IN PVOID Context)
Definition: irp.c:1480
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define STATUS_NO_MATCH
Definition: ntstatus.h:737
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
KSDDKAPI VOID NTAPI KsAddIrpToCancelableQueue(IN OUT PLIST_ENTRY QueueHead, IN PKSPIN_LOCK SpinLock, IN PIRP Irp, IN KSLIST_ENTRY_LOCATION ListLocation, IN PDRIVER_CANCEL DriverCancel OPTIONAL)
Definition: irp.c:1633
LONG ReferenceCount
Definition: kstypes.h:50
NTSTATUS FindMatchingCreateItem(PLIST_ENTRY ListHead, PUNICODE_STRING String, OUT PCREATE_ITEM_ENTRY *OutCreateItem)
Definition: irp.c:1750
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo
Definition: iotypes.h:1694
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
IO_COMPLETION_ROUTINE * PIO_COMPLETION_ROUTINE
Definition: iotypes.h:2479
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
KSLIST_ENTRY_LOCATION
Definition: ks.h:1291
#define DPRINT1
Definition: precomp.h:8
#define FileStandardInformation
Definition: propsheet.cpp:61
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_DEALLOCATE_BUFFER
LIST_ENTRY ItemList
Definition: kstypes.h:94
#define OUT
Definition: typedefs.h:39
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
PVOID PIRP
Definition: usb.h:38
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
KSDDKAPI NTSTATUS NTAPI KsAllocateExtraData(IN PIRP Irp, IN ULONG ExtraSize, OUT PVOID *ExtraBuffer)
Definition: irp.c:1078
#define UNIMPLEMENTED
Definition: debug.h:114
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468
NTKERNELAPI NTSTATUS NTAPI SeQuerySecurityDescriptorInfo(_In_ PSECURITY_INFORMATION SecurityInformation, _Out_writes_bytes_(*Length) PSECURITY_DESCRIPTOR SecurityDescriptor, _Inout_ PULONG Length, _Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor)
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
KSDDKAPI NTSTATUS NTAPI KsStreamIo(IN PFILE_OBJECT FileObject, IN PKEVENT Event OPTIONAL, IN PVOID PortContext OPTIONAL, IN PIO_COMPLETION_ROUTINE CompletionRoutine OPTIONAL, IN PVOID CompletionContext OPTIONAL, IN KSCOMPLETION_INVOCATION CompletionInvocationFlags OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN OUT PVOID StreamHeaders, IN ULONG Length, IN ULONG Flags, IN KPROCESSOR_MODE RequestorMode)
Definition: irp.c:526
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2777
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
base of all file and directory entries
Definition: entries.h:82
KSDDKAPI VOID NTAPI KsRemoveSpecificIrpFromCancelableQueue(IN PIRP Irp)
Definition: irp.c:1605
NTSTATUS NTAPI IKsDevice_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:591
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
IN BOOLEAN Wait
Definition: fatprocs.h:1529
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68