ReactOS  0.4.14-dev-384-g5b37caa
csqtest.c File Reference
#include <ntddk.h>
#include <csq.h>
Include dependency graph for csqtest.c:

Go to the source code of this file.

Macros

#define assert(x)
 
#define KdPrint(x)   DbgPrint x
 
#define NT_DEVICE_NAME   L"\\Device\\csqtest"
 
#define DOS_DEVICE_NAME   L"\\??\\csqtest"
 

Functions

VOID NTAPI CsqInsertIrp (PIO_CSQ Csq, PIRP Irp)
 
VOID NTAPI CsqRemoveIrp (PIO_CSQ Csq, PIRP Irp)
 
PIRP NTAPI CsqPeekNextIrp (PIO_CSQ Csq, PIRP Irp, PVOID PeekContext)
 
VOID NTAPI CsqAcquireLock (PIO_CSQ Csq, PKIRQL Irql)
 
VOID NTAPI CsqReleaseLock (PIO_CSQ Csq, KIRQL Irql)
 
VOID NTAPI CsqCompleteCancelledIrp (PIO_CSQ Csq, PIRP Irp)
 
NTSTATUS NTAPI CsqInsertIrpEx (PIO_CSQ Csq, PIRP Irp, PVOID InsertContext)
 
NTSTATUS NTAPI DispatchCreateCloseCleanup (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI DispatchReadWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI DispatchIoctl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID NTAPI Unload (PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 

Variables

IO_CSQ Csq
 
LIST_ENTRY IrpQueue
 
KSPIN_LOCK IrpQueueLock
 
PDEVICE_OBJECT DeviceObject
 

Macro Definition Documentation

◆ assert

#define assert (   x)

Definition at line 13 of file csqtest.c.

◆ DOS_DEVICE_NAME

#define DOS_DEVICE_NAME   L"\\??\\csqtest"

Definition at line 22 of file csqtest.c.

◆ KdPrint

#define KdPrint (   x)    DbgPrint x

Definition at line 15 of file csqtest.c.

◆ NT_DEVICE_NAME

#define NT_DEVICE_NAME   L"\\Device\\csqtest"

Definition at line 19 of file csqtest.c.

Function Documentation

◆ CsqAcquireLock()

VOID NTAPI CsqAcquireLock ( PIO_CSQ  Csq,
PKIRQL  Irql 
)

Definition at line 62 of file csqtest.c.

63 {
64  KdPrint(("Acquiring spin lock\n"));
66 }
_Out_ PKIRQL Irql
Definition: csq.h:179
#define KdPrint(x)
Definition: csqtest.c:15
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KSPIN_LOCK IrpQueueLock
Definition: csqtest.c:29

Referenced by DriverEntry().

◆ CsqCompleteCancelledIrp()

VOID NTAPI CsqCompleteCancelledIrp ( PIO_CSQ  Csq,
PIRP  Irp 
)

Definition at line 74 of file csqtest.c.

75 {
76  KdPrint(("cancelling irp 0x%x\n", Irp));
77  Irp->IoStatus.Status = STATUS_CANCELLED;
78  Irp->IoStatus.Information = 0;
80 }
_In_ PIRP Irp
Definition: csq.h:116
#define KdPrint(x)
Definition: csqtest.c:15
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by DriverEntry().

◆ CsqInsertIrp()

VOID NTAPI CsqInsertIrp ( PIO_CSQ  Csq,
PIRP  Irp 
)

Definition at line 37 of file csqtest.c.

38 {
39  KdPrint(("Inserting IRP 0x%x into CSQ\n", Irp));
40  InsertTailList(&IrpQueue, &Irp->Tail.Overlay.ListEntry);
41 }
LIST_ENTRY IrpQueue
Definition: csqtest.c:28
_In_ PIRP Irp
Definition: csq.h:116
#define InsertTailList(ListHead, Entry)
#define KdPrint(x)
Definition: csqtest.c:15

Referenced by CsqInsertIrpEx(), and DriverEntry().

◆ CsqInsertIrpEx()

NTSTATUS NTAPI CsqInsertIrpEx ( PIO_CSQ  Csq,
PIRP  Irp,
PVOID  InsertContext 
)

Definition at line 82 of file csqtest.c.

88 {
90  return STATUS_PENDING;
91 }
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI CsqInsertIrp(PIO_CSQ Csq, PIRP Irp)
Definition: csqtest.c:37
IO_CSQ Csq
Definition: csqtest.c:25
#define STATUS_PENDING
Definition: ntstatus.h:82

Referenced by IoCsqInitializeEx().

◆ CsqPeekNextIrp()

PIRP NTAPI CsqPeekNextIrp ( PIO_CSQ  Csq,
PIRP  Irp,
PVOID  PeekContext 
)

Definition at line 49 of file csqtest.c.

50 {
51  KdPrint(("Peeking for next IRP\n"));
52 
53  if(Irp)
54  return CONTAINING_RECORD(&Irp->Tail.Overlay.ListEntry.Flink, IRP, Tail.Overlay.ListEntry);
55 
56  if(IsListEmpty(&IrpQueue))
57  return NULL;
58 
59  return CONTAINING_RECORD(IrpQueue.Flink, IRP, Tail.Overlay.ListEntry);
60 }
LIST_ENTRY IrpQueue
Definition: csqtest.c:28
_In_ PIRP Irp
Definition: csq.h:116
IRP
Definition: iotypes.h:2463
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define KdPrint(x)
Definition: csqtest.c:15
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119

Referenced by DriverEntry().

◆ CsqReleaseLock()

VOID NTAPI CsqReleaseLock ( PIO_CSQ  Csq,
KIRQL  Irql 
)

Definition at line 68 of file csqtest.c.

69 {
70  KdPrint(("Releasing spin lock\n"));
72 }
_Out_ PKIRQL Irql
Definition: csq.h:179
#define KdPrint(x)
Definition: csqtest.c:15
KSPIN_LOCK IrpQueueLock
Definition: csqtest.c:29
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by DriverEntry().

◆ CsqRemoveIrp()

VOID NTAPI CsqRemoveIrp ( PIO_CSQ  Csq,
PIRP  Irp 
)

Definition at line 43 of file csqtest.c.

44 {
45  KdPrint(("Removing IRP 0x%x from CSQ\n", Irp));
46  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
47 }
_In_ PIRP Irp
Definition: csq.h:116
#define KdPrint(x)
Definition: csqtest.c:15
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105

Referenced by DriverEntry().

◆ DispatchCreateCloseCleanup()

NTSTATUS NTAPI DispatchCreateCloseCleanup ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 97 of file csqtest.c.

98 {
100 
101  if(StackLocation->MajorFunction == IRP_MJ_CLEANUP)
102  {
103  /* flush the irp queue */
104  PIRP CurrentIrp;
105 
106  KdPrint(("csqtest: Cleanup received; flushing the IRP queue with cancel\n"));
107 
108  while((CurrentIrp = IoCsqRemoveNextIrp(&Csq, 0)))
109  {
110  CurrentIrp->IoStatus.Status = STATUS_CANCELLED;
111  CurrentIrp->IoStatus.Information = 0;
112 
113  IoCompleteRequest(CurrentIrp, IO_NO_INCREMENT);
114  }
115  }
116 
117  Irp->IoStatus.Status = STATUS_SUCCESS;
118  Irp->IoStatus.Information = 0;
119 
121 
122  return STATUS_SUCCESS;
123 }
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
_In_ PIRP Irp
Definition: csq.h:116
#define KdPrint(x)
Definition: csqtest.c:15
#define IoCompleteRequest
Definition: irp.c:1240
IO_CSQ Csq
Definition: csqtest.c:25
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IRP_MJ_CLEANUP
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ DispatchIoctl()

NTSTATUS NTAPI DispatchIoctl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 135 of file csqtest.c.

139 {
140  PIRP CurrentIrp;
141 
142  KdPrint(("csqtest: Ioctl received; flushing the IRP queue with success\n"));
143 
144  while((CurrentIrp = IoCsqRemoveNextIrp(&Csq, 0)))
145  {
146  CurrentIrp->IoStatus.Status = STATUS_SUCCESS;
147  CurrentIrp->IoStatus.Information = 0;
148 
149  IoCompleteRequest(CurrentIrp, IO_NO_INCREMENT);
150  }
151 
152  Irp->IoStatus.Status = STATUS_SUCCESS;
153  Irp->IoStatus.Information = 0;
154 
156 
157  return STATUS_SUCCESS;
158 }
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
_In_ PIRP Irp
Definition: csq.h:116
#define KdPrint(x)
Definition: csqtest.c:15
#define IoCompleteRequest
Definition: irp.c:1240
IO_CSQ Csq
Definition: csqtest.c:25
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ DispatchReadWrite()

NTSTATUS NTAPI DispatchReadWrite ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 125 of file csqtest.c.

126 {
127  /* According to the cancel sample in the DDK, IoCsqInsertIrp() marks the irp pending */
128  /* However, I think it's wrong. */
130  IoCsqInsertIrp(&Csq, Irp, 0);
131 
132  return STATUS_PENDING;
133 }
_In_ PIRP Irp
Definition: csq.h:116
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
IO_CSQ Csq
Definition: csqtest.c:25
#define STATUS_PENDING
Definition: ntstatus.h:82
IoMarkIrpPending(Irp)

Referenced by DriverEntry().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 179 of file csqtest.c.

180 {
182  UNICODE_STRING NtName;
184 
192 
195 
196  if(Status != STATUS_SUCCESS)
197  KdPrint(("csqtest: IoCsqInitialize failed: 0x%x\n", Status));
198  else
199  KdPrint(("csqtest: IoCsqInitialize succeeded\n"));
200 
203 
204  /* Set up a device */
207 
208  if(!NT_SUCCESS(Status))
209  {
210  KdPrint(("csqtest: Unable to create device: 0x%x\n", Status));
211  return Status;
212  }
213 
215  Status = IoCreateSymbolicLink(&DosName, &NtName);
216 
217  if(!NT_SUCCESS(Status))
218  {
219  KdPrint(("csqtest: Unable to create link: 0x%x\n", Status));
220  return Status;
221  }
222 
224 
225  return STATUS_SUCCESS;
226 }
VOID NTAPI CsqAcquireLock(PIO_CSQ Csq, PKIRQL Irql)
Definition: csqtest.c:62
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
LIST_ENTRY IrpQueue
Definition: csqtest.c:28
PDEVICE_OBJECT DeviceObject
Definition: csqtest.c:32
VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: csqtest.c:160
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CsqInsertIrp(PIO_CSQ Csq, PIRP Irp)
Definition: csqtest.c:37
#define KdPrint(x)
Definition: csqtest.c:15
VOID NTAPI CsqRemoveIrp(PIO_CSQ Csq, PIRP Irp)
Definition: csqtest.c:43
NTSTATUS NTAPI DispatchIoctl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: csqtest.c:135
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
VOID NTAPI CsqCompleteCancelledIrp(PIO_CSQ Csq, PIRP Irp)
Definition: csqtest.c:74
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
IO_CSQ Csq
Definition: csqtest.c:25
NTSTATUS NTAPI DispatchCreateCloseCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: csqtest.c:97
NTSTATUS NTAPI DispatchReadWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: csqtest.c:125
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define NT_DEVICE_NAME
Definition: csqtest.c:19
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
VOID NTAPI CsqReleaseLock(PIO_CSQ Csq, KIRQL Irql)
Definition: csqtest.c:68
KSPIN_LOCK IrpQueueLock
Definition: csqtest.c:29
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
Status
Definition: gdiplustypes.h:24
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_Out_ PUNICODE_STRING DosName
Definition: rtlfuncs.h:1270
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
#define IRP_MJ_READ
Definition: rdpdr.c:46
PIRP NTAPI CsqPeekNextIrp(PIO_CSQ Csq, PIRP Irp, PVOID PeekContext)
Definition: csqtest.c:49
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
NTKERNELAPI NTSTATUS NTAPI IoCsqInitialize(_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP CsqInsertIrp, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
Set up a CSQ struct to initialize the queue.
Definition: csq.c:103
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define DOS_DEVICE_NAME
Definition: csqtest.c:22
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ Unload()

VOID NTAPI Unload ( PDRIVER_OBJECT  DriverObject)

Definition at line 160 of file csqtest.c.

164 {
165  UNICODE_STRING LinkName;
166 
168 
169  IoDeleteSymbolicLink(&LinkName);
170 
171  if(DeviceObject)
173 }
PDEVICE_OBJECT DeviceObject
Definition: csqtest.c:32
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DOS_DEVICE_NAME
Definition: csqtest.c:22

Referenced by co_IntClientLoadLibrary(), DECLARE_INTERFACE_(), DriverEntry(), IntLoadHookModule(), and KdpTrap().

Variable Documentation

◆ Csq

◆ DeviceObject

PDEVICE_OBJECT DeviceObject

Definition at line 32 of file csqtest.c.

Referenced by DriverEntry(), and Unload().

◆ IrpQueue

LIST_ENTRY IrpQueue

Definition at line 28 of file csqtest.c.

Referenced by CsqInsertIrp(), CsqPeekNextIrp(), and DriverEntry().

◆ IrpQueueLock

KSPIN_LOCK IrpQueueLock

Definition at line 29 of file csqtest.c.

Referenced by CsqAcquireLock(), CsqReleaseLock(), and DriverEntry().