ReactOS 0.4.15-dev-6712-g46b4b55
irp.c File Reference
#include "precomp.h"
#include <ntifs.h>
#include <debug.h>
Include dependency graph for irp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

KSDDKAPI NTSTATUS NTAPI KsDispatchQuerySecurity (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsDispatchSetSecurity (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsDispatchSpecificMethod (IN PIRP Irp, IN PFNKSHANDLER Handler)
 
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)
 
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)
 
KSDDKAPI NTSTATUS NTAPI KsQueryInformationFile (IN PFILE_OBJECT FileObject, OUT PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
 
KSDDKAPI NTSTATUS NTAPI KsSetInformationFile (IN PFILE_OBJECT FileObject, IN PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
 
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)
 
KSDDKAPI NTSTATUS NTAPI KsProbeStreamIrp (IN PIRP Irp, IN ULONG ProbeFlags, IN ULONG HeaderSize)
 
KSDDKAPI NTSTATUS NTAPI KsAllocateExtraData (IN PIRP Irp, IN ULONG ExtraSize, OUT PVOID *ExtraBuffer)
 
KSDDKAPI VOID NTAPI KsNullDriverUnload (IN PDRIVER_OBJECT DriverObject)
 
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsDefaultDeviceIoCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
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)
 
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)
 
KSDDKAPI VOID NTAPI KsCancelIo (IN OUT PLIST_ENTRY QueueHead, IN PKSPIN_LOCK SpinLock)
 
KSDDKAPI VOID NTAPI KsReleaseIrpOnCancelableQueue (IN PIRP Irp, IN PDRIVER_CANCEL DriverCancel OPTIONAL)
 
KSDDKAPI PIRP NTAPI KsRemoveIrpFromCancelableQueue (IN OUT PLIST_ENTRY QueueHead, IN PKSPIN_LOCK SpinLock, IN KSLIST_ENTRY_LOCATION ListLocation, IN KSIRP_REMOVAL_OPERATION RemovalOperation)
 
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)
 
KSDDKAPI VOID NTAPI KsRemoveSpecificIrpFromCancelableQueue (IN PIRP Irp)
 
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)
 
KSDDKAPI VOID NTAPI KsCancelRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS FindMatchingCreateItem (PLIST_ENTRY ListHead, PUNICODE_STRING String, OUT PCREATE_ITEM_ENTRY *OutCreateItem)
 
