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.

146 lines
4.1 KiB

  1. //========================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. //========================================================================
  4. #ifndef _MM_RANGE_H_
  5. #define _MM_RANGE_H_
  6. typedef struct _M_RANGE {
  7. DWORD Start;
  8. DWORD End;
  9. DWORD Mask;
  10. DWORD State;
  11. ULONG BootpAllocated;
  12. ULONG MaxBootpAllowed;
  13. DWORD DirtyOps; // how many unsaved ops done?
  14. M_OPTCLASS Options;
  15. PM_BITMASK BitMask;
  16. ULONG UniqId;
  17. // Reservations?
  18. } M_RANGE, *PM_RANGE, *LPM_RANGE;
  19. DWORD _inline
  20. MemRangeInit(
  21. IN OUT PM_RANGE Range,
  22. IN DWORD Start,
  23. IN DWORD End,
  24. IN DWORD Mask,
  25. IN DWORD State,
  26. IN ULONG BootpAllocated,
  27. IN ULONG MaxBootpAllowed
  28. )
  29. {
  30. DWORD Error;
  31. AssertRet(Range, ERROR_INVALID_PARAMETER);
  32. if( Start > End || (Start & Mask) != (End & Mask) )
  33. return ERROR_INVALID_PARAMETER;
  34. Range->Start = Start;
  35. Range->End = End;
  36. Range->Mask = Mask;
  37. Range->State = State;
  38. Range->DirtyOps = 0;
  39. Range->BootpAllocated = BootpAllocated;
  40. Range->MaxBootpAllowed = MaxBootpAllowed;
  41. Error = MemBitInit(&Range->BitMask, End - Start + 1);
  42. if( ERROR_SUCCESS != Error ) return Error;
  43. return MemOptClassInit(&Range->Options);
  44. } // MemRangeInit()
  45. DWORD _inline
  46. MemRangeCleanup(
  47. IN OUT PM_RANGE Range
  48. )
  49. {
  50. DWORD Error;
  51. AssertRet(Range, ERROR_INVALID_PARAMETER);
  52. Error = MemBitCleanup(Range->BitMask);
  53. if( ERROR_SUCCESS != Error ) return Error;
  54. return MemOptClassCleanup(&Range->Options);
  55. }
  56. PM_OPTCLASS _inline
  57. MemRangeGetOptions(
  58. IN PM_RANGE Range
  59. )
  60. {
  61. AssertRet(Range, NULL);
  62. return &Range->Options;
  63. }
  64. enum /* anonymous */ {
  65. X_LESSTHAN_Y,
  66. Y_LESSTHAN_X,
  67. X_IN_Y,
  68. Y_IN_X,
  69. X_LESSTHAN_Y_OVERLAP,
  70. Y_LESSTHAN_X_OVERLAP
  71. };
  72. DWORD _inline
  73. MemRangeCompare(
  74. IN DWORD StartX,
  75. IN DWORD EndX,
  76. IN DWORD StartY,
  77. IN DWORD EndY
  78. )
  79. {
  80. if( EndX < StartY ) return X_LESSTHAN_Y;
  81. if( EndY < StartX ) return Y_LESSTHAN_X;
  82. if( StartX < StartY ) {
  83. if( EndX < EndY ) return X_LESSTHAN_Y_OVERLAP;
  84. return Y_IN_X;
  85. }
  86. if( StartX == StartY ) {
  87. if( EndX <= EndY ) return X_IN_Y;
  88. if( EndY <= EndX ) return Y_IN_X;
  89. }
  90. if( EndX <= EndY ) return X_IN_Y;
  91. return Y_LESSTHAN_X_OVERLAP;
  92. } // MemRangeCompare()
  93. DWORD
  94. MemRangeExtendOrContract(
  95. IN OUT PM_RANGE Range,
  96. IN DWORD nAddresses, // to contract by or expand by
  97. IN BOOL fExtend, // is this extend or contract?
  98. IN BOOL fEnd // to expand/contract at End or ar Start?
  99. ) ;
  100. DWORD _inline
  101. MemRangeConvertToClusters(
  102. IN PM_RANGE Range,
  103. OUT LPBYTE *InUseClusters,
  104. OUT DWORD *InUseClustersSize,
  105. OUT LPBYTE *UsedClusters,
  106. OUT DWORD *UsedClustersSize
  107. )
  108. {
  109. AssertRet(Range && InUseClusters && InUseClustersSize, ERROR_INVALID_PARAMETER);
  110. AssertRet(UsedClusters && UsedClustersSize, ERROR_INVALID_PARAMETER);
  111. return MemBitConvertToCluster(
  112. Range->BitMask, Range->Start,
  113. InUseClusters, InUseClustersSize,
  114. UsedClusters, UsedClustersSize
  115. );
  116. } // MemRangeConvertToClusters()
  117. #endif // _MM_RANGE_H_