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
18 KsDispatchQuerySecurity(
19 IN PDEVICE_OBJECT DeviceObject
,
22 PKSOBJECT_CREATE_ITEM CreateItem
;
23 PIO_STACK_LOCATION IoStack
;
27 /* get current irp stack */
28 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
31 CreateItem
= KSCREATE_ITEM_IRP_STORAGE(Irp
);
33 if (!CreateItem
|| !CreateItem
->SecurityDescriptor
)
36 Irp
->IoStatus
.Status
= STATUS_NO_SECURITY_ON_OBJECT
;
37 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
38 return STATUS_NO_SECURITY_ON_OBJECT
;
42 /* get input length */
43 Length
= IoStack
->Parameters
.QuerySecurity
.Length
;
45 /* clone the security descriptor */
46 Status
= SeQuerySecurityDescriptorInfo(&IoStack
->Parameters
.QuerySecurity
.SecurityInformation
, (PSECURITY_DESCRIPTOR
)Irp
->UserBuffer
, &Length
, &CreateItem
->SecurityDescriptor
);
48 DPRINT("SeQuerySecurityDescriptorInfo Status %x\n", Status
);
50 Irp
->IoStatus
.Status
= Status
;
51 Irp
->IoStatus
.Information
= Length
;
53 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
63 KsDispatchSetSecurity(
64 IN PDEVICE_OBJECT DeviceObject
,
67 PKSOBJECT_CREATE_ITEM CreateItem
;
68 PIO_STACK_LOCATION IoStack
;
69 PGENERIC_MAPPING Mapping
;
70 PSECURITY_DESCRIPTOR Descriptor
;
73 /* get current irp stack */
74 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
77 CreateItem
= KSCREATE_ITEM_IRP_STORAGE(Irp
);
79 if (!CreateItem
|| !CreateItem
->SecurityDescriptor
)
82 Irp
->IoStatus
.Status
= STATUS_NO_SECURITY_ON_OBJECT
;
83 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
84 return STATUS_NO_SECURITY_ON_OBJECT
;
87 /* backup old descriptor */
88 Descriptor
= CreateItem
->SecurityDescriptor
;
90 /* get generic mapping */
91 Mapping
= IoGetFileObjectGenericMapping();
93 /* change security descriptor */
94 Status
= SeSetSecurityDescriptorInfo(NULL
, /*FIXME */
95 &IoStack
->Parameters
.SetSecurity
.SecurityInformation
,
96 IoStack
->Parameters
.SetSecurity
.SecurityDescriptor
,
97 &CreateItem
->SecurityDescriptor
,
101 if (NT_SUCCESS(Status
))
103 /* free old descriptor */
104 FreeItem(Descriptor
);
106 /* mark create item as changed */
107 CreateItem
->Flags
|= KSCREATE_ITEM_SECURITYCHANGED
;
111 Irp
->IoStatus
.Status
= Status
;
112 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
123 KsDispatchSpecificMethod(
125 IN PFNKSHANDLER Handler
)
128 return STATUS_UNSUCCESSFUL
;
139 IN PFILE_OBJECT FileObject
,
140 IN PKEVENT Event OPTIONAL
,
141 IN PVOID PortContext OPTIONAL
,
142 OUT PIO_STATUS_BLOCK IoStatusBlock
,
145 IN ULONG Key OPTIONAL
,
146 IN KPROCESSOR_MODE RequestorMode
)
148 PDEVICE_OBJECT DeviceObject
;
156 /* make sure event is reset */
160 if (RequestorMode
== UserMode
)
162 /* probe the user buffer */
165 ProbeForWrite(Buffer
, Length
, sizeof(UCHAR
));
166 Status
= STATUS_SUCCESS
;
168 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
170 /* Exception, get the error code */
171 Status
= _SEH2_GetExceptionCode();
175 if (!NT_SUCCESS(Status
))
177 DPRINT1("Invalid user buffer provided\n");
182 /* get corresponding device object */
183 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
185 /* fast-io read is only available for kernel mode clients */
186 if (RequestorMode
== KernelMode
&& ExGetPreviousMode() == KernelMode
&&
187 DeviceObject
->DriverObject
->FastIoDispatch
->FastIoRead
)
189 /* call fast io write */
190 Result
= DeviceObject
->DriverObject
->FastIoDispatch
->FastIoRead(FileObject
, &FileObject
->CurrentByteOffset
, Length
, TRUE
, Key
, Buffer
, IoStatusBlock
, DeviceObject
);
192 if (Result
&& NT_SUCCESS(IoStatusBlock
->Status
))
194 /* request was handeled and succeeded */
195 return STATUS_SUCCESS
;
199 /* do the slow way */
202 /* initialize temp event */
203 KeInitializeEvent(&LocalEvent
, NotificationEvent
, FALSE
);
207 /* build the irp packet */
208 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
, DeviceObject
, Buffer
, Length
, &FileObject
->CurrentByteOffset
, Event
, IoStatusBlock
);
211 /* not enough resources */
212 return STATUS_INSUFFICIENT_RESOURCES
;
215 /* send the packet */
216 Status
= IoCallDriver(DeviceObject
, Irp
);
218 if (Status
== STATUS_PENDING
)
220 /* operation is pending, is sync file object */
221 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
224 KeWaitForSingleObject(Event
, Executive
, RequestorMode
, FALSE
, NULL
);
225 Status
= IoStatusBlock
->Status
;
239 IN PFILE_OBJECT FileObject
,
240 IN PKEVENT Event OPTIONAL
,
241 IN PVOID PortContext OPTIONAL
,
242 OUT PIO_STATUS_BLOCK IoStatusBlock
,
245 IN ULONG Key OPTIONAL
,
246 IN KPROCESSOR_MODE RequestorMode
)
248 PDEVICE_OBJECT DeviceObject
;
256 /* make sure event is reset */
260 if (RequestorMode
== UserMode
)
262 /* probe the user buffer */
265 ProbeForRead(Buffer
, Length
, sizeof(UCHAR
));
266 Status
= STATUS_SUCCESS
;
268 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
270 /* Exception, get the error code */
271 Status
= _SEH2_GetExceptionCode();
275 if (!NT_SUCCESS(Status
))
277 DPRINT1("Invalid user buffer provided\n");
282 /* get corresponding device object */
283 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
285 /* fast-io write is only available for kernel mode clients */
286 if (RequestorMode
== KernelMode
&& ExGetPreviousMode() == KernelMode
&&
287 DeviceObject
->DriverObject
->FastIoDispatch
->FastIoWrite
)
289 /* call fast io write */
290 Result
= DeviceObject
->DriverObject
->FastIoDispatch
->FastIoWrite(FileObject
, &FileObject
->CurrentByteOffset
, Length
, TRUE
, Key
, Buffer
, IoStatusBlock
, DeviceObject
);
292 if (Result
&& NT_SUCCESS(IoStatusBlock
->Status
))
294 /* request was handeled and succeeded */
295 return STATUS_SUCCESS
;
299 /* do the slow way */
302 /* initialize temp event */
303 KeInitializeEvent(&LocalEvent
, NotificationEvent
, FALSE
);
307 /* build the irp packet */
308 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
, DeviceObject
, Buffer
, Length
, &FileObject
->CurrentByteOffset
, Event
, IoStatusBlock
);
311 /* not enough resources */
312 return STATUS_INSUFFICIENT_RESOURCES
;
315 /* send the packet */
316 Status
= IoCallDriver(DeviceObject
, Irp
);
318 if (Status
== STATUS_PENDING
)
320 /* operation is pending, is sync file object */
321 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
324 KeWaitForSingleObject(Event
, Executive
, RequestorMode
, FALSE
, NULL
);
325 Status
= IoStatusBlock
->Status
;
338 KsQueryInformationFile(
339 IN PFILE_OBJECT FileObject
,
340 OUT PVOID FileInformation
,
342 IN FILE_INFORMATION_CLASS FileInformationClass
)
344 PDEVICE_OBJECT DeviceObject
;
345 PFAST_IO_DISPATCH FastIoDispatch
;
347 PIO_STACK_LOCATION IoStack
;
348 IO_STATUS_BLOCK IoStatus
;
350 LARGE_INTEGER Offset
;
351 IO_STATUS_BLOCK StatusBlock
;
354 /* get related file object */
355 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
357 /* get fast i/o table */
358 FastIoDispatch
= DeviceObject
->DriverObject
->FastIoDispatch
;
360 /* is there a fast table */
363 /* check the class */
364 if (FileInformationClass
== FileBasicInformation
)
366 /* use FastIoQueryBasicInfo routine */
367 if (FastIoDispatch
->FastIoQueryBasicInfo
)
369 return FastIoDispatch
->FastIoQueryBasicInfo(FileObject
, TRUE
, (PFILE_BASIC_INFORMATION
)FileInformation
, &IoStatus
, DeviceObject
);
372 else if (FileInformationClass
== FileStandardInformation
)
374 /* use FastIoQueryBasicInfo routine */
375 if (FastIoDispatch
->FastIoQueryBasicInfo
)
377 return FastIoDispatch
->FastIoQueryStandardInfo(FileObject
, TRUE
, (PFILE_STANDARD_INFORMATION
)FileInformation
, &IoStatus
, DeviceObject
);
382 KeClearEvent(&FileObject
->Event
);
384 /* initialize event */
385 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
387 /* set offset to zero */
388 Offset
.QuadPart
= 0L;
390 /* build the request */
391 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_QUERY_INFORMATION
, IoGetRelatedDeviceObject(FileObject
), NULL
, 0, &Offset
, &Event
, &StatusBlock
);
394 return STATUS_INSUFFICIENT_RESOURCES
;
396 /* get next stack location */
397 IoStack
= IoGetNextIrpStackLocation(Irp
);
399 /* setup parameters */
400 IoStack
->Parameters
.QueryFile
.FileInformationClass
= FileInformationClass
;
401 IoStack
->Parameters
.QueryFile
.Length
= Length
;
402 Irp
->AssociatedIrp
.SystemBuffer
= FileInformation
;
405 /* call the driver */
406 Status
= IoCallDriver(IoGetRelatedDeviceObject(FileObject
), Irp
);
408 if (Status
== STATUS_PENDING
)
410 /* wait for the operation to complete */
411 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
414 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
415 Status
= FileObject
->FinalStatus
;
417 Status
= StatusBlock
.Status
;
430 KsSetInformationFile(
431 IN PFILE_OBJECT FileObject
,
432 IN PVOID FileInformation
,
434 IN FILE_INFORMATION_CLASS FileInformationClass
)
436 PIO_STACK_LOCATION IoStack
;
437 PDEVICE_OBJECT DeviceObject
;
441 LARGE_INTEGER Offset
;
442 IO_STATUS_BLOCK IoStatus
;
445 /* get related device object */
446 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
448 /* copy file information */
449 Buffer
= AllocateItem(NonPagedPool
, Length
);
451 return STATUS_INSUFFICIENT_RESOURCES
;
455 ProbeForRead(Buffer
, Length
, sizeof(UCHAR
));
456 RtlMoveMemory(Buffer
, FileInformation
, Length
);
457 Status
= STATUS_SUCCESS
;
459 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
461 /* Exception, get the error code */
462 Status
= _SEH2_GetExceptionCode();
466 if (!NT_SUCCESS(Status
))
468 /* invalid user buffer */
473 /* initialize the event */
474 KeInitializeEvent(&Event
, SynchronizationEvent
, FALSE
);
477 Offset
.QuadPart
= 0LL;
480 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_SET_INFORMATION
, DeviceObject
, NULL
, 0, &Offset
, &Event
, &IoStatus
);
484 /* failed to allocate irp */
486 return STATUS_INSUFFICIENT_RESOURCES
;
489 /* get next stack location */
490 IoStack
= IoGetNextIrpStackLocation(Irp
);
492 /* set irp parameters */
493 IoStack
->Parameters
.SetFile
.FileInformationClass
= FileInformationClass
;
494 IoStack
->Parameters
.SetFile
.Length
= Length
;
495 IoStack
->Parameters
.SetFile
.FileObject
= FileObject
;
496 Irp
->AssociatedIrp
.SystemBuffer
= Buffer
;
497 Irp
->UserBuffer
= FileInformation
;
499 /* dispatch the irp */
500 Status
= IoCallDriver(DeviceObject
, Irp
);
502 if (Status
== STATUS_PENDING
)
504 /* wait untill the operation has completed */
505 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
506 /* is a sync file object */
507 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
508 Status
= FileObject
->FinalStatus
;
510 Status
= IoStatus
.Status
;
523 IN PFILE_OBJECT FileObject
,
524 IN PKEVENT Event OPTIONAL
,
525 IN PVOID PortContext OPTIONAL
,
526 IN PIO_COMPLETION_ROUTINE CompletionRoutine OPTIONAL
,
527 IN PVOID CompletionContext OPTIONAL
,
528 IN KSCOMPLETION_INVOCATION CompletionInvocationFlags OPTIONAL
,
529 OUT PIO_STATUS_BLOCK IoStatusBlock
,
530 IN OUT PVOID StreamHeaders
,
533 IN KPROCESSOR_MODE RequestorMode
)
536 PIO_STACK_LOCATION IoStack
;
537 PDEVICE_OBJECT DeviceObject
;
539 LARGE_INTEGER Offset
;
540 PKSIOBJECT_HEADER ObjectHeader
;
543 /* get related device object */
544 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
546 ASSERT(DeviceObject
!= NULL
);
548 /* is there a event provided */
555 if (RequestorMode
|| ExGetPreviousMode() == KernelMode
)
557 /* requestor is from kernel land */
558 ObjectHeader
= (PKSIOBJECT_HEADER
)FileObject
->FsContext2
;
562 /* there is a object header */
563 if (Flags
== KSSTREAM_READ
)
565 /* is fast read supported */
566 if (ObjectHeader
->DispatchTable
.FastRead
)
568 /* call fast read dispatch routine */
569 Ret
= ObjectHeader
->DispatchTable
.FastRead(FileObject
, NULL
, Length
, FALSE
, 0, StreamHeaders
, IoStatusBlock
, DeviceObject
);
573 /* the request was handeled */
574 return IoStatusBlock
->Status
;
578 else if (Flags
== KSSTREAM_WRITE
)
580 /* is fast write supported */
581 if (ObjectHeader
->DispatchTable
.FastWrite
)
583 /* call fast write dispatch routine */
584 Ret
= ObjectHeader
->DispatchTable
.FastWrite(FileObject
, NULL
, Length
, FALSE
, 0, StreamHeaders
, IoStatusBlock
, DeviceObject
);
588 /* the request was handeled */
589 return IoStatusBlock
->Status
;
596 /* clear file object event */
597 KeClearEvent(&FileObject
->Event
);
599 /* set the offset to zero */
600 Offset
.QuadPart
= 0LL;
602 /* now build the irp */
603 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_DEVICE_CONTROL
,
604 DeviceObject
, (PVOID
)StreamHeaders
, Length
, &Offset
, Event
, IoStatusBlock
);
607 /* not enough memory */
608 return STATUS_INSUFFICIENT_RESOURCES
;
611 /* setup irp parameters */
612 Irp
->RequestorMode
= RequestorMode
;
613 Irp
->Overlay
.AsynchronousParameters
.UserApcContext
= PortContext
;
614 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
615 Irp
->UserBuffer
= StreamHeaders
;
617 /* get next irp stack location */
618 IoStack
= IoGetNextIrpStackLocation(Irp
);
619 /* setup stack parameters */
620 IoStack
->FileObject
= FileObject
;
621 IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
= Length
;
622 IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
= StreamHeaders
;
623 IoStack
->Parameters
.DeviceIoControl
.IoControlCode
= (Flags
== KSSTREAM_READ
? IOCTL_KS_READ_STREAM
: IOCTL_KS_WRITE_STREAM
);
625 if (CompletionRoutine
)
627 /* setup completion routine for async processing */
628 IoSetCompletionRoutine(Irp
, CompletionRoutine
, CompletionContext
, (CompletionInvocationFlags
& KsInvokeOnSuccess
), (CompletionInvocationFlags
& KsInvokeOnError
), (CompletionInvocationFlags
& KsInvokeOnCancel
));
631 /* now call the driver */
632 Status
= IoCallDriver(DeviceObject
, Irp
);
650 LOCK_OPERATION Operation
;
651 NTSTATUS Status
= STATUS_SUCCESS
;
652 PKSSTREAM_HEADER StreamHeader
;
653 PIO_STACK_LOCATION IoStack
;
655 BOOLEAN AllocateMdl
= FALSE
;
657 /* get current irp stack */
658 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
660 Length
= IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
662 if (Irp
->RequestorMode
== KernelMode
|| Irp
->AssociatedIrp
.SystemBuffer
)
665 /* check if alloc mdl flag is passed */
666 if (!(ProbeFlags
& KSPROBE_ALLOCATEMDL
))
668 /* nothing more to do */
669 return STATUS_SUCCESS
;
674 if (ProbeFlags
& KSPROBE_PROBEANDLOCK
)
676 if (Irp
->MdlAddress
->MdlFlags
& (MDL_PAGES_LOCKED
| MDL_SOURCE_IS_NONPAGED_POOL
))
678 if (ProbeFlags
& KSPROBE_SYSTEMADDRESS
)
682 /* loop through all mdls and probe them */
683 Mdl
= Irp
->MdlAddress
;
686 /* the mapping can fail */
687 Mdl
->MdlFlags
|= MDL_MAPPING_CAN_FAIL
;
689 if (Mdl
->MdlFlags
& (MDL_MAPPED_TO_SYSTEM_VA
| MDL_SOURCE_IS_NONPAGED_POOL
))
691 /* no need to probe these pages */
692 Buffer
= Mdl
->MappedSystemVa
;
697 Buffer
= MmMapLockedPages(Mdl
, KernelMode
);
700 /* check if the mapping succeeded */
703 /* raise exception we'll catch */
704 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
707 /* iterate to next mdl */
712 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
714 /* Exception, get the error code */
715 Status
= _SEH2_GetExceptionCode();
723 /* loop through all mdls and probe them */
724 Mdl
= Irp
->MdlAddress
;
726 /* determine operation */
727 if (!(ProbeFlags
& KSPROBE_STREAMWRITE
) || (ProbeFlags
& KSPROBE_MODIFY
))
729 /* operation is read / modify stream, need write access */
730 Operation
= IoWriteAccess
;
734 /* operation is write to device, so we need read access */
735 Operation
= IoReadAccess
;
740 /* probe the pages */
741 MmProbeAndLockPages(Mdl
, Irp
->RequestorMode
, Operation
);
743 if (ProbeFlags
& KSPROBE_SYSTEMADDRESS
)
745 /* the mapping can fail */
746 Mdl
->MdlFlags
|= MDL_MAPPING_CAN_FAIL
;
748 if (Mdl
->MdlFlags
& (MDL_MAPPED_TO_SYSTEM_VA
| MDL_SOURCE_IS_NONPAGED_POOL
))
750 /* no need to probe these pages */
751 Buffer
= Mdl
->MappedSystemVa
;
756 Buffer
= MmMapLockedPages(Mdl
, KernelMode
);
759 /* check if the mapping succeeded */
762 /* raise exception we'll catch */
763 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
767 /* iterate to next mdl */
772 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
774 /* Exception, get the error code */
775 Status
= _SEH2_GetExceptionCode();
782 /* check all stream headers */
783 StreamHeader
= (PKSSTREAM_HEADER
)Irp
->AssociatedIrp
.SystemBuffer
;
784 ASSERT(StreamHeader
);
791 /* does the supplied header size match stream header size and no type changed */
792 if (StreamHeader
->Size
!= HeaderSize
&& !(StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
))
794 /* invalid stream header */
795 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
800 /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
801 if (StreamHeader
->Size
< sizeof(KSSTREAM_HEADER
) || (StreamHeader
->Size
& 7))
803 /* invalid stream header */
804 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
808 if (Length
< StreamHeader
->Size
)
810 /* length is too short */
811 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
814 if (ProbeFlags
& KSPROBE_STREAMWRITE
)
816 if (StreamHeader
->DataUsed
> StreamHeader
->FrameExtent
)
818 /* frame extend can never be smaller */
819 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
822 /* is this stream change packet */
823 if (StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
)
825 if (Length
!= sizeof(KSSTREAM_HEADER
) || (PVOID
)StreamHeader
!= Irp
->AssociatedIrp
.SystemBuffer
)
827 /* stream changed - must be send in a single packet */
828 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
831 if (!(ProbeFlags
& KSPROBE_ALLOWFORMATCHANGE
))
833 /* caller does not permit format changes */
834 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
837 if (StreamHeader
->FrameExtent
)
839 /* allocate an mdl */
840 Mdl
= IoAllocateMdl(StreamHeader
->Data
, StreamHeader
->FrameExtent
, FALSE
, TRUE
, Irp
);
844 /* not enough memory */
845 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
848 /* break-out to probe for the irp */
855 if (StreamHeader
->DataUsed
)
857 /* DataUsed must be zero for stream read operation */
858 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
861 if (StreamHeader
->OptionsFlags
)
863 /* no flags supported for reading */
864 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
868 if (StreamHeader
->FrameExtent
)
870 /* allocate an mdl */
871 ASSERT(Irp
->MdlAddress
== NULL
);
872 Mdl
= IoAllocateMdl(StreamHeader
->Data
, StreamHeader
->FrameExtent
, FALSE
, TRUE
, Irp
);
875 /* not enough memory */
876 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
880 /* move to next stream header */
881 Length
-= StreamHeader
->Size
;
882 StreamHeader
= (PKSSTREAM_HEADER
)((ULONG_PTR
)StreamHeader
+ StreamHeader
->Size
);
885 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
887 /* Exception, get the error code */
888 Status
= _SEH2_GetExceptionCode();
891 /* now probe the allocated mdl's */
892 if (!NT_SUCCESS(Status
))
894 DPRINT("Status %x\n", Status
);
901 /* probe user mode buffers */
902 if (Length
&& ( (!HeaderSize
) || (Length
% HeaderSize
== 0) || ((ProbeFlags
& KSPROBE_ALLOWFORMATCHANGE
) && (Length
== sizeof(KSSTREAM_HEADER
))) ) )
904 /* allocate stream header buffer */
905 Irp
->AssociatedIrp
.SystemBuffer
= AllocateItem(NonPagedPool
, Length
);
907 if (!Irp
->AssociatedIrp
.SystemBuffer
)
910 return STATUS_INSUFFICIENT_RESOURCES
;
915 if (ProbeFlags
& KSPROBE_STREAMWRITE
)
917 if (ProbeFlags
& KSPROBE_MODIFY
)
918 ProbeForWrite(Irp
->UserBuffer
, Length
, sizeof(UCHAR
));
920 ProbeForRead(Irp
->UserBuffer
, Length
, sizeof(UCHAR
));
924 /* stream reads means writing */
925 ProbeForWrite(Irp
->UserBuffer
, Length
, sizeof(UCHAR
));
928 /* copy stream buffer */
929 RtlMoveMemory(Irp
->AssociatedIrp
.SystemBuffer
, Irp
->UserBuffer
, Length
);
931 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
933 /* Exception, get the error code */
934 Status
= _SEH2_GetExceptionCode();
937 if (!NT_SUCCESS(Status
))
943 if (ProbeFlags
& KSPROBE_ALLOCATEMDL
)
949 /* check all stream headers */
950 StreamHeader
= (PKSSTREAM_HEADER
)Irp
->AssociatedIrp
.SystemBuffer
;
958 /* does the supplied header size match stream header size and no type changed */
959 if (StreamHeader
->Size
!= HeaderSize
&& !(StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
))
961 /* invalid stream header */
962 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
967 /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
968 if (StreamHeader
->Size
< sizeof(KSSTREAM_HEADER
) || (StreamHeader
->Size
& 7))
970 /* invalid stream header */
971 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
975 if (Length
< StreamHeader
->Size
)
977 /* length is too short */
978 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
981 if (ProbeFlags
& KSPROBE_STREAMWRITE
)
983 if (StreamHeader
->DataUsed
> StreamHeader
->FrameExtent
)
985 /* frame extend can never be smaller */
986 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
989 /* is this stream change packet */
990 if (StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
)
992 if (Length
!= sizeof(KSSTREAM_HEADER
) || (PVOID
)StreamHeader
!= Irp
->AssociatedIrp
.SystemBuffer
)
994 /* stream changed - must be send in a single packet */
995 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
998 if (!(ProbeFlags
& KSPROBE_ALLOWFORMATCHANGE
))
1000 /* caller does not permit format changes */
1001 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
1004 if (StreamHeader
->FrameExtent
)
1006 /* allocate an mdl */
1007 Mdl
= IoAllocateMdl(StreamHeader
->Data
, StreamHeader
->FrameExtent
, FALSE
, TRUE
, Irp
);
1011 /* not enough memory */
1012 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
1015 /* break out to probe for the irp */
1023 if (StreamHeader
->DataUsed
)
1025 /* DataUsed must be zero for stream read operation */
1026 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
1029 if (StreamHeader
->OptionsFlags
)
1031 /* no flags supported for reading */
1032 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
1036 /* move to next stream header */
1037 Length
-= StreamHeader
->Size
;
1038 StreamHeader
= (PKSSTREAM_HEADER
)((ULONG_PTR
)StreamHeader
+ StreamHeader
->Size
);
1041 }_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1043 /* Exception, get the error code */
1044 Status
= _SEH2_GetExceptionCode();
1047 /* now probe the allocated mdl's */
1048 if (NT_SUCCESS(Status
))
1054 return STATUS_INVALID_BUFFER_SIZE
;
1063 KsAllocateExtraData(
1066 OUT PVOID
* ExtraBuffer
)
1068 PIO_STACK_LOCATION IoStack
;
1070 PUCHAR Buffer
, BufferOrg
;
1071 PKSSTREAM_HEADER Header
;
1072 NTSTATUS Status
= STATUS_SUCCESS
;
1074 /* get current irp stack */
1075 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1078 ASSERT(IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
>= sizeof(KSSTREAM_HEADER
));
1080 /* get total length */
1081 Count
= IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
/ sizeof(KSSTREAM_HEADER
);
1083 /* allocate buffer */
1084 Buffer
= BufferOrg
= AllocateItem(NonPagedPool
, Count
* (sizeof(KSSTREAM_HEADER
) + ExtraSize
));
1086 return STATUS_INSUFFICIENT_RESOURCES
;
1090 /* get input buffer */
1091 Header
= (PKSSTREAM_HEADER
)IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1092 for(Index
= 0; Index
< Count
; Index
++)
1094 /* copy stream header */
1095 RtlMoveMemory(Buffer
, Header
, sizeof(KSSTREAM_HEADER
));
1097 /* move to next header */
1099 /* increment output buffer offset */
1100 Buffer
+= sizeof(KSSTREAM_HEADER
) + ExtraSize
;
1103 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1105 /* Exception, get the error code */
1106 Status
= _SEH2_GetExceptionCode();
1110 if (!NT_SUCCESS(Status
))
1112 /* free buffer on exception */
1118 *ExtraBuffer
= BufferOrg
;
1121 return STATUS_SUCCESS
;
1131 IN PDRIVER_OBJECT DriverObject
)
1141 KsDispatchInvalidDeviceRequest(
1142 IN PDEVICE_OBJECT DeviceObject
,
1145 Irp
->IoStatus
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1146 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1148 return STATUS_INVALID_DEVICE_REQUEST
;
1157 KsDefaultDeviceIoCompletion(
1158 IN PDEVICE_OBJECT DeviceObject
,
1161 PIO_STACK_LOCATION IoStack
;
1164 /* get current irp stack */
1165 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1167 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_KS_PROPERTY
&&
1168 IoStack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_KS_METHOD
&&
1169 IoStack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_KS_PROPERTY
)
1171 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_KS_RESET_STATE
)
1174 Status
= STATUS_SUCCESS
;
1178 /* request unsupported */
1179 Status
= STATUS_INVALID_DEVICE_REQUEST
;
1184 /* property / method / event not found */
1185 Status
= STATUS_PROPSET_NOT_FOUND
;
1188 /* complete request */
1189 Irp
->IoStatus
.Status
= Status
;
1190 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1202 KsDispatchFastIoDeviceControlFailure(
1203 IN PFILE_OBJECT FileObject
,
1205 IN PVOID InputBuffer OPTIONAL
,
1206 IN ULONG InputBufferLength
,
1207 OUT PVOID OutputBuffer OPTIONAL
,
1208 IN ULONG OutputBufferLength
,
1209 IN ULONG IoControlCode
,
1210 OUT PIO_STATUS_BLOCK IoStatus
,
1211 IN PDEVICE_OBJECT DeviceObject
)
1222 KsDispatchFastReadFailure(
1223 IN PFILE_OBJECT FileObject
,
1224 IN PLARGE_INTEGER FileOffset
,
1229 OUT PIO_STATUS_BLOCK IoStatus
,
1230 IN PDEVICE_OBJECT DeviceObject
)
1243 IN OUT PLIST_ENTRY QueueHead
,
1244 IN PKSPIN_LOCK SpinLock
)
1246 PDRIVER_CANCEL OldDriverCancel
;
1247 PIO_STACK_LOCATION IoStack
;
1249 PLIST_ENTRY NextEntry
;
1253 /* acquire spinlock */
1254 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1255 /* point to first entry */
1256 Entry
= QueueHead
->Flink
;
1257 /* loop all items */
1258 while(Entry
!= QueueHead
)
1260 /* get irp offset */
1261 Irp
= (PIRP
)CONTAINING_RECORD(Entry
, IRP
, Tail
.Overlay
.ListEntry
);
1263 /* get next entry */
1264 NextEntry
= Entry
->Flink
;
1266 /* set cancelled bit */
1269 /* now set the cancel routine */
1270 OldDriverCancel
= IoSetCancelRoutine(Irp
, NULL
);
1271 if (OldDriverCancel
)
1273 /* this irp hasnt been yet used, so free to cancel */
1274 KeReleaseSpinLock(SpinLock
, OldLevel
);
1276 /* get current irp stack */
1277 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1279 /* acquire cancel spinlock */
1280 IoAcquireCancelSpinLock(&Irp
->CancelIrql
);
1282 /* call provided cancel routine */
1283 OldDriverCancel(IoStack
->DeviceObject
, Irp
);
1285 /* re-acquire spinlock */
1286 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1289 /* move on to next entry */
1293 /* the irp has already been canceled */
1294 KeReleaseSpinLock(SpinLock
, OldLevel
);
1304 KsReleaseIrpOnCancelableQueue(
1306 IN PDRIVER_CANCEL DriverCancel OPTIONAL
)
1308 PKSPIN_LOCK SpinLock
;
1309 PDRIVER_CANCEL OldDriverCancel
;
1310 PIO_STACK_LOCATION IoStack
;
1313 /* check for required parameters */
1319 /* default to KsCancelRoutine */
1320 DriverCancel
= KsCancelRoutine
;
1323 /* get current irp stack */
1324 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1326 /* get internal queue lock */
1327 SpinLock
= KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
);
1329 /* acquire spinlock */
1330 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1332 /* now set the cancel routine */
1333 OldDriverCancel
= IoSetCancelRoutine(Irp
, DriverCancel
);
1335 if (Irp
->Cancel
&& OldDriverCancel
== NULL
)
1337 /* the irp has already been canceled */
1338 KeReleaseSpinLock(SpinLock
, OldLevel
);
1340 /* cancel routine requires that cancel spinlock is held */
1341 IoAcquireCancelSpinLock(&Irp
->CancelIrql
);
1344 DriverCancel(IoStack
->DeviceObject
, Irp
);
1349 KeReleaseSpinLock(SpinLock
, OldLevel
);
1359 KsRemoveIrpFromCancelableQueue(
1360 IN OUT PLIST_ENTRY QueueHead
,
1361 IN PKSPIN_LOCK SpinLock
,
1362 IN KSLIST_ENTRY_LOCATION ListLocation
,
1363 IN KSIRP_REMOVAL_OPERATION RemovalOperation
)
1366 PLIST_ENTRY CurEntry
;
1369 DPRINT("KsRemoveIrpFromCancelableQueue ListHead %p SpinLock %p ListLocation %x RemovalOperation %x\n", QueueHead
, SpinLock
, ListLocation
, RemovalOperation
);
1371 /* check parameters */
1372 if (!QueueHead
|| !SpinLock
)
1375 /* check if parameter ListLocation is valid */
1376 if (ListLocation
!= KsListEntryTail
&& ListLocation
!= KsListEntryHead
)
1379 /* acquire list lock */
1380 KeAcquireSpinLock(SpinLock
, &OldIrql
);
1382 /* point to queue head */
1383 CurEntry
= QueueHead
;
1387 /* reset irp to null */
1390 /* iterate to next entry */
1391 if (ListLocation
== KsListEntryHead
)
1392 CurEntry
= CurEntry
->Flink
;
1394 CurEntry
= CurEntry
->Blink
;
1396 /* is the end of list reached */
1397 if (CurEntry
== QueueHead
)
1399 /* reached end of list */
1403 /* get irp offset */
1404 Irp
= (PIRP
)CONTAINING_RECORD(CurEntry
, IRP
, Tail
.Overlay
.ListEntry
);
1408 /* irp has been canceled */
1412 if (Irp
->CancelRoutine
)
1414 /* remove cancel routine */
1415 Irp
->CancelRoutine
= NULL
;
1417 if (RemovalOperation
== KsAcquireAndRemove
|| RemovalOperation
== KsAcquireAndRemoveOnlySingleItem
)
1419 /* remove irp from list */
1420 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1423 if (RemovalOperation
== KsAcquireAndRemoveOnlySingleItem
|| RemovalOperation
== KsAcquireOnlySingleItem
)
1430 KeReleaseSpinLock(SpinLock
, OldIrql
);
1432 if (!Irp
|| Irp
->CancelRoutine
== NULL
)
1434 /* either an irp has been acquired or nothing found */
1438 /* time to remove the canceled irp */
1439 IoAcquireCancelSpinLock(&OldIrql
);
1440 /* acquire list lock */
1441 KeAcquireSpinLockAtDpcLevel(SpinLock
);
1443 if (RemovalOperation
== KsAcquireAndRemove
|| RemovalOperation
== KsAcquireAndRemoveOnlySingleItem
)
1446 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1449 /* release list lock */
1450 KeReleaseSpinLockFromDpcLevel(SpinLock
);
1452 /* release cancel spinlock */
1453 IoReleaseCancelSpinLock(OldIrql
);
1454 /* no non canceled irp has been found */
1464 KsMoveIrpsOnCancelableQueue(
1465 IN OUT PLIST_ENTRY SourceList
,
1466 IN PKSPIN_LOCK SourceLock
,
1467 IN OUT PLIST_ENTRY DestinationList
,
1468 IN PKSPIN_LOCK DestinationLock OPTIONAL
,
1469 IN KSLIST_ENTRY_LOCATION ListLocation
,
1470 IN PFNKSIRPLISTCALLBACK ListCallback
,
1474 PLIST_ENTRY SrcEntry
;
1476 NTSTATUS Status
= STATUS_SUCCESS
;
1478 if (!DestinationLock
)
1480 /* no destination lock just acquire the source lock */
1481 KeAcquireSpinLock(SourceLock
, &OldLevel
);
1485 /* acquire cancel spinlock */
1486 IoAcquireCancelSpinLock(&OldLevel
);
1488 /* now acquire source lock */
1489 KeAcquireSpinLockAtDpcLevel(SourceLock
);
1491 /* now acquire destination lock */
1492 KeAcquireSpinLockAtDpcLevel(DestinationLock
);
1495 /* point to list head */
1496 SrcEntry
= SourceList
;
1498 /* now move all irps */
1501 if (ListLocation
== KsListEntryTail
)
1503 /* move queue downwards */
1504 SrcEntry
= SrcEntry
->Flink
;
1508 /* move queue upwards */
1509 SrcEntry
= SrcEntry
->Blink
;
1512 if (SrcEntry
== SourceList
)
1514 /* eof list reached */
1518 /* get irp offset */
1519 Irp
= (PIRP
)CONTAINING_RECORD(SrcEntry
, IRP
, Tail
.Overlay
.ListEntry
);
1521 /* now check if irp can be moved */
1522 Status
= ListCallback(Irp
, Context
);
1524 /* check if irp can be moved */
1525 if (Status
== STATUS_SUCCESS
)
1527 /* remove irp from src list */
1528 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1530 if (ListLocation
== KsListEntryTail
)
1532 /* insert irp end of list */
1533 InsertTailList(DestinationList
, &Irp
->Tail
.Overlay
.ListEntry
);
1537 /* insert irp head of list */
1538 InsertHeadList(DestinationList
, &Irp
->Tail
.Overlay
.ListEntry
);
1541 /* do we need to update the irp lock */
1542 if (DestinationLock
)
1544 /* update irp lock */
1545 KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
) = DestinationLock
;
1550 if (Status
!= STATUS_NO_MATCH
)
1552 /* callback decided to stop enumeration */
1556 /* reset return value */
1557 Status
= STATUS_SUCCESS
;
1561 if (!DestinationLock
)
1563 /* release source lock */
1564 KeReleaseSpinLock(SourceLock
, OldLevel
);
1568 /* now release destination lock */
1569 KeReleaseSpinLockFromDpcLevel(DestinationLock
);
1571 /* now release source lock */
1572 KeReleaseSpinLockFromDpcLevel(SourceLock
);
1575 /* now release cancel spinlock */
1576 IoReleaseCancelSpinLock(OldLevel
);
1589 KsRemoveSpecificIrpFromCancelableQueue(
1592 PKSPIN_LOCK SpinLock
;
1595 DPRINT("KsRemoveSpecificIrpFromCancelableQueue %p\n", Irp
);
1597 /* get internal queue lock */
1598 SpinLock
= KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
);
1600 /* acquire spinlock */
1601 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1603 /* remove the irp from the list */
1604 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1606 /* release spinlock */
1607 KeReleaseSpinLock(SpinLock
, OldLevel
);
1617 KsAddIrpToCancelableQueue(
1618 IN OUT PLIST_ENTRY QueueHead
,
1619 IN PKSPIN_LOCK SpinLock
,
1621 IN KSLIST_ENTRY_LOCATION ListLocation
,
1622 IN PDRIVER_CANCEL DriverCancel OPTIONAL
)
1624 PDRIVER_CANCEL OldDriverCancel
;
1625 PIO_STACK_LOCATION IoStack
;
1628 /* check for required parameters */
1629 if (!QueueHead
|| !SpinLock
|| !Irp
)
1632 /* get current irp stack */
1633 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1635 DPRINT("KsAddIrpToCancelableQueue QueueHead %p SpinLock %p Irp %p ListLocation %x DriverCancel %p\n", QueueHead
, SpinLock
, Irp
, ListLocation
, DriverCancel
);
1637 // HACK for ms portcls
1638 if (IoStack
->MajorFunction
== IRP_MJ_CREATE
)
1640 // complete the request
1641 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1642 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1650 /* default to KsCancelRoutine */
1651 DriverCancel
= KsCancelRoutine
;
1655 /* acquire spinlock */
1656 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1658 if (ListLocation
== KsListEntryTail
)
1660 /* insert irp to tail of list */
1661 InsertTailList(QueueHead
, &Irp
->Tail
.Overlay
.ListEntry
);
1665 /* insert irp to head of list */
1666 InsertHeadList(QueueHead
, &Irp
->Tail
.Overlay
.ListEntry
);
1669 /* store internal queue lock */
1670 KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
) = SpinLock
;
1672 /* now set the cancel routine */
1673 OldDriverCancel
= IoSetCancelRoutine(Irp
, DriverCancel
);
1675 if (Irp
->Cancel
&& OldDriverCancel
== NULL
)
1677 /* the irp has already been canceled */
1678 KeReleaseSpinLock(SpinLock
, OldLevel
);
1680 /* cancel routine requires that cancel spinlock is held */
1681 IoAcquireCancelSpinLock(&Irp
->CancelIrql
);
1684 DriverCancel(IoStack
->DeviceObject
, Irp
);
1689 KeReleaseSpinLock(SpinLock
, OldLevel
);
1700 IN PDEVICE_OBJECT DeviceObject
,
1703 PKSPIN_LOCK SpinLock
;
1705 /* get internal queue lock */
1706 SpinLock
= KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
);
1708 /* acquire spinlock */
1709 KeAcquireSpinLockAtDpcLevel(SpinLock
);
1712 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
1714 /* release cancel spinlock */
1715 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
1717 /* remove the irp from the list */
1718 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1720 /* release spinlock */
1721 KeReleaseSpinLock(SpinLock
, Irp
->CancelIrql
);
1723 /* has the irp already been canceled */
1724 if (Irp
->IoStatus
.Status
!= STATUS_CANCELLED
)
1726 /* let's complete it */
1727 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
1728 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1733 FindMatchingCreateItem(
1734 PLIST_ENTRY ListHead
,
1737 OUT PCREATE_ITEM_ENTRY
*OutCreateItem
)
1740 PCREATE_ITEM_ENTRY CreateItemEntry
;
1741 UNICODE_STRING RefString
;
1744 /* get terminator */
1745 pStr
= wcschr(Buffer
, L
'\\');
1748 ASSERT(pStr
!= NULL
);
1753 RtlInitUnicodeString(&RefString
, ++pStr
);
1757 // request is for pin / node / allocator
1758 RefString
.Buffer
= Buffer
;
1759 RefString
.Length
= BufferSize
= RefString
.MaximumLength
= ((ULONG_PTR
)pStr
- (ULONG_PTR
)Buffer
);
1762 /* point to first entry */
1763 Entry
= ListHead
->Flink
;
1765 /* loop all device items */
1766 while(Entry
!= ListHead
)
1768 /* get create item entry */
1769 CreateItemEntry
= (PCREATE_ITEM_ENTRY
)CONTAINING_RECORD(Entry
, CREATE_ITEM_ENTRY
, Entry
);
1771 ASSERT(CreateItemEntry
->CreateItem
);
1773 if(CreateItemEntry
->CreateItem
->Flags
& KSCREATE_ITEM_WILDCARD
)
1775 /* create item is default */
1776 *OutCreateItem
= CreateItemEntry
;
1777 return STATUS_SUCCESS
;
1780 if (!CreateItemEntry
->CreateItem
->Create
)
1782 /* skip free create item */
1783 Entry
= Entry
->Flink
;
1787 ASSERT(CreateItemEntry
->CreateItem
->ObjectClass
.Buffer
);
1789 DPRINT("CreateItem %S Length %u Request %wZ %u\n", CreateItemEntry
->CreateItem
->ObjectClass
.Buffer
,
1790 CreateItemEntry
->CreateItem
->ObjectClass
.Length
,
1794 if (CreateItemEntry
->CreateItem
->ObjectClass
.Length
> BufferSize
)
1796 /* create item doesnt match in length */
1797 Entry
= Entry
->Flink
;
1801 /* now check if the object class is the same */
1802 if (!RtlCompareUnicodeString(&CreateItemEntry
->CreateItem
->ObjectClass
, &RefString
, TRUE
))
1804 /* found matching create item */
1805 *OutCreateItem
= CreateItemEntry
;
1806 return STATUS_SUCCESS
;
1808 /* iterate to next */
1809 Entry
= Entry
->Flink
;
1812 return STATUS_NOT_FOUND
;
1818 IN PDEVICE_OBJECT DeviceObject
,
1821 PCREATE_ITEM_ENTRY CreateItemEntry
;
1822 PIO_STACK_LOCATION IoStack
;
1823 PDEVICE_EXTENSION DeviceExtension
;
1824 PKSIDEVICE_HEADER DeviceHeader
;
1825 PKSIOBJECT_HEADER ObjectHeader
;
1828 DPRINT("KS / CREATE\n");
1830 /* get current stack location */
1831 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1832 /* get device extension */
1833 DeviceExtension
= (PDEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
1834 /* get device header */
1835 DeviceHeader
= DeviceExtension
->DeviceHeader
;
1838 if (IoStack
->FileObject
->FileName
.Buffer
== NULL
)
1840 /* FIXME Pnp-Issue */
1841 DPRINT("Using reference string hack\n");
1842 Irp
->IoStatus
.Information
= 0;
1843 /* set return status */
1844 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1845 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1846 return STATUS_SUCCESS
;
1849 if (IoStack
->FileObject
->RelatedFileObject
!= NULL
)
1851 /* request is to instantiate a pin / node / clock / allocator */
1852 ObjectHeader
= (PKSIOBJECT_HEADER
)IoStack
->FileObject
->RelatedFileObject
->FsContext2
;
1855 ASSERT(ObjectHeader
);
1857 /* find a matching a create item */
1858 Status
= FindMatchingCreateItem(&ObjectHeader
->ItemList
, IoStack
->FileObject
->FileName
.Length
, IoStack
->FileObject
->FileName
.Buffer
, &CreateItemEntry
);
1862 /* request to create a filter */
1863 Status
= FindMatchingCreateItem(&DeviceHeader
->ItemList
, IoStack
->FileObject
->FileName
.Length
, IoStack
->FileObject
->FileName
.Buffer
, &CreateItemEntry
);
1866 if (NT_SUCCESS(Status
))
1868 /* set object create item */
1869 KSCREATE_ITEM_IRP_STORAGE(Irp
) = CreateItemEntry
->CreateItem
;
1871 /* call create function */
1872 Status
= CreateItemEntry
->CreateItem
->Create(DeviceObject
, Irp
);
1874 if (NT_SUCCESS(Status
))
1876 /* increment create item reference count */
1877 InterlockedIncrement(&CreateItemEntry
->ReferenceCount
);
1882 Irp
->IoStatus
.Information
= 0;
1883 /* set return status */
1884 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
1885 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1886 return STATUS_UNSUCCESSFUL
;
1892 IN PDEVICE_OBJECT DeviceObject
,
1895 PIO_STACK_LOCATION IoStack
;
1896 PDEVICE_EXTENSION DeviceExtension
;
1897 PKSIOBJECT_HEADER ObjectHeader
;
1898 PKSIDEVICE_HEADER DeviceHeader
;
1899 PDRIVER_DISPATCH Dispatch
;
1902 /* get current stack location */
1903 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1905 /* get device extension */
1906 DeviceExtension
= (PDEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
1907 /* get device header */
1908 DeviceHeader
= DeviceExtension
->DeviceHeader
;
1910 ASSERT(IoStack
->FileObject
);
1912 /* get object header */
1913 ObjectHeader
= (PKSIOBJECT_HEADER
) IoStack
->FileObject
->FsContext2
;
1917 /* FIXME Pnp-Issue*/
1918 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1919 Irp
->IoStatus
.Information
= 0;
1920 /* complete and forget */
1921 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1922 return STATUS_SUCCESS
;
1926 ASSERT(ObjectHeader
);
1927 /* store create item */
1928 //KSCREATE_ITEM_IRP_STORAGE(Irp) = (PKSOBJECT_CREATE_ITEM)0x12345678; //ObjectHeader->CreateItem;
1930 /* retrieve matching dispatch function */
1931 switch(IoStack
->MajorFunction
)
1934 Dispatch
= ObjectHeader
->DispatchTable
.Close
;
1936 case IRP_MJ_DEVICE_CONTROL
:
1937 Dispatch
= ObjectHeader
->DispatchTable
.DeviceIoControl
;
1940 Dispatch
= ObjectHeader
->DispatchTable
.Read
;
1943 Dispatch
= ObjectHeader
->DispatchTable
.Write
;
1945 case IRP_MJ_FLUSH_BUFFERS
:
1946 Dispatch
= ObjectHeader
->DispatchTable
.Flush
;
1948 case IRP_MJ_QUERY_SECURITY
:
1949 Dispatch
= ObjectHeader
->DispatchTable
.QuerySecurity
;
1951 case IRP_MJ_SET_SECURITY
:
1952 Dispatch
= ObjectHeader
->DispatchTable
.SetSecurity
;
1955 Dispatch
= KsDefaultDispatchPnp
;
1960 /* is the request supported */
1963 /* now call the dispatch function */
1964 Status
= Dispatch(DeviceObject
, Irp
);
1968 /* not supported request */
1969 Status
= KsDispatchInvalidDeviceRequest(DeviceObject
, Irp
);
1982 KsSetMajorFunctionHandler(
1983 IN PDRIVER_OBJECT DriverObject
,
1984 IN ULONG MajorFunction
)
1986 DPRINT("KsSetMajorFunctionHandler Function %x\n", MajorFunction
);
1988 switch ( MajorFunction
)
1991 DriverObject
->MajorFunction
[MajorFunction
] = KspCreate
;
1993 case IRP_MJ_DEVICE_CONTROL
:
1997 case IRP_MJ_FLUSH_BUFFERS
:
1998 case IRP_MJ_QUERY_SECURITY
:
1999 case IRP_MJ_SET_SECURITY
:
2000 DriverObject
->MajorFunction
[MajorFunction
] = KspDispatchIrp
;
2003 DPRINT1("NotSupported %x\n", MajorFunction
);
2004 return STATUS_INVALID_PARAMETER
;
2007 return STATUS_SUCCESS
;
2017 IN PDEVICE_OBJECT DeviceObject
,
2020 PIO_STACK_LOCATION IoStack
;
2021 PKSIDEVICE_HEADER DeviceHeader
;
2022 PDEVICE_EXTENSION DeviceExtension
;
2024 DPRINT("KsDispatchIrp DeviceObject %p Irp %p\n", DeviceObject
, Irp
);
2026 /* get device extension */
2027 DeviceExtension
= (PDEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
2028 /* get device header */
2029 DeviceHeader
= DeviceExtension
->DeviceHeader
;
2032 /* get current irp stack */
2033 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
2035 if (IoStack
->MajorFunction
<= IRP_MJ_DEVICE_CONTROL
)
2037 if (IoStack
->MajorFunction
== IRP_MJ_CREATE
)
2039 /* check internal type */
2040 if (DeviceHeader
->BasicHeader
.OuterUnknown
) /* FIXME improve check */
2042 /* AVStream client */
2043 return IKsDevice_Create(DeviceObject
, Irp
);
2047 /* external client (portcls) */
2048 return KspCreate(DeviceObject
, Irp
);
2052 switch (IoStack
->MajorFunction
)
2057 case IRP_MJ_FLUSH_BUFFERS
:
2058 case IRP_MJ_QUERY_SECURITY
:
2059 case IRP_MJ_SET_SECURITY
:
2061 case IRP_MJ_DEVICE_CONTROL
:
2062 return KspDispatchIrp(DeviceObject
, Irp
);
2064 return KsDispatchInvalidDeviceRequest(DeviceObject
, Irp
);
2068 /* dispatch power */
2069 if (IoStack
->MajorFunction
== IRP_MJ_POWER
)
2071 /* check internal type */
2072 if (DeviceHeader
->BasicHeader
.OuterUnknown
) /* FIXME improve check */
2074 /* AVStream client */
2075 return IKsDevice_Power(DeviceObject
, Irp
);
2079 /* external client (portcls) */
2080 return KsDefaultDispatchPower(DeviceObject
, Irp
);
2083 else if (IoStack
->MajorFunction
== IRP_MJ_PNP
) /* dispatch pnp */
2085 /* check internal type */
2086 if (DeviceHeader
->BasicHeader
.OuterUnknown
) /* FIXME improve check */
2088 /* AVStream client */
2089 return IKsDevice_Pnp(DeviceObject
, Irp
);
2093 /* external client (portcls) */
2094 return KsDefaultDispatchPnp(DeviceObject
, Irp
);
2097 else if (IoStack
->MajorFunction
== IRP_MJ_SYSTEM_CONTROL
)
2100 return KsDefaultForwardIrp(DeviceObject
, Irp
);
2105 return KsDispatchInvalidDeviceRequest(DeviceObject
, Irp
);
2119 return KSFILTER_NODE
;