NTSTATUS NTAPI KspCreate (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KspDispatchIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler (IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
 
KSDDKAPI NTSTATUS NTAPI KsDispatchIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI ULONG NTAPI KsGetNodeIdFromIrp (IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file irp.c.

Function Documentation

◆ FindMatchingCreateItem()

NTSTATUS FindMatchingCreateItem ( PLIST_ENTRY  ListHead,
PUNICODE_STRING  String,
OUT PCREATE_ITEM_ENTRY OutCreateItem 
)

Definition at line 1762 of file irp.c.

1766{
1768 PCREATE_ITEM_ENTRY CreateItemEntry;
1770 LPWSTR pStr;
1771 ULONG Count;
1772
1773 /* Copy the input string */
1774 RefString = *String;
1775
1776 /* Check if the string starts with a backslash */
1777 if (String->Buffer[0] == L'\\')
1778 {
1779 /* Skip backslash */
1780 RefString.Buffer++;
1781 RefString.Length -= sizeof(WCHAR);
1782 }
1783 else
1784 {
1785 /* get terminator */
1786 pStr = String->Buffer;
1787 Count = String->Length / sizeof(WCHAR);
1788 while ((Count > 0) && (*pStr != L'\\'))
1789 {
1790 pStr++;
1791 Count--;
1792 }
1793
1794 /* sanity check */
1795 ASSERT(Count != 0);
1796
1797 // request is for pin / node / allocator
1798 RefString.Length = (USHORT)((PCHAR)pStr - (PCHAR)String->Buffer);
1799 }
1800
1801 /* point to first entry */
1802 Entry = ListHead->Flink;
1803
1804 /* loop all device items */
1805 while (Entry != ListHead)
1806 {
1807 /* get create item entry */
1808 CreateItemEntry = (PCREATE_ITEM_ENTRY)CONTAINING_RECORD(Entry,
1810 Entry);
1811
1812 ASSERT(CreateItemEntry->CreateItem);
1813
1814 if(CreateItemEntry->CreateItem->Flags & KSCREATE_ITEM_WILDCARD)
1815 {
1816 /* create item is default */
1817 *OutCreateItem = CreateItemEntry;
1818 return STATUS_SUCCESS;
1819 }
1820
1821 if (!CreateItemEntry->CreateItem->Create)
1822 {
1823 /* skip free create item */
1824 Entry = Entry->Flink;
1825 continue;
1826 }
1827
1828 DPRINT("CreateItem %S Length %u Request %wZ %u\n",
1829 CreateItemEntry->CreateItem->ObjectClass.Buffer,
1830 CreateItemEntry->CreateItem->ObjectClass.Length,
1831 &RefString,
1832 RefString.Length);
1833
1834 if (CreateItemEntry->CreateItem->ObjectClass.Length > RefString.Length)
1835 {
1836 /* create item doesnt match in length */
1837 Entry = Entry->Flink;
1838 continue;
1839 }
1840
1841 /* now check if the object class is the same */
1842 if (!RtlCompareUnicodeString(&CreateItemEntry->CreateItem->ObjectClass,
1843 &RefString,
1844 TRUE))
1845 {
1846 /* found matching create item */
1847 *OutCreateItem = CreateItemEntry;
1848 return STATUS_SUCCESS;
1849 }
1850 /* iterate to next */
1851 Entry = Entry->Flink;
1852 }
1853
1854 return STATUS_NOT_FOUND;
1855}
#define TRUE
Definition: types.h:120
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
__in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING RefString
struct CREATE_ITEM_ENTRY * PCREATE_ITEM_ENTRY
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
int Count
Definition: noreturn.cpp:7
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define DPRINT
Definition: sndvol32.h:71
Definition: kstypes.h:46
PKSOBJECT_CREATE_ITEM CreateItem
Definition: kstypes.h:48
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by IKsDevice_Create(), and KspCreate().

◆ KsAddIrpToCancelableQueue()

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 at line 1645 of file irp.c.

1651{
1652 PDRIVER_CANCEL OldDriverCancel;
1653 PIO_STACK_LOCATION IoStack;
1654 KIRQL OldLevel;
1655
1656 /* check for required parameters */
1657 if (!QueueHead || !SpinLock || !Irp)
1658 return;
1659
1660 /* get current irp stack */
1662
1663 DPRINT("KsAddIrpToCancelableQueue QueueHead %p SpinLock %p Irp %p ListLocation %x DriverCancel %p\n", QueueHead, SpinLock, Irp, ListLocation, DriverCancel);
1664
1665 // HACK for ms portcls
1666 if (IoStack->MajorFunction == IRP_MJ_CREATE)
1667 {
1668 // complete the request
1669 DPRINT1("MS HACK\n");
1670 Irp->IoStatus.Status = STATUS_SUCCESS;
1672
1673 return;
1674 }
1675
1676
1677 if (!DriverCancel)
1678 {
1679 /* default to KsCancelRoutine */
1680 DriverCancel = KsCancelRoutine;
1681 }
1682
1683
1684 /* acquire spinlock */
1685 KeAcquireSpinLock(SpinLock, &OldLevel);
1686
1687 if (ListLocation == KsListEntryTail)
1688 {
1689 /* insert irp to tail of list */
1690 InsertTailList(QueueHead, &Irp->Tail.Overlay.ListEntry);
1691 }
1692 else
1693 {
1694 /* insert irp to head of list */
1695 InsertHeadList(QueueHead, &Irp->Tail.Overlay.ListEntry);
1696 }
1697
1698 /* store internal queue lock */
1699 KSQUEUE_SPINLOCK_IRP_STORAGE(Irp) = SpinLock;
1700
1701 /* now set the cancel routine */
1702 OldDriverCancel = IoSetCancelRoutine(Irp, DriverCancel);
1703
1704 if (Irp->Cancel && OldDriverCancel == NULL)
1705 {
1706 /* the irp has already been canceled */
1707 KeReleaseSpinLock(SpinLock, OldLevel);
1708
1709 /* cancel routine requires that cancel spinlock is held */
1710 IoAcquireCancelSpinLock(&Irp->CancelIrql);
1711
1712 /* cancel irp */
1713 DriverCancel(IoStack->DeviceObject, Irp);
1714 }
1715 else
1716 {
1717 /* done */
1718 KeReleaseSpinLock(SpinLock, OldLevel);
1719 }
1720}
#define DPRINT1
Definition: precomp.h:8
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
KSDDKAPI VOID NTAPI KsCancelRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1728
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
IoSetCancelRoutine(Irp, CancelRoutine)
@ KsListEntryTail
Definition: ks.h:1262
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3223
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IO_NO_INCREMENT
Definition: iotypes.h:598
DRIVER_CANCEL * PDRIVER_CANCEL
Definition: iotypes.h:2759

Referenced by IKsPin_DispatchKsStream().

◆ KsAllocateExtraData()

KSDDKAPI NTSTATUS NTAPI KsAllocateExtraData ( IN PIRP  Irp,
IN ULONG  ExtraSize,
OUT PVOID ExtraBuffer 
)

Definition at line 1090 of file irp.c.

1094{
1095 PIO_STACK_LOCATION IoStack;
1096 ULONG Count, Index;
1097 PUCHAR Buffer, BufferOrg;
1100
1101 /* get current irp stack */
1103
1104 /* sanity check */
1105 ASSERT(IoStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(KSSTREAM_HEADER));
1106
1107 /* get total length */
1108 Count = IoStack->Parameters.DeviceIoControl.InputBufferLength / sizeof(KSSTREAM_HEADER);
1109
1110 /* allocate buffer */
1111 Buffer = BufferOrg = AllocateItem(NonPagedPool, Count * (sizeof(KSSTREAM_HEADER) + ExtraSize));
1112 if (!Buffer)
1114
1115 _SEH2_TRY
1116 {
1117 /* get input buffer */
1118 Header = (PKSSTREAM_HEADER)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
1119 for(Index = 0; Index < Count; Index++)
1120 {
1121 /* copy stream header */
1123
1124 /* move to next header */
1125 Header++;
1126 /* increment output buffer offset */
1127 Buffer += sizeof(KSSTREAM_HEADER) + ExtraSize;
1128 }
1129 }
1131 {
1132 /* Exception, get the error code */
1134 }
1135 _SEH2_END;
1136
1137 if (!NT_SUCCESS(Status))
1138 {
1139 /* free buffer on exception */
1141 return Status;
1142 }
1143
1144 /* store result */
1145 *ExtraBuffer = BufferOrg;
1146
1147 /* done */
1148 return STATUS_SUCCESS;
1149}
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
Definition: Header.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NonPagedPool
Definition: env_spec_w32.h:307
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
struct KSSTREAM_HEADER * PKSSTREAM_HEADER
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ ULONG Index

◆ KsCancelIo()

KSDDKAPI VOID NTAPI KsCancelIo ( IN OUT PLIST_ENTRY  QueueHead,
IN PKSPIN_LOCK  SpinLock 
)

Definition at line 1270 of file irp.c.

1273{
1274 PDRIVER_CANCEL OldDriverCancel;
1275 PIO_STACK_LOCATION IoStack;
1277 PLIST_ENTRY NextEntry;
1278 PIRP Irp;
1279 KIRQL OldLevel;
1280
1281 /* acquire spinlock */
1282 KeAcquireSpinLock(SpinLock, &OldLevel);
1283 /* point to first entry */
1284 Entry = QueueHead->Flink;
1285 /* loop all items */
1286 while(Entry != QueueHead)
1287 {
1288 /* get irp offset */
1289 Irp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
1290
1291 /* get next entry */
1292 NextEntry = Entry->Flink;
1293
1294 /* set cancelled bit */
1295 Irp->Cancel = TRUE;
1296
1297 /* now set the cancel routine */
1298 OldDriverCancel = IoSetCancelRoutine(Irp, NULL);
1299 if (OldDriverCancel)
1300 {
1301 /* this irp hasnt been yet used, so free to cancel */
1302 KeReleaseSpinLock(SpinLock, OldLevel);
1303
1304 /* get current irp stack */
1306
1307 /* acquire cancel spinlock */
1308 IoAcquireCancelSpinLock(&Irp->CancelIrql);
1309
1310 /* call provided cancel routine */
1311 OldDriverCancel(IoStack->DeviceObject, Irp);
1312
1313 /* re-acquire spinlock */
1314 KeAcquireSpinLock(SpinLock, &OldLevel);
1315 }
1316
1317 /* move on to next entry */
1318 Entry = NextEntry;
1319 }
1320
1321 /* the irp has already been canceled */
1322 KeReleaseSpinLock(SpinLock, OldLevel);
1323
1324}
struct _IRP * PIRP

◆ KsCancelRoutine()

KSDDKAPI VOID NTAPI KsCancelRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1728 of file irp.c.

1731{
1733
1734 /* get internal queue lock */
1735 SpinLock = KSQUEUE_SPINLOCK_IRP_STORAGE(Irp);
1736
1737 /* acquire spinlock */
1739
1740 /* sanity check */
1742
1743 /* release cancel spinlock */
1744 IoReleaseCancelSpinLock(Irp->CancelIrql);
1745
1746 /* remove the irp from the list */
1747 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1748
1749 /* release spinlock */
1750 KeReleaseSpinLock(SpinLock, Irp->CancelIrql);
1751
1752 /* has the irp already been canceled */
1753 if (Irp->IoStatus.Status != STATUS_CANCELLED)
1754 {
1755 /* let's complete it */
1756 Irp->IoStatus.Status = STATUS_CANCELLED;
1758 }
1759}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

Referenced by KsAddIrpToCancelableQueue(), and KsReleaseIrpOnCancelableQueue().

◆ KsDefaultDeviceIoCompletion()

KSDDKAPI NTSTATUS NTAPI KsDefaultDeviceIoCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1184 of file irp.c.

1187{
1188 PIO_STACK_LOCATION IoStack;
1190
1191 /* get current irp stack */
1193
1194 if (IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY &&
1195 IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_METHOD &&
1196 IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_ENABLE_EVENT &&
1197 IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_DISABLE_EVENT)
1198 {
1199 if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_KS_RESET_STATE)
1200 {
1201 /* fake success */
1203 }
1204 else
1205 {
1206 /* request unsupported */
1208 }
1209 }
1210 else
1211 {
1212 /* property / method / event not found */
1214 }
1215
1216 /* complete request */
1217 Irp->IoStatus.Status = Status;
1219
1220
1221 return Status;
1222}
#define IOCTL_KS_RESET_STATE
Definition: ks.h:145
#define IOCTL_KS_METHOD
Definition: ks.h:136
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define IOCTL_KS_ENABLE_EVENT
Definition: ks.h:130
#define IOCTL_KS_DISABLE_EVENT
Definition: ks.h:133
#define STATUS_PROPSET_NOT_FOUND
Definition: ntstatus.h:692
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138

◆ KsDispatchFastIoDeviceControlFailure()

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 at line 1230 of file irp.c.

1240{
1241 return FALSE;
1242}
#define FALSE
Definition: types.h:117

◆ KsDispatchFastReadFailure()

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 at line 1250 of file irp.c.

1259{
1260 return FALSE;
1261}

◆ KsDispatchInvalidDeviceRequest()

KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1168 of file irp.c.

1171{
1172 Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
1174
1176}

Referenced by KsDispatchIrp(), and KspDispatchIrp().

◆ KsDispatchIrp()

KSDDKAPI NTSTATUS NTAPI KsDispatchIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 2063 of file irp.c.

2066{
2067 PIO_STACK_LOCATION IoStack;
2068 PKSIDEVICE_HEADER DeviceHeader;
2069 PDEVICE_EXTENSION DeviceExtension;
2070
2071 DPRINT("KsDispatchIrp DeviceObject %p Irp %p\n", DeviceObject, Irp);
2072
2073 /* get device extension */
2074 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
2075
2076 /* get device header */
2077 DeviceHeader = DeviceExtension->DeviceHeader;
2078
2079
2080 /* get current irp stack */
2082
2083 if (IoStack->MajorFunction <= IRP_MJ_DEVICE_CONTROL)
2084 {
2085 if (IoStack->MajorFunction == IRP_MJ_CREATE)
2086 {
2087 /* check internal type */
2088 if (DeviceHeader->BasicHeader.OuterUnknown) /* FIXME improve check */
2089 {
2090 /* AVStream client */
2092 }
2093 else
2094 {
2095 /* external client (portcls) */
2096 return KspCreate(DeviceObject, Irp);
2097 }
2098 }
2099
2100 switch (IoStack->MajorFunction)
2101 {
2102 case IRP_MJ_CLOSE:
2103 case IRP_MJ_READ:
2104 case IRP_MJ_WRITE:
2108 case IRP_MJ_PNP:
2111 default:
2113 }
2114 }
2115
2116 /* dispatch power */
2117 if (IoStack->MajorFunction == IRP_MJ_POWER)
2118 {
2119 /* check internal type */
2120 if (DeviceHeader->BasicHeader.OuterUnknown) /* FIXME improve check */
2121 {
2122 /* AVStream client */
2124 }
2125 else
2126 {
2127 /* external client (portcls) */
2129 }
2130 }
2131 else if (IoStack->MajorFunction == IRP_MJ_PNP) /* dispatch pnp */
2132 {
2133 /* check internal type */
2134 if (DeviceHeader->BasicHeader.OuterUnknown) /* FIXME improve check */
2135 {
2136 /* AVStream client */
2138 }
2139 else
2140 {
2141 /* external client (portcls) */
2143 }
2144 }
2145 else if (IoStack->MajorFunction == IRP_MJ_SYSTEM_CONTROL)
2146 {
2147 /* forward irp */
2149 }
2150 else
2151 {
2152 /* not supported */
2154 }
2155}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
KSDDKAPI NTSTATUS NTAPI KsDefaultDispatchPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:110
KSDDKAPI NTSTATUS NTAPI KsDefaultForwardIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:227
KSDDKAPI NTSTATUS NTAPI KsDefaultDispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:166
NTSTATUS NTAPI IKsDevice_Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:549
NTSTATUS NTAPI IKsDevice_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:566
NTSTATUS NTAPI IKsDevice_Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:409
KSDDKAPI NTSTATUS NTAPI KsDispatchInvalidDeviceRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1168
NTSTATUS NTAPI KspCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1859
NTSTATUS NTAPI KspDispatchIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1937
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
KSBASIC_HEADER BasicHeader
Definition: kstypes.h:87
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_FLUSH_BUFFERS
#define IRP_MJ_POWER
#define IRP_MJ_SET_SECURITY

Referenced by PcDispatchIrp(), and PortClsCreate().

◆ KsDispatchQuerySecurity()

KSDDKAPI NTSTATUS NTAPI KsDispatchQuerySecurity ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 22 of file irp.c.

25{
26 PKSOBJECT_CREATE_ITEM CreateItem;
27 PIO_STACK_LOCATION IoStack;
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}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_NO_SECURITY_ON_OBJECT
Definition: ntstatus.h:451
NTKERNELAPI NTSTATUS NTAPI SeQuerySecurityDescriptorInfo(_In_ PSECURITY_INFORMATION SecurityInformation, _Out_writes_bytes_(*Length) PSECURITY_DESCRIPTOR SecurityDescriptor, _Inout_ PULONG Length, _Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor)

◆ KsDispatchSetSecurity()

KSDDKAPI NTSTATUS NTAPI KsDispatchSetSecurity ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 67 of file irp.c.

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,
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}
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
PGENERIC_MAPPING NTAPI IoGetFileObjectGenericMapping(VOID)
Definition: file.c:3267
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
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)

