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.

450 lines
10 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. if (MmFlags & DRIVER_VERIFIER_IO_CHECKING) {
  60. VfSettingsSetOption(NULL, VERIFIER_OPTION_EXAMINE_RELATION_PDOS, TRUE);
  61. VfSettingsSetOption(NULL, VERIFIER_OPTION_TRACK_IRPS, TRUE);
  62. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_IRP_ALLOCS, TRUE);
  63. VfSettingsSetOption(NULL, VERIFIER_OPTION_POLICE_IRPS, TRUE);
  64. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_MAJORS, TRUE);
  65. if (MmFlags & DRIVER_VERIFIER_ENHANCED_IO_CHECKING) {
  66. #if 0
  67. //
  68. // These are untested options:
  69. //
  70. VfSettingsSetOption(NULL, VERIFIER_OPTION_BUFFER_DIRECT_IO, TRUE);
  71. VfSettingsSetOption(NULL, VERIFIER_OPTION_DEFER_COMPLETION, TRUE);
  72. VfSettingsSetOption(NULL, VERIFIER_OPTION_COMPLETE_AT_PASSIVE, TRUE);
  73. VfSettingsSetOption(NULL, VERIFIER_OPTION_FORCE_PENDING, TRUE);
  74. VfSettingsSetOption(NULL, VERIFIER_OPTION_COMPLETE_AT_DISPATCH, TRUE);
  75. VfSettingsSetOption(NULL, VERIFIER_OPTION_DETECT_DEADLOCKS, TRUE);
  76. VfSettingsSetOption(NULL, VERIFIER_OPTION_VERIFY_DO_FLAGS, TRUE);
  77. VfSettingsSetOption(NULL, VERIFIER_OPTION_SMASH_SRBS, TRUE);
  78. VfSettingsSetOption(NULL, VERIFIER_OPTION_SURROGATE_IRPS, TRUE);
  79. #endif
  80. VfSettingsSetOption(NULL, VERIFIER_OPTION_INSERT_WDM_FILTERS, TRUE);
  81. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_PENDING_IO, TRUE);
  82. VfSettingsSetOption(NULL, VERIFIER_OPTION_SEEDSTACK, TRUE);
  83. VfSettingsSetOption(NULL, VERIFIER_OPTION_ROTATE_STATUS, TRUE);
  84. VfSettingsSetOption(NULL, VERIFIER_OPTION_SCRAMBLE_RELATIONS, TRUE);
  85. VfSettingsSetOption(NULL, VERIFIER_OPTION_CONSUME_ALWAYS, TRUE);
  86. VfSettingsSetOption(NULL, VERIFIER_OPTION_MONITOR_REMOVES, TRUE);
  87. VfSettingsSetOption(NULL, VERIFIER_OPTION_SEND_BOGUS_WMI_IRPS, TRUE);
  88. VfSettingsSetOption(NULL, VERIFIER_OPTION_SEND_BOGUS_POWER_IRPS, TRUE);
  89. VfSettingsSetOption(NULL, VERIFIER_OPTION_RELATION_IGNORANCE_TEST, TRUE);
  90. }
  91. }
  92. if (MmFlags & DRIVER_VERIFIER_DMA_VERIFIER) {
  93. VfSettingsSetOption(NULL, VERIFIER_OPTION_VERIFY_DMA, TRUE);
  94. VfSettingsSetOption(NULL, VERIFIER_OPTION_DOUBLE_BUFFER_DMA, TRUE);
  95. }
  96. if (MmFlags & DRIVER_VERIFIER_HARDWARE_VERIFICATION) {
  97. VfSettingsSetOption(NULL, VERIFIER_OPTION_HARDWARE_VERIFICATION, TRUE);
  98. }
  99. if (MmFlags & DRIVER_VERIFIER_SYSTEM_BIOS_VERIFICATION) {
  100. VfSettingsSetOption(NULL, VERIFIER_OPTION_SYSTEM_BIOS_VERIFICATION, TRUE);
  101. }
  102. }
  103. VOID
  104. FASTCALL
  105. VfSettingsCreateSnapshot(
  106. IN OUT PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot
  107. )
  108. /*++
  109. Description:
  110. This routine creates a snapshot of the current global verifier settings.
  111. Arguments:
  112. VerifierSettingsSnapshot - Pointer to an uninitialized block of memory,
  113. the size of which is determined by calling
  114. VfSettingsGetSnapshotSize.
  115. Return Value:
  116. Size of snapshot data in bytes.
  117. --*/
  118. {
  119. RtlCopyMemory(
  120. VerifierSettingsSnapshot,
  121. VfSettingsGlobal,
  122. VfSettingsGetSnapshotSize()
  123. );
  124. }
  125. ULONG
  126. FASTCALL
  127. VfSettingsGetSnapshotSize(
  128. VOID
  129. )
  130. /*++
  131. Description:
  132. This routine returns the size of a snapshot. It allows callers to create
  133. an appropriate sized buffer for storing verifier settings.
  134. Arguments:
  135. None.
  136. Return Value:
  137. Size of snapshot data in bytes.
  138. --*/
  139. {
  140. return (OPTION_SIZE + sizeof(ULONG) * VERIFIER_VALUE_MAX);
  141. }
  142. BOOLEAN
  143. FASTCALL
  144. VfSettingsIsOptionEnabled(
  145. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  146. IN VERIFIER_OPTION VerifierOption
  147. )
  148. /*++
  149. Description:
  150. This routine determines whether a given verifier option is enabled.
  151. Arguments:
  152. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  153. current system-wide verifier setting are used.
  154. VerifierOption - Option to examine
  155. Return Value:
  156. TRUE if option is currently enabled, FALSE otherwise.
  157. --*/
  158. {
  159. ULONG verifierIndex, verifierMask;
  160. PULONG verifierData;
  161. //
  162. // Bounds check.
  163. //
  164. if ((VerifierOption >= VERIFIER_OPTION_MAX) || (VerifierOption == 0)) {
  165. ASSERT(0);
  166. return FALSE;
  167. }
  168. //
  169. // Extract appropriate bit.
  170. //
  171. verifierIndex = (ULONG) VerifierOption;
  172. verifierMask = 1 << (verifierIndex % 32);
  173. verifierIndex /= 32;
  174. if (VerifierSettingsSnapshot) {
  175. verifierData = (PULONG) VerifierSettingsSnapshot;
  176. } else {
  177. verifierData = (PULONG) VfSettingsGlobal;
  178. }
  179. //
  180. // And now the test.
  181. //
  182. return (BOOLEAN)((verifierData[verifierIndex]&verifierMask) != 0);
  183. }
  184. VOID
  185. FASTCALL
  186. VfSettingsSetOption(
  187. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  188. IN VERIFIER_OPTION VerifierOption,
  189. IN BOOLEAN Setting
  190. )
  191. /*++
  192. Description:
  193. This routine sets the state of a given verifier option.
  194. Arguments:
  195. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  196. current system-wide verifier setting are used.
  197. VerifierOption - Option to set
  198. Setting - TRUE if option should be enabled, FALSE otherwise.
  199. Return Value:
  200. None.
  201. --*/
  202. {
  203. ULONG verifierIndex, verifierMask, oldValue, newValue, lastValue;
  204. PULONG verifierData;
  205. //
  206. // Bounds check.
  207. //
  208. if ((VerifierOption >= VERIFIER_OPTION_MAX) || (VerifierOption == 0)) {
  209. ASSERT(0);
  210. return;
  211. }
  212. //
  213. // Extract appropriate bit.
  214. //
  215. verifierIndex = (ULONG) VerifierOption;
  216. verifierMask = 1 << (verifierIndex % 32);
  217. verifierIndex /= 32;
  218. if (VerifierSettingsSnapshot) {
  219. verifierData = (PULONG) VerifierSettingsSnapshot;
  220. } else {
  221. verifierData = (PULONG) VfSettingsGlobal;
  222. }
  223. //
  224. // And now to set the value as atomically as possible.
  225. //
  226. do {
  227. oldValue = verifierData[verifierIndex];
  228. if (Setting) {
  229. newValue = oldValue | verifierMask;
  230. } else {
  231. newValue = oldValue &= ~verifierMask;
  232. }
  233. lastValue = InterlockedExchange((PLONG)(verifierData + verifierIndex), newValue);
  234. } while ( lastValue != newValue );
  235. }
  236. VOID
  237. FASTCALL
  238. VfSettingsGetValue(
  239. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  240. IN VERIFIER_VALUE VerifierValue,
  241. OUT ULONG *Value
  242. )
  243. /*++
  244. Description:
  245. This routine retrieves a given verifier value.
  246. Arguments:
  247. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  248. current system-wide verifier setting are used.
  249. VerifierValue - Value to retrieve.
  250. Value - Receives verifier value (0 if bad VerifierValue was specified.)
  251. Return Value:
  252. None.
  253. --*/
  254. {
  255. PULONG valueArray;
  256. //
  257. // Sanity check values
  258. //
  259. if ((VerifierValue == 0) || (VerifierValue >= VERIFIER_VALUE_MAX)) {
  260. *Value = 0;
  261. return;
  262. }
  263. //
  264. // Get appropriate array
  265. //
  266. if (VerifierSettingsSnapshot) {
  267. valueArray = (PULONG) (((PUCHAR) VerifierSettingsSnapshot) + OPTION_SIZE);
  268. } else {
  269. valueArray = (PULONG) (((PUCHAR) VfSettingsGlobal) + OPTION_SIZE);
  270. }
  271. //
  272. // Read out the value.
  273. //
  274. *Value = valueArray[VerifierValue];
  275. }
  276. VOID
  277. FASTCALL
  278. VfSettingsSetValue(
  279. IN PVERIFIER_SETTINGS_SNAPSHOT VerifierSettingsSnapshot OPTIONAL,
  280. IN VERIFIER_VALUE VerifierValue,
  281. IN ULONG Value
  282. )
  283. /*++
  284. Description:
  285. This routine sets the state of a given verifier value.
  286. Arguments:
  287. VerifierSettingsSnapshot - A snapshot of verifier settings. If NULL the
  288. current system-wide verifier setting are used.
  289. VerifierValue - Value to set.
  290. Value - ULONG to store.
  291. Return Value:
  292. None.
  293. --*/
  294. {
  295. PULONG valueArray;
  296. //
  297. // Sanity check values
  298. //
  299. if ((VerifierValue == 0) || (VerifierValue >= VERIFIER_VALUE_MAX)) {
  300. return;
  301. }
  302. //
  303. // Get appropriate array
  304. //
  305. if (VerifierSettingsSnapshot) {
  306. valueArray = (PULONG) (((PUCHAR) VerifierSettingsSnapshot) + OPTION_SIZE);
  307. } else {
  308. valueArray = (PULONG) (((PUCHAR) VfSettingsGlobal) + OPTION_SIZE);
  309. }
  310. //
  311. // Set the value.
  312. //
  313. valueArray[VerifierValue] = Value;
  314. }