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.

293 lines
5.9 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ppvutil.c
  5. Abstract:
  6. This module implements various utilities required to do driver verification.
  7. Author:
  8. Adrian J. Oney (adriao) 20-Apr-1998
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. AdriaO 02/10/2000 - Seperated out from ntos\io\trackirp.c
  13. --*/
  14. #include "pnpmgrp.h"
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(PAGEVRFY, PpvUtilInit)
  17. //#pragma alloc_text(PAGEVRFY, PpvUtilFailDriver)
  18. //#pragma alloc_text(PAGEVRFY, PpvUtilCallAddDevice)
  19. //#pragma alloc_text(PAGEVRFY, PpvUtilTestStartedPdoStack)
  20. #ifndef NO_VERIFIER
  21. #pragma alloc_text(PAGEVRFY, PpvUtilGetDevnodeRemovalOption)
  22. #pragma alloc_text(PAGEVRFY, PpvUtilIsHardwareBeingVerified)
  23. #endif // NO_VERIFIER
  24. #endif // ALLOC_PRAGMA
  25. //
  26. // This entire implementation is specific to the verifier
  27. //
  28. #ifndef NO_VERIFIER
  29. BOOLEAN PpvUtilVerifierEnabled = FALSE;
  30. VOID
  31. FASTCALL
  32. PpvUtilInit(
  33. VOID
  34. )
  35. {
  36. PpvUtilVerifierEnabled = TRUE;
  37. }
  38. NTSTATUS
  39. FASTCALL
  40. PpvUtilCallAddDevice(
  41. IN PDEVICE_OBJECT PhysicalDeviceObject,
  42. IN PDRIVER_OBJECT DriverObject,
  43. IN PDRIVER_ADD_DEVICE AddDeviceFunction,
  44. IN VF_DEVOBJ_TYPE DevObjType
  45. )
  46. {
  47. NTSTATUS status;
  48. if (!PpvUtilVerifierEnabled) {
  49. return AddDeviceFunction(DriverObject, PhysicalDeviceObject);
  50. }
  51. //
  52. // Notify the verifier prior to AddDevice
  53. //
  54. VfDevObjPreAddDevice(
  55. PhysicalDeviceObject,
  56. DriverObject,
  57. AddDeviceFunction,
  58. DevObjType
  59. );
  60. status = AddDeviceFunction(DriverObject, PhysicalDeviceObject);
  61. //
  62. // Let the verifier know how it turned out.
  63. //
  64. VfDevObjPostAddDevice(
  65. PhysicalDeviceObject,
  66. DriverObject,
  67. AddDeviceFunction,
  68. DevObjType,
  69. status
  70. );
  71. return status;
  72. }
  73. VOID
  74. FASTCALL
  75. PpvUtilTestStartedPdoStack(
  76. IN PDEVICE_OBJECT DeviceObject
  77. )
  78. {
  79. if (PpvUtilVerifierEnabled) {
  80. VfMajorTestStartedPdoStack(DeviceObject);
  81. }
  82. }
  83. VOID
  84. FASTCALL
  85. PpvUtilFailDriver(
  86. IN PPVFAILURE_TYPE FailureType,
  87. IN PVOID CulpritAddress,
  88. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  89. IN PVOID ExtraneousInfo OPTIONAL
  90. )
  91. {
  92. if (!PpvUtilVerifierEnabled) {
  93. return;
  94. }
  95. switch(FailureType) {
  96. case PPVERROR_DUPLICATE_PDO_ENUMERATED:
  97. WDM_FAIL_ROUTINE((
  98. DCERROR_DUPLICATE_ENUMERATION,
  99. DCPARAM_ROUTINE + DCPARAM_DEVOBJ*2,
  100. CulpritAddress,
  101. DeviceObject,
  102. ExtraneousInfo
  103. ));
  104. break;
  105. case PPVERROR_MISHANDLED_TARGET_DEVICE_RELATIONS:
  106. WDM_FAIL_ROUTINE((
  107. DCERROR_MISHANDLED_TARGET_DEVICE_RELATIONS,
  108. DCPARAM_ROUTINE + DCPARAM_DEVOBJ,
  109. CulpritAddress,
  110. DeviceObject
  111. ));
  112. break;
  113. case PPVERROR_DDI_REQUIRES_PDO:
  114. WDM_FAIL_ROUTINE((
  115. DCERROR_DDI_REQUIRES_PDO,
  116. DCPARAM_ROUTINE + DCPARAM_DEVOBJ,
  117. CulpritAddress,
  118. DeviceObject
  119. ));
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. PPVREMOVAL_OPTION
  126. FASTCALL
  127. PpvUtilGetDevnodeRemovalOption(
  128. IN PDEVICE_OBJECT PhysicalDeviceObject
  129. )
  130. {
  131. PDEVICE_NODE devNode;
  132. devNode = PhysicalDeviceObject->DeviceObjectExtension->DeviceNode;
  133. if (devNode == NULL) {
  134. //
  135. // This must be PartMgr device, we have no opinion
  136. //
  137. return PPVREMOVAL_MAY_DEFER_DELETION;
  138. }
  139. if (devNode->Flags & DNF_ENUMERATED) {
  140. //
  141. // It's still present, so it mustn't delete itself.
  142. //
  143. return PPVREMOVAL_SHOULDNT_DELETE;
  144. } else if (devNode->Flags & DNF_DEVICE_GONE) {
  145. //
  146. // It's been reported missing, it must delete itself now as it's parent
  147. // may already have been removed.
  148. //
  149. return PPVREMOVAL_SHOULD_DELETE;
  150. } else {
  151. //
  152. // Corner case - in theory it should delete itself, but it's parent
  153. // will get a remove immediately after it does. As such it can defer
  154. // it's deletion.
  155. //
  156. return PPVREMOVAL_MAY_DEFER_DELETION;
  157. }
  158. }
  159. BOOLEAN
  160. FASTCALL
  161. PpvUtilIsHardwareBeingVerified(
  162. IN PDEVICE_OBJECT PhysicalDeviceObject
  163. )
  164. {
  165. PDEVICE_NODE devNode;
  166. if (!IS_PDO(PhysicalDeviceObject)) {
  167. return FALSE;
  168. }
  169. devNode = PhysicalDeviceObject->DeviceObjectExtension->DeviceNode;
  170. if ((devNode->Flags & DNF_HARDWARE_VERIFICATION) != 0) {
  171. return TRUE;
  172. }
  173. return FALSE;
  174. }
  175. #else // NO_VERIFIER
  176. //
  177. // The code below should be built into a future stub that deadens out IO
  178. // support for the verifier.
  179. //
  180. VOID
  181. FASTCALL
  182. PpvUtilInit(
  183. VOID
  184. )
  185. {
  186. }
  187. NTSTATUS
  188. FASTCALL
  189. PpvUtilCallAddDevice(
  190. IN PDEVICE_OBJECT PhysicalDeviceObject,
  191. IN PDRIVER_OBJECT DriverObject,
  192. IN PDRIVER_ADD_DEVICE AddDeviceFunction,
  193. IN VF_DEVOBJ_TYPE DevObjType
  194. )
  195. {
  196. UNREFERENCED_PARAMETER(DevObjType);
  197. return AddDeviceFunction(DriverObject, PhysicalDeviceObject);
  198. }
  199. VOID
  200. FASTCALL
  201. PpvUtilTestStartedPdoStack(
  202. IN PDEVICE_OBJECT DeviceObject
  203. )
  204. {
  205. UNREFERENCED_PARAMETER(DeviceObject);
  206. }
  207. VOID
  208. FASTCALL
  209. PpvUtilFailDriver(
  210. IN PPVFAILURE_TYPE FailureType,
  211. IN PVOID CulpritAddress,
  212. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  213. IN PVOID ExtraneousInfo OPTIONAL
  214. )
  215. {
  216. UNREFERENCED_PARAMETER(FailureType);
  217. UNREFERENCED_PARAMETER(CulpritAddress);
  218. UNREFERENCED_PARAMETER(DeviceObject);
  219. UNREFERENCED_PARAMETER(ExtraneousInfo);
  220. }
  221. #endif