◆ KsDispatchSpecificMethod()

KSDDKAPI NTSTATUS NTAPI KsDispatchSpecificMethod ( IN PIRP  Irp,
IN PFNKSHANDLER  Handler 
)

Definition at line 127 of file irp.c.

130{
132 return STATUS_UNSUCCESSFUL;
133}
#define UNIMPLEMENTED
Definition: debug.h:115
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ KsGetNodeIdFromIrp()

KSDDKAPI ULONG NTAPI KsGetNodeIdFromIrp ( IN PIRP  Irp)

Definition at line 2163 of file irp.c.

2165{
2167 return KSFILTER_NODE;
2168}
#define KSFILTER_NODE
Definition: ks.h:44

◆ KsMoveIrpsOnCancelableQueue()

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 at line 1492 of file irp.c.

1500{
1501 KIRQL OldLevel;
1502 PLIST_ENTRY SrcEntry;
1503 PIRP Irp;
1505
1506 if (!DestinationLock)
1507 {
1508 /* no destination lock just acquire the source lock */
1509 KeAcquireSpinLock(SourceLock, &OldLevel);
1510 }
1511 else
1512 {
1513 /* acquire cancel spinlock */
1514 IoAcquireCancelSpinLock(&OldLevel);
1515
1516 /* now acquire source lock */
1517 KeAcquireSpinLockAtDpcLevel(SourceLock);
1518
1519 /* now acquire destination lock */
1520 KeAcquireSpinLockAtDpcLevel(DestinationLock);
1521 }
1522
1523 /* point to list head */
1524 SrcEntry = SourceList;
1525
1526 /* now move all irps */
1527 while(TRUE)
1528 {
1529 if (ListLocation == KsListEntryTail)
1530 {
1531 /* move queue downwards */
1532 SrcEntry = SrcEntry->Flink;
1533 }
1534 else
1535 {
1536 /* move queue upwards */
1537 SrcEntry = SrcEntry->Blink;
1538 }
1539
1540 if (SrcEntry == SourceList)
1541 {
1542 /* eof list reached */
1543 break;
1544 }
1545
1546 /* get irp offset */
1547 Irp = (PIRP)CONTAINING_RECORD(SrcEntry, IRP, Tail.Overlay.ListEntry);
1548
1549 /* now check if irp can be moved */
1550 Status = ListCallback(Irp, Context);
1551
1552 /* check if irp can be moved */
1553 if (Status == STATUS_SUCCESS)
1554 {
1555 /* remove irp from src list */
1556 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1557
1558 if (ListLocation == KsListEntryTail)
1559 {
1560 /* insert irp end of list */
1561 InsertTailList(DestinationList, &Irp->Tail.Overlay.ListEntry);
1562 }
1563 else
1564 {
1565 /* insert irp head of list */
1566 InsertHeadList(DestinationList, &Irp->Tail.Overlay.ListEntry);
1567 }
1568
1569 /* do we need to update the irp lock */
1570 if (DestinationLock)
1571 {
1572 /* update irp lock */
1573 KSQUEUE_SPINLOCK_IRP_STORAGE(Irp) = DestinationLock;
1574 }
1575 }
1576 else
1577 {
1578 if (Status != STATUS_NO_MATCH)
1579 {
1580 /* callback decided to stop enumeration */
1581 break;
1582 }
1583
1584 /* reset return value */
1586 }
1587 }
1588
1589 if (!DestinationLock)
1590 {
1591 /* release source lock */
1592 KeReleaseSpinLock(SourceLock, OldLevel);
1593 }
1594 else
1595 {
1596 /* now release destination lock */
1597 KeReleaseSpinLockFromDpcLevel(DestinationLock);
1598
1599 /* now release source lock */
1601
1602
1603 /* now release cancel spinlock */
1604 IoReleaseCancelSpinLock(OldLevel);
1605 }
1606
1607 /* done */
1608 return Status;
1609}
#define STATUS_NO_MATCH
Definition: ntstatus.h:751
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
_In_ IN_ADDR _In_ IN_ADDR _Out_ MULTICAST_MODE_TYPE _Inout_ ULONG _Out_writes_ SourceCount IN_ADDR * SourceList
Definition: ws2tcpip.h:622

