win-pvdrivers

view xenhide/xenhide.c @ 188:a416c66be9c2

Committing changes to xenhide, but giving up on this approach
author James Harper <james.harper@bendigoit.com.au>
date Mon Feb 18 16:12:48 2008 +1100 (2008-02-18)
parents 8c87bd40fe36
children eeeeb6924803
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #include "xenhide.h"
21 #include <stdlib.h>
23 DRIVER_INITIALIZE DriverEntry;
24 static NTSTATUS
25 XenHide_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject);
26 static NTSTATUS
27 XenHide_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp);
28 static NTSTATUS
29 XenHide_Pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp);
30 static NTSTATUS
31 XenHide_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp);
32 static NTSTATUS
33 XenHide_AddDevice();
34 //static NTSTATUS
35 //XenHide_Unload();
37 #ifdef ALLOC_PRAGMA
38 #pragma alloc_text (INIT, DriverEntry)
39 #pragma alloc_text (PAGE, XenHide_AddDevice)
40 #endif
42 static BOOLEAN AutoEnumerate;
44 NTSTATUS
45 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
46 {
47 NTSTATUS status;
48 UNICODE_STRING RegKeyName;
49 UNICODE_STRING RegValueName;
50 HANDLE RegHandle;
51 OBJECT_ATTRIBUTES RegObjectAttributes;
52 char Buf[200];
53 ULONG BufLen = 200;
54 PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
55 int State = 0;
56 int StartPos = 0;
57 WCHAR *SystemStartOptions;
58 size_t SystemStartOptionsLen;
59 size_t i;
61 UNREFERENCED_PARAMETER(RegistryPath);
63 KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
64 KdPrint((__DRIVER_NAME " IRQL = %d\n", KeGetCurrentIrql()));
66 RtlInitUnicodeString(&RegKeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
67 InitializeObjectAttributes(&RegObjectAttributes, &RegKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
68 status = ZwOpenKey(&RegHandle, KEY_READ, &RegObjectAttributes);
69 if(!NT_SUCCESS(status))
70 {
71 KdPrint((__DRIVER_NAME " ZwOpenKey returned %08x\n", status));
72 }
74 RtlInitUnicodeString(&RegValueName, L"SystemStartOptions");
75 status = ZwQueryValueKey(RegHandle, &RegValueName, KeyValuePartialInformation, Buf, BufLen, &BufLen);
76 if(!NT_SUCCESS(status))
77 {
78 KdPrint((__DRIVER_NAME " ZwQueryKeyValue returned %08x\n", status));
79 }
80 else
81 ZwClose(RegHandle);
82 KeyPartialValue = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
83 SystemStartOptions = (WCHAR *)KeyPartialValue->Data;
85 AutoEnumerate = FALSE;
87 RtlStringCbLengthW(SystemStartOptions, KeyPartialValue->DataLength, &SystemStartOptionsLen);
89 for (i = 0; i <= SystemStartOptionsLen/2; i++)
90 {
91 //KdPrint((__DRIVER_NAME " pos = %d, state = %d, char = '%wc' (%d)\n", i, State, SystemStartOptions[i], SystemStartOptions[i]));
93 switch (State)
94 {
95 case 0:
96 if (SystemStartOptions[i] == L'G')
97 {
98 StartPos = i;
99 State = 2;
100 } else if (SystemStartOptions[i] != L' ')
101 {
102 State = 1;
103 }
104 break;
105 case 1:
106 if (SystemStartOptions[i] == L' ')
107 State = 0;
108 break;
109 case 2:
110 if (SystemStartOptions[i] == L'P')
111 State = 3;
112 else
113 State = 0;
114 break;
115 case 3:
116 if (SystemStartOptions[i] == L'L')
117 State = 4;
118 else
119 State = 0;
120 break;
121 case 4:
122 if (SystemStartOptions[i] == L'P')
123 State = 5;
124 else
125 State = 0;
126 break;
127 case 5:
128 if (SystemStartOptions[i] == L'V')
129 State = 6;
130 else
131 State = 0;
132 break;
133 case 6:
134 if (SystemStartOptions[i] == L' ' || SystemStartOptions[i] == 0)
135 AutoEnumerate = TRUE;
136 State = 0;
137 break;
138 }
139 }
141 KdPrint((__DRIVER_NAME " AutoEnumerate = %d\n", AutoEnumerate));
143 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
144 DriverObject->MajorFunction[i] = XenHide_Pass;
146 DriverObject->MajorFunction[IRP_MJ_POWER] = XenHide_Power;
148 if (AutoEnumerate)
149 DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
151 DriverObject->DriverExtension->AddDevice = XenHide_AddDevice;
153 KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
155 return status;
156 }
158 static NTSTATUS
159 XenHide_AddDevice(
160 PDRIVER_OBJECT DriverObject,
161 PDEVICE_OBJECT PhysicalDeviceObject
162 )
163 {
164 NTSTATUS status;
165 PDEVICE_OBJECT DeviceObject = NULL;
166 PDEVICE_EXTENSION DeviceExtension;
167 ULONG Length;
168 WCHAR Buffer[1000];
170 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
172 Length = 1000;
173 status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyDeviceDescription, Length, Buffer, &Length);
174 KdPrint((__DRIVER_NAME " status = %08x, DevicePropertyDeviceDescription = %ws\n", status, Buffer));
176 if (!NT_SUCCESS(status) || wcscmp(Buffer, L"PCI bus") != 0)
177 {
178 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
179 return STATUS_SUCCESS;
180 }
181 KdPrint((__DRIVER_NAME " Found\n"));
183 status = IoCreateDevice(DriverObject,
184 sizeof(DEVICE_EXTENSION),
185 NULL,
186 FILE_DEVICE_UNKNOWN,
187 FILE_DEVICE_SECURE_OPEN,
188 FALSE,
189 &DeviceObject);
190 if (!NT_SUCCESS(status))
191 {
192 KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
193 return status;
194 }
196 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
198 DeviceExtension->Self = DeviceObject;
199 DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
200 DeviceExtension->DriverObject = DriverObject;
201 DeviceExtension->Type = XENHIDE_TYPE_PCI;
202 DeviceExtension->InternalState = 0;
204 DeviceExtension->NextLowerDevice = IoAttachDeviceToDeviceStack(
205 DeviceObject,
206 PhysicalDeviceObject);
208 DeviceObject->Flags |= DeviceExtension->NextLowerDevice->Flags;
210 DeviceObject->DeviceType = DeviceExtension->NextLowerDevice->DeviceType;
212 DeviceObject->Characteristics =
213 DeviceExtension->NextLowerDevice->Characteristics;
215 // IoInitializeRemoveLock(&DeviceExtension->RemoveLock, XENHIDE_POOL_TAG, 1, 100);
217 #if 0
218 if (AutoEnumerate)
219 {
220 status = IoRegisterDeviceInterface(PhysicalDeviceObject, (LPGUID)&GUID_XENHIDE_IFACE, NULL, &DeviceExtension->InterfaceName);
221 if (!NT_SUCCESS(status))
222 {
223 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface failed 0x%08x\n", status));
224 return status;
225 }
226 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface complete, SymbolicLinkName = %wZ\n", &DeviceExtension->InterfaceName));
227 status = IoSetDeviceInterfaceState(&DeviceExtension->InterfaceName, TRUE);
228 if (!NT_SUCCESS(status))
229 {
230 KdPrint((__DRIVER_NAME " IoSetDeviceInterfaceState failed 0x%08x\n", status));
231 return status;
232 }
233 }
234 else
235 {
236 KdPrint((__DRIVER_NAME " Not registering Interface\n"));
237 }
238 #endif
240 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
242 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
244 return STATUS_SUCCESS;
245 }
247 static int
248 XenHide_StringMatches(PWCHAR String1, PWCHAR String2)
249 {
250 for(;*String1 != 0 && *String2 != 0 && *String1 == *String2; String1++, String2++);
251 return ((*String1 == 0 && *String2 == 0) || (*String1 == 0 && *String2 == L'\n') || (*String1 == L'\n' && *String2 == 0));
252 }
254 static NTSTATUS
255 XenHide_IoCompletionPciQueryDeviceRelations(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
256 {
257 ULONG i, j;
258 PDEVICE_RELATIONS Relations;
259 WCHAR Buffer[1000];
260 PWCHAR Ptr;
261 ULONG Length;
262 size_t StrLen;
263 int Match;
264 NTSTATUS status;
265 PDEVICE_OBJECT NewDeviceObject;
266 PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)Context;
267 PDEVICE_EXTENSION NewDeviceExtension;
269 UNREFERENCED_PARAMETER(DeviceObject);
270 UNREFERENCED_PARAMETER(Context);
272 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
273 KdPrint((__DRIVER_NAME " IRQL = %d\n", KeGetCurrentIrql()));
274 KdPrint((__DRIVER_NAME " InternalState = %d\n", DeviceExtension->InternalState));
276 if (Irp->PendingReturned)
277 IoMarkIrpPending(Irp);
279 switch (DeviceExtension->InternalState)
280 {
281 case 0:
282 DeviceExtension->InternalState = 1;
283 break;
284 case 1:
285 DeviceExtension->InternalState = 2;
286 Relations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
288 for (i = 0; i < Relations->Count; i++)
289 {
290 Match = 0;
291 for (j = 0; j < 2 && !Match; j++)
292 {
293 Length = sizeof(Buffer);
294 if (j == 0)
295 IoGetDeviceProperty(Relations->Objects[i], DevicePropertyCompatibleIDs, Length, Buffer, &Length);
296 else
297 IoGetDeviceProperty(Relations->Objects[i], DevicePropertyHardwareID, Length, Buffer, &Length);
298 StrLen = 0;
299 for (Ptr = Buffer; *Ptr != 0; Ptr += StrLen + 1)
300 {
301 // Qemu PCI
302 if (XenHide_StringMatches(Ptr, L"PCI\\VEN_8086&DEV_7010")) {
303 KdPrint((__DRIVER_NAME " %ws\n", Ptr));
304 Match = 1;
305 break;
306 }
307 // Qemu Network
308 if (XenHide_StringMatches(Ptr, L"PCI\\VEN_10EC&DEV_8139")) {
309 KdPrint((__DRIVER_NAME " %ws\n", Ptr));
310 Match = 1;
311 break;
312 }
313 RtlStringCchLengthW(Ptr, Length, &StrLen);
314 }
315 }
316 if (Match)
317 {
318 KdPrint((__DRIVER_NAME " Creating and attaching Device\n"));
319 NewDeviceObject = NULL;
320 status = IoCreateDevice(DeviceExtension->DriverObject,
321 sizeof(DEVICE_EXTENSION),
322 NULL,
323 FILE_DEVICE_UNKNOWN,
324 FILE_DEVICE_SECURE_OPEN,
325 FALSE,
326 &NewDeviceObject);
327 if (!NT_SUCCESS(status))
328 {
329 KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
330 continue;
331 }
333 NewDeviceExtension = (PDEVICE_EXTENSION)NewDeviceObject->DeviceExtension;
334 NewDeviceExtension->PhysicalDeviceObject = Relations->Objects[i];
335 NewDeviceExtension->InternalState = 0;
336 NewDeviceExtension->NextLowerDevice = IoAttachDeviceToDeviceStack(
337 NewDeviceObject,
338 Relations->Objects[i]);
339 NewDeviceObject->Flags |= NewDeviceExtension->NextLowerDevice->Flags;
341 NewDeviceObject->DeviceType = NewDeviceExtension->NextLowerDevice->DeviceType;
343 NewDeviceObject->Characteristics =
344 NewDeviceExtension->NextLowerDevice->Characteristics;
346 // IoInitializeRemoveLock(&NewDeviceExtension->RemoveLock, XENHIDE_POOL_TAG, 1, 100);
348 NewDeviceExtension->Self = NewDeviceObject;
349 NewDeviceExtension->Type = XENHIDE_TYPE_HIDE;
351 NewDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
352 }
353 }
354 break;
355 default:
356 break;
357 }
359 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
361 return STATUS_SUCCESS; //Irp->IoStatus.Status;
362 }
364 static NTSTATUS
365 XenHide_IoCompletionHideQueryPnpDeviceState(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
366 {
367 UNREFERENCED_PARAMETER(DeviceObject);
368 UNREFERENCED_PARAMETER(Context);
370 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
372 if (Irp->PendingReturned)
373 IoMarkIrpPending(Irp);
375 Irp->IoStatus.Information |= PNP_DEVICE_DONT_DISPLAY_IN_UI|PNP_DEVICE_DISABLED;
377 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
378 return STATUS_SUCCESS;
379 }
381 static NTSTATUS
382 XenHide_IoCompletionPciQueryId(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
383 {
384 PIO_STACK_LOCATION Stack;
386 UNREFERENCED_PARAMETER(DeviceObject);
387 UNREFERENCED_PARAMETER(Context);
389 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
391 if (Irp->PendingReturned)
392 IoMarkIrpPending(Irp);
394 Stack = IoGetCurrentIrpStackLocation(Irp);
396 switch (Stack->Parameters.QueryId.IdType)
397 {
398 case BusQueryDeviceID:
399 KdPrint((__DRIVER_NAME " IdType = BusQueryDeviceID\n"));
400 KdPrint((__DRIVER_NAME " %ws\n", Irp->IoStatus.Information));
401 break;
402 case BusQueryHardwareIDs:
403 KdPrint((__DRIVER_NAME " IdType = BusQueryHardwareIDs\n"));
404 KdPrint((__DRIVER_NAME " %ws\n", Irp->IoStatus.Information));
405 break;
406 case BusQueryCompatibleIDs:
407 KdPrint((__DRIVER_NAME " IdType = BusQueryCompatibleIDs\n"));
408 KdPrint((__DRIVER_NAME " %ws\n", Irp->IoStatus.Information));
409 break;
410 case BusQueryInstanceID:
411 KdPrint((__DRIVER_NAME " IdType = BusQueryInstanceID\n"));
412 KdPrint((__DRIVER_NAME " %ws\n", Irp->IoStatus.Information));
413 break;
414 default:
415 KdPrint((__DRIVER_NAME " IdType = %08x\n", Stack->Parameters.QueryId.IdType));
416 KdPrint((__DRIVER_NAME " %ws\n", Irp->IoStatus.Information));
417 break;
418 }
420 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
421 return STATUS_SUCCESS;
422 }
424 static NTSTATUS
425 XenHide_IoCompletionHideStartDevice(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
426 {
427 UNREFERENCED_PARAMETER(DeviceObject);
428 UNREFERENCED_PARAMETER(Context);
430 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
431 KdPrint((__DRIVER_NAME " IRQL = %d\n", KeGetCurrentIrql()));
433 if (Irp->PendingReturned)
434 IoMarkIrpPending(Irp);
436 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
437 return STATUS_SUCCESS;
438 }
440 static NTSTATUS
441 XenHide_Pass(PDEVICE_OBJECT DeviceObject, PIRP Irp)
442 {
443 PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
444 NTSTATUS Status;
446 #if 0
447 Status = IoAcquireRemoveLock (&DeviceExtension->RemoveLock, Irp);
448 if (!NT_SUCCESS(Status)) {
449 Irp->IoStatus.Status = Status;
450 IoCompleteRequest(Irp, IO_NO_INCREMENT);
451 return Status;
452 }
453 #endif
454 IoSkipCurrentIrpStackLocation(Irp);
455 Status = IoCallDriver(DeviceExtension->NextLowerDevice, Irp);
456 // IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
457 return Status;
458 }
460 static NTSTATUS
461 XenHide_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp)
462 {
463 NTSTATUS Status = STATUS_SUCCESS;
464 PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
466 // Status = IoAcquireRemoveLock (&DeviceExtension->RemoveLock, Irp);
467 if (!NT_SUCCESS(Status)) {
468 Irp->IoStatus.Status = Status;
469 PoStartNextPowerIrp(Irp);
470 IoCompleteRequest(Irp, IO_NO_INCREMENT);
471 return Status;
472 }
474 PoStartNextPowerIrp(Irp);
475 IoSkipCurrentIrpStackLocation(Irp);
476 Status = PoCallDriver(DeviceExtension->NextLowerDevice, Irp);
477 // IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
478 return Status;
479 }
481 static NTSTATUS
482 XenHide_Pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
483 {
484 NTSTATUS Status = STATUS_SUCCESS;
485 PIO_STACK_LOCATION Stack;
486 PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
488 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
489 KdPrint((__DRIVER_NAME " DeviceObject = %p\n", DeviceObject));
490 KdPrint((__DRIVER_NAME " IRQL = %d\n", KeGetCurrentIrql()));
492 /*
493 Status = IoAcquireRemoveLock (&DeviceExtension->RemoveLock, Irp);
494 if (!NT_SUCCESS(Status)) {
495 Irp->IoStatus.Status = Status;
496 IoCompleteRequest(Irp, IO_NO_INCREMENT);
497 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", Status));
498 return Status;
499 }
500 */
501 Stack = IoGetCurrentIrpStackLocation(Irp);
503 switch (Stack->MinorFunction)
504 {
505 case IRP_MN_START_DEVICE:
506 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_START_DEVICE\n"));
507 break;
508 case IRP_MN_QUERY_STOP_DEVICE:
509 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_STOP_DEVICE\n"));
510 break;
511 case IRP_MN_STOP_DEVICE:
512 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_STOP_DEVICE\n"));
513 break;
514 case IRP_MN_CANCEL_STOP_DEVICE:
515 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_CANCEL_STOP_DEVICE\n"));
516 break;
517 case IRP_MN_QUERY_REMOVE_DEVICE:
518 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_REMOVE_DEVICE\n"));
519 break;
520 case IRP_MN_REMOVE_DEVICE:
521 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_REMOVE_DEVICE\n"));
522 break;
523 case IRP_MN_CANCEL_REMOVE_DEVICE:
524 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_CANCEL_REMOVE_DEVICE\n"));
525 break;
526 case IRP_MN_SURPRISE_REMOVAL:
527 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_SURPRISE_REMOVAL\n"));
528 break;
529 case IRP_MN_QUERY_CAPABILITIES:
530 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_CAPABILITIES\n"));
531 break;
532 case IRP_MN_QUERY_PNP_DEVICE_STATE:
533 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_PNP_DEVICE_STATE\n"));
534 break;
535 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
536 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
537 break;
538 case IRP_MN_DEVICE_USAGE_NOTIFICATION:
539 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_DEVICE_USAGE_NOTIFICATION\n"));
540 break;
541 case IRP_MN_QUERY_DEVICE_RELATIONS:
542 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS\n"));
543 break;
544 case IRP_MN_QUERY_RESOURCES:
545 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_RESOURCES\n"));
546 break;
547 case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
548 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n"));
549 break;
550 case IRP_MN_QUERY_ID:
551 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_ID\n"));
552 break;
553 case IRP_MN_QUERY_DEVICE_TEXT:
554 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_DEVICE_TEXT\n"));
555 break;
556 case IRP_MN_QUERY_BUS_INFORMATION:
557 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_BUS_INFORMATION\n"));
558 break;
559 case IRP_MN_QUERY_INTERFACE:
560 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_QUERY_INTERFACE\n"));
561 break;
562 case IRP_MN_READ_CONFIG:
563 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_READ_CONFIG\n"));
564 break;
565 case IRP_MN_WRITE_CONFIG:
566 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_WRITE_CONFIG\n"));
567 break;
568 case IRP_MN_EJECT:
569 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_EJECT\n"));
570 break;
571 case IRP_MN_SET_LOCK:
572 KdPrint((__DRIVER_NAME " MinorFunction = IRP_MN_SET_LOCK\n"));
573 break;
574 default:
575 KdPrint((__DRIVER_NAME " MinorFunction = %02x\n", Stack->MinorFunction));
576 break;
577 }
579 switch (DeviceExtension->Type)
580 {
581 case XENHIDE_TYPE_PCI:
582 KdPrint((__DRIVER_NAME " As PCI\n"));
584 switch (Stack->MinorFunction) {
585 case IRP_MN_QUERY_DEVICE_RELATIONS:
586 KdPrint((__DRIVER_NAME " IRP_MN_QUERY_DEVICE_RELATIONS\n"));
587 switch (Stack->Parameters.QueryDeviceRelations.Type)
588 {
589 case BusRelations:
590 KdPrint((__DRIVER_NAME " BusRelations\n"));
591 IoCopyCurrentIrpStackLocationToNext(Irp);
592 IoSetCompletionRoutine(Irp, XenHide_IoCompletionPciQueryDeviceRelations, DeviceExtension, TRUE, TRUE, TRUE);
593 break;
594 default:
595 IoSkipCurrentIrpStackLocation(Irp);
596 break;
597 }
598 break;
599 case IRP_MN_QUERY_ID:
600 IoCopyCurrentIrpStackLocationToNext(Irp);
601 IoSetCompletionRoutine(Irp, XenHide_IoCompletionPciQueryId, DeviceExtension, TRUE, TRUE, TRUE);
602 break;
603 case IRP_MN_QUERY_CAPABILITIES:
604 default:
605 IoSkipCurrentIrpStackLocation(Irp);
606 break;
607 }
608 Status = IoCallDriver(DeviceExtension->NextLowerDevice, Irp);
609 break;
610 case XENHIDE_TYPE_HIDE:
611 KdPrint((__DRIVER_NAME " As Hide\n"));
612 switch (Stack->MinorFunction)
613 {
614 /*
615 case IRP_MN_START_DEVICE:
616 IoCopyCurrentIrpStackLocationToNext(Irp);
617 IoSetCompletionRoutine(Irp, XenHide_IoCompletionHideStartDevice, DeviceExtension, TRUE, TRUE, TRUE);
618 IoCopyCurrentIrpStackLocationToNext(Irp);
619 Stack = IoGetNextIrpStackLocation(Irp);
620 Stack->Parameters.StartDevice.AllocatedResources = ExAllocatePoolWithTag(NonPagedPool, sizeof(CM_RESOURCE_LIST), XENHIDE_POOL_TAG);
621 Stack->Parameters.StartDevice.AllocatedResources->Count = 1;
622 Stack->Parameters.StartDevice.AllocatedResources->List[0].InterfaceType = Internal;
623 Stack->Parameters.StartDevice.AllocatedResources->List[0].BusNumber = 0;
624 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Version = 1;
625 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Revision = 1;
626 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Count = 0;
627 Stack->Parameters.StartDevice.AllocatedResourcesTranslated = ExAllocatePoolWithTag(NonPagedPool, sizeof(CM_RESOURCE_LIST), XENHIDE_POOL_TAG);
628 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->Count = 1;
629 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].InterfaceType = Internal;
630 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].BusNumber = 0;
631 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Version = 1;
632 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Revision = 1;
633 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Count = 0;
634 break;
635 case IRP_MN_QUERY_PNP_DEVICE_STATE:
636 IoCopyCurrentIrpStackLocationToNext(Irp);
637 IoSetCompletionRoutine(Irp, XenHide_IoCompletionHideQueryPnpDeviceState, DeviceExtension, TRUE, TRUE, TRUE);
638 break;
639 */
640 case IRP_MN_QUERY_ID:
641 switch (Stack->Parameters.QueryId.IdType)
642 {
643 case BusQueryDeviceID:
644 KdPrint((__DRIVER_NAME " BusQueryDeviceID\n"));
645 break;
646 case BusQueryHardwareIDs:
647 KdPrint((__DRIVER_NAME " BusQueryHardwareIDs\n"));
648 break;
649 case BusQueryCompatibleIDs:
650 KdPrint((__DRIVER_NAME " BusQueryCompatibleIDs\n"));
651 break;
652 case BusQueryInstanceID:
653 KdPrint((__DRIVER_NAME " BusQueryInstanceID\n"));
654 break;
655 default:
656 KdPrint((__DRIVER_NAME " %08x\n", Stack->Parameters.QueryId.IdType));
657 break;
658 }
659 IoCopyCurrentIrpStackLocationToNext(Irp);
660 IoSetCompletionRoutine(Irp, XenHide_IoCompletionPciQueryId, DeviceExtension, TRUE, TRUE, TRUE);
661 break;
662 default:
663 IoSkipCurrentIrpStackLocation(Irp);
664 break;
665 }
666 Status = IoCallDriver(DeviceExtension->NextLowerDevice, Irp);
667 break;
668 }
670 // IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
672 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", Status));
674 return Status;
675 }