patch for -Werror -Wall by jonathan wilson
[reactos.git] / reactos / regtests / kmregtests / driver.c
1 /*
2 * PROJECT: ReactOS kernel
3 * FILE: regtests/kmregtests/driver.c
4 * PURPOSE: Kernel-mode regression testing driver
5 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
6 * UPDATE HISTORY:
7 * 06-07-2003 CSH Created
8 */
9 #define NTOS_MODE_KERNEL
10 #include <ntos.h>
11 #include "regtests.h"
12 #include "kmregtests.h"
13
14 #define NDEBUG
15 #include <debug.h>
16
17 PVOID
18 AllocateMemory(ULONG Size)
19 {
20 return ExAllocatePool(NonPagedPool, Size);
21 }
22
23
24 VOID
25 FreeMemory(PVOID Base)
26 {
27 ExFreePool(NonPagedPool);
28 }
29
30 VOID
31 ShutdownBochs()
32 {
33 /* Shutdown bochs programmatically */
34 WRITE_PORT_BUFFER_UCHAR((PUCHAR) 0x8900,
35 (PUCHAR) "Shutdown",
36 strlen("Shutdown"));
37 }
38
39 NTSTATUS
40 STDCALL
41 KMRegTestsRun(
42 PIRP Irp,
43 PIO_STACK_LOCATION IrpSp)
44 {
45 InitializeTests();
46 RegisterTests();
47 PerformTests();
48 ShutdownBochs();
49
50 Irp->IoStatus.Status = STATUS_SUCCESS;
51 Irp->IoStatus.Information = 0;
52 return STATUS_SUCCESS;
53 }
54
55 NTSTATUS
56 STDCALL
57 KMRegTestsDispatch(
58 PDEVICE_OBJECT DeviceObject,
59 PIRP Irp)
60 /*
61 * FUNCTION: IOCTL dispatch routine
62 * ARGUMENTS:
63 * DeviceObject = Pointer to a device object for this driver
64 * Irp = Pointer to a I/O request packet
65 * RETURNS:
66 * Status of the operation
67 */
68 {
69 NTSTATUS Status;
70 PIO_STACK_LOCATION IrpSp;
71
72 IrpSp = IoGetCurrentIrpStackLocation(Irp);
73
74 DPRINT("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
75 DeviceObject, Irp, IrpSp->FileObject);
76
77 Irp->IoStatus.Information = 0;
78
79 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
80 case IOCTL_KMREGTESTS_RUN:
81 Status = KMRegTestsRun(Irp, IrpSp);
82 break;
83
84 default:
85 DPRINT("Unknown IOCTL (0x%X).\n",
86 IrpSp->Parameters.DeviceIoControl.IoControlCode);
87 Status = STATUS_NOT_IMPLEMENTED;
88 break;
89 }
90
91 if (Status != STATUS_PENDING) {
92 Irp->IoStatus.Status = Status;
93 IoCompleteRequest(Irp, IO_NO_INCREMENT);
94 }
95
96 DPRINT("Leaving. Status (0x%X).\n", Status);
97
98 return Status;
99 }
100
101 NTSTATUS STDCALL
102 KMRegTestsOpenClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
103 {
104 PIO_STACK_LOCATION piosStack = IoGetCurrentIrpStackLocation(Irp);
105 NTSTATUS nErrCode;
106
107 nErrCode = STATUS_SUCCESS;
108
109 switch(piosStack->MajorFunction)
110 {
111 /* Opening and closing handles to the device */
112 case IRP_MJ_CREATE:
113 case IRP_MJ_CLOSE:
114 break;
115
116 /* Write data */
117 case IRP_MJ_WRITE:
118 /* Ignore */
119 Irp->IoStatus.Information = 0;
120 break;
121
122 /* Read data */
123 case IRP_MJ_READ:
124 /* Ignore */
125 Irp->IoStatus.Information = 0;
126 nErrCode = STATUS_END_OF_FILE;
127 break;
128
129 /* Unsupported operations */
130 default:
131 nErrCode = STATUS_NOT_IMPLEMENTED;
132 }
133
134 Irp->IoStatus.Status = nErrCode;
135 IoCompleteRequest(Irp, IO_NO_INCREMENT);
136
137 return nErrCode;
138 }
139
140 NTSTATUS STDCALL
141 KMRegTestsUnload(PDRIVER_OBJECT DriverObject)
142 {
143 return STATUS_SUCCESS;
144 }
145
146 NTSTATUS STDCALL
147 DriverEntry(PDRIVER_OBJECT DriverObject,
148 PUNICODE_STRING RegistryPath)
149 {
150 PDEVICE_OBJECT DeviceObject;
151 UNICODE_STRING DeviceName;
152 NTSTATUS Status;
153
154 /* Register driver routines */
155 DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH) KMRegTestsOpenClose;
156 DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH) KMRegTestsOpenClose;
157 DriverObject->MajorFunction[IRP_MJ_WRITE] = (PDRIVER_DISPATCH) KMRegTestsOpenClose;
158 DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH) KMRegTestsOpenClose;
159 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH) KMRegTestsDispatch;
160 DriverObject->DriverUnload = (PDRIVER_UNLOAD) KMRegTestsUnload;
161
162 /* Create device */
163 RtlInitUnicodeString(&DeviceName,
164 L"\\Device\\KMRegTests");
165
166 Status = IoCreateDevice(DriverObject,
167 0,
168 &DeviceName,
169 FILE_DEVICE_NULL,
170 0,
171 FALSE,
172 &DeviceObject);
173 if (!NT_SUCCESS(Status))
174 {
175 return Status;
176 }
177
178 DeviceObject->Flags |= DO_BUFFERED_IO;
179
180 return Status;
181 }