◆ KsNullDriverUnload()

KSDDKAPI VOID NTAPI KsNullDriverUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 1157 of file irp.c.

1159{
1160}

Referenced by DriverEntry(), KoDriverInitialize(), KsInitializeDriver(), and StreamClassRegisterAdapter().

◆ KspCreate()

NTSTATUS NTAPI KspCreate ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1859 of file irp.c.

1862{
1863 PCREATE_ITEM_ENTRY CreateItemEntry;
1864 PIO_STACK_LOCATION IoStack;
1865 PDEVICE_EXTENSION DeviceExtension;
1866 PKSIDEVICE_HEADER DeviceHeader;
1867 PKSIOBJECT_HEADER ObjectHeader;
1869
1870 DPRINT("KS / CREATE\n");
1871
1872 /* get current stack location */
1874 /* get device extension */
1875 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
1876 /* get device header */
1877 DeviceHeader = DeviceExtension->DeviceHeader;
1878
1879
1880 if (IoStack->FileObject->FileName.Buffer == NULL)
1881 {
1882 /* FIXME Pnp-Issue */
1883 DPRINT("Using reference string hack\n");
1884 Irp->IoStatus.Information = 0;
1885 /* set return status */
1886 Irp->IoStatus.Status = STATUS_SUCCESS;
1888 return STATUS_SUCCESS;
1889 }
1890
1891 if (IoStack->FileObject->RelatedFileObject != NULL)
1892 {
1893 /* request is to instantiate a pin / node / clock / allocator */
1894 ObjectHeader = (PKSIOBJECT_HEADER)IoStack->FileObject->RelatedFileObject->FsContext2;
1895
1896 /* sanity check */
1897 ASSERT(ObjectHeader);
1898
1899 /* find a matching a create item */
1900 Status = FindMatchingCreateItem(&ObjectHeader->ItemList,
1901 &IoStack->FileObject->FileName,
1902 &CreateItemEntry);
1903 }
1904 else
1905 {
1906 /* request to create a filter */
1907 Status = FindMatchingCreateItem(&DeviceHeader->ItemList,
1908 &IoStack->FileObject->FileName,
1909 &CreateItemEntry);
1910 }
1911
1912 if (NT_SUCCESS(Status))
1913 {
1914 /* set object create item */
1915 KSCREATE_ITEM_IRP_STORAGE(Irp) = CreateItemEntry->CreateItem;
1916
1917 /* call create function */
1918 Status = CreateItemEntry->CreateItem->Create(DeviceObject, Irp);
1919
1920 if (NT_SUCCESS(Status))
1921 {
1922 /* increment create item reference count */
1923 InterlockedIncrement(&CreateItemEntry->ReferenceCount);
1924 }
1925 return Status;
1926 }
1927
1928 Irp->IoStatus.Information = 0;
1929 /* set return status */
1930 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
1932 return STATUS_UNSUCCESSFUL;
1933}
#define InterlockedIncrement
Definition: armddk.h:53
NTSTATUS FindMatchingCreateItem(PLIST_ENTRY ListHead, PUNICODE_STRING String, OUT PCREATE_ITEM_ENTRY *OutCreateItem)
Definition: irp.c:1762
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
if(dx< 0)
Definition: linetemp.h:194
LONG ReferenceCount
Definition: kstypes.h:50
LIST_ENTRY ItemList
Definition: kstypes.h:94
LIST_ENTRY ItemList
Definition: kstypes.h:26
PFILE_OBJECT FileObject
Definition: iotypes.h:3169

Referenced by KsDispatchIrp(), and KsSetMajorFunctionHandler().

◆ KspDispatchIrp()

NTSTATUS NTAPI KspDispatchIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1937 of file irp.c.

