ReactOS 0.4.16-dev-205-g7b2bb7e
dbgbitmap.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS SDK
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Helper functions to debug RTL_BITMAP
5 * COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#pragma once
9
10#include <ndk/rtlfuncs.h>
11
12typedef struct _RTL_BITMAP_DBG
13{
14 union
15 {
16 struct
17 {
20 };
22 };
26
27static inline
29{
30 ULONG hash = 2166136261u; // FNV offset basis (a large prime number)
31 for (size_t i = 0; i < length; ++i)
32 {
33 hash ^= data[i];
34 hash *= 16777619u; // FNV prime
35 }
36 return hash;
37}
38
39static inline
42 _In_ PRTL_BITMAP_DBG BitMapHeader)
43{
44 ULONG SizeInBytes = ALIGN_UP_BY(BitMapHeader->BitMap.SizeOfBitMap, 32) / 32;
45 return fnv1a_hash(BitMapHeader->BitMap.Buffer, SizeInBytes / sizeof(ULONG));
46}
47
48static inline
49VOID
51 _Inout_ PRTL_BITMAP_DBG BitMapHeader)
52{
53 ULONG NumberOfSetBits = RtlNumberOfSetBits(&BitMapHeader->BitMap);
54 ASSERT(BitMapHeader->NumberOfSetBits == NumberOfSetBits);
55 ULONG BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
56 ASSERT(BitMapHeader->BitmapHash == BitmapHash);
57}
58
59_At_(BitMapHeader->SizeOfBitMap, _Post_equal_to_(SizeOfBitMap))
60_At_(BitMapHeader->Buffer, _Post_equal_to_(BitMapBuffer))
61static inline
62VOID
63RtlInitializeBitMapDbg(
64 _Out_ PRTL_BITMAP_DBG BitMapHeader,
65 _In_opt_ __drv_aliasesMem PULONG BitMapBuffer,
66 _In_opt_ ULONG SizeOfBitMap)
67{
68 RtlInitializeBitMap(&BitMapHeader->BitMap, BitMapBuffer, SizeOfBitMap);
69 BitMapHeader->NumberOfSetBits = RtlNumberOfSetBits(&BitMapHeader->BitMap);
70 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
71}
72
73static inline
76 _In_ PRTL_BITMAP_DBG BitMapHeader,
79{
80 RtlValidateBitmapDbg(BitMapHeader);
81 return RtlAreBitsClear(&BitMapHeader->BitMap, StartingIndex, Length);
82}
83
84static inline
87 _In_ PRTL_BITMAP_DBG BitMapHeader,
90{
91 RtlValidateBitmapDbg(BitMapHeader);
92 return RtlAreBitsSet(&BitMapHeader->BitMap, StartingIndex, Length);
93}
94
95static inline
96VOID
98 _In_ PRTL_BITMAP_DBG BitMapHeader)
99{
100 RtlValidateBitmapDbg(BitMapHeader);
101 RtlClearAllBits(&BitMapHeader->BitMap);
102 BitMapHeader->NumberOfSetBits = 0;
103 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
104}
105
106static inline
107VOID
109 _In_ PRTL_BITMAP_DBG BitMapHeader,
110 _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
111{
112 RtlValidateBitmapDbg(BitMapHeader);
113 if (RtlCheckBit(&BitMapHeader->BitMap, BitNumber) == FALSE)
114 {
115 BitMapHeader->NumberOfSetBits--;
116 }
117 RtlClearBit(&BitMapHeader->BitMap, BitNumber);
118 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
119}
120
121static inline
122VOID
124 _In_ PRTL_BITMAP_DBG BitMapHeader,
125 _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToClear) ULONG StartingIndex,
126 _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToClear)
127{
128 RtlValidateBitmapDbg(BitMapHeader);
129 RtlClearBits(&BitMapHeader->BitMap, StartingIndex, NumberToClear);
130 BitMapHeader->NumberOfSetBits = RtlNumberOfSetBits(&BitMapHeader->BitMap);
131 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
132}
133
134static inline
135ULONG
137 _In_ PRTL_BITMAP_DBG BitMapHeader,
140{
141 RtlValidateBitmapDbg(BitMapHeader);
142 return RtlFindClearBits(&BitMapHeader->BitMap, NumberToFind, HintIndex);
143}
144
145static inline
146ULONG
148 _In_ PRTL_BITMAP_DBG BitMapHeader,
151{
152 RtlValidateBitmapDbg(BitMapHeader);
153 return RtlFindClearBitsAndSet(&BitMapHeader->BitMap, NumberToFind, HintIndex);
154}
155
156static inline
157ULONG
159 _In_ PRTL_BITMAP_DBG BitMapHeader,
161{
162 RtlValidateBitmapDbg(BitMapHeader);
163 return RtlFindFirstRunClear(&BitMapHeader->BitMap, StartingIndex);
164}
165
166static inline
167ULONG
169 _In_ PRTL_BITMAP_DBG BitMapHeader,
170 _Out_writes_to_(SizeOfRunArray, return) PRTL_BITMAP_RUN RunArray,
171 _In_range_(>, 0) ULONG SizeOfRunArray,
172 _In_ BOOLEAN LocateLongestRuns)
173{
174 RtlValidateBitmapDbg(BitMapHeader);
175 return RtlFindClearRuns(&BitMapHeader->BitMap, RunArray, SizeOfRunArray, LocateLongestRuns);
176}
177
178static inline
179ULONG
181 _In_ PRTL_BITMAP_DBG BitMapHeader,
182 _In_ ULONG FromIndex,
183 _Out_ PULONG StartingRunIndex)
184{
185 RtlValidateBitmapDbg(BitMapHeader);
186 return RtlFindLastBackwardRunClear(&BitMapHeader->BitMap, FromIndex, StartingRunIndex);
187}
188
189static inline
190ULONG
192 _In_ PRTL_BITMAP_DBG BitMapHeader,
194{
195 RtlValidateBitmapDbg(BitMapHeader);
196 return RtlFindLongestRunClear(&BitMapHeader->BitMap, StartingIndex);
197}
198
199static inline
200ULONG
202 _In_ PRTL_BITMAP_DBG BitMapHeader,
203 _In_ ULONG FromIndex,
204 _Out_ PULONG StartingRunIndex)
205{
206 RtlValidateBitmapDbg(BitMapHeader);
207 return RtlFindNextForwardRunClear(&BitMapHeader->BitMap, FromIndex, StartingRunIndex);
208}
209
210static inline
211ULONG
213 _In_ PRTL_BITMAP_DBG BitMapHeader,
214 _In_ ULONG FromIndex,
215 _Out_ PULONG StartingRunIndex)
216{
217 RtlValidateBitmapDbg(BitMapHeader);
218 return RtlFindNextForwardRunSet(&BitMapHeader->BitMap, FromIndex, StartingRunIndex);
219}
220
221static inline
222ULONG
224 _In_ PRTL_BITMAP_DBG BitMapHeader,
227{
228 RtlValidateBitmapDbg(BitMapHeader);
229 return RtlFindSetBits(&BitMapHeader->BitMap, NumberToFind, HintIndex);
230}
231
232static inline
233ULONG
235 _In_ PRTL_BITMAP_DBG BitMapHeader,
238{
239 RtlValidateBitmapDbg(BitMapHeader);
240 return RtlFindSetBitsAndClear(&BitMapHeader->BitMap, NumberToFind, HintIndex);
241}
242
243static inline
244ULONG
246 _In_ PRTL_BITMAP_DBG BitMapHeader)
247{
248 RtlValidateBitmapDbg(BitMapHeader);
249 return RtlNumberOfClearBits(&BitMapHeader->BitMap);
250}
251
252static inline
253ULONG
255 _In_ PRTL_BITMAP_DBG BitMapHeader)
256{
257 RtlValidateBitmapDbg(BitMapHeader);
258 return RtlNumberOfSetBits(&BitMapHeader->BitMap);
259}
260
261static inline
262VOID
264 _In_ PRTL_BITMAP_DBG BitMapHeader,
265 _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
266{
267 RtlValidateBitmapDbg(BitMapHeader);
268 if (RtlCheckBit(&BitMapHeader->BitMap, BitNumber) == FALSE)
269 {
270 BitMapHeader->NumberOfSetBits++;
271 }
272 RtlSetBit(&BitMapHeader->BitMap, BitNumber);
273 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
274}
275
276static inline
277VOID
279 _In_ PRTL_BITMAP_DBG BitMapHeader,
280 _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
281 _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet)
282{
283 RtlValidateBitmapDbg(BitMapHeader);
284 RtlSetBits(&BitMapHeader->BitMap, StartingIndex, NumberToSet);
285 BitMapHeader->NumberOfSetBits = RtlNumberOfSetBits(&BitMapHeader->BitMap);
286 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
287}
288
289static inline
290VOID
292 _In_ PRTL_BITMAP_DBG BitMapHeader)
293{
294 RtlValidateBitmapDbg(BitMapHeader);
295 RtlSetAllBits(&BitMapHeader->BitMap);
296 BitMapHeader->NumberOfSetBits = BitMapHeader->BitMap.SizeOfBitMap;
297 BitMapHeader->BitmapHash = RtlComputeBitmapHashDbg(BitMapHeader);
298}
299
301static inline
304 _In_ PRTL_BITMAP_DBG BitMapHeader,
305 _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
306{
307 RtlValidateBitmapDbg(BitMapHeader);
308 return RtlTestBit(&BitMapHeader->BitMap, BitNumber);
309}
310
312static inline
315 _In_ PRTL_BITMAP_DBG BitMapHeader,
316 _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitPosition)
317{
318 RtlValidateBitmapDbg(BitMapHeader);
319 return RtlCheckBit(&BitMapHeader->BitMap, BitPosition);
320}
321
322#define _RTL_BITMAP _RTL_BITMAP_DBG
323#define RTL_BITMAP RTL_BITMAP_DBG
324#define PRTL_BITMAP PRTL_BITMAP_DBG
325
326#define RtlInitializeBitMap RtlInitializeBitMapDbg
327#define RtlAreBitsClear RtlAreBitsClearDbg
328#define RtlAreBitsSet RtlAreBitsSetDbg
329#define RtlClearAllBits RtlClearAllBitsDbg
330#define RtlClearBit RtlClearBitDbg
331#define RtlClearBits RtlClearBitsDbg
332#define RtlFindClearBits RtlFindClearBitsDbg
333#define RtlFindClearBitsAndSet RtlFindClearBitsAndSetDbg
334#define RtlFindFirstRunClear RtlFindFirstRunClearDbg
335#define RtlFindClearRuns RtlFindClearRunsDbg
336#define RtlFindLastBackwardRunClear RtlFindLastBackwardRunClearDbg
337#define RtlFindLongestRunClear RtlFindLongestRunClearDbg
338#define RtlFindNextForwardRunClear RtlFindNextForwardRunClearDbg
339#define RtlFindNextForwardRunSet RtlFindNextForwardRunSetDbg
340#define RtlFindSetBits RtlFindSetBitsDbg
341#define RtlFindSetBitsAndClear RtlFindSetBitsAndClearDbg
342#define RtlNumberOfClearBits RtlNumberOfClearBitsDbg
343#define RtlNumberOfSetBits RtlNumberOfSetBitsDbg
344#define RtlSetBit RtlSetBitDbg
345#define RtlSetBits RtlSetBitsDbg
346#define RtlSetAllBits RtlSetAllBitsDbg
347#define RtlTestBit RtlTestBitDbg
348#undef RtlCheckBit
349#define RtlCheckBit RtlCheckBitDbg
#define ALIGN_UP_BY(size, align)
unsigned char BOOLEAN
#define __drv_aliasesMem
Definition: btrfs_drv.h:203
static ULONG RtlFindSetBitsAndClearDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG NumberToFind, _In_ ULONG HintIndex)
Definition: dbgbitmap.h:234
#define RtlAreBitsSet
Definition: dbgbitmap.h:328
#define RtlFindClearBits
Definition: dbgbitmap.h:332
#define RtlClearBits
Definition: dbgbitmap.h:331
static ULONG RtlNumberOfClearBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader)
Definition: dbgbitmap.h:245
struct _RTL_BITMAP_DBG RTL_BITMAP_DBG
#define RtlAreBitsClear
Definition: dbgbitmap.h:327
#define RtlInitializeBitMap
Definition: dbgbitmap.h:326
static ULONG RtlFindClearBitsAndSetDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG NumberToFind, _In_ ULONG HintIndex)
Definition: dbgbitmap.h:147
static VOID RtlClearBitDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: dbgbitmap.h:108
static VOID RtlClearBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToClear) ULONG StartingIndex, _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToClear)
Definition: dbgbitmap.h:123
#define RtlFindNextForwardRunClear
Definition: dbgbitmap.h:338
struct _RTL_BITMAP_DBG * PRTL_BITMAP_DBG
static ULONG RtlFindFirstRunClearDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _Out_ PULONG StartingIndex)
Definition: dbgbitmap.h:158
#define RtlClearAllBits
Definition: dbgbitmap.h:329
#define RtlFindLastBackwardRunClear
Definition: dbgbitmap.h:336
#define RtlClearBit
Definition: dbgbitmap.h:330
static ULONG RtlFindLongestRunClearDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _Out_ PULONG StartingIndex)
Definition: dbgbitmap.h:191
#define RtlFindClearBitsAndSet
Definition: dbgbitmap.h:333
static BOOLEAN RtlAreBitsSetDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG StartingIndex, _In_ ULONG Length)
Definition: dbgbitmap.h:86
static ULONG RtlFindClearBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG NumberToFind, _In_ ULONG HintIndex)
Definition: dbgbitmap.h:136
#define RtlTestBit
Definition: dbgbitmap.h:347
#define RtlNumberOfSetBits
Definition: dbgbitmap.h:343
static _Must_inspect_result_ BOOLEAN RtlTestBitDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: dbgbitmap.h:303
#define RtlFindNextForwardRunSet
Definition: dbgbitmap.h:339
static ULONG RtlFindNextForwardRunClearDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG FromIndex, _Out_ PULONG StartingRunIndex)
Definition: dbgbitmap.h:201
static BOOLEAN RtlAreBitsClearDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG StartingIndex, _In_ ULONG Length)
Definition: dbgbitmap.h:75
#define RtlSetAllBits
Definition: dbgbitmap.h:346
#define RtlCheckBit
Definition: dbgbitmap.h:349
static ULONG RtlFindSetBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG NumberToFind, _In_ ULONG HintIndex)
Definition: dbgbitmap.h:223
static ULONG RtlFindClearRunsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _Out_writes_to_(SizeOfRunArray, return) PRTL_BITMAP_RUN RunArray, _In_range_(>, 0) ULONG SizeOfRunArray, _In_ BOOLEAN LocateLongestRuns)
Definition: dbgbitmap.h:168
static VOID RtlSetBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex, _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet)
Definition: dbgbitmap.h:278
static VOID RtlSetBitDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: dbgbitmap.h:263
#define RtlFindLongestRunClear
Definition: dbgbitmap.h:337
static ULONG fnv1a_hash(ULONG *data, size_t length)
Definition: dbgbitmap.h:28
#define RtlFindClearRuns
Definition: dbgbitmap.h:335
static ULONG RtlComputeBitmapHashDbg(_In_ PRTL_BITMAP_DBG BitMapHeader)
Definition: dbgbitmap.h:41
#define RtlFindFirstRunClear
Definition: dbgbitmap.h:334
static ULONG RtlFindLastBackwardRunClearDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG FromIndex, _Out_ PULONG StartingRunIndex)
Definition: dbgbitmap.h:180
#define RtlSetBit
Definition: dbgbitmap.h:344
static _Must_inspect_result_ BOOLEAN RtlCheckBitDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitPosition)
Definition: dbgbitmap.h:314
#define RtlFindSetBitsAndClear
Definition: dbgbitmap.h:341
static VOID RtlSetAllBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader)
Definition: dbgbitmap.h:291
#define RtlNumberOfClearBits
Definition: dbgbitmap.h:342
#define RtlSetBits
Definition: dbgbitmap.h:345
static ULONG RtlNumberOfSetBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader)
Definition: dbgbitmap.h:254
#define RtlFindSetBits
Definition: dbgbitmap.h:340
static ULONG RtlFindNextForwardRunSetDbg(_In_ PRTL_BITMAP_DBG BitMapHeader, _In_ ULONG FromIndex, _Out_ PULONG StartingRunIndex)
Definition: dbgbitmap.h:212
static VOID RtlClearAllBitsDbg(_In_ PRTL_BITMAP_DBG BitMapHeader)
Definition: dbgbitmap.h:97
static VOID RtlValidateBitmapDbg(_Inout_ PRTL_BITMAP_DBG BitMapHeader)
Definition: dbgbitmap.h:50
#define FALSE
Definition: types.h:117
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
#define _Inout_
Definition: ms_sal.h:378
#define _Post_equal_to_(expr)
Definition: ms_sal.h:578
#define _At_(target, annos)
Definition: ms_sal.h:244
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#define _Out_writes_to_(size, count)
Definition: ms_sal.h:355
#define _In_range_(lb, ub)
Definition: ms_sal.h:571
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
ULONG BitmapHash
Definition: dbgbitmap.h:24
PULONG Buffer
Definition: dbgbitmap.h:19
ULONG NumberOfSetBits
Definition: dbgbitmap.h:23
ULONG SizeOfBitMap
Definition: dbgbitmap.h:18
RTL_BITMAP BitMap
Definition: dbgbitmap.h:21
Definition: _hash_fun.h:40
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
_In_ ULONG NumberToFind
Definition: rtlfuncs.h:609
_In_ ULONG _In_ ULONG HintIndex
Definition: rtlfuncs.h:610
_In_ ULONG StartingIndex
Definition: rtlfuncs.h:395