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.

183 lines
5.0 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: implements the basic structures for options, including class id
  5. // ThreadSafe: no
  6. // Locks: none
  7. // Please read stdinfo.txt for programming style.
  8. //================================================================================
  9. #include <mm.h>
  10. #include <array.h>
  11. #include <opt.h>
  12. #include <optl.h>
  13. #include <optclass.h>
  14. #include <bitmask.h>
  15. //BeginExport(typedef)
  16. typedef struct _M_RANGE {
  17. DWORD Start;
  18. DWORD End;
  19. DWORD Mask;
  20. DWORD State;
  21. ULONG BootpAllocated;
  22. ULONG MaxBootpAllowed;
  23. DWORD DirtyOps; // how many unsaved ops done?
  24. M_OPTCLASS Options;
  25. PM_BITMASK BitMask;
  26. // Reservations?
  27. } M_RANGE, *PM_RANGE, *LPM_RANGE;
  28. //EndExport(typedef)
  29. //BeginExport(inline)
  30. DWORD _inline
  31. MemRangeInit(
  32. IN OUT PM_RANGE Range,
  33. IN DWORD Start,
  34. IN DWORD End,
  35. IN DWORD Mask,
  36. IN DWORD State,
  37. IN ULONG BootpAllocated,
  38. IN ULONG MaxBootpAllowed
  39. ) {
  40. DWORD Error;
  41. AssertRet(Range, ERROR_INVALID_PARAMETER);
  42. if( Start > End || (Start & Mask) != (End & Mask) )
  43. return ERROR_INVALID_PARAMETER;
  44. Range->Start = Start;
  45. Range->End = End;
  46. Range->Mask = Mask;
  47. Range->State = State;
  48. Range->DirtyOps = 0;
  49. Range->BootpAllocated = BootpAllocated;
  50. Range->MaxBootpAllowed = MaxBootpAllowed;
  51. Error = MemBitInit(&Range->BitMask, End - Start + 1);
  52. if( ERROR_SUCCESS != Error ) return Error;
  53. return MemOptClassInit(&Range->Options);
  54. }
  55. //EndExport(inline)
  56. //BeginExport(inline)
  57. DWORD _inline
  58. MemRangeCleanup(
  59. IN OUT PM_RANGE Range
  60. ) {
  61. DWORD Error;
  62. AssertRet(Range, ERROR_INVALID_PARAMETER);
  63. Error = MemBitCleanup(Range->BitMask);
  64. if( ERROR_SUCCESS != Error ) return Error;
  65. return MemOptClassCleanup(&Range->Options);
  66. }
  67. //EndExport(inline)
  68. //BeginExport(inline)
  69. PM_OPTCLASS _inline
  70. MemRangeGetOptions(
  71. IN PM_RANGE Range
  72. ) {
  73. AssertRet(Range, NULL);
  74. return &Range->Options;
  75. }
  76. //EndExport(inline)
  77. //BeginExport(enum)
  78. enum /* anonymous */ {
  79. X_LESSTHAN_Y,
  80. Y_LESSTHAN_X,
  81. X_IN_Y,
  82. Y_IN_X,
  83. X_LESSTHAN_Y_OVERLAP,
  84. Y_LESSTHAN_X_OVERLAP
  85. };
  86. //EndExport(enum)
  87. //BeginExport(inline)
  88. DWORD _inline
  89. MemRangeCompare(
  90. IN DWORD StartX,
  91. IN DWORD EndX,
  92. IN DWORD StartY,
  93. IN DWORD EndY
  94. ) {
  95. if( EndX < StartY ) return X_LESSTHAN_Y;
  96. if( EndY < StartX ) return Y_LESSTHAN_X;
  97. if( StartX < StartY ) {
  98. if( EndX < EndY ) return X_LESSTHAN_Y_OVERLAP;
  99. return Y_IN_X;
  100. }
  101. if( StartX == StartY ) {
  102. if( EndX <= EndY ) return X_IN_Y;
  103. if( EndY <= EndX ) return Y_IN_X;
  104. }
  105. if( EndX <= EndY ) return X_IN_Y;
  106. return Y_LESSTHAN_X_OVERLAP;
  107. }
  108. //EndExport(inline)
  109. //BeginExport(function)
  110. DWORD
  111. MemRangeExtendOrContract(
  112. IN OUT PM_RANGE Range,
  113. IN DWORD nAddresses, // to contract by or expand by
  114. IN BOOL fExtend, // is this extend or contract?
  115. IN BOOL fEnd // to expand/contract at End or ar Start?
  116. ) //EndExport(function)
  117. {
  118. DWORD Error;
  119. AssertRet(Range && nAddresses > 0, ERROR_INVALID_PARAMETER);
  120. Error = MemBitAddOrDelBits(
  121. Range->BitMask,
  122. nAddresses,
  123. fExtend,
  124. fEnd
  125. );
  126. if( ERROR_SUCCESS != Error ) return Error;
  127. if( fExtend ) {
  128. if( fEnd ) Range->End += nAddresses;
  129. else Range->Start -= nAddresses;
  130. } else {
  131. if( fEnd ) Range->End -= nAddresses;
  132. else Range->Start += nAddresses;
  133. }
  134. return ERROR_SUCCESS;
  135. }
  136. //BeginExport(inline)
  137. DWORD _inline
  138. MemRangeConvertToClusters(
  139. IN PM_RANGE Range,
  140. OUT LPBYTE *InUseClusters,
  141. OUT DWORD *InUseClustersSize,
  142. OUT LPBYTE *UsedClusters,
  143. OUT DWORD *UsedClustersSize
  144. )
  145. {
  146. AssertRet(Range && InUseClusters && InUseClustersSize, ERROR_INVALID_PARAMETER);
  147. AssertRet(UsedClusters && UsedClustersSize, ERROR_INVALID_PARAMETER);
  148. return MemBitConvertToCluster(
  149. Range->BitMask, Range->Start,
  150. InUseClusters, InUseClustersSize,
  151. UsedClusters, UsedClustersSize
  152. );
  153. }
  154. //================================================================================
  155. // end of file
  156. //================================================================================