1940{
1941 PIO_STACK_LOCATION IoStack;
1942 //PDEVICE_EXTENSION DeviceExtension;
1943 PKSIOBJECT_HEADER ObjectHeader;
1944 //PKSIDEVICE_HEADER DeviceHeader;
1947
1948 /* get current stack location */
1950
1951 /* get device extension */
1952 //DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
1953 /* get device header */
1954 //DeviceHeader = DeviceExtension->DeviceHeader;
1955
1956 ASSERT(IoStack->FileObject);
1957
1958 /* get object header */
1959 ObjectHeader = (PKSIOBJECT_HEADER) IoStack->FileObject->FsContext2;
1960
1961 if (!ObjectHeader)
1962 {
1963 /* FIXME Pnp-Issue*/
1964 Irp->IoStatus.Status = STATUS_SUCCESS;
1965 Irp->IoStatus.Information = 0;
1966 /* complete and forget */
1968 return STATUS_SUCCESS;
1969 }
1970
1971 /* sanity check */
1972 ASSERT(ObjectHeader);
1973 /* store create item */
1974 //KSCREATE_ITEM_IRP_STORAGE(Irp) = (PKSOBJECT_CREATE_ITEM)0x12345678; //ObjectHeader->CreateItem;
1975
1976 /* retrieve matching dispatch function */
1977 switch(IoStack->MajorFunction)
1978 {
1979 case IRP_MJ_CLOSE:
1980 Dispatch = ObjectHeader->DispatchTable.Close;
1981 break;
1983 Dispatch = ObjectHeader->DispatchTable.DeviceIoControl;
1984 break;
1985 case IRP_MJ_READ:
1986 Dispatch = ObjectHeader->DispatchTable.Read;
1987 break;
1988 case IRP_MJ_WRITE:
1989 Dispatch = ObjectHeader->DispatchTable.Write;
1990 break;
1992 Dispatch = ObjectHeader->DispatchTable.Flush;
1993 break;
1995 Dispatch = ObjectHeader->DispatchTable.QuerySecurity;
1996 break;
1998 Dispatch = ObjectHeader->DispatchTable.SetSecurity;
1999 break;
2000 case IRP_MJ_PNP:
2002 break;
2003 default:
2004 Dispatch = NULL;
2005 }
2006
2007 /* is the request supported */
2008 if (Dispatch)
2009 {
2010 /* now call the dispatch function */
2012 }
2013 else
2014 {
2015 /* not supported request */
2017 }
2018
2019 /* done */
2020 return Status;
2021}
KSDISPATCH_TABLE DispatchTable
Definition: kstypes.h:22
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH * Dispatch
Definition: wsk.h:188
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2262

Referenced by KsDispatchIrp(), and KsSetMajorFunctionHandler().

◆ KsProbeStreamIrp()

KSDDKAPI NTSTATUS NTAPI KsProbeStreamIrp ( IN PIRP  Irp,
IN ULONG  ProbeFlags,
IN ULONG  HeaderSize 
)

Definition at line 659 of file irp.c.

