testhook.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. testhook.c
  5. Abstract:
  6. This module implements test hooks for the I/O subsystem.
  7. Author:
  8. Chris Stevens 10-Jun-2013
  9. Environment:
  10. Kernel
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <minoca/kernel/kernel.h>
  16. #include "iop.h"
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // ------------------------------------------------------ Data Type Definitions
  22. //
  23. //
  24. // ----------------------------------------------- Internal Function Prototypes
  25. //
  26. //
  27. // -------------------------------------------------------------------- Globals
  28. //
  29. //
  30. // Stores a bitmask for I/O subsystem test hooks.
  31. //
  32. volatile ULONG IoTestHooks = 0;
  33. //
  34. // ------------------------------------------------------------------ Functions
  35. //
  36. KERNEL_API
  37. VOID
  38. IoSetTestHook (
  39. ULONG TestHookMask
  40. )
  41. /*++
  42. Routine Description:
  43. This routine sets the provided test hook mask in the test hook bitmask.
  44. Arguments:
  45. TestHookMask - Supplies the test hook mask that is to be added to the test
  46. hook bitmask.
  47. Return Value:
  48. None.
  49. --*/
  50. {
  51. RtlAtomicOr32(&IoTestHooks, TestHookMask);
  52. return;
  53. }
  54. KERNEL_API
  55. VOID
  56. IoClearTestHook (
  57. ULONG TestHookMask
  58. )
  59. /*++
  60. Routine Description:
  61. This routine unsets the provided test hook mask from the test hook bitmask.
  62. Arguments:
  63. TestHookMask - Supplies the test hook mast hat is to be removed from the
  64. test hook bitmask.
  65. Return Value:
  66. None.
  67. --*/
  68. {
  69. RtlAtomicAnd32(&IoTestHooks, ~TestHookMask);
  70. return;
  71. }
  72. BOOL
  73. IopIsTestHookSet (
  74. ULONG TestHookMask
  75. )
  76. /*++
  77. Routine Description:
  78. This routine checks to see if the given test hook field is currently set in
  79. the test hook bitmask. This clears the bit if it is set.
  80. Arguments:
  81. TestHookMask - Supplies the test hook field this routine will check the
  82. test hook bitmask against.
  83. Return Value:
  84. Returns TRUE if the test hook is set, or FALSE otherwise.
  85. --*/
  86. {
  87. ULONG OldTestHooks;
  88. //
  89. // If the test hook is present in the test hooks field, then remove it and
  90. // return true.
  91. //
  92. OldTestHooks = RtlAtomicAnd32(&IoTestHooks, ~TestHookMask);
  93. if ((OldTestHooks & TestHookMask) != 0) {
  94. return TRUE;
  95. }
  96. return FALSE;
  97. }
  98. //
  99. // --------------------------------------------------------- Internal Functions
  100. //