ReactOS 0.4.15-dev-8393-g61b7fb9
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
KSPIN_LOCK IrpQueueLock
Definition: csqtest.c:29
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609

◆ 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 IoCompleteRequest
Definition: irp.c:1240
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define IO_NO_INCREMENT
Definition: iotypes.h:598

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
#define InsertTailList(ListHead, Entry)

◆ 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}
IO_CSQ Csq
Definition: csqtest.c:25
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ PIO_CSQ_INSERT_IRP CsqInsertIrp
Definition: iofuncs.h:1888

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
57 return NULL;
58
59 return CONTAINING_RECORD(IrpQueue.Flink, IRP, Tail.Overlay.ListEntry);
60}
#define NULL
Definition: types.h:112
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ 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}
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

◆ 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}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

◆ 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
114 }
115 }
116
117 Irp->IoStatus.Status = STATUS_SUCCESS;
118 Irp->IoStatus.Information = 0;
119
121
122 return STATUS_SUCCESS;
123}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
#define STATUS_SUCCESS
Definition: shellext.h:65
IO_STATUS_BLOCK IoStatus
#define IRP_MJ_CLEANUP

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
150 }
151
152 Irp->IoStatus.Status = STATUS_SUCCESS;
153 Irp->IoStatus.Information = 0;
154
156
157 return STATUS_SUCCESS;
158}

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}
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
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
191 DriverObject->DriverUnload = Unload;
192
195
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
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}
LONG NTSTATUS
Definition: precomp.h:26
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
VOID NTAPI CsqCompleteCancelledIrp(PIO_CSQ Csq, PIRP Irp)
Definition: csqtest.c:74
NTSTATUS NTAPI DispatchReadWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: csqtest.c:125
NTSTATUS NTAPI DispatchIoctl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: csqtest.c:135
#define DOS_DEVICE_NAME
Definition: csqtest.c:22
#define NT_DEVICE_NAME
Definition: csqtest.c:19
NTSTATUS NTAPI DispatchCreateCloseCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: csqtest.c:97
VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: csqtest.c:160
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:25
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:79
#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
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp
Definition: iofuncs.h:1890
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock
Definition: iofuncs.h:1891
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp
Definition: iofuncs.h:1889
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP _In_ PIO_CSQ_ACQUIRE_LOCK _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock
Definition: iofuncs.h:1892
_Out_ PUNICODE_STRING DosName
Definition: rtlfuncs.h:1269

◆ 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}
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251

Referenced by DriverEntry().

Variable Documentation

◆ Csq

◆ DeviceObject

Definition at line 32 of file csqtest.c.

◆ 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().