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.

461 lines
11 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vfsettings.c
  5. Abstract:
  6. This module contains code that tracks whether various verifier tests are
  7. enabled. It also keeps track of various values.
  8. Author:
  9. Adrian J. Oney (adriao) 31-May-2000
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "vfdef.h"
  15. #include "visettings.h"
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text(PAGEVRFY, VfSettingsInit)
  18. #pragma alloc_text(PAGEVRFY, VfSettingsCreateSnapshot)
  19. #pragma alloc_text(PAGEVRFY, VfSettingsGetSnapshotSize)
  20. #pragma alloc_text(PAGEVRFY, VfSettingsIsOptionEnabled)
  21. #pragma alloc_text(PAGEVRFY, VfSettingsSetOption)
  22. #pragma alloc_text(PAGEVRFY, VfSettingsGetValue)
  23. #pragma alloc_text(PAGEVRFY, VfSettingsSetValue)
  24. #endif
  25. #define POOL_TAG_VERIFIER_SETTINGS 'oGfV'
  26. //
  27. // This points to the global list of verifier settings.
  28. //
  29. PVERIFIER_SETTINGS_SNAPSHOT VfSettingsGlobal = NULL;
  30. VOID
  31. FASTCALL
  32. VfSettingsInit(
  33. IN ULONG MmFlags
  34. )
  35. /*++
  36. Description:
  37. This routine is called to initialize the current set of verifier settings.
  38. Arguments:
  39. MmFlags - A mask of flags (DRIVER_VERIFIER_xxx) indicating which verifier
  40. settings should be enabled.
  41. Return Value:
  42. None.
  43. --*/
  44. {
  45. //
  46. // As this is system startup code, it is one of the very few places where
  47. // it's ok to use MustSucceed.
  48. //
  49. VfSettingsGlobal = (PVERIFIER_SETTINGS_SNAPSHOT) ExAllocatePoolWithTag(
  50. NonPagedPoolMustSucceed,
  51. VfSettingsGetSnapshotSize(),
  52. POOL_TAG_VERIFIER_SETTINGS
  53. );
  54. RtlZeroMemory(VfSettingsGlobal, VfSettingsGetSnapshotSize());
  55. //
  56. // Set IRP deferral time to 300 us.
  57. //
  58. VfSettingsSetValue(NULL, VERIFIER_VALUE_IRP_DEFERRAL_TIME, 10 * 300);
  59. //
  60. // Set the IRPs-to-log-per-devobj to 20
  61. //
  62. VfSettingsSetValue(NULL, VERIFIER_VALUE_IRPLOG_COUNT, 20);
  63. if (MmFlags & DRIVER_VERIFIER_IO_CHECKING) {
  64. VfSettingsSetOption(NULL, VERIFIER_OPTION_EXAMINE_RELATION_PDOS, TRUE);
  65. VfSettingsSetOption(NULL, VERIFIER_OPTION_TRACK_IRPS, TRUE);
  66. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_IRP_ALLOCS, TRUE);
  67. VfSettingsSetOption(NULL, VERIFIER_OPTION_POLICE_IRPS, TRUE);
  68. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_MAJORS, TRUE);
  69. if (MmFlags & DRIVER_VERIFIER_ENHANCED_IO_CHECKING) {
  70. #if 0
  71. //
  72. // These are untested options:
  73. //
  74. VfSettingsSetOption(NULL, VERIFIER_OPTION_BUFFER_DIRECT_IO, TRUE);
  75. VfSettingsSetOption(NULL, VERIFIER_OPTION_DEFER_COMPLETION, TRUE);
  76. VfSettingsSetOption(NULL, VERIFIER_OPTION_COMPLETE_AT_PASSIVE, TRUE);
  77. VfSettingsSetOption(NULL, VERIFIER_OPTION_FORCE_PENDING, TRUE);
  78. VfSettingsSetOption(NULL, VERIFIER_OPTION_COMPLETE_AT_DISPATCH, TRUE);
  79. VfSettingsSetOption(NULL, VERIFIER_OPTION_DETECT_DEADLOCKS, TRUE);
  80. VfSettingsSetOption(NULL, VERIFIER_OPTION_VERIFY_DO_FLAGS, TRUE);
  81. VfSettingsSetOption(NULL, VERIFIER_OPTION_SMASH_SRBS, TRUE);
  82. VfSettingsSetOption(NULL, VERIFIER_OPTION_SURROGATE_IRPS, TRUE);
  83. VfSettingsSetOption(NULL, VERIFIER_OPTION_SCRAMBLE_RELATIONS, TRUE);
  84. #endif
  85. VfSettingsSetOption(NULL, VERIFIER_OPTION_INSERT_WDM_FILTERS, TRUE);
  86. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_PENDING_IO, TRUE);
  87. VfSettingsSetOption(NULL, VERIFIER_OPTION_SEEDSTACK, TRUE);
  88. VfSettingsSetOption(NULL, VERIFIER_OPTION_ROTATE_STATUS, TRUE);
  89. VfSettingsSetOption(NULL, VERIFIER_OPTION_CONSUME_ALWAYS, TRUE);
  90. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_REMOVES, TRUE);
  91. VfSettingsSetOption(NULL, VERIFIER_OPTION_SEND_BOGUS_WMI_IRPS, TRUE);
  92. VfSettingsSetOption(NULL, VERIFIER_OPTION_SEND_BOGUS_POWER_IRPS, TRUE);
  93. VfSettingsSetOption(NULL, VERIFIER_OPTION_RELATION_IGNORANCE_TEST, TRUE);
  94. }
  95. }
  96. if (MmFlags & DRIVER_VERIFIER_EXPOSE_IRP_HISTORY) {
  97. VfSettingsSetOption(NULL, VERIFIER_OPTION_TRACK_IRPS, TRUE);
  98. VfSettingsSetOption(NULL, VERIFIER_OPTION_EXPOSE_IRP_HISTORY, TRUE);
  99. }
  100. if (MmFlags & DRIVER_VERIFIER_DMA_VERIFIER) {
  101. VfSettingsSetOption(NULL, VERIFIER_OPTION_VERIFY_DMA, TRUE);
  102. VfSettingsSetOption(NULL, VERIFIER_OPTION_DOUBLE_BUFFER_DMA, TRUE);
  103. }
  104. if (MmFlags & DRIVER_VERIFIER_HARDWARE_VERIFICATION) {
  105. VfSettingsSetOption(NULL, VERIFIER_OPTION_HARDWARE_VERIFICATION, TRUE);
  106. }
  107. if (MmFlags & DRIVER_VERIFIER_SYSTEM_BIOS_VERIFICATION) {
  108. VfSettingsSetOption(NULL, VERIFIER_OPTION_SYSTEM_BIOS_VERIFICATION, TRUE);
  109. }
  110. }
  111. VOID
  112. FASTCALL
  113. VfSettingsCreateSnapshot(
  114. IN OUT PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot
  115. )
  116. /*++
  117. Description:
  118. This routine creates a snapshot of the current global verifier settings.
  119. Arguments:
  120. VerifierSettingsSnapshot - Pointer to an uninitialized block of memory,
  121. the size of which is determined by calling
  122. VfSettingsGetSnapshotSize.
  123. Return Value:
  124. Size of snapshot data in bytes.
  125. --*/
  126. {
  127. RtlCopyMemory(
  128. VerifierSettingsSnapshot,
  129. VfSettingsGlobal,
  130. VfSettingsGetSnapshotSize()
  131. );
  132. }
  133. ULONG
  134. FASTCALL
  135. VfSettingsGetSnapshotSize(
  136. VOID
  137. )
  138. /*++
  139. Description:
  140. This routine returns the size of a snapshot. It allows callers to create
  141. an appropriate sized buffer for storing verifier settings.
  142. Arguments:
  143. None.
  144. Return Value:
  145. Size of snapshot data in bytes.
  146. --*/
  147. {
  148. return (OPTION_SIZE + sizeof(ULONG) * VERIFIER_VALUE_MAX);
  149. }
  150. BOOLEAN
  151. FASTCALL
  152. VfSettingsIsOptionEnabled(
  153. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  154. IN VERIFIER_OPTION VerifierOption
  155. )
  156. /*++
  157. Description:
  158. This routine determines whether a given verifier option is enabled.
  159. Arguments:
  160. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  161. current system-wide verifier setting are used.
  162. VerifierOption - Option to examine
  163. Return Value:
  164. TRUE if option is currently enabled, FALSE otherwise.
  165. --*/
  166. {
  167. ULONG verifierIndex, verifierMask;
  168. PULONG verifierData;
  169. //
  170. // Bounds check.
  171. //
  172. if ((VerifierOption >= VERIFIER_OPTION_MAX) || (VerifierOption == 0)) {
  173. ASSERT(0);
  174. return FALSE;
  175. }
  176. //
  177. // Extract appropriate bit.
  178. //
  179. verifierIndex = (ULONG) VerifierOption;
  180. verifierMask = 1 << (verifierIndex % 32);
  181. verifierIndex /= 32;
  182. if (VerifierSettingsSnapshot) {
  183. verifierData = (PULONG) VerifierSettingsSnapshot;
  184. } else {
  185. verifierData = (PULONG) VfSettingsGlobal;
  186. }
  187. //
  188. // And now the test.
  189. //
  190. return (BOOLEAN)((verifierData[verifierIndex]&verifierMask) != 0);
  191. }
  192. VOID
  193. FASTCALL
  194. VfSettingsSetOption(
  195. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  196. IN VERIFIER_OPTION VerifierOption,
  197. IN BOOLEAN Setting
  198. )
  199. /*++
  200. Description:
  201. This routine sets the state of a given verifier option.
  202. Arguments:
  203. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  204. current system-wide verifier setting are used.
  205. VerifierOption - Option to set
  206. Setting - TRUE if option should be enabled, FALSE otherwise.
  207. Return Value:
  208. None.
  209. --*/
  210. {
  211. ULONG verifierIndex, verifierMask, oldValue, newValue, lastValue;
  212. PULONG verifierData;
  213. //
  214. // Bounds check.
  215. //
  216. if ((VerifierOption >= VERIFIER_OPTION_MAX) || (VerifierOption == 0)) {
  217. ASSERT(0);
  218. return;
  219. }
  220. //
  221. // Extract appropriate bit.
  222. //
  223. verifierIndex = (ULONG) VerifierOption;
  224. verifierMask = 1 << (verifierIndex % 32);
  225. verifierIndex /= 32;
  226. if (VerifierSettingsSnapshot) {
  227. verifierData = (PULONG) VerifierSettingsSnapshot;
  228. } else {
  229. verifierData = (PULONG) VfSettingsGlobal;
  230. }
  231. //
  232. // And now to set the value as atomically as possible.
  233. //
  234. do {
  235. oldValue = verifierData[verifierIndex];
  236. if (Setting) {
  237. newValue = oldValue | verifierMask;
  238. } else {
  239. newValue = oldValue &= ~verifierMask;
  240. }
  241. lastValue = InterlockedExchange((PLONG)(verifierData + verifierIndex), newValue);
  242. } while ( lastValue != newValue );
  243. }
  244. VOID
  245. FASTCALL
  246. VfSettingsGetValue(
  247. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  248. IN VERIFIER_VALUE VerifierValue,
  249. OUT ULONG *Value
  250. )
  251. /*++
  252. Description:
  253. This routine retrieves a given verifier value.
  254. Arguments:
  255. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  256. current system-wide verifier setting are used.
  257. VerifierValue - Value to retrieve.
  258. Value - Receives verifier value (0 if bad VerifierValue was specified.)
  259. Return Value:
  260. None.
  261. --*/
  262. {
  263. PULONG valueArray;
  264. //
  265. // Sanity check values
  266. //
  267. if ((VerifierValue == 0) || (VerifierValue >= VERIFIER_VALUE_MAX)) {
  268. *Value = 0;
  269. return;
  270. }
  271. //
  272. // Get appropriate array
  273. //
  274. if (VerifierSettingsSnapshot) {
  275. valueArray = (PULONG) (((PUCHAR) VerifierSettingsSnapshot) + OPTION_SIZE);
  276. } else {
  277. valueArray = (PULONG) (((PUCHAR) VfSettingsGlobal) + OPTION_SIZE);
  278. }
  279. //
  280. // Read out the value.
  281. //
  282. *Value = valueArray[VerifierValue];
  283. }
  284. VOID
  285. FASTCALL
  286. VfSettingsSetValue(
  287. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  288. IN VERIFIER_VALUE VerifierValue,
  289. IN ULONG Value
  290. )
  291. /*++
  292. Description:
  293. This routine sets the state of a given verifier value.
  294. Arguments:
  295. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  296. current system-wide verifier setting are used.
  297. VerifierValue - Value to set.
  298. Value - ULONG to store.
  299. Return Value:
  300. None.
  301. --*/
  302. {
  303. PULONG valueArray;
  304. //
  305. // Sanity check values
  306. //
  307. if ((VerifierValue == 0) || (VerifierValue >= VERIFIER_VALUE_MAX)) {
  308. return;
  309. }
  310. //
  311. // Get appropriate array
  312. //
  313. if (VerifierSettingsSnapshot) {
  314. valueArray = (PULONG) (((PUCHAR) VerifierSettingsSnapshot) + OPTION_SIZE);
  315. } else {
  316. valueArray = (PULONG) (((PUCHAR) VfSettingsGlobal) + OPTION_SIZE);
  317. }
  318. //
  319. // Set the value.
  320. //
  321. valueArray[VerifierValue] = Value;
  322. }