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.

112 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vfutil.c
  5. Abstract:
  6. This module implements various utilities required to do driver verification.
  7. Author:
  8. Adrian J. Oney (adriao) 20-Apr-1998
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. AdriaO 02/10/2000 - Seperated out from ntos\io\ioassert.c
  13. --*/
  14. #include "vfdef.h"
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(PAGEVRFY, VfUtilIsMemoryRangeReadable)
  17. #endif // ALLOC_PRAGMA
  18. // allow constructions like `((PCHAR)Address)++'
  19. #pragma warning(disable:4213) // type cast on l-value
  20. BOOLEAN
  21. VfUtilIsMemoryRangeReadable(
  22. IN PVOID Location,
  23. IN size_t Length,
  24. IN MEMORY_PERSISTANCE Persistance
  25. )
  26. {
  27. while (((ULONG_PTR)Location & (sizeof(ULONG_PTR)-1)) && (Length > 0)) {
  28. //
  29. // Check to determine if the move will succeed before actually performing
  30. // the operation.
  31. //
  32. if (MmIsAddressValid(Location)==FALSE) {
  33. return FALSE;
  34. }
  35. if (Persistance == VFMP_INSTANT_NONPAGED) {
  36. if (!MmIsNonPagedSystemAddressValid(Location)) {
  37. return FALSE;
  38. }
  39. }
  40. ((PCHAR) Location)++;
  41. Length--;
  42. }
  43. while (Length > (sizeof(ULONG_PTR)-1)) {
  44. //
  45. // Check to determine if the move will succeed before actually performing
  46. // the operation.
  47. //
  48. if (MmIsAddressValid(Location)==FALSE) {
  49. return FALSE;
  50. }
  51. if (Persistance == VFMP_INSTANT_NONPAGED) {
  52. if (!MmIsNonPagedSystemAddressValid(Location)) {
  53. return FALSE;
  54. }
  55. }
  56. ((PCHAR) Location) += sizeof(ULONG_PTR);
  57. Length -= sizeof(ULONG_PTR);
  58. }
  59. while (Length > 0) {
  60. //
  61. // Check to determine if the move will succeed before actually performing
  62. // the operation.
  63. //
  64. if (MmIsAddressValid(Location)==FALSE) {
  65. return FALSE;
  66. }
  67. if (Persistance == VFMP_INSTANT_NONPAGED) {
  68. if (!MmIsNonPagedSystemAddressValid(Location)) {
  69. return FALSE;
  70. }
  71. }
  72. ((PCHAR) Location)++;
  73. Length--;
  74. }
  75. return TRUE;
  76. }