Source code of Windows XP (NT5)
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.

522 lines
15 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. vfddi.c
  5. Abstract:
  6. This module contains the list of device driver interfaces exported by the
  7. driver verifier and the kernel. Note that thunked exports are *not* placed
  8. here.
  9. All the exports are concentrated in one file because
  10. 1) There are relatively few driver verifier exports
  11. 2) The function naming convention differs from that used elsewhere in
  12. the driver verifier.
  13. Author:
  14. Adrian J. Oney (adriao) 26-Apr-2001
  15. Environment:
  16. Kernel mode
  17. Revision History:
  18. --*/
  19. #include "vfdef.h"
  20. #include "viddi.h"
  21. #ifdef ALLOC_PRAGMA
  22. #pragma alloc_text(INIT, VfDdiInit)
  23. //#pragma alloc_text(NONPAGED, VfFailDeviceNode)
  24. //#pragma alloc_text(NONPAGED, VfFailSystemBIOS)
  25. //#pragma alloc_text(NONPAGED, VfFailDriver)
  26. //#pragma alloc_text(NONPAGED, VfIsVerificationEnabled)
  27. #pragma alloc_text(PAGEVRFY, ViDdiThrowException)
  28. #endif // ALLOC_PRAGMA
  29. BOOLEAN ViDdiInitialized = FALSE;
  30. #ifdef ALLOC_DATA_PRAGMA
  31. #pragma const_seg("PAGEVRFC")
  32. #endif
  33. //
  34. // These are the general "classifications" of device errors, along with the
  35. // default flags that will be applied the first time this is hit.
  36. //
  37. const VFMESSAGE_CLASS ViDdiClassFailDeviceInField = {
  38. VFM_FLAG_BEEP | VFM_LOGO_FAILURE | VFM_DEPLOYMENT_FAILURE,
  39. "DEVICE FAILURE"
  40. };
  41. // VFM_DEPLOYMENT_FAILURE is set here because we don't yet have a "logo" mode
  42. const VFMESSAGE_CLASS ViDdiClassFailDeviceLogo = {
  43. VFM_FLAG_BEEP | VFM_LOGO_FAILURE | VFM_DEPLOYMENT_FAILURE,
  44. "DEVICE FAILURE"
  45. };
  46. const VFMESSAGE_CLASS ViDdiClassFailDeviceUnderDebugger = {
  47. VFM_FLAG_BEEP,
  48. "DEVICE FAILURE"
  49. };
  50. #ifdef ALLOC_DATA_PRAGMA
  51. #pragma const_seg()
  52. #endif // ALLOC_DATA_PRAGMA
  53. VOID
  54. VfDdiInit(
  55. VOID
  56. )
  57. /*++
  58. Routine Description:
  59. This routine initializes the Device Driver Interface support.
  60. Arguments:
  61. None.
  62. Return Value:
  63. None.
  64. --*/
  65. {
  66. ViDdiInitialized = TRUE;
  67. }
  68. VOID
  69. VfFailDeviceNode(
  70. IN PDEVICE_OBJECT PhysicalDeviceObject,
  71. IN ULONG BugCheckMajorCode,
  72. IN ULONG BugCheckMinorCode,
  73. IN VF_FAILURE_CLASS FailureClass,
  74. IN OUT PULONG AssertionControl,
  75. IN PSTR DebuggerMessageText,
  76. IN PSTR ParameterFormatString,
  77. ...
  78. )
  79. /*++
  80. Routine Description:
  81. This routine fails a Pnp enumerated hardware or virtual device if
  82. verification is enabled against it.
  83. Arguments:
  84. PhysicalDeviceObject - Bottom of the stack that identifies the PnP
  85. device.
  86. BugCheckMajorCode - BugCheck Major Code
  87. BugCheckMinorCode - BugCheck Minor Code
  88. Note - Zero is reserved!!!
  89. FailureClass - Either VFFAILURE_FAIL_IN_FIELD,
  90. VFFAILURE_FAIL_LOGO, or
  91. VFFAILURE_FAIL_UNDER_DEBUGGER
  92. AssertionControl - Points to a ULONG associated with the failure,
  93. used to store information across multiple calls.
  94. Must be statically preinitialized to zero.
  95. DebuggerMessageText - Text to be displayed in the debugger. Note that
  96. the text may reference parameters such as:
  97. %Routine - passed in Routine
  98. %Irp - passed in Irp
  99. %DevObj - passed in DevObj
  100. %Status - passed in Status
  101. %Ulong - passed in ULONG
  102. %Ulong1 - first passed in ULONG
  103. %Ulong3 - third passed in ULONG (max 3, any param)
  104. %Pvoid2 - second passed in PVOID
  105. etc
  106. (note, capitalization matters)
  107. ParameterFormatString - Contains ordered list of parameters referenced by
  108. above debugger text. For instance,
  109. (..., "%Status1%Status2%Ulong1%Ulong2", Status1, Status2, Ulong1, Ulong2);
  110. Note - If %Routine/%Routine1 is supplied as a param,
  111. the driver at %Routine must also be under verification.
  112. ... - Actual parameters
  113. Return Value:
  114. None.
  115. Note - this function may return if the device is not currently being
  116. verified.
  117. --*/
  118. {
  119. va_list arglist;
  120. if (!VfIsVerificationEnabled(VFOBJTYPE_DEVICE, (PVOID) PhysicalDeviceObject)) {
  121. return;
  122. }
  123. va_start(arglist, ParameterFormatString);
  124. ViDdiThrowException(
  125. BugCheckMajorCode,
  126. BugCheckMinorCode,
  127. FailureClass,
  128. AssertionControl,
  129. DebuggerMessageText,
  130. ParameterFormatString,
  131. &arglist
  132. );
  133. va_end(arglist);
  134. }
  135. VOID
  136. VfFailSystemBIOS(
  137. IN ULONG BugCheckMajorCode,
  138. IN ULONG BugCheckMinorCode,
  139. IN VF_FAILURE_CLASS FailureClass,
  140. IN OUT PULONG AssertionControl,
  141. IN PSTR DebuggerMessageText,
  142. IN PSTR ParameterFormatString,
  143. ...
  144. )
  145. /*++
  146. Routine Description:
  147. This routine fails the system BIOS if verification is enabled against it.
  148. Arguments:
  149. BugCheckMajorCode - BugCheck Major Code
  150. BugCheckMinorCode - BugCheck Minor Code
  151. Note - Zero is reserved!!!
  152. FailureClass - Either VFFAILURE_FAIL_IN_FIELD,
  153. VFFAILURE_FAIL_LOGO, or
  154. VFFAILURE_FAIL_UNDER_DEBUGGER
  155. AssertionControl - Points to a ULONG associated with the failure,
  156. used to store information across multiple calls.
  157. Must be statically preinitialized to zero.
  158. DebuggerMessageText - Text to be displayed in the debugger. Note that
  159. the text may reference parameters such as:
  160. %Routine - passed in Routine
  161. %Irp - passed in Irp
  162. %DevObj - passed in DevObj
  163. %Status - passed in Status
  164. %Ulong - passed in ULONG
  165. %Ulong1 - first passed in ULONG
  166. %Ulong3 - third passed in ULONG (max 3, any param)
  167. %Pvoid2 - second passed in PVOID
  168. etc
  169. (note, capitalization matters)
  170. ParameterFormatString - Contains ordered list of parameters referenced by
  171. above debugger text. For instance,
  172. (..., "%Status1%Status2%Ulong1%Ulong2", Status1, Status2, Ulong1, Ulong2);
  173. Note - If %Routine/%Routine1 is supplied as a param,
  174. the driver at %Routine must also be under verification.
  175. ... - Actual parameters
  176. Return Value:
  177. None.
  178. Note - this function may return if the device is not currently being
  179. verified.
  180. --*/
  181. {
  182. va_list arglist;
  183. if (!VfIsVerificationEnabled(VFOBJTYPE_SYSTEM_BIOS, NULL)) {
  184. return;
  185. }
  186. va_start(arglist, ParameterFormatString);
  187. ViDdiThrowException(
  188. BugCheckMajorCode,
  189. BugCheckMinorCode,
  190. FailureClass,
  191. AssertionControl,
  192. DebuggerMessageText,
  193. ParameterFormatString,
  194. &arglist
  195. );
  196. va_end(arglist);
  197. }
  198. VOID
  199. VfFailDriver(
  200. IN ULONG BugCheckMajorCode,
  201. IN ULONG BugCheckMinorCode,
  202. IN VF_FAILURE_CLASS FailureClass,
  203. IN OUT PULONG AssertionControl,
  204. IN PSTR DebuggerMessageText,
  205. IN PSTR ParameterFormatString,
  206. ...
  207. )
  208. /*++
  209. Routine Description:
  210. This routine fails a driver if verification is enabled against it.
  211. Arguments:
  212. BugCheckMajorCode - BugCheck Major Code
  213. BugCheckMinorCode - BugCheck Minor Code
  214. Note - Zero is reserved!!!
  215. FailureClass - Either VFFAILURE_FAIL_IN_FIELD,
  216. VFFAILURE_FAIL_LOGO, or
  217. VFFAILURE_FAIL_UNDER_DEBUGGER
  218. AssertionControl - Points to a ULONG associated with the failure.
  219. Must be preinitialized to zero!!!
  220. DebuggerMessageText - Text to be displayed in the debugger. Note that
  221. the text may reference parameters such as:
  222. %Routine - passed in Routine
  223. %Irp - passed in Irp
  224. %DevObj - passed in DevObj
  225. %Status - passed in Status
  226. %Ulong - passed in ULONG
  227. %Ulong1 - first passed in ULONG
  228. %Ulong3 - third passed in ULONG (max 3, any param)
  229. %Pvoid2 - second passed in PVOID
  230. etc
  231. (note, capitalization matters)
  232. ParameterFormatString - Contains ordered list of parameters referenced by
  233. above debugger text. For instance,
  234. (..., "%Status1%Status2%Ulong1%Ulong2", Status1, Status2, Ulong1, Ulong2);
  235. One of these parameters should be %Routine. This will
  236. be what the OS uses to identify the driver.
  237. static minorFlags = 0;
  238. VfFailDriver(
  239. major,
  240. minor,
  241. VFFAILURE_FAIL_LOGO,
  242. &minorFlags,
  243. "Driver at %Routine returned %Ulong",
  244. "%Ulong%Routine",
  245. value,
  246. routine
  247. );
  248. Return Value:
  249. None.
  250. Note - this function may return if the driver is not currently being
  251. verified.
  252. --*/
  253. {
  254. va_list arglist;
  255. if (!ViDdiInitialized) {
  256. return;
  257. }
  258. va_start(arglist, ParameterFormatString);
  259. ViDdiThrowException(
  260. BugCheckMajorCode,
  261. BugCheckMinorCode,
  262. FailureClass,
  263. AssertionControl,
  264. DebuggerMessageText,
  265. ParameterFormatString,
  266. &arglist
  267. );
  268. va_end(arglist);
  269. }
  270. VOID
  271. ViDdiThrowException(
  272. IN ULONG BugCheckMajorCode,
  273. IN ULONG BugCheckMinorCode,
  274. IN VF_FAILURE_CLASS FailureClass,
  275. IN OUT PULONG AssertionControl,
  276. IN PSTR DebuggerMessageText,
  277. IN PSTR ParameterFormatString,
  278. IN va_list * MessageParameters
  279. )
  280. /*++
  281. Routine Description:
  282. This routine fails either a devnode or a driver.
  283. Arguments:
  284. BugCheckMajorCode - BugCheck Major Code
  285. BugCheckMinorCode - BugCheck Minor Code
  286. Note - Zero is reserved!!!
  287. FailureClass - Either VFFAILURE_FAIL_IN_FIELD,
  288. VFFAILURE_FAIL_LOGO, or
  289. VFFAILURE_FAIL_UNDER_DEBUGGER
  290. AssertionControl - Points to a ULONG associated with the failure.
  291. Must be preinitialized to zero.
  292. DebuggerMessageText - Text to be displayed in the debugger. Note that
  293. the text may reference parameters such as:
  294. %Routine - passed in Routine
  295. %Irp - passed in Irp
  296. %DevObj - passed in DevObj
  297. %Status - passed in Status
  298. %Ulong - passed in ULONG
  299. %Ulong1 - first passed in ULONG
  300. %Ulong3 - third passed in ULONG (max 3, any param)
  301. %Pvoid2 - second passed in PVOID
  302. etc
  303. (note, capitalization matters)
  304. ParameterFormatString - Contains ordered list of parameters referenced by
  305. above debugger text. For instance,
  306. (..., "%Status1%Status2%Ulong1%Ulong2", Status1, Status2, Ulong1, Ulong2);
  307. MessageParameters - arg list of parameters matching
  308. ParameterFormatString
  309. Return Value:
  310. None.
  311. Note - this function may return if the device is not currently being
  312. verified.
  313. --*/
  314. {
  315. PCVFMESSAGE_CLASS messageClass;
  316. VFMESSAGE_TEMPLATE messageTemplates[2];
  317. VFMESSAGE_TEMPLATE_TABLE messageTable;
  318. NTSTATUS status;
  319. ASSERT(BugCheckMinorCode != 0);
  320. switch(FailureClass) {
  321. case VFFAILURE_FAIL_IN_FIELD:
  322. messageClass = &ViDdiClassFailDeviceInField;
  323. break;
  324. case VFFAILURE_FAIL_LOGO:
  325. messageClass = &ViDdiClassFailDeviceLogo;
  326. break;
  327. case VFFAILURE_FAIL_UNDER_DEBUGGER:
  328. messageClass = &ViDdiClassFailDeviceUnderDebugger;
  329. break;
  330. default:
  331. ASSERT(0);
  332. messageClass = NULL;
  333. break;
  334. }
  335. //
  336. // Program the template.
  337. //
  338. RtlZeroMemory(messageTemplates, sizeof(messageTemplates));
  339. messageTemplates[0].MessageID = BugCheckMinorCode-1;
  340. messageTemplates[1].MessageID = BugCheckMinorCode;
  341. messageTemplates[1].MessageClass = messageClass;
  342. messageTemplates[1].Flags = *AssertionControl;
  343. messageTemplates[1].ParamString = ParameterFormatString;
  344. messageTemplates[1].MessageText = DebuggerMessageText;
  345. //
  346. // Fill out the message table.
  347. //
  348. messageTable.TableID = 0;
  349. messageTable.BugCheckMajor = BugCheckMajorCode;
  350. messageTable.TemplateArray = messageTemplates;
  351. messageTable.TemplateCount = ARRAY_COUNT(messageTemplates);
  352. messageTable.OverrideArray = NULL;
  353. messageTable.OverrideCount = 0;
  354. status = VfBugcheckThrowException(
  355. &messageTable,
  356. BugCheckMinorCode,
  357. ParameterFormatString,
  358. MessageParameters
  359. );
  360. //
  361. // Write back the assertion control.
  362. //
  363. *AssertionControl = messageTemplates[1].Flags;
  364. }
  365. BOOLEAN
  366. VfIsVerificationEnabled(
  367. IN VF_OBJECT_TYPE VfObjectType,
  368. IN PVOID Object
  369. )
  370. {
  371. if (!ViDdiInitialized) {
  372. return FALSE;
  373. }
  374. switch(VfObjectType) {
  375. case VFOBJTYPE_DRIVER:
  376. return (BOOLEAN) MmIsDriverVerifying((PDRIVER_OBJECT) Object);
  377. case VFOBJTYPE_DEVICE:
  378. if (!VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_HARDWARE_VERIFICATION)) {
  379. return FALSE;
  380. }
  381. return PpvUtilIsHardwareBeingVerified((PDEVICE_OBJECT) Object);
  382. case VFOBJTYPE_SYSTEM_BIOS:
  383. return VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_SYSTEM_BIOS_VERIFICATION);
  384. }
  385. return FALSE;
  386. }