663{
664 PMDL Mdl;
668 PKSSTREAM_HEADER StreamHeader;
669 PIO_STACK_LOCATION IoStack;
671 //BOOLEAN AllocateMdl = FALSE;
672
673 /* get current irp stack */
675
676 Length = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
677
678 if (Irp->RequestorMode == KernelMode || Irp->AssociatedIrp.SystemBuffer)
679 {
680 if (Irp->RequestorMode == KernelMode)
681 {
682 /* no need to allocate stream header */
683 Irp->AssociatedIrp.SystemBuffer = Irp->UserBuffer;
684 }
685AllocMdl:
686 /* check if alloc mdl flag is passed */
687 if (!(ProbeFlags & KSPROBE_ALLOCATEMDL))
688 {
689 /* nothing more to do */
690 return STATUS_SUCCESS;
691 }
692 if (Irp->MdlAddress)
693 {
694ProbeMdl:
695 if (ProbeFlags & KSPROBE_PROBEANDLOCK)
696 {
697 if (Irp->MdlAddress->MdlFlags & (MDL_PAGES_LOCKED | MDL_SOURCE_IS_NONPAGED_POOL))
698 {
699 if (ProbeFlags & KSPROBE_SYSTEMADDRESS)
700 {
702 {
703 /* loop through all mdls and probe them */
704 Mdl = Irp->MdlAddress;
705 do
706 {
707 /* the mapping can fail */
708 Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
709
711 {
712 /* no need to probe these pages */
713 Buffer = Mdl->MappedSystemVa;
714 }
715 else
716 {
717 /* probe that mdl */
719 }
720
721 /* check if the mapping succeeded */
722 if (!Buffer)
723 {
724 /* raise exception we'll catch */
726 }
727
728 /* iterate to next mdl */
729 Mdl = Mdl->Next;
730
731 }while(Mdl);
732 }
734 {
735 /* Exception, get the error code */
737 } _SEH2_END;
738 }
739 }
740 else
741 {
743 {
744 /* loop through all mdls and probe them */
745 Mdl = Irp->MdlAddress;
746
747 /* determine operation */
748 if (!(ProbeFlags & KSPROBE_STREAMWRITE) || (ProbeFlags & KSPROBE_MODIFY))
749 {
750 /* operation is read / modify stream, need write access */
752 }
753 else
754 {
755 /* operation is write to device, so we need read access */
757 }
758
759 do
760 {
761 /* probe the pages */
762 MmProbeAndLockPages(Mdl, Irp->RequestorMode, Operation);
763
764 if (ProbeFlags & KSPROBE_SYSTEMADDRESS)
765 {
766 /* the mapping can fail */
767 Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
768
770 {
771 /* no need to probe these pages */
772 Buffer = Mdl->MappedSystemVa;
773 }
774 else
775 {
776 /* probe that mdl */
778 }
779
780 /* check if the mapping succeeded */
781 if (!Buffer)
782 {
783 /* raise exception we'll catch */
785 }
786 }
787
788 /* iterate to next mdl */
789 Mdl = Mdl->Next;
790
791 }while(Mdl);
792 }
794 {
795 /* Exception, get the error code */
797 } _SEH2_END;
798 }
799 }
800 return Status;
801 }
802
803 /* check all stream headers */
804 StreamHeader = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;
805 ASSERT(StreamHeader);
807 {
808 do
809 {
810 if (HeaderSize)
811 {
812 /* does the supplied header size match stream header size and no type changed */
813 if (StreamHeader->Size != HeaderSize && !(StreamHeader->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_TYPECHANGED))
814 {
815 /* invalid stream header */
817 }
818 }
819 else
820 {
821 /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
822 if (StreamHeader->Size < sizeof(KSSTREAM_HEADER) || (StreamHeader->Size & 7))
823 {
824 /* invalid stream header */
826 }
827 }
828
829 if (Length < StreamHeader->Size)
830 {
831 /* length is too short */
833 }
834
835 if (ProbeFlags & KSPROBE_STREAMWRITE)
836 {
837 if (StreamHeader->DataUsed > StreamHeader->FrameExtent)
838 {
839 /* frame extend can never be smaller */
841 }
842
843 /* is this stream change packet */
845 {
846 if (Length != sizeof(KSSTREAM_HEADER) || (PVOID)StreamHeader != Irp->AssociatedIrp.SystemBuffer)
847 {
848 /* stream changed - must be send in a single packet */
850 }
851
852 if (!(ProbeFlags & KSPROBE_ALLOWFORMATCHANGE))
853 {
854 /* caller does not permit format changes */
856 }
857
858 if (StreamHeader->FrameExtent)
859 {
860 /* allocate an mdl */
861 Mdl = IoAllocateMdl(StreamHeader->Data, StreamHeader->FrameExtent, FALSE, TRUE, Irp);
862
863 if (!Mdl)
864 {
865 /* not enough memory */
867 }
868
869 /* break-out to probe for the irp */
870 break;
871 }
872 }
873 }
874 else
875 {
876 if (StreamHeader->DataUsed)
877 {
878 /* DataUsed must be zero for stream read operation */
880 }
881
882 if (StreamHeader->OptionsFlags)
883 {
884 /* no flags supported for reading */
886 }
887 }
888
889 if (StreamHeader->FrameExtent)
890 {
891 /* allocate an mdl */
892 ASSERT(Irp->MdlAddress == NULL);
893 Mdl = IoAllocateMdl(StreamHeader->Data, StreamHeader->FrameExtent, FALSE, TRUE, Irp);
894 if (!Mdl)
895 {
896 /* not enough memory */
898 }
899 }
900
901 /* move to next stream header */
902 Length -= StreamHeader->Size;
903 StreamHeader = (PKSSTREAM_HEADER)((ULONG_PTR)StreamHeader + StreamHeader->Size);
904 }while(Length);
905 }
907 {
908 /* Exception, get the error code */
910 }_SEH2_END;
911
912 /* now probe the allocated mdl's */
913 if (!NT_SUCCESS(Status))
914 {
915 DPRINT("Status %x\n", Status);
916 return Status;
917 }
918 else
919 goto ProbeMdl;
920 }
921
922 /* probe user mode buffers */
923 if (Length && ( (!HeaderSize) || (Length % HeaderSize == 0) || ((ProbeFlags & KSPROBE_ALLOWFORMATCHANGE) && (Length == sizeof(KSSTREAM_HEADER))) ) )
924 {
925 /* allocate stream header buffer */
926 Irp->AssociatedIrp.SystemBuffer = AllocateItem(NonPagedPool, Length);
927
928 if (!Irp->AssociatedIrp.SystemBuffer)
929 {
930 /* no memory */
932 }
933
934 /* mark irp as buffered so that changes the stream headers are propagated back */
936
938 {
939 if (ProbeFlags & KSPROBE_STREAMWRITE)
940 {
941 if (ProbeFlags & KSPROBE_MODIFY)
942 ProbeForWrite(Irp->UserBuffer, Length, sizeof(UCHAR));
943 else
944 ProbeForRead(Irp->UserBuffer, Length, sizeof(UCHAR));
945 }
946 else
947 {
948 /* stream reads means writing */
949 ProbeForWrite(Irp->UserBuffer, Length, sizeof(UCHAR));
950
951 /* set input operation flags */
952 Irp->Flags |= IRP_INPUT_OPERATION;
953 }
954
955 /* copy stream buffer */
956 RtlMoveMemory(Irp->AssociatedIrp.SystemBuffer, Irp->UserBuffer, Length);
957 }
959 {
960 /* Exception, get the error code */
962 }_SEH2_END;
963
964 if (!NT_SUCCESS(Status))
965 {
966 /* failed */
967 return Status;
968 }
969
970 if (ProbeFlags & KSPROBE_ALLOCATEMDL)
971 {
972 /* alloc mdls */
973 goto AllocMdl;
974 }
975
976 /* check all stream headers */
977 StreamHeader = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;
978
980 {
981 do
982 {
983 if (HeaderSize)
984 {
985 /* does the supplied header size match stream header size and no type changed */
986 if (StreamHeader->Size != HeaderSize && !(StreamHeader->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_TYPECHANGED))
987 {
988 /* invalid stream header */
990 }
991 }
992 else
993 {
994 /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
995 if (StreamHeader->Size < sizeof(KSSTREAM_HEADER) || (StreamHeader->Size & 7))
996 {
997 /* invalid stream header */
999 }
1000 }
1001
1002 if (Length < StreamHeader->Size)
1003 {
1004 /* length is too short */
1006 }
1007
1008 if (ProbeFlags & KSPROBE_STREAMWRITE)
1009 {
1010 if (StreamHeader->DataUsed > StreamHeader->FrameExtent)
1011 {
1012 /* frame extend can never be smaller */
1014 }
1015
1016 /* is this stream change packet */
1018 {
1019 if (Length != sizeof(KSSTREAM_HEADER) || (PVOID)StreamHeader != Irp->AssociatedIrp.SystemBuffer)
1020 {
1021 /* stream changed - must be send in a single packet */
1023 }
1024
1025 if (!(ProbeFlags & KSPROBE_ALLOWFORMATCHANGE))
1026 {
1027 /* caller does not permit format changes */
1029 }
1030
1031 if (StreamHeader->FrameExtent)
1032 {
1033 /* allocate an mdl */
1034 Mdl = IoAllocateMdl(StreamHeader->Data, StreamHeader->FrameExtent, FALSE, TRUE, Irp);
1035
1036 if (!Mdl)
1037 {
1038 /* not enough memory */
1040 }
1041
1042 /* break out to probe for the irp */
1043 //AllocateMdl = TRUE;
1044 break;
1045 }
1046 }
1047 }
1048 else
1049 {
1050 if (StreamHeader->DataUsed)
1051 {
1052 /* DataUsed must be zero for stream read operation */
1054 }
1055
1056 if (StreamHeader->OptionsFlags)
1057 {
1058 /* no flags supported for reading */
1060 }
1061 }
1062
1063 /* move to next stream header */
1064 Length -= StreamHeader->Size;
1065 StreamHeader = (PKSSTREAM_HEADER)((ULONG_PTR)StreamHeader + StreamHeader->Size);
1066 }while(Length);
1067
1069 {
1070 /* Exception, get the error code */
1072 }_SEH2_END;
1073
1074 /* now probe the allocated mdl's */
1075 if (NT_SUCCESS(Status))
1076 goto AllocMdl;
1077 else
1078 return Status;
1079 }
1080
1082}
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
FP_OP Operation
Definition: fpcontrol.c:150
#define IoAllocateMdl
Definition: fxmdl.h:88
#define KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
Definition: ks.h:2752
PVOID NTAPI MmMapLockedPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode)
Definition: mdlsup.c:818
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
#define KernelMode
Definition: asm.h:34
#define ExRaiseStatus
Definition: ntoskrnl.h:114
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
ULONG FrameExtent
Definition: ks.h:2740
ULONG Size
Definition: ks.h:2736
PVOID Data
Definition: ks.h:2742
ULONG DataUsed
Definition: ks.h:2741
ULONG OptionsFlags
Definition: ks.h:2743
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define IRP_DEALLOCATE_BUFFER
#define IRP_INPUT_OPERATION
#define IRP_BUFFERED_IO
enum _LOCK_OPERATION LOCK_OPERATION
@ IoReadAccess
Definition: ketypes.h:863
@ IoWriteAccess
Definition: ketypes.h:864
#define MDL_MAPPING_CAN_FAIL
Definition: mmtypes.h:31
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by IKsPin_DispatchKsStream(), and WdmAudReadWrite().

◆ KsQueryInformationFile()

KSDDKAPI NTSTATUS NTAPI KsQueryInformationFile ( IN PFILE_OBJECT  FileObject,
OUT PVOID  FileInformation,
IN ULONG  Length,
IN FILE_INFORMATION_CLASS  FileInformationClass 
)

Definition at line 342 of file irp.c.

347{
350 PIRP Irp;
351 PIO_STACK_LOCATION IoStack;
356
357 /* get related file object */
359
360 /* get fast i/o table */
361 FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
362
363 /* is there a fast table */
364 if (FastIoDispatch)
365 {
366 /* check the class */
368 {
369 /* use FastIoQueryBasicInfo routine */
373 TRUE,
377 {
378 /* request was handled */
379 return IoStatusBlock.Status;
380 }
381 }
383 {
384 /* use FastIoQueryStandardInfo routine */
388 TRUE,
392 {
393 /* request was handled */
394 return IoStatusBlock.Status;
395 }
396 }
397 }
398
399 /* clear event */
400 KeClearEvent(&FileObject->Event);
401
402 /* initialize event */
404
405 /* set offset to zero */
406 Offset.QuadPart = 0L;
407
408 /* build the request */
410 if (!Irp)
412
413 /* get next stack location */
415
416 /* setup parameters */
417 IoStack->Parameters.QueryFile.FileInformationClass = FileInformationClass;
418 IoStack->Parameters.QueryFile.Length = Length;
419 Irp->AssociatedIrp.SystemBuffer = FileInformation;
420
421
422 /* call the driver */
424
425 if (Status == STATUS_PENDING)
426 {
427 /* wait for the operation to complete */
429
430 /* is object sync */
431 if (FileObject->Flags & FO_SYNCHRONOUS_IO)
432 Status = FileObject->FinalStatus;
433 else
435 }
436
437 /* done */
438 return Status;
439}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
@ FileBasicInformation
Definition: from_kernel.h:65
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
@ NotificationEvent
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
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
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
#define FileStandardInformation
Definition: propsheet.cpp:61
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo
Definition: iotypes.h:1738
PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo
Definition: iotypes.h:1737
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
@ Executive
Definition: ketypes.h:415

◆ KsReadFile()

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 at line 142 of file irp.c.

151{
153 PIRP Irp;
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 */
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 */
230 }
231 }
232 /* return result */
233 return Status;
234}
unsigned char BOOLEAN
#define ExGetPreviousMode
Definition: ex.h:140
#define UserMode
Definition: asm.h:35
_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:409

◆ KsReleaseIrpOnCancelableQueue()

KSDDKAPI VOID NTAPI KsReleaseIrpOnCancelableQueue ( IN PIRP  Irp,
IN PDRIVER_CANCEL DriverCancel  OPTIONAL 
)

Definition at line 1332 of file irp.c.

1335{
1337 PDRIVER_CANCEL OldDriverCancel;
1338 PIO_STACK_LOCATION IoStack;
1339 KIRQL OldLevel;
1340
1341 /* check for required parameters */
1342 if (!Irp)
1343 return;
1344
1345 if (!DriverCancel)
1346 {
1347 /* default to KsCancelRoutine */
1348 DriverCancel = KsCancelRoutine;
1349 }
1350
1351 /* get current irp stack */
1353
1354 /* get internal queue lock */
1355 SpinLock = KSQUEUE_SPINLOCK_IRP_STORAGE(Irp);
1356
1357 /* acquire spinlock */
1358 KeAcquireSpinLock(SpinLock, &OldLevel);
1359
1360 /* now set the cancel routine */
1361 OldDriverCancel = IoSetCancelRoutine(Irp, DriverCancel);
1362
1363 if (Irp->Cancel && OldDriverCancel == NULL)
1364 {
1365 /* the irp has already been canceled */
1366 KeReleaseSpinLock(SpinLock, OldLevel);
1367
1368 /* cancel routine requires that cancel spinlock is held */
1369 IoAcquireCancelSpinLock(&Irp->CancelIrql);
1370
1371 /* cancel irp */
1372 DriverCancel(IoStack->DeviceObject, Irp);
1373 }
1374 else
1375 {
1376 /* done */
1377 KeReleaseSpinLock(SpinLock, OldLevel);
1378 }
1379}

◆ KsRemoveIrpFromCancelableQueue()

KSDDKAPI PIRP NTAPI KsRemoveIrpFromCancelableQueue ( IN OUT PLIST_ENTRY  QueueHead,
IN PKSPIN_LOCK  SpinLock,
IN KSLIST_ENTRY_LOCATION  ListLocation,
IN KSIRP_REMOVAL_OPERATION  RemovalOperation 
)

Definition at line 1387 of file irp.c.

1392{
1393 PIRP Irp;
1394 PLIST_ENTRY CurEntry;
1395 KIRQL OldIrql;
1396
1397 DPRINT("KsRemoveIrpFromCancelableQueue ListHead %p SpinLock %p ListLocation %x RemovalOperation %x\n", QueueHead, SpinLock, ListLocation, RemovalOperation);
1398
1399 /* check parameters */
1400 if (!QueueHead || !SpinLock)
1401 return NULL;
1402
1403 /* check if parameter ListLocation is valid */
1404 if (ListLocation != KsListEntryTail && ListLocation != KsListEntryHead)
1405 return NULL;
1406
1407 /* acquire list lock */
1409
1410 /* point to queue head */
1411 CurEntry = QueueHead;
1412
1413 do
1414 {
1415 /* reset irp to null */
1416 Irp = NULL;
1417
1418 /* iterate to next entry */
1419 if (ListLocation == KsListEntryHead)
1420 CurEntry = CurEntry->Flink;
1421 else
1422 CurEntry = CurEntry->Blink;
1423
1424 /* is the end of list reached */
1425 if (CurEntry == QueueHead)
1426 {
1427 /* reached end of list */
1428 break;
1429 }
1430
1431 /* get irp offset */
1432 Irp = (PIRP)CONTAINING_RECORD(CurEntry, IRP, Tail.Overlay.ListEntry);
1433
1434 if (Irp->Cancel)
1435 {
1436 /* irp has been canceled */
1437 break;
1438 }
1439
1440 if (Irp->CancelRoutine)
1441 {
1442 /* remove cancel routine */
1443 Irp->CancelRoutine = NULL;
1444
1445 if (RemovalOperation == KsAcquireAndRemove || RemovalOperation == KsAcquireAndRemoveOnlySingleItem)
1446 {
1447 /* remove irp from list */
1448 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1449 }
1450
1451 if (RemovalOperation == KsAcquireAndRemoveOnlySingleItem || RemovalOperation == KsAcquireOnlySingleItem)
1452 break;
1453 }
1454
1455 }while(TRUE);
1456
1457 /* release lock */
1459
1460 if (!Irp || Irp->CancelRoutine == NULL)
1461 {
1462 /* either an irp has been acquired or nothing found */
1463 return Irp;
1464 }
1465
1466 /* time to remove the canceled irp */
1468 /* acquire list lock */
1470
1471 if (RemovalOperation == KsAcquireAndRemove || RemovalOperation == KsAcquireAndRemoveOnlySingleItem)
1472 {
1473 /* remove it */
1474 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1475 }
1476
1477 /* release list lock */
1479
1480 /* release cancel spinlock */
1482 /* no non canceled irp has been found */
1483 return NULL;
1484}
@ KsListEntryHead
Definition: ks.h:1263
@ KsAcquireOnlySingleItem
Definition: ks.h:1275
@ KsAcquireAndRemove
Definition: ks.h:1274
@ KsAcquireAndRemoveOnlySingleItem
Definition: ks.h:1276
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792

Referenced by IKsPin_PrepareStreamHeader().

◆ KsRemoveSpecificIrpFromCancelableQueue()

KSDDKAPI VOID NTAPI KsRemoveSpecificIrpFromCancelableQueue ( IN PIRP  Irp)

Definition at line 1617 of file irp.c.

1619{
1621 KIRQL OldLevel;
1622
1623 DPRINT("KsRemoveSpecificIrpFromCancelableQueue %p\n", Irp);
1624
1625 /* get internal queue lock */
1626 SpinLock = KSQUEUE_SPINLOCK_IRP_STORAGE(Irp);
1627
1628 /* acquire spinlock */
1629 KeAcquireSpinLock(SpinLock, &OldLevel);
1630
1631 /* remove the irp from the list */
1632 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
1633
1634 /* release spinlock */
1635 KeReleaseSpinLock(SpinLock, OldLevel);
1636}

◆ KsSetInformationFile()

KSDDKAPI NTSTATUS NTAPI KsSetInformationFile ( IN PFILE_OBJECT  FileObject,
IN PVOID  FileInformation,
IN ULONG  Length,
IN FILE_INFORMATION_CLASS  FileInformationClass 
)

Definition at line 447 of file irp.c.

452{
453 PIO_STACK_LOCATION IoStack;
455 PIRP Irp;
461
462 /* get related device object */
464
465 /* copy file information */
467 if (!Buffer)
469
471 {
472 ProbeForRead(Buffer, Length, sizeof(UCHAR));
475 }
477 {
478 /* Exception, get the error code */
480 }
481 _SEH2_END;
482
483 if (!NT_SUCCESS(Status))
484 {
485 /* invalid user buffer */
487 return Status;
488 }
489
490 /* initialize the event */
492
493 /* zero offset */
494 Offset.QuadPart = 0LL;
495
496 /* build the irp */
498 if (!Irp)
499 {
500 /* failed to allocate irp */
503 }
504
505 /* get next stack location */
507
508 /* set irp parameters */
509 IoStack->Parameters.SetFile.FileInformationClass = FileInformationClass;
510 IoStack->Parameters.SetFile.Length = Length;
511 IoStack->Parameters.SetFile.FileObject = FileObject;
512 Irp->AssociatedIrp.SystemBuffer = Buffer;
513 Irp->UserBuffer = FileInformation;
514
515 /* dispatch the irp */
517
518 if (Status == STATUS_PENDING)
519 {
520 /* wait untill the operation has completed */
522 /* is a sync file object */
523 if (FileObject->Flags & FO_SYNCHRONOUS_IO)
524 Status = FileObject->FinalStatus;
525 else
526 Status = IoStatus.Status;
527 }
528 /* done */
529 return Status;
530}
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
@ SynchronizationEvent
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define LL
Definition: tui.h:150

◆ KsSetMajorFunctionHandler()

KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler ( IN PDRIVER_OBJECT  DriverObject,
IN ULONG  MajorFunction 
)

Definition at line 2029 of file irp.c.

2032{
2033 DPRINT("KsSetMajorFunctionHandler Function %x\n", MajorFunction);
2034
2035 switch ( MajorFunction )
2036 {
2037 case IRP_MJ_CREATE:
2038 DriverObject->MajorFunction[MajorFunction] = KspCreate;
2039 break;
2041 case IRP_MJ_CLOSE:
2042 case IRP_MJ_READ:
2043 case IRP_MJ_WRITE:
2047 DriverObject->MajorFunction[MajorFunction] = KspDispatchIrp;
2048 break;
2049 default:
2050 DPRINT1("NotSupported %x\n", MajorFunction);
2052 };
2053
2054 return STATUS_SUCCESS;
2055}
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

Referenced by DriverEntry(), KoDriverInitialize(), KsInitializeDriver(), PcInitializeAdapterDriver(), and StreamClassRegisterAdapter().

◆ KsStreamIo()

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 at line 538 of file irp.c.

550{
551 PIRP Irp;
552 PIO_STACK_LOCATION IoStack;
556 PKSIOBJECT_HEADER ObjectHeader;
557 BOOLEAN Ret;
558
559 /* get related device object */
561 /* sanity check */
563
564 /* is there a event provided */
565 if (Event)
566 {
567 /* reset event */
569 }
570
571 if (RequestorMode || ExGetPreviousMode() == KernelMode)
572 {
573 /* requestor is from kernel land */
574 ObjectHeader = (PKSIOBJECT_HEADER)FileObject->FsContext2;
575
576 if (ObjectHeader)
577 {
578 /* there is a object header */
579 if (Flags == KSSTREAM_READ)
580 {
581 /* is fast read supported */
582 if (ObjectHeader->DispatchTable.FastRead)
583 {
584 /* call fast read dispatch routine */
585 Ret = ObjectHeader->DispatchTable.FastRead(FileObject, NULL, Length, FALSE, 0, StreamHeaders, IoStatusBlock, DeviceObject);
586
587 if (Ret)
588 {
589 /* the request was handled */
590 return IoStatusBlock->Status;
591 }
592 }
593 }
594 else if (Flags == KSSTREAM_WRITE)
595 {
596 /* is fast write supported */
597 if (ObjectHeader->DispatchTable.FastWrite)
598 {
599 /* call fast write dispatch routine */
600 Ret = ObjectHeader->DispatchTable.FastWrite(FileObject, NULL, Length, FALSE, 0, StreamHeaders, IoStatusBlock, DeviceObject);
601
602 if (Ret)
603 {
604 /* the request was handled */
605 return IoStatusBlock->Status;
606 }
607 }
608 }
609 }
610 }
611
612 /* clear file object event */
613 KeClearEvent(&FileObject->Event);
614
615 /* set the offset to zero */
616 Offset.QuadPart = 0LL;
617
618 /* now build the irp */
620 DeviceObject, (PVOID)StreamHeaders, Length, &Offset, Event, IoStatusBlock);
621 if (!Irp)
622 {
623 /* not enough memory */
625 }
626
627 /* setup irp parameters */
628 Irp->RequestorMode = RequestorMode;
629 Irp->Overlay.AsynchronousParameters.UserApcContext = PortContext;
630 Irp->Tail.Overlay.OriginalFileObject = FileObject;
631 Irp->UserBuffer = StreamHeaders;
632
633 /* get next irp stack location */
635 /* setup stack parameters */
636 IoStack->FileObject = FileObject;
637 IoStack->Parameters.DeviceIoControl.InputBufferLength = Length;
638 IoStack->Parameters.DeviceIoControl.Type3InputBuffer = StreamHeaders;
639 IoStack->Parameters.DeviceIoControl.IoControlCode = (Flags == KSSTREAM_READ ? IOCTL_KS_READ_STREAM : IOCTL_KS_WRITE_STREAM);
640
642 {
643 /* setup completion routine for async processing */
644 IoSetCompletionRoutine(Irp, CompletionRoutine, CompletionContext, (CompletionInvocationFlags & KsInvokeOnSuccess), (CompletionInvocationFlags & KsInvokeOnError), (CompletionInvocationFlags & KsInvokeOnCancel));
645 }
646
647 /* now call the driver */
649 /* done */
650 return Status;
651}
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
@ KsInvokeOnSuccess
Definition: ks.h:1280
@ KsInvokeOnCancel
Definition: ks.h:1282
@ KsInvokeOnError
Definition: ks.h:1281
#define IOCTL_KS_READ_STREAM
Definition: ks.h:142
#define IOCTL_KS_WRITE_STREAM
Definition: ks.h:139
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE _In_opt_ __drv_aliasesMem WDFCONTEXT CompletionContext
Definition: wdfrequest.h:898
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ KsWriteFile()

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 at line 242 of file irp.c.

251{
253 PIRP Irp;
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 */
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 */
330 }
331 }
332 /* return result */
333 return Status;
334}