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.

175 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vffileio.c
  5. Abstract:
  6. This module contains code that monitors file I/O functions for misuse.
  7. Author:
  8. Adrian J. Oney (adriao) 19-Dec-2000
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #include "vfdef.h"
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text(PAGEVRFY,VerifierNtCreateFile)
  16. #pragma alloc_text(PAGEVRFY,VerifierNtWriteFile)
  17. #pragma alloc_text(PAGEVRFY,VerifierNtReadFile)
  18. #endif // ALLOC_PRAGMA
  19. NTSTATUS
  20. VerifierNtCreateFile(
  21. OUT PHANDLE FileHandle,
  22. IN ACCESS_MASK DesiredAccess,
  23. IN POBJECT_ATTRIBUTES ObjectAttributes,
  24. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  26. IN ULONG FileAttributes,
  27. IN ULONG ShareAccess,
  28. IN ULONG CreateDisposition,
  29. IN ULONG CreateOptions,
  30. IN PVOID EaBuffer OPTIONAL,
  31. IN ULONG EaLength
  32. )
  33. {
  34. //
  35. // We use VERIFIER_OPTION_TRACK_IRPS until we add a generic IOVerifier
  36. // setting.
  37. //
  38. if (VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_TRACK_IRPS)) {
  39. if (KeGetCurrentIrql() > PASSIVE_LEVEL) {
  40. //
  41. // The driver has made a mistake. Fail it now.
  42. //
  43. WDM_FAIL_ROUTINE((
  44. DCERROR_FILE_IO_AT_BAD_IRQL,
  45. DCPARAM_ROUTINE,
  46. _ReturnAddress()
  47. ));
  48. }
  49. }
  50. return NtCreateFile(
  51. FileHandle,
  52. DesiredAccess,
  53. ObjectAttributes,
  54. IoStatusBlock,
  55. AllocationSize,
  56. FileAttributes,
  57. ShareAccess,
  58. CreateDisposition,
  59. CreateOptions,
  60. EaBuffer,
  61. EaLength
  62. );
  63. }
  64. NTSTATUS
  65. VerifierNtWriteFile(
  66. IN HANDLE FileHandle,
  67. IN HANDLE Event OPTIONAL,
  68. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  69. IN PVOID ApcContext OPTIONAL,
  70. OUT PIO_STATUS_BLOCK IoStatusBlock,
  71. IN PVOID Buffer,
  72. IN ULONG Length,
  73. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  74. IN PULONG Key OPTIONAL
  75. )
  76. {
  77. //
  78. // We use VERIFIER_OPTION_TRACK_IRPS until we add a generic IOVerifier
  79. // setting.
  80. //
  81. if (VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_TRACK_IRPS)) {
  82. if (KeGetCurrentIrql() > PASSIVE_LEVEL) {
  83. //
  84. // The driver has made a mistake. Fail it now.
  85. //
  86. WDM_FAIL_ROUTINE((
  87. DCERROR_FILE_IO_AT_BAD_IRQL,
  88. DCPARAM_ROUTINE,
  89. _ReturnAddress()
  90. ));
  91. }
  92. }
  93. return NtWriteFile(
  94. FileHandle,
  95. Event,
  96. ApcRoutine,
  97. ApcContext,
  98. IoStatusBlock,
  99. Buffer,
  100. Length,
  101. ByteOffset,
  102. Key
  103. );
  104. }
  105. NTSTATUS
  106. VerifierNtReadFile(
  107. IN HANDLE FileHandle,
  108. IN HANDLE Event OPTIONAL,
  109. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  110. IN PVOID ApcContext OPTIONAL,
  111. OUT PIO_STATUS_BLOCK IoStatusBlock,
  112. OUT PVOID Buffer,
  113. IN ULONG Length,
  114. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  115. IN PULONG Key OPTIONAL
  116. )
  117. {
  118. //
  119. // We use VERIFIER_OPTION_TRACK_IRPS until we add a generic IOVerifier
  120. // setting.
  121. //
  122. if (VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_TRACK_IRPS)) {
  123. if (KeGetCurrentIrql() > PASSIVE_LEVEL) {
  124. //
  125. // The driver has made a mistake. Fail it now.
  126. //
  127. WDM_FAIL_ROUTINE((
  128. DCERROR_FILE_IO_AT_BAD_IRQL,
  129. DCPARAM_ROUTINE,
  130. _ReturnAddress()
  131. ));
  132. }
  133. }
  134. return NtReadFile(
  135. FileHandle,
  136. Event,
  137. ApcRoutine,
  138. ApcContext,
  139. IoStatusBlock,
  140. Buffer,
  141. Length,
  142. ByteOffset,
  143. Key
  144. );
  145. }