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.

275 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. BitMap.h
  5. Abstract:
  6. RTL Bitmap definitions and prototypes.
  7. Revision History:
  8. Borrowed from ntoskrnl for compatibility on other platforms (Win9x).
  9. --*/
  10. #ifndef _TCPIP_BITMAP_H_
  11. #define _TCPIP_BITMAP_H_
  12. #if MILLEN
  13. //
  14. // BitMap routines. The following structure, routines, and macros are
  15. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  16. // structure (which is really a header) and a buffer (which must be longword
  17. // aligned and multiple longwords in size).
  18. //
  19. typedef struct _RTL_BITMAP {
  20. ULONG SizeOfBitMap; // Number of bits in bit map
  21. PULONG Buffer; // Pointer to the bit map itself
  22. } RTL_BITMAP;
  23. typedef RTL_BITMAP *PRTL_BITMAP;
  24. //
  25. // The following routine initializes a new bitmap. It does not alter the
  26. // data currently in the bitmap. This routine must be called before
  27. // any other bitmap routine/macro.
  28. VOID
  29. RtlInitializeBitMap (
  30. PRTL_BITMAP BitMapHeader,
  31. PULONG BitMapBuffer,
  32. ULONG SizeOfBitMap
  33. );
  34. //
  35. // The following three routines clear, set, and test the state of a
  36. // single bit in a bitmap.
  37. //
  38. VOID
  39. RtlClearBit (
  40. PRTL_BITMAP BitMapHeader,
  41. ULONG BitNumber
  42. );
  43. VOID
  44. RtlSetBit (
  45. PRTL_BITMAP BitMapHeader,
  46. ULONG BitNumber
  47. );
  48. BOOLEAN
  49. RtlTestBit (
  50. PRTL_BITMAP BitMapHeader,
  51. ULONG BitNumber
  52. );
  53. //
  54. // The following two routines either clear or set all of the bits
  55. // in a bitmap.
  56. //
  57. VOID
  58. RtlClearAllBits (
  59. PRTL_BITMAP BitMapHeader
  60. );
  61. VOID
  62. RtlSetAllBits (
  63. PRTL_BITMAP BitMapHeader
  64. );
  65. //
  66. // The following two routines locate a contiguous region of either
  67. // clear or set bits within the bitmap. The region will be at least
  68. // as large as the number specified, and the search of the bitmap will
  69. // begin at the specified hint index (which is a bit index within the
  70. // bitmap, zero based). The return value is the bit index of the located
  71. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  72. // be located
  73. //
  74. ULONG
  75. RtlFindClearBits (
  76. PRTL_BITMAP BitMapHeader,
  77. ULONG NumberToFind,
  78. ULONG HintIndex
  79. );
  80. ULONG
  81. RtlFindSetBits (
  82. PRTL_BITMAP BitMapHeader,
  83. ULONG NumberToFind,
  84. ULONG HintIndex
  85. );
  86. //
  87. // The following two routines locate a contiguous region of either
  88. // clear or set bits within the bitmap and either set or clear the bits
  89. // within the located region. The region will be as large as the number
  90. // specified, and the search for the region will begin at the specified
  91. // hint index (which is a bit index within the bitmap, zero based). The
  92. // return value is the bit index of the located region (zero based) or
  93. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  94. // cannot be located then the setting/clearing of the bitmap is not performed.
  95. //
  96. ULONG
  97. RtlFindClearBitsAndSet (
  98. PRTL_BITMAP BitMapHeader,
  99. ULONG NumberToFind,
  100. ULONG HintIndex
  101. );
  102. ULONG
  103. RtlFindSetBitsAndClear (
  104. PRTL_BITMAP BitMapHeader,
  105. ULONG NumberToFind,
  106. ULONG HintIndex
  107. );
  108. //
  109. // The following two routines clear or set bits within a specified region
  110. // of the bitmap. The starting index is zero based.
  111. //
  112. VOID
  113. RtlClearBits (
  114. PRTL_BITMAP BitMapHeader,
  115. ULONG StartingIndex,
  116. ULONG NumberToClear
  117. );
  118. VOID
  119. RtlSetBits (
  120. PRTL_BITMAP BitMapHeader,
  121. ULONG StartingIndex,
  122. ULONG NumberToSet
  123. );
  124. //
  125. // The following routine locates a set of contiguous regions of clear
  126. // bits within the bitmap. The caller specifies whether to return the
  127. // longest runs or just the first found lcoated. The following structure is
  128. // used to denote a contiguous run of bits. The two routines return an array
  129. // of this structure, one for each run located.
  130. //
  131. typedef struct _RTL_BITMAP_RUN {
  132. ULONG StartingIndex;
  133. ULONG NumberOfBits;
  134. } RTL_BITMAP_RUN;
  135. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  136. ULONG
  137. RtlFindClearRuns (
  138. PRTL_BITMAP BitMapHeader,
  139. PRTL_BITMAP_RUN RunArray,
  140. ULONG SizeOfRunArray,
  141. BOOLEAN LocateLongestRuns
  142. );
  143. //
  144. // The following routine locates the longest contiguous region of
  145. // clear bits within the bitmap. The returned starting index value
  146. // denotes the first contiguous region located satisfying our requirements
  147. // The return value is the length (in bits) of the longest region found.
  148. //
  149. ULONG
  150. RtlFindLongestRunClear (
  151. PRTL_BITMAP BitMapHeader,
  152. PULONG StartingIndex
  153. );
  154. //
  155. // The following routine locates the first contiguous region of
  156. // clear bits within the bitmap. The returned starting index value
  157. // denotes the first contiguous region located satisfying our requirements
  158. // The return value is the length (in bits) of the region found.
  159. //
  160. ULONG
  161. RtlFindFirstRunClear (
  162. PRTL_BITMAP BitMapHeader,
  163. PULONG StartingIndex
  164. );
  165. //
  166. // The following macro returns the value of the bit stored within the
  167. // bitmap at the specified location. If the bit is set a value of 1 is
  168. // returned otherwise a value of 0 is returned.
  169. //
  170. // ULONG
  171. // RtlCheckBit (
  172. // PRTL_BITMAP BitMapHeader,
  173. // ULONG BitPosition
  174. // );
  175. //
  176. //
  177. // To implement CheckBit the macro retrieves the longword containing the
  178. // bit in question, shifts the longword to get the bit in question into the
  179. // low order bit position and masks out all other bits.
  180. //
  181. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  182. //
  183. // The following two procedures return to the caller the total number of
  184. // clear or set bits within the specified bitmap.
  185. //
  186. ULONG
  187. RtlNumberOfClearBits (
  188. PRTL_BITMAP BitMapHeader
  189. );
  190. ULONG
  191. RtlNumberOfSetBits (
  192. PRTL_BITMAP BitMapHeader
  193. );
  194. //
  195. // The following two procedures return to the caller a boolean value
  196. // indicating if the specified range of bits are all clear or set.
  197. //
  198. BOOLEAN
  199. RtlAreBitsClear (
  200. PRTL_BITMAP BitMapHeader,
  201. ULONG StartingIndex,
  202. ULONG Length
  203. );
  204. BOOLEAN
  205. RtlAreBitsSet (
  206. PRTL_BITMAP BitMapHeader,
  207. ULONG StartingIndex,
  208. ULONG Length
  209. );
  210. ULONG
  211. RtlFindNextForwardRunClear (
  212. IN PRTL_BITMAP BitMapHeader,
  213. IN ULONG FromIndex,
  214. IN PULONG StartingRunIndex
  215. );
  216. ULONG
  217. RtlFindLastBackwardRunClear (
  218. IN PRTL_BITMAP BitMapHeader,
  219. IN ULONG FromIndex,
  220. IN PULONG StartingRunIndex
  221. );
  222. #endif // MILLEN
  223. #endif // !_TCPIP_BITMAP_H_