Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1480 lines
44 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vfpnp.c
  5. Abstract:
  6. This module handles Pnp Irp verification.
  7. Author:
  8. Adrian J. Oney (adriao) 20-Apr-1998
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. AdriaO 06/15/2000 - Seperated out from ntos\io\flunkirp.c
  13. --*/
  14. #include "vfdef.h"
  15. #include "vipnp.h"
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text(INIT, VfPnpInit)
  18. #pragma alloc_text(PAGEVRFY, VfPnpDumpIrpStack)
  19. #pragma alloc_text(PAGEVRFY, VfPnpVerifyNewRequest)
  20. #pragma alloc_text(PAGEVRFY, VfPnpVerifyIrpStackDownward)
  21. #pragma alloc_text(PAGEVRFY, VfPnpVerifyIrpStackUpward)
  22. #pragma alloc_text(PAGEVRFY, VfPnpIsSystemRestrictedIrp)
  23. #pragma alloc_text(PAGEVRFY, VfPnpAdvanceIrpStatus)
  24. #pragma alloc_text(PAGEVRFY, VfPnpTestStartedPdoStack)
  25. #pragma alloc_text(PAGEVRFY, ViPnpVerifyMinorWasProcessedProperly)
  26. #endif
  27. #ifdef ALLOC_DATA_PRAGMA
  28. #pragma const_seg("PAGEVRFC")
  29. #endif
  30. const PCHAR PnPIrpNames[] = {
  31. "IRP_MN_START_DEVICE", // 0x00
  32. "IRP_MN_QUERY_REMOVE_DEVICE", // 0x01
  33. "IRP_MN_REMOVE_DEVICE - ", // 0x02
  34. "IRP_MN_CANCEL_REMOVE_DEVICE", // 0x03
  35. "IRP_MN_STOP_DEVICE", // 0x04
  36. "IRP_MN_QUERY_STOP_DEVICE", // 0x05
  37. "IRP_MN_CANCEL_STOP_DEVICE", // 0x06
  38. "IRP_MN_QUERY_DEVICE_RELATIONS", // 0x07
  39. "IRP_MN_QUERY_INTERFACE", // 0x08
  40. "IRP_MN_QUERY_CAPABILITIES", // 0x09
  41. "IRP_MN_QUERY_RESOURCES", // 0x0A
  42. "IRP_MN_QUERY_RESOURCE_REQUIREMENTS", // 0x0B
  43. "IRP_MN_QUERY_DEVICE_TEXT", // 0x0C
  44. "IRP_MN_FILTER_RESOURCE_REQUIREMENTS", // 0x0D
  45. "INVALID_IRP_CODE", //
  46. "IRP_MN_READ_CONFIG", // 0x0F
  47. "IRP_MN_WRITE_CONFIG", // 0x10
  48. "IRP_MN_EJECT", // 0x11
  49. "IRP_MN_SET_LOCK", // 0x12
  50. "IRP_MN_QUERY_ID", // 0x13
  51. "IRP_MN_QUERY_PNP_DEVICE_STATE", // 0x14
  52. "IRP_MN_QUERY_BUS_INFORMATION", // 0x15
  53. "IRP_MN_DEVICE_USAGE_NOTIFICATION", // 0x16
  54. "IRP_MN_SURPRISE_REMOVAL", // 0x17
  55. "IRP_MN_QUERY_LEGACY_BUS_INFORMATION", // 0x18
  56. NULL
  57. };
  58. #define MAX_NAMED_PNP_IRP 0x18
  59. #include <initguid.h>
  60. DEFINE_GUID( GUID_BOGUS_INTERFACE, 0x00000000L, 0x0000, 0x0000,
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
  62. #ifdef ALLOC_DATA_PRAGMA
  63. #pragma const_seg()
  64. #endif // ALLOC_DATA_PRAGMA
  65. VOID
  66. VfPnpInit(
  67. VOID
  68. )
  69. {
  70. VfMajorRegisterHandlers(
  71. IRP_MJ_PNP,
  72. VfPnpDumpIrpStack,
  73. VfPnpVerifyNewRequest,
  74. VfPnpVerifyIrpStackDownward,
  75. VfPnpVerifyIrpStackUpward,
  76. VfPnpIsSystemRestrictedIrp,
  77. VfPnpAdvanceIrpStatus,
  78. NULL,
  79. NULL,
  80. NULL,
  81. NULL,
  82. VfPnpTestStartedPdoStack,
  83. NULL
  84. );
  85. }
  86. VOID
  87. FASTCALL
  88. VfPnpVerifyNewRequest(
  89. IN PIOV_REQUEST_PACKET IovPacket,
  90. IN PDEVICE_OBJECT DeviceObject,
  91. IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
  92. IN PIO_STACK_LOCATION IrpSp,
  93. IN PIOV_STACK_LOCATION StackLocationData,
  94. IN PVOID CallerAddress OPTIONAL
  95. )
  96. {
  97. PIRP irp;
  98. NTSTATUS currentStatus;
  99. PDEVICE_OBJECT possiblePdo;
  100. PDEVICE_CAPABILITIES deviceCapabilities;
  101. UNREFERENCED_PARAMETER (IrpLastSp);
  102. irp = IovPacket->TrackedIrp;
  103. currentStatus = irp->IoStatus.Status;
  104. //
  105. // Verify new IRPs start out life accordingly
  106. //
  107. if (currentStatus!=STATUS_NOT_SUPPORTED) {
  108. //
  109. // This is a special WDM (9x) compatibility hack.
  110. //
  111. if ((IrpSp->MinorFunction != IRP_MN_FILTER_RESOURCE_REQUIREMENTS) &&
  112. (!(IovPacket->Flags & TRACKFLAG_BOGUS))) {
  113. WDM_FAIL_ROUTINE((
  114. DCERROR_PNP_IRP_BAD_INITIAL_STATUS,
  115. DCPARAM_IRP + DCPARAM_ROUTINE,
  116. CallerAddress,
  117. irp
  118. ));
  119. }
  120. //
  121. // Don't blame anyone else for this guy's mistake.
  122. //
  123. if (!NT_SUCCESS(currentStatus)) {
  124. StackLocationData->Flags |= STACKFLAG_FAILURE_FORWARDED;
  125. }
  126. }
  127. if (IrpSp->MinorFunction == IRP_MN_QUERY_CAPABILITIES) {
  128. deviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
  129. if (VfUtilIsMemoryRangeReadable(deviceCapabilities, sizeof(DEVICE_CAPABILITIES), VFMP_INSTANT_NONPAGED)) {
  130. //
  131. // Verify fields are initialized correctly
  132. //
  133. if (deviceCapabilities->Version < 1) {
  134. //
  135. // Whoops, it didn't initialize the version correctly!
  136. //
  137. WDM_FAIL_ROUTINE((
  138. DCERROR_PNP_QUERY_CAP_BAD_VERSION,
  139. DCPARAM_IRP + DCPARAM_ROUTINE,
  140. CallerAddress,
  141. irp
  142. ));
  143. }
  144. if (deviceCapabilities->Size < sizeof(DEVICE_CAPABILITIES)) {
  145. //
  146. // Whoops, it didn't initialize the size field correctly!
  147. //
  148. WDM_FAIL_ROUTINE((
  149. DCERROR_PNP_QUERY_CAP_BAD_SIZE,
  150. DCPARAM_IRP + DCPARAM_ROUTINE,
  151. CallerAddress,
  152. irp
  153. ));
  154. }
  155. if (deviceCapabilities->Address != (ULONG) -1) {
  156. //
  157. // Whoops, it didn't initialize the address field correctly!
  158. //
  159. WDM_FAIL_ROUTINE((
  160. DCERROR_PNP_QUERY_CAP_BAD_ADDRESS,
  161. DCPARAM_IRP + DCPARAM_ROUTINE,
  162. CallerAddress,
  163. irp
  164. ));
  165. }
  166. if (deviceCapabilities->UINumber != (ULONG) -1) {
  167. //
  168. // Whoops, it didn't initialize the UI number field correctly!
  169. //
  170. WDM_FAIL_ROUTINE((
  171. DCERROR_PNP_QUERY_CAP_BAD_UI_NUM,
  172. DCPARAM_IRP + DCPARAM_ROUTINE,
  173. CallerAddress,
  174. irp
  175. ));
  176. }
  177. }
  178. }
  179. //
  180. // If this is a target device relation IRP, verify the appropriate
  181. // object will be referenced.
  182. //
  183. if (!VfSettingsIsOptionEnabled(IovPacket->VerifierSettings, VERIFIER_OPTION_TEST_TARGET_REFCOUNT)) {
  184. return;
  185. }
  186. if ((IrpSp->MinorFunction == IRP_MN_QUERY_DEVICE_RELATIONS)&&
  187. (IrpSp->Parameters.QueryDeviceRelations.Type == TargetDeviceRelation)) {
  188. IovUtilGetBottomDeviceObject(DeviceObject, &possiblePdo);
  189. if (IovUtilIsPdo(possiblePdo)) {
  190. if (StackLocationData->ReferencingObject == NULL) {
  191. //
  192. // Got'm!
  193. //
  194. StackLocationData->Flags |= STACKFLAG_CHECK_FOR_REFERENCE;
  195. StackLocationData->ReferencingObject = possiblePdo;
  196. StackLocationData->ReferencingCount = (LONG)ObvUtilStartObRefMonitoring(possiblePdo);
  197. IovPacket->RefTrackingCount++;
  198. }
  199. }
  200. //
  201. // Free our reference (we will have one if we are snapshotting anyway)
  202. //
  203. ObDereferenceObject(possiblePdo);
  204. }
  205. }
  206. VOID
  207. FASTCALL
  208. VfPnpVerifyIrpStackDownward(
  209. IN PIOV_REQUEST_PACKET IovPacket,
  210. IN PDEVICE_OBJECT DeviceObject,
  211. IN PIO_STACK_LOCATION IrpLastSp OPTIONAL,
  212. IN PIO_STACK_LOCATION IrpSp,
  213. IN PIOV_STACK_LOCATION RequestHeadLocationData,
  214. IN PIOV_STACK_LOCATION StackLocationData,
  215. IN PVOID CallerAddress OPTIONAL
  216. )
  217. {
  218. PIRP irp;
  219. NTSTATUS currentStatus, lastStatus;
  220. BOOLEAN statusChanged;
  221. PDRIVER_OBJECT driverObject;
  222. PIOV_SESSION_DATA iovSessionData;
  223. HOW_PROCESSED howProcessed;
  224. VF_DEVOBJ_TYPE devObjType;
  225. UNREFERENCED_PARAMETER (StackLocationData);
  226. if (!IovUtilIsWdmStack(DeviceObject)) {
  227. return;
  228. }
  229. irp = IovPacket->TrackedIrp;
  230. currentStatus = irp->IoStatus.Status;
  231. lastStatus = RequestHeadLocationData->LastStatusBlock.Status;
  232. statusChanged = (BOOLEAN)(currentStatus != lastStatus);
  233. iovSessionData = VfPacketGetCurrentSessionData(IovPacket);
  234. //
  235. // Verify the IRP was forwarded properly
  236. //
  237. switch(iovSessionData->ForwardMethod) {
  238. case SKIPPED_A_DO:
  239. WDM_FAIL_ROUTINE((
  240. DCERROR_SKIPPED_DEVICE_OBJECT,
  241. DCPARAM_IRP + DCPARAM_ROUTINE,
  242. CallerAddress,
  243. irp
  244. ));
  245. break;
  246. case STARTED_TOP_OF_STACK:
  247. case FORWARDED_TO_NEXT_DO:
  248. //
  249. // Perfectly normal
  250. //
  251. break;
  252. case STARTED_INSIDE_STACK:
  253. //
  254. // Probably an Internal irp (query cap's, etc)
  255. //
  256. break;
  257. case CHANGED_STACKS_MID_STACK:
  258. case CHANGED_STACKS_AT_BOTTOM:
  259. //
  260. // ADRIAO N.B. - Ensure drivers aren't rerouting certain IRPs off
  261. // PnP stacks.
  262. //
  263. #if 0
  264. ASSERT(0);
  265. #endif
  266. break ;
  267. }
  268. //
  269. // For some IRP major's going down a stack, there *must* be a handler
  270. //
  271. driverObject = DeviceObject->DriverObject;
  272. if (!IovUtilHasDispatchHandler(driverObject, IRP_MJ_PNP)) {
  273. RequestHeadLocationData->Flags |= STACKFLAG_BOGUS_IRP_TOUCHED;
  274. WDM_FAIL_ROUTINE((
  275. DCERROR_MISSING_DISPATCH_FUNCTION,
  276. DCPARAM_IRP + DCPARAM_ROUTINE,
  277. driverObject->DriverInit,
  278. irp
  279. ));
  280. StackLocationData->Flags |= STACKFLAG_NO_HANDLER;
  281. }
  282. //
  283. // The following is only executed if we are not a new IRP...
  284. //
  285. if (IrpLastSp == NULL) {
  286. return;
  287. }
  288. //
  289. // The only legit failure code to pass down is STATUS_NOT_SUPPORTED
  290. //
  291. if ((!NT_SUCCESS(currentStatus)) && (currentStatus != STATUS_NOT_SUPPORTED) &&
  292. (!(RequestHeadLocationData->Flags & STACKFLAG_FAILURE_FORWARDED))) {
  293. WDM_FAIL_ROUTINE((
  294. DCERROR_PNP_FAILURE_FORWARDED,
  295. DCPARAM_IRP + DCPARAM_ROUTINE,
  296. CallerAddress,
  297. irp
  298. ));
  299. //
  300. // Don't blame anyone else for this driver's mistakes...
  301. //
  302. RequestHeadLocationData->Flags |= STACKFLAG_FAILURE_FORWARDED;
  303. }
  304. //
  305. // Status of a PnP IRP may not be converted to
  306. // STATUS_NOT_SUPPORTED on the way down
  307. //
  308. if ((currentStatus == STATUS_NOT_SUPPORTED)&&statusChanged&&
  309. (!(RequestHeadLocationData->Flags & STACKFLAG_FAILURE_FORWARDED))) {
  310. WDM_FAIL_ROUTINE((
  311. DCERROR_PNP_IRP_STATUS_RESET,
  312. DCPARAM_IRP + DCPARAM_ROUTINE,
  313. CallerAddress,
  314. irp
  315. ));
  316. //
  317. // Don't blame anyone else for this driver's mistakes...
  318. //
  319. RequestHeadLocationData->Flags |= STACKFLAG_FAILURE_FORWARDED;
  320. }
  321. //
  322. // Some IRPs FDO's are required to handle before passing down. And some
  323. // IRPs should not be touched by the FDO. Assert it is so...
  324. //
  325. if ((!iovSessionData->DeviceLastCalled) ||
  326. (!IovUtilIsDesignatedFdo(iovSessionData->DeviceLastCalled))) {
  327. return;
  328. }
  329. if (currentStatus != STATUS_NOT_SUPPORTED) {
  330. howProcessed = DEFINITELY_PROCESSED;
  331. } else if (IrpSp->CompletionRoutine == NULL) {
  332. howProcessed = NOT_PROCESSED;
  333. } else {
  334. howProcessed = POSSIBLY_PROCESSED;
  335. }
  336. //
  337. // How could a Raw FDO (aka a PDO) get here? Well, a PDO could forward
  338. // to another stack if he's purposely reserved enough stack locations
  339. // for that eventuality.
  340. //
  341. devObjType = IovUtilIsRawPdo(iovSessionData->DeviceLastCalled) ?
  342. VF_DEVOBJ_PDO : VF_DEVOBJ_FDO;
  343. ViPnpVerifyMinorWasProcessedProperly(
  344. irp,
  345. IrpSp,
  346. devObjType,
  347. iovSessionData->VerifierSettings,
  348. howProcessed,
  349. CallerAddress
  350. );
  351. }
  352. VOID
  353. FASTCALL
  354. VfPnpVerifyIrpStackUpward(
  355. IN PIOV_REQUEST_PACKET IovPacket,
  356. IN PIO_STACK_LOCATION IrpSp,
  357. IN PIOV_STACK_LOCATION RequestHeadLocationData,
  358. IN PIOV_STACK_LOCATION StackLocationData,
  359. IN BOOLEAN IsNewlyCompleted,
  360. IN BOOLEAN RequestFinalized
  361. )
  362. {
  363. PIRP irp;
  364. NTSTATUS currentStatus;
  365. BOOLEAN mustPassDown, isBogusIrp, isPdo, touchable;
  366. PVOID routine;
  367. LONG referencesTaken;
  368. PDEVICE_RELATIONS deviceRelations;
  369. PIOV_SESSION_DATA iovSessionData;
  370. ULONG index, swapIndex;
  371. PDEVICE_OBJECT swapObject, lowerDevObj;
  372. HOW_PROCESSED howProcessed;
  373. UNREFERENCED_PARAMETER (RequestFinalized);
  374. if (!IovUtilIsWdmStack(IrpSp->DeviceObject)) {
  375. return;
  376. }
  377. isPdo = FALSE;
  378. irp = IovPacket->TrackedIrp;
  379. currentStatus = irp->IoStatus.Status;
  380. iovSessionData = VfPacketGetCurrentSessionData(IovPacket);
  381. //
  382. // Who'd we call for this one?
  383. //
  384. routine = StackLocationData->LastDispatch;
  385. ASSERT(routine) ;
  386. //
  387. // If this "Request" has been "Completed", perform some checks
  388. //
  389. if (IsNewlyCompleted) {
  390. //
  391. // Remember bogosity...
  392. //
  393. isBogusIrp = (BOOLEAN)((IovPacket->Flags&TRACKFLAG_BOGUS)!=0);
  394. //
  395. // Is this a PDO?
  396. //
  397. isPdo = (BOOLEAN)((StackLocationData->Flags&STACKFLAG_REACHED_PDO)!=0);
  398. //
  399. // Was anything completed too early?
  400. // A driver may outright fail almost anything but a bogus IRP
  401. //
  402. mustPassDown = (BOOLEAN)(!(StackLocationData->Flags&STACKFLAG_NO_HANDLER));
  403. mustPassDown &= (!isPdo);
  404. mustPassDown &= (isBogusIrp || NT_SUCCESS(currentStatus) || (currentStatus == STATUS_NOT_SUPPORTED));
  405. if (mustPassDown) {
  406. //
  407. // Print appropriate error message
  408. //
  409. if (IovPacket->Flags&TRACKFLAG_BOGUS) {
  410. WDM_FAIL_ROUTINE((
  411. DCERROR_BOGUS_PNP_IRP_COMPLETED,
  412. DCPARAM_IRP + DCPARAM_ROUTINE,
  413. routine,
  414. irp
  415. ));
  416. } else if (NT_SUCCESS(currentStatus)) {
  417. WDM_FAIL_ROUTINE((
  418. DCERROR_SUCCESSFUL_PNP_IRP_NOT_FORWARDED,
  419. DCPARAM_IRP + DCPARAM_ROUTINE,
  420. routine,
  421. irp
  422. ));
  423. } else if (currentStatus == STATUS_NOT_SUPPORTED) {
  424. WDM_FAIL_ROUTINE((
  425. DCERROR_UNTOUCHED_PNP_IRP_NOT_FORWARDED,
  426. DCPARAM_IRP + DCPARAM_ROUTINE,
  427. routine,
  428. irp
  429. ));
  430. }
  431. }
  432. }
  433. //
  434. // Did the PDO respond to it's required set of IRPs?
  435. //
  436. if (IsNewlyCompleted && isPdo) {
  437. if (currentStatus != STATUS_NOT_SUPPORTED) {
  438. howProcessed = DEFINITELY_PROCESSED;
  439. } else {
  440. howProcessed = POSSIBLY_PROCESSED;
  441. }
  442. ViPnpVerifyMinorWasProcessedProperly(
  443. irp,
  444. IrpSp,
  445. VF_DEVOBJ_PDO,
  446. iovSessionData->VerifierSettings,
  447. howProcessed,
  448. routine
  449. );
  450. }
  451. //
  452. // Was TargetDeviceRelation implemented correctly?
  453. //
  454. if (IsNewlyCompleted &&
  455. (RequestHeadLocationData->Flags&STACKFLAG_CHECK_FOR_REFERENCE)) {
  456. ASSERT ((IrpSp->MajorFunction == IRP_MJ_PNP)&&
  457. (IrpSp->MinorFunction == IRP_MN_QUERY_DEVICE_RELATIONS)&&
  458. (IrpSp->Parameters.QueryDeviceRelations.Type == TargetDeviceRelation));
  459. ASSERT(RequestHeadLocationData->ReferencingObject);
  460. ASSERT(IovPacket->RefTrackingCount);
  461. referencesTaken = (LONG)ObvUtilStopObRefMonitoring(
  462. RequestHeadLocationData->ReferencingObject,
  463. RequestHeadLocationData->ReferencingCount
  464. );
  465. IovPacket->RefTrackingCount--;
  466. RequestHeadLocationData->ReferencingObject = NULL;
  467. RequestHeadLocationData->Flags &= ~STACKFLAG_CHECK_FOR_REFERENCE;
  468. if (NT_SUCCESS(currentStatus)&&(!referencesTaken)) {
  469. WDM_FAIL_ROUTINE((
  470. DCERROR_TARGET_RELATION_NEEDS_REF,
  471. DCPARAM_IRP + DCPARAM_ROUTINE,
  472. routine,
  473. irp
  474. ));
  475. }
  476. }
  477. //
  478. // Did anyone stomp the status erroneously?
  479. //
  480. if ((currentStatus == STATUS_NOT_SUPPORTED) &&
  481. (!(RequestHeadLocationData->Flags & STACKFLAG_FAILURE_FORWARDED)) &&
  482. (currentStatus != RequestHeadLocationData->LastStatusBlock.Status)) {
  483. //
  484. // Status of a PnP or Power IRP may not be converted from success to
  485. // STATUS_NOT_SUPPORTED on the way down.
  486. //
  487. WDM_FAIL_ROUTINE((
  488. DCERROR_PNP_IRP_STATUS_RESET,
  489. DCPARAM_IRP + DCPARAM_ROUTINE,
  490. routine,
  491. irp
  492. ));
  493. //
  494. // Don't blame anyone else for this driver's mistakes...
  495. //
  496. RequestHeadLocationData->Flags |= STACKFLAG_FAILURE_FORWARDED;
  497. }
  498. switch(IrpSp->MinorFunction) {
  499. case IRP_MN_QUERY_DEVICE_RELATIONS:
  500. //
  501. // Rotate device relations if so ordered.
  502. //
  503. if ((RequestHeadLocationData == StackLocationData) &&
  504. ((IrpSp->Parameters.QueryDeviceRelations.Type == BusRelations) ||
  505. (IrpSp->Parameters.QueryDeviceRelations.Type == RemovalRelations) ||
  506. (IrpSp->Parameters.QueryDeviceRelations.Type == EjectionRelations)) &&
  507. VfSettingsIsOptionEnabled(iovSessionData->VerifierSettings,
  508. VERIFIER_OPTION_SCRAMBLE_RELATIONS)) {
  509. if (NT_SUCCESS(currentStatus) && irp->IoStatus.Information) {
  510. deviceRelations = (PDEVICE_RELATIONS) irp->IoStatus.Information;
  511. touchable = VfUtilIsMemoryRangeReadable(
  512. deviceRelations,
  513. (sizeof(DEVICE_RELATIONS)-sizeof(PVOID)),
  514. VFMP_INSTANT_NONPAGED
  515. );
  516. if (!touchable) {
  517. break;
  518. }
  519. touchable = VfUtilIsMemoryRangeReadable(
  520. deviceRelations,
  521. (sizeof(DEVICE_RELATIONS)+((LONG) (deviceRelations->Count-1))*sizeof(PVOID)),
  522. VFMP_INSTANT_NONPAGED
  523. );
  524. if (!touchable) {
  525. break;
  526. }
  527. if (deviceRelations->Count > 1) {
  528. //
  529. // Scramble the relation list by random swapping.
  530. //
  531. for(index = 0; index < (deviceRelations->Count+1)/2; index++) {
  532. swapIndex = VfRandomGetNumber(1, deviceRelations->Count-1);
  533. swapObject = deviceRelations->Objects[0];
  534. deviceRelations->Objects[0] = deviceRelations->Objects[swapIndex];
  535. deviceRelations->Objects[swapIndex] = swapObject;
  536. }
  537. }
  538. }
  539. }
  540. break;
  541. case IRP_MN_SURPRISE_REMOVAL:
  542. if (VfSettingsIsOptionEnabled(iovSessionData->VerifierSettings,
  543. VERIFIER_OPTION_MONITOR_REMOVES)) {
  544. //
  545. // Verify driver didn't do an IoDetachDevice upon recieving the
  546. // SURPRISE_REMOVAL IRP.
  547. //
  548. IovUtilGetLowerDeviceObject(IrpSp->DeviceObject, &lowerDevObj);
  549. if (lowerDevObj) {
  550. ObDereferenceObject(lowerDevObj);
  551. } else if (!IovUtilIsPdo(IrpSp->DeviceObject)) {
  552. WDM_FAIL_ROUTINE((
  553. DCERROR_DETACHED_IN_SURPRISE_REMOVAL,
  554. DCPARAM_IRP + DCPARAM_ROUTINE + DCPARAM_DEVOBJ,
  555. routine,
  556. iovSessionData->BestVisibleIrp,
  557. IrpSp->DeviceObject
  558. ));
  559. }
  560. //
  561. // Verify driver didn't do an IoDeleteDevice upon recieving the
  562. // SURPRISE_REMOVAL IRP.
  563. //
  564. if (IovUtilIsDeviceObjectMarked(IrpSp->DeviceObject, MARKTYPE_DELETED)) {
  565. WDM_FAIL_ROUTINE((
  566. DCERROR_DELETED_IN_SURPRISE_REMOVAL,
  567. DCPARAM_IRP + DCPARAM_ROUTINE + DCPARAM_DEVOBJ,
  568. routine,
  569. iovSessionData->BestVisibleIrp,
  570. IrpSp->DeviceObject
  571. ));
  572. }
  573. }
  574. break;
  575. default:
  576. break;
  577. }
  578. }
  579. VOID
  580. FASTCALL
  581. VfPnpDumpIrpStack(
  582. IN PIO_STACK_LOCATION IrpSp
  583. )
  584. {
  585. DbgPrint("IRP_MJ_PNP.");
  586. if (IrpSp->MinorFunction<=MAX_NAMED_PNP_IRP) {
  587. DbgPrint(PnPIrpNames[IrpSp->MinorFunction]);
  588. } else if (IrpSp->MinorFunction==0xFF) {
  589. DbgPrint("IRP_MN_BOGUS");
  590. } else {
  591. DbgPrint("(Bogus)");
  592. }
  593. switch(IrpSp->MinorFunction) {
  594. case IRP_MN_QUERY_DEVICE_RELATIONS:
  595. switch(IrpSp->Parameters.QueryDeviceRelations.Type) {
  596. case BusRelations:
  597. DbgPrint("(BusRelations)");
  598. break;
  599. case EjectionRelations:
  600. DbgPrint("(EjectionRelations)");
  601. break;
  602. case PowerRelations:
  603. DbgPrint("(PowerRelations)");
  604. break;
  605. case RemovalRelations:
  606. DbgPrint("(RemovalRelations)");
  607. break;
  608. case TargetDeviceRelation:
  609. DbgPrint("(TargetDeviceRelation)");
  610. break;
  611. default:
  612. DbgPrint("(Bogus)");
  613. break;
  614. }
  615. break;
  616. case IRP_MN_QUERY_INTERFACE:
  617. break;
  618. case IRP_MN_QUERY_DEVICE_TEXT:
  619. switch(IrpSp->Parameters.QueryId.IdType) {
  620. case DeviceTextDescription:
  621. DbgPrint("(DeviceTextDescription)");
  622. break;
  623. case DeviceTextLocationInformation:
  624. DbgPrint("(DeviceTextLocationInformation)");
  625. break;
  626. default:
  627. DbgPrint("(Bogus)");
  628. break;
  629. }
  630. break;
  631. case IRP_MN_WRITE_CONFIG:
  632. case IRP_MN_READ_CONFIG:
  633. DbgPrint("(WhichSpace=%x, Buffer=%x, Offset=%x, Length=%x)",
  634. IrpSp->Parameters.ReadWriteConfig.WhichSpace,
  635. IrpSp->Parameters.ReadWriteConfig.Buffer,
  636. IrpSp->Parameters.ReadWriteConfig.Offset,
  637. IrpSp->Parameters.ReadWriteConfig.Length
  638. );
  639. break;
  640. case IRP_MN_SET_LOCK:
  641. if (IrpSp->Parameters.SetLock.Lock) DbgPrint("(True)");
  642. else DbgPrint("(False)");
  643. break;
  644. case IRP_MN_QUERY_ID:
  645. switch(IrpSp->Parameters.QueryId.IdType) {
  646. case BusQueryDeviceID:
  647. DbgPrint("(BusQueryDeviceID)");
  648. break;
  649. case BusQueryHardwareIDs:
  650. DbgPrint("(BusQueryHardwareIDs)");
  651. break;
  652. case BusQueryCompatibleIDs:
  653. DbgPrint("(BusQueryCompatibleIDs)");
  654. break;
  655. case BusQueryInstanceID:
  656. DbgPrint("(BusQueryInstanceID)");
  657. break;
  658. default:
  659. DbgPrint("(Bogus)");
  660. break;
  661. }
  662. break;
  663. case IRP_MN_QUERY_BUS_INFORMATION:
  664. break;
  665. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  666. switch(IrpSp->Parameters.UsageNotification.Type) {
  667. case DeviceUsageTypeUndefined:
  668. DbgPrint("(DeviceUsageTypeUndefined");
  669. break;
  670. case DeviceUsageTypePaging:
  671. DbgPrint("(DeviceUsageTypePaging");
  672. break;
  673. case DeviceUsageTypeHibernation:
  674. DbgPrint("(DeviceUsageTypeHibernation");
  675. break;
  676. case DeviceUsageTypeDumpFile:
  677. DbgPrint("(DeviceUsageTypeDumpFile");
  678. break;
  679. default:
  680. DbgPrint("(Bogus)");
  681. break;
  682. }
  683. if (IrpSp->Parameters.UsageNotification.InPath) {
  684. DbgPrint(", InPath=TRUE)");
  685. } else {
  686. DbgPrint(", InPath=FALSE)");
  687. }
  688. break;
  689. case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
  690. break;
  691. default:
  692. break;
  693. }
  694. }
  695. BOOLEAN
  696. FASTCALL
  697. VfPnpIsSystemRestrictedIrp(
  698. IN PIO_STACK_LOCATION IrpSp
  699. )
  700. {
  701. switch(IrpSp->MinorFunction) {
  702. case IRP_MN_START_DEVICE:
  703. case IRP_MN_QUERY_REMOVE_DEVICE:
  704. case IRP_MN_REMOVE_DEVICE:
  705. case IRP_MN_CANCEL_REMOVE_DEVICE:
  706. case IRP_MN_STOP_DEVICE:
  707. case IRP_MN_QUERY_STOP_DEVICE:
  708. case IRP_MN_CANCEL_STOP_DEVICE:
  709. case IRP_MN_SURPRISE_REMOVAL:
  710. return TRUE;
  711. case IRP_MN_QUERY_DEVICE_RELATIONS:
  712. switch(IrpSp->Parameters.QueryDeviceRelations.Type) {
  713. case BusRelations:
  714. case PowerRelations:
  715. return TRUE;
  716. case RemovalRelations:
  717. case EjectionRelations:
  718. case TargetDeviceRelation:
  719. return FALSE;
  720. default:
  721. break;
  722. }
  723. break;
  724. case IRP_MN_QUERY_INTERFACE:
  725. case IRP_MN_QUERY_CAPABILITIES:
  726. return FALSE;
  727. case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  728. case IRP_MN_QUERY_DEVICE_TEXT:
  729. return TRUE;
  730. case IRP_MN_READ_CONFIG:
  731. case IRP_MN_WRITE_CONFIG:
  732. return FALSE;
  733. case IRP_MN_EJECT:
  734. case IRP_MN_SET_LOCK:
  735. case IRP_MN_QUERY_RESOURCES:
  736. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  737. case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
  738. return TRUE;
  739. case IRP_MN_QUERY_ID:
  740. switch(IrpSp->Parameters.QueryId.IdType) {
  741. case BusQueryHardwareIDs:
  742. case BusQueryCompatibleIDs:
  743. return TRUE;
  744. case BusQueryDeviceID:
  745. case BusQueryInstanceID:
  746. return FALSE;
  747. default:
  748. break;
  749. }
  750. break;
  751. case IRP_MN_QUERY_PNP_DEVICE_STATE:
  752. case IRP_MN_QUERY_BUS_INFORMATION:
  753. return TRUE;
  754. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  755. return FALSE;
  756. default:
  757. break;
  758. }
  759. return TRUE;
  760. }
  761. BOOLEAN
  762. FASTCALL
  763. VfPnpAdvanceIrpStatus(
  764. IN PIO_STACK_LOCATION IrpSp,
  765. IN NTSTATUS OriginalStatus,
  766. IN OUT NTSTATUS *StatusToAdvance
  767. )
  768. /*++
  769. Description:
  770. Given an IRP stack pointer, is it legal to change the status for
  771. debug-ability? If so, this function determines what the new status
  772. should be. Note that for each stack location, this function is iterated
  773. over n times where n is equal to the number of drivers who IoSkip'd this
  774. location.
  775. Arguments:
  776. IrpSp - Current stack right after complete for the given stack
  777. location, but before the completion routine for the
  778. stack location above has been called.
  779. OriginalStatus - The status of the IRP at the time listed above. Does
  780. not change over iteration per skipping driver.
  781. StatusToAdvance - Pointer to the current status that should be updated.
  782. Return Value:
  783. TRUE if the status has been adjusted, FALSE otherwise (in this case
  784. StatusToAdvance is untouched).
  785. --*/
  786. {
  787. UNREFERENCED_PARAMETER (IrpSp);
  788. if (((ULONG) OriginalStatus) >= 256) {
  789. return FALSE;
  790. }
  791. (*StatusToAdvance)++;
  792. if ((*StatusToAdvance) == STATUS_PENDING) {
  793. (*StatusToAdvance)++;
  794. }
  795. return TRUE;
  796. }
  797. VOID
  798. FASTCALL
  799. VfPnpTestStartedPdoStack(
  800. IN PDEVICE_OBJECT PhysicalDeviceObject
  801. )
  802. /*++
  803. Description:
  804. As per the title, we are going to throw some IRPs at the stack to
  805. see if they are handled correctly.
  806. Returns:
  807. Nothing
  808. --*/
  809. {
  810. IO_STACK_LOCATION irpSp;
  811. PDEVICE_RELATIONS targetDeviceRelationList;
  812. INTERFACE interface;
  813. NTSTATUS status;
  814. PAGED_CODE();
  815. //
  816. // Initialize the stack location to pass to IopSynchronousCall()
  817. //
  818. RtlZeroMemory(&irpSp, sizeof(IO_STACK_LOCATION));
  819. //
  820. // send lots of bogus PNP IRPs
  821. //
  822. irpSp.MajorFunction = IRP_MJ_PNP;
  823. irpSp.MinorFunction = 0xff;
  824. VfIrpSendSynchronousIrp(
  825. PhysicalDeviceObject,
  826. &irpSp,
  827. TRUE,
  828. STATUS_NOT_SUPPORTED,
  829. 0,
  830. NULL,
  831. NULL
  832. );
  833. irpSp.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
  834. irpSp.Parameters.QueryDeviceRelations.Type = (DEVICE_RELATION_TYPE) -1;
  835. VfIrpSendSynchronousIrp(
  836. PhysicalDeviceObject,
  837. &irpSp,
  838. TRUE,
  839. STATUS_NOT_SUPPORTED,
  840. 0,
  841. NULL,
  842. NULL
  843. );
  844. if (VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_RELATION_IGNORANCE_TEST)) {
  845. irpSp.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
  846. irpSp.Parameters.QueryDeviceRelations.Type = (DEVICE_RELATION_TYPE) -1;
  847. VfIrpSendSynchronousIrp(
  848. PhysicalDeviceObject,
  849. &irpSp,
  850. TRUE,
  851. STATUS_NOT_SUPPORTED,
  852. (ULONG_PTR) -1,
  853. NULL,
  854. NULL
  855. );
  856. }
  857. irpSp.MinorFunction = IRP_MN_QUERY_DEVICE_TEXT;
  858. irpSp.Parameters.QueryDeviceText.DeviceTextType = (DEVICE_TEXT_TYPE) -1;
  859. VfIrpSendSynchronousIrp(
  860. PhysicalDeviceObject,
  861. &irpSp,
  862. TRUE,
  863. STATUS_NOT_SUPPORTED,
  864. 0,
  865. NULL,
  866. NULL
  867. );
  868. irpSp.MinorFunction = IRP_MN_QUERY_ID;
  869. irpSp.Parameters.QueryId.IdType = (BUS_QUERY_ID_TYPE) -1;
  870. VfIrpSendSynchronousIrp(
  871. PhysicalDeviceObject,
  872. &irpSp,
  873. TRUE,
  874. STATUS_NOT_SUPPORTED,
  875. 0,
  876. NULL,
  877. NULL
  878. );
  879. /*
  880. irpSp.MinorFunction = IRP_MN_QUERY_ID;
  881. irpSp.Parameters.QueryId.IdType = (BUS_QUERY_ID_TYPE) -1;
  882. VfIrpSendSynchronousIrp(
  883. PhysicalDeviceObject,
  884. &irpSp,
  885. TRUE,
  886. STATUS_SUCCESS,
  887. (ULONG_PTR) -1,
  888. NULL,
  889. NULL
  890. );
  891. */
  892. //
  893. // Target device relation test...
  894. //
  895. irpSp.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
  896. irpSp.Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
  897. targetDeviceRelationList = NULL;
  898. if (VfIrpSendSynchronousIrp(
  899. PhysicalDeviceObject,
  900. &irpSp,
  901. FALSE,
  902. STATUS_NOT_SUPPORTED,
  903. 0,
  904. (ULONG_PTR *) &targetDeviceRelationList,
  905. &status
  906. )) {
  907. if (NT_SUCCESS(status)) {
  908. ASSERT(targetDeviceRelationList);
  909. ASSERT(targetDeviceRelationList->Count == 1);
  910. ASSERT(targetDeviceRelationList->Objects[0]);
  911. ObDereferenceObject(targetDeviceRelationList->Objects[0]);
  912. ExFreePool(targetDeviceRelationList);
  913. } else {
  914. //
  915. // IRP was asserted in other code. We need to do nothing here...
  916. //
  917. }
  918. }
  919. RtlZeroMemory(&interface, sizeof(INTERFACE));
  920. irpSp.MinorFunction = IRP_MN_QUERY_INTERFACE;
  921. irpSp.Parameters.QueryInterface.Size = (USHORT)-1;
  922. irpSp.Parameters.QueryInterface.Version = 1;
  923. irpSp.Parameters.QueryInterface.InterfaceType = &GUID_BOGUS_INTERFACE;
  924. irpSp.Parameters.QueryInterface.Interface = &interface;
  925. irpSp.Parameters.QueryInterface.InterfaceSpecificData = (PVOID) -1;
  926. VfIrpSendSynchronousIrp(
  927. PhysicalDeviceObject,
  928. &irpSp,
  929. TRUE,
  930. STATUS_NOT_SUPPORTED,
  931. 0,
  932. NULL,
  933. NULL
  934. );
  935. RtlZeroMemory(&interface, sizeof(INTERFACE));
  936. irpSp.MinorFunction = IRP_MN_QUERY_INTERFACE;
  937. irpSp.Parameters.QueryInterface.Size = (USHORT)-1;
  938. irpSp.Parameters.QueryInterface.Version = 1;
  939. irpSp.Parameters.QueryInterface.InterfaceType = &GUID_BOGUS_INTERFACE;
  940. irpSp.Parameters.QueryInterface.Interface = &interface;
  941. irpSp.Parameters.QueryInterface.InterfaceSpecificData = (PVOID) -1;
  942. VfIrpSendSynchronousIrp(
  943. PhysicalDeviceObject,
  944. &irpSp,
  945. TRUE,
  946. STATUS_SUCCESS,
  947. 0,
  948. NULL,
  949. NULL
  950. );
  951. //
  952. // We could do more chaff here. For example, bogus device usage
  953. // notifications, etc...
  954. //
  955. }
  956. VOID
  957. ViPnpVerifyMinorWasProcessedProperly(
  958. IN PIRP Irp,
  959. IN PIO_STACK_LOCATION IrpSp,
  960. IN VF_DEVOBJ_TYPE DevObjType,
  961. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSnapshot,
  962. IN HOW_PROCESSED HowProcessed,
  963. IN PVOID CallerAddress
  964. )
  965. {
  966. PDEVICE_OBJECT relationObject, relationPdo;
  967. PDEVICE_RELATIONS deviceRelations;
  968. BOOLEAN touchable;
  969. ULONG index;
  970. switch(IrpSp->MinorFunction) {
  971. case IRP_MN_SURPRISE_REMOVAL:
  972. if ((HowProcessed != NOT_PROCESSED) ||
  973. (!VfSettingsIsOptionEnabled(VerifierSnapshot,
  974. VERIFIER_OPTION_EXTENDED_REQUIRED_IRPS))) {
  975. break;
  976. }
  977. WDM_FAIL_ROUTINE((
  978. DCERROR_PNP_IRP_NEEDS_HANDLING,
  979. DCPARAM_IRP + DCPARAM_ROUTINE,
  980. CallerAddress,
  981. Irp
  982. ));
  983. break;
  984. case IRP_MN_START_DEVICE:
  985. case IRP_MN_QUERY_REMOVE_DEVICE:
  986. case IRP_MN_REMOVE_DEVICE:
  987. case IRP_MN_STOP_DEVICE:
  988. case IRP_MN_QUERY_STOP_DEVICE:
  989. //
  990. // The driver must set the status as appropriate.
  991. //
  992. if (HowProcessed != NOT_PROCESSED) {
  993. break;
  994. }
  995. WDM_FAIL_ROUTINE((
  996. DCERROR_PNP_IRP_NEEDS_HANDLING,
  997. DCPARAM_IRP + DCPARAM_ROUTINE,
  998. CallerAddress,
  999. Irp
  1000. ));
  1001. break;
  1002. case IRP_MN_CANCEL_REMOVE_DEVICE:
  1003. case IRP_MN_CANCEL_STOP_DEVICE:
  1004. //
  1005. // The driver must set the status of these IRPs to something
  1006. // successful!
  1007. //
  1008. if (HowProcessed == NOT_PROCESSED) {
  1009. WDM_FAIL_ROUTINE((
  1010. DCERROR_PNP_IRP_NEEDS_HANDLING,
  1011. DCPARAM_IRP + DCPARAM_ROUTINE,
  1012. CallerAddress,
  1013. Irp
  1014. ));
  1015. } else if ((HowProcessed == DEFINITELY_PROCESSED) &&
  1016. (!NT_SUCCESS(Irp->IoStatus.Status)) &&
  1017. (VfSettingsIsOptionEnabled(VerifierSnapshot,
  1018. VERIFIER_OPTION_EXTENDED_REQUIRED_IRPS))) {
  1019. WDM_FAIL_ROUTINE((
  1020. DCERROR_NON_FAILABLE_IRP,
  1021. DCPARAM_IRP + DCPARAM_ROUTINE,
  1022. CallerAddress,
  1023. Irp
  1024. ));
  1025. }
  1026. break;
  1027. case IRP_MN_QUERY_DEVICE_RELATIONS:
  1028. switch(IrpSp->Parameters.QueryDeviceRelations.Type) {
  1029. case TargetDeviceRelation:
  1030. if (DevObjType != VF_DEVOBJ_PDO) {
  1031. if (HowProcessed != DEFINITELY_PROCESSED) {
  1032. break;
  1033. }
  1034. WDM_FAIL_ROUTINE((
  1035. DCERROR_PNP_IRP_HANDS_OFF,
  1036. DCPARAM_IRP + DCPARAM_ROUTINE,
  1037. CallerAddress,
  1038. Irp
  1039. ));
  1040. } else {
  1041. if (HowProcessed == NOT_PROCESSED) {
  1042. WDM_FAIL_ROUTINE((
  1043. DCERROR_PNP_IRP_NEEDS_PDO_HANDLING,
  1044. DCPARAM_IRP + DCPARAM_ROUTINE,
  1045. CallerAddress,
  1046. Irp
  1047. ));
  1048. } else if (NT_SUCCESS(Irp->IoStatus.Status)) {
  1049. if (Irp->IoStatus.Information == (ULONG_PTR) NULL) {
  1050. WDM_FAIL_ROUTINE((
  1051. DCERROR_TARGET_RELATION_LIST_EMPTY,
  1052. DCPARAM_IRP + DCPARAM_ROUTINE,
  1053. CallerAddress,
  1054. Irp
  1055. ));
  1056. }
  1057. //
  1058. // ADRIAO N.B. - I could also assert the Information
  1059. // matches DeviceObject.
  1060. //
  1061. }
  1062. }
  1063. break;
  1064. case BusRelations:
  1065. case PowerRelations:
  1066. case RemovalRelations:
  1067. case EjectionRelations:
  1068. //
  1069. // Ejection relations are usually a bad idea for
  1070. // FDO's - As stopping a device implies powerdown,
  1071. // RemovalRelations are usually the proper response
  1072. // for an FDO. One exception is ISAPNP, as PCI-to-ISA
  1073. // bridges can never be powered down.
  1074. //
  1075. default:
  1076. break;
  1077. }
  1078. //
  1079. // Verify we got back PDO's.
  1080. //
  1081. if (!VfSettingsIsOptionEnabled(
  1082. VerifierSnapshot,
  1083. VERIFIER_OPTION_EXAMINE_RELATION_PDOS)) {
  1084. break;
  1085. }
  1086. if ((!NT_SUCCESS(Irp->IoStatus.Status)) ||
  1087. (((PVOID) Irp->IoStatus.Information) == NULL)) {
  1088. break;
  1089. }
  1090. switch(IrpSp->Parameters.QueryDeviceRelations.Type) {
  1091. case TargetDeviceRelation:
  1092. case BusRelations:
  1093. case PowerRelations:
  1094. case RemovalRelations:
  1095. case EjectionRelations:
  1096. deviceRelations = (PDEVICE_RELATIONS) Irp->IoStatus.Information;
  1097. touchable = VfUtilIsMemoryRangeReadable(
  1098. deviceRelations,
  1099. (sizeof(DEVICE_RELATIONS)-sizeof(PVOID)),
  1100. VFMP_INSTANT_NONPAGED
  1101. );
  1102. if (!touchable) {
  1103. break;
  1104. }
  1105. touchable = VfUtilIsMemoryRangeReadable(
  1106. deviceRelations,
  1107. (sizeof(DEVICE_RELATIONS)+((LONG) (deviceRelations->Count-1))*sizeof(PVOID)),
  1108. VFMP_INSTANT_NONPAGED
  1109. );
  1110. if (!touchable) {
  1111. break;
  1112. }
  1113. for(index = 0; index < deviceRelations->Count; index++) {
  1114. relationObject = deviceRelations->Objects[index];
  1115. if (IovUtilIsDeviceObjectMarked(relationObject, MARKTYPE_RELATION_PDO_EXAMINED)) {
  1116. continue;
  1117. }
  1118. IovUtilGetBottomDeviceObject(relationObject, &relationPdo);
  1119. if (relationPdo != relationObject) {
  1120. //
  1121. // Fail the appropriate driver.
  1122. //
  1123. WDM_FAIL_ROUTINE((
  1124. DCERROR_NON_PDO_RETURNED_IN_RELATION,
  1125. DCPARAM_IRP + DCPARAM_ROUTINE + DCPARAM_DEVOBJ,
  1126. CallerAddress,
  1127. Irp,
  1128. relationObject
  1129. ));
  1130. }
  1131. //
  1132. // Don't blame the next driver that handles the IRP.
  1133. //
  1134. IovUtilMarkDeviceObject(
  1135. relationObject,
  1136. MARKTYPE_RELATION_PDO_EXAMINED
  1137. );
  1138. //
  1139. // Drop ref
  1140. //
  1141. ObDereferenceObject(relationPdo);
  1142. }
  1143. break;
  1144. }
  1145. break;
  1146. case IRP_MN_QUERY_INTERFACE:
  1147. case IRP_MN_QUERY_CAPABILITIES:
  1148. case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  1149. break;
  1150. case IRP_MN_QUERY_DEVICE_TEXT:
  1151. case IRP_MN_READ_CONFIG:
  1152. case IRP_MN_WRITE_CONFIG:
  1153. case IRP_MN_EJECT:
  1154. case IRP_MN_SET_LOCK:
  1155. case IRP_MN_QUERY_RESOURCES:
  1156. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  1157. case IRP_MN_QUERY_BUS_INFORMATION:
  1158. if ((DevObjType == VF_DEVOBJ_PDO) ||
  1159. (HowProcessed != DEFINITELY_PROCESSED)) {
  1160. break;
  1161. }
  1162. WDM_FAIL_ROUTINE((
  1163. DCERROR_PNP_IRP_HANDS_OFF,
  1164. DCPARAM_IRP + DCPARAM_ROUTINE,
  1165. CallerAddress,
  1166. Irp
  1167. ));
  1168. break;
  1169. case IRP_MN_QUERY_ID:
  1170. switch(IrpSp->Parameters.QueryId.IdType) {
  1171. case BusQueryDeviceID:
  1172. case BusQueryHardwareIDs:
  1173. case BusQueryCompatibleIDs:
  1174. case BusQueryInstanceID:
  1175. if ((DevObjType == VF_DEVOBJ_PDO) ||
  1176. (HowProcessed != DEFINITELY_PROCESSED)) {
  1177. break;
  1178. }
  1179. WDM_FAIL_ROUTINE((
  1180. DCERROR_PNP_IRP_HANDS_OFF,
  1181. DCPARAM_IRP + DCPARAM_ROUTINE,
  1182. CallerAddress,
  1183. Irp
  1184. ));
  1185. break;
  1186. default:
  1187. break;
  1188. }
  1189. break;
  1190. case IRP_MN_QUERY_PNP_DEVICE_STATE:
  1191. case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
  1192. break;
  1193. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  1194. if ((HowProcessed != NOT_PROCESSED) ||
  1195. (!VfSettingsIsOptionEnabled(VerifierSnapshot,
  1196. VERIFIER_OPTION_EXTENDED_REQUIRED_IRPS))) {
  1197. break;
  1198. }
  1199. WDM_FAIL_ROUTINE((
  1200. DCERROR_PNP_IRP_NEEDS_HANDLING,
  1201. DCPARAM_IRP + DCPARAM_ROUTINE,
  1202. CallerAddress,
  1203. Irp
  1204. ));
  1205. break;
  1206. default:
  1207. break;
  1208. }
  1209. }