1 2 #include <apitest.h> 3 4 #define WIN32_NO_STATUS 5 #include <ndk/mmfuncs.h> 6 #include <ndk/rtlfuncs.h> 7 8 static 9 PVOID 10 AllocateGuarded( 11 _In_ SIZE_T SizeRequested) 12 { 13 NTSTATUS Status; 14 SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 15 PVOID VirtualMemory = NULL; 16 PCHAR StartOfBuffer; 17 18 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 19 20 if (!NT_SUCCESS(Status)) 21 return NULL; 22 23 Size -= PAGE_SIZE; 24 if (Size) 25 { 26 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 27 if (!NT_SUCCESS(Status)) 28 { 29 Size = 0; 30 Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 31 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 32 return NULL; 33 } 34 } 35 36 StartOfBuffer = VirtualMemory; 37 StartOfBuffer += Size - SizeRequested; 38 39 return StartOfBuffer; 40 } 41 42 static 43 VOID 44 FreeGuarded( 45 _In_ PVOID Pointer) 46 { 47 NTSTATUS Status; 48 PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 49 SIZE_T Size = 0; 50 51 Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 52 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 53 } 54 55 void 56 Test_RtlFindMostSignificantBit(void) 57 { 58 ok_int(RtlFindMostSignificantBit(0), -1); 59 60 ok_int(RtlFindMostSignificantBit(0x0000000000000001ULL), 0); 61 ok_int(RtlFindMostSignificantBit(0x0000000000000002ULL), 1); 62 ok_int(RtlFindMostSignificantBit(0x1000000000000000ULL), 60); 63 ok_int(RtlFindMostSignificantBit(0x8000000000000000ULL), 63); 64 ok_int(RtlFindMostSignificantBit(0x8000000000000001ULL), 63); 65 ok_int(RtlFindMostSignificantBit(0xFFFFFFFFFFFFFFFFULL), 63); 66 ok_int(RtlFindMostSignificantBit(0x0000000070000000ULL), 30); 67 } 68 69 void 70 Test_RtlFindLeastSignificantBit(void) 71 { 72 ok_int(RtlFindLeastSignificantBit(0), -1); 73 74 ok_int(RtlFindLeastSignificantBit(0x0000000000000001ULL), 0); 75 ok_int(RtlFindLeastSignificantBit(0x0000000000000002ULL), 1); 76 ok_int(RtlFindLeastSignificantBit(0x1000000000000000ULL), 60); 77 ok_int(RtlFindLeastSignificantBit(0x8000000000000000ULL), 63); 78 ok_int(RtlFindLeastSignificantBit(0x8000000000000000ULL), 63); 79 ok_int(RtlFindLeastSignificantBit(0xFFFFFFFFFFFFFFFFULL), 0); 80 ok_int(RtlFindLeastSignificantBit(0x0000000070000000ULL), 28); 81 } 82 83 void 84 Test_RtlInitializeBitMap(void) 85 { 86 RTL_BITMAP BitMapHeader; 87 ULONG Buffer[2]; 88 BOOLEAN Exception = FALSE; 89 90 _SEH2_TRY 91 { 92 RtlInitializeBitMap(NULL, NULL, 0); 93 } 94 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 95 { 96 Exception = TRUE; 97 } 98 _SEH2_END; 99 ok_int(Exception, 1); 100 101 memset(Buffer, 0xcc, sizeof(Buffer)); 102 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 103 ok_int(BitMapHeader.SizeOfBitMap, 0); 104 ok_ptr(BitMapHeader.Buffer, Buffer); 105 ok_hex(Buffer[0], 0xcccccccc); 106 107 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 108 ok_int(BitMapHeader.SizeOfBitMap, 8); 109 ok_hex(Buffer[0], 0xcccccccc); 110 } 111 112 void 113 Test_RtlClearAllBits(void) 114 { 115 RTL_BITMAP BitMapHeader; 116 ULONG *Buffer; 117 ULONG BufferSize = 2 * sizeof(*Buffer); 118 119 Buffer = AllocateGuarded(BufferSize); 120 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 121 memset(Buffer, 0xcc, BufferSize); 122 RtlClearAllBits(&BitMapHeader); 123 ok_hex(Buffer[0], 0x00000000); 124 ok_hex(Buffer[1], 0xcccccccc); 125 126 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 127 memset(Buffer, 0xcc, BufferSize); 128 RtlClearAllBits(&BitMapHeader); 129 ok_hex(Buffer[0], 0xcccccccc); 130 ok_hex(Buffer[1], 0xcccccccc); 131 132 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 133 memset(Buffer, 0xcc, BufferSize); 134 RtlClearAllBits(&BitMapHeader); 135 ok_hex(Buffer[0], 0x00000000); 136 ok_hex(Buffer[1], 0x00000000); 137 FreeGuarded(Buffer); 138 } 139 140 void 141 Test_RtlSetAllBits(void) 142 { 143 RTL_BITMAP BitMapHeader; 144 ULONG *Buffer; 145 ULONG BufferSize = 2 * sizeof(*Buffer); 146 147 Buffer = AllocateGuarded(BufferSize); 148 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 149 memset(Buffer, 0xcc, BufferSize); 150 RtlSetAllBits(&BitMapHeader); 151 ok_hex(Buffer[0], 0xffffffff); 152 ok_hex(Buffer[1], 0xcccccccc); 153 154 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 155 memset(Buffer, 0xcc, BufferSize); 156 RtlSetAllBits(&BitMapHeader); 157 ok_hex(Buffer[0], 0xcccccccc); 158 ok_hex(Buffer[1], 0xcccccccc); 159 160 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 161 memset(Buffer, 0xcc, BufferSize); 162 RtlSetAllBits(&BitMapHeader); 163 ok_hex(Buffer[0], 0xffffffff); 164 ok_hex(Buffer[1], 0xffffffff); 165 FreeGuarded(Buffer); 166 } 167 168 void 169 Test_RtlClearBits(void) 170 { 171 RTL_BITMAP BitMapHeader; 172 ULONG *Buffer; 173 ULONG BufferSize = 2 * sizeof(*Buffer); 174 175 Buffer = AllocateGuarded(BufferSize); 176 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 177 178 memset(Buffer, 0xff, BufferSize); 179 RtlClearBits(&BitMapHeader, 0, 0); 180 ok_hex(Buffer[0], 0xffffffff); 181 ok_hex(Buffer[1], 0xffffffff); 182 183 memset(Buffer, 0xff, BufferSize); 184 RtlClearBits(&BitMapHeader, 0, 1); 185 ok_hex(Buffer[0], 0xfffffffe); 186 ok_hex(Buffer[1], 0xffffffff); 187 188 memset(Buffer, 0xff, BufferSize); 189 RtlClearBits(&BitMapHeader, 21, 1); 190 ok_hex(Buffer[0], 0xffdfffff); 191 ok_hex(Buffer[1], 0xffffffff); 192 193 memset(Buffer, 0xff, BufferSize); 194 RtlClearBits(&BitMapHeader, 7, 9); 195 ok_hex(Buffer[0], 0xffff007f); 196 ok_hex(Buffer[1], 0xffffffff); 197 198 memset(Buffer, 0xff, BufferSize); 199 RtlClearBits(&BitMapHeader, 13, 22); 200 ok_hex(Buffer[0], 0x00001fff); 201 ok_hex(Buffer[1], 0xfffffff8); 202 203 memset(Buffer, 0xff, BufferSize); 204 RtlClearBits(&BitMapHeader, 63, 1); 205 ok_hex(Buffer[0], 0xffffffff); 206 ok_hex(Buffer[1], 0x7fffffff); 207 208 memset(Buffer, 0xcc, BufferSize); 209 RtlClearBits(&BitMapHeader, 3, 6); 210 RtlClearBits(&BitMapHeader, 11, 5); 211 RtlClearBits(&BitMapHeader, 21, 7); 212 RtlClearBits(&BitMapHeader, 37, 4); 213 ok_hex(Buffer[0], 0xc00c0404); 214 ok_hex(Buffer[1], 0xcccccc0c); 215 FreeGuarded(Buffer); 216 } 217 218 void 219 Test_RtlSetBits(void) 220 { 221 RTL_BITMAP BitMapHeader; 222 ULONG *Buffer; 223 ULONG BufferSize = 2 * sizeof(*Buffer); 224 225 Buffer = AllocateGuarded(BufferSize); 226 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 227 228 memset(Buffer, 0x00, BufferSize); 229 RtlSetBits(&BitMapHeader, 0, 0); 230 ok_hex(Buffer[0], 0x00000000); 231 ok_hex(Buffer[1], 0x00000000); 232 233 memset(Buffer, 0x00, BufferSize); 234 RtlSetBits(&BitMapHeader, 0, 1); 235 ok_hex(Buffer[0], 0x00000001); 236 ok_hex(Buffer[1], 0x00000000); 237 238 memset(Buffer, 0x00, BufferSize); 239 RtlSetBits(&BitMapHeader, 21, 1); 240 ok_hex(Buffer[0], 0x00200000); 241 ok_hex(Buffer[1], 0x00000000); 242 243 memset(Buffer, 0x00, BufferSize); 244 RtlSetBits(&BitMapHeader, 7, 9); 245 ok_hex(Buffer[0], 0x0000ff80); 246 ok_hex(Buffer[1], 0x00000000); 247 248 memset(Buffer, 0x00, BufferSize); 249 RtlSetBits(&BitMapHeader, 13, 22); 250 ok_hex(Buffer[0], 0xffffe000); 251 ok_hex(Buffer[1], 0x00000007); 252 253 memset(Buffer, 0x00, BufferSize); 254 RtlSetBits(&BitMapHeader, 63, 1); 255 ok_hex(Buffer[0], 0x00000000); 256 ok_hex(Buffer[1], 0x80000000); 257 258 memset(Buffer, 0xcc, BufferSize); 259 RtlSetBits(&BitMapHeader, 3, 6); 260 RtlSetBits(&BitMapHeader, 11, 5); 261 RtlSetBits(&BitMapHeader, 21, 7); 262 RtlSetBits(&BitMapHeader, 37, 4); 263 ok_hex(Buffer[0], 0xcfecfdfc); 264 ok_hex(Buffer[1], 0xcccccdec); 265 FreeGuarded(Buffer); 266 } 267 268 void 269 Test_RtlAreBitsClear(void) 270 { 271 RTL_BITMAP BitMapHeader; 272 ULONG *Buffer; 273 274 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 275 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 276 Buffer[0] = 0x00ff00ff; 277 Buffer[1] = 0xc0cfc0cf; 278 279 ok_hex(RtlAreBitsClear(&BitMapHeader, 0, 8), FALSE); 280 ok_hex(RtlAreBitsClear(&BitMapHeader, 8, 8), TRUE); 281 ok_hex(RtlAreBitsClear(&BitMapHeader, 7, 8), FALSE); 282 ok_hex(RtlAreBitsClear(&BitMapHeader, 8, 9), FALSE); 283 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 1), FALSE); 284 285 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 286 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 1), TRUE); 287 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 7), TRUE); 288 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 8), FALSE); 289 290 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 291 ok_hex(RtlAreBitsClear(&BitMapHeader, 60, 4), FALSE); 292 FreeGuarded(Buffer); 293 } 294 295 void 296 Test_RtlAreBitsSet(void) 297 { 298 RTL_BITMAP BitMapHeader; 299 ULONG *Buffer; 300 301 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 302 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 303 Buffer[0] = 0xff00ff00; 304 Buffer[1] = 0x3F303F30; 305 306 ok_hex(RtlAreBitsSet(&BitMapHeader, 0, 8), FALSE); 307 ok_hex(RtlAreBitsSet(&BitMapHeader, 8, 8), TRUE); 308 ok_hex(RtlAreBitsSet(&BitMapHeader, 7, 8), FALSE); 309 ok_hex(RtlAreBitsSet(&BitMapHeader, 8, 9), FALSE); 310 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 1), FALSE); 311 312 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 313 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 1), TRUE); 314 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 7), TRUE); 315 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 8), FALSE); 316 317 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 318 ok_hex(RtlAreBitsSet(&BitMapHeader, 60, 4), FALSE); 319 FreeGuarded(Buffer); 320 } 321 322 void 323 Test_RtlNumberOfSetBits(void) 324 { 325 RTL_BITMAP BitMapHeader; 326 ULONG *Buffer; 327 328 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 329 Buffer[0] = 0xff00ff0f; 330 Buffer[1] = 0x3F303F30; 331 332 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 333 ok_int(RtlNumberOfSetBits(&BitMapHeader), 0); 334 335 RtlInitializeBitMap(&BitMapHeader, Buffer, 4); 336 ok_int(RtlNumberOfSetBits(&BitMapHeader), 4); 337 338 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 339 ok_int(RtlNumberOfSetBits(&BitMapHeader), 19); 340 341 RtlInitializeBitMap(&BitMapHeader, Buffer, 56); 342 ok_int(RtlNumberOfSetBits(&BitMapHeader), 30); 343 344 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 345 ok_int(RtlNumberOfSetBits(&BitMapHeader), 36); 346 FreeGuarded(Buffer); 347 } 348 349 void 350 Test_RtlNumberOfClearBits(void) 351 { 352 RTL_BITMAP BitMapHeader; 353 ULONG *Buffer; 354 355 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 356 Buffer[0] = 0xff00fff0; 357 Buffer[1] = 0x3F303F30; 358 359 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 360 ok_int(RtlNumberOfClearBits(&BitMapHeader), 0); 361 362 RtlInitializeBitMap(&BitMapHeader, Buffer, 4); 363 ok_int(RtlNumberOfClearBits(&BitMapHeader), 4); 364 365 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 366 ok_int(RtlNumberOfClearBits(&BitMapHeader), 12); 367 368 RtlInitializeBitMap(&BitMapHeader, Buffer, 56); 369 ok_int(RtlNumberOfClearBits(&BitMapHeader), 26); 370 371 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 372 ok_int(RtlNumberOfClearBits(&BitMapHeader), 28); 373 FreeGuarded(Buffer); 374 } 375 376 void 377 Test_RtlFindClearBits(void) 378 { 379 RTL_BITMAP BitMapHeader; 380 ULONG *Buffer; 381 382 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 383 Buffer[0] = 0x060F874D; 384 Buffer[1] = 0x3F303F30; 385 386 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 387 ok_int(RtlFindClearBits(&BitMapHeader, 0, 0), 0); 388 ok_int(RtlFindClearBits(&BitMapHeader, 0, 3), 0); 389 ok_int(RtlFindClearBits(&BitMapHeader, 1, 0), -1); 390 ok_int(RtlFindClearBits(&BitMapHeader, 1, 1), -1); 391 392 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 393 ok_int(RtlFindClearBits(&BitMapHeader, 0, 3), 0); 394 ok_int(RtlFindClearBits(&BitMapHeader, 1, 0), 1); 395 ok_int(RtlFindClearBits(&BitMapHeader, 1, 1), 1); 396 ok_int(RtlFindClearBits(&BitMapHeader, 1, 2), 4); 397 398 ok_int(RtlFindClearBits(&BitMapHeader, 2, 0), 4); 399 ok_int(RtlFindClearBits(&BitMapHeader, 3, 0), -1); 400 401 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 402 ok_int(RtlFindClearBits(&BitMapHeader, 0, 3), 0); 403 ok_int(RtlFindClearBits(&BitMapHeader, 0, 21), 16); 404 ok_int(RtlFindClearBits(&BitMapHeader, 0, 12), 8); 405 ok_int(RtlFindClearBits(&BitMapHeader, 0, 31), 24); 406 ok_int(RtlFindClearBits(&BitMapHeader, 0, 32), 0); 407 ok_int(RtlFindClearBits(&BitMapHeader, 0, 39), 0); 408 ok_int(RtlFindClearBits(&BitMapHeader, 4, 0), 11); 409 ok_int(RtlFindClearBits(&BitMapHeader, 5, 0), 20); 410 ok_int(RtlFindClearBits(&BitMapHeader, 4, 11), 11); 411 ok_int(RtlFindClearBits(&BitMapHeader, 4, 12), 20); 412 ok_int(RtlFindClearBits(&BitMapHeader, 2, 11), 11); 413 ok_int(RtlFindClearBits(&BitMapHeader, 2, 12), 12); 414 ok_int(RtlFindClearBits(&BitMapHeader, 1, 32), 1); 415 ok_int(RtlFindClearBits(&BitMapHeader, 4, 32), 11); 416 ok_int(RtlFindClearBits(&BitMapHeader, 5, 32), 20); 417 418 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 419 ok_int(RtlFindClearBits(&BitMapHeader, 5, 64), 20); 420 ok_int(RtlFindClearBits(&BitMapHeader, 9, 28), 27); 421 ok_int(RtlFindClearBits(&BitMapHeader, 10, 0), -1); 422 Buffer[1] = 0xFF303F30; 423 ok_int(RtlFindClearBits(&BitMapHeader, 1, 56), 1); 424 FreeGuarded(Buffer); 425 } 426 427 void 428 Test_RtlFindSetBits(void) 429 { 430 RTL_BITMAP BitMapHeader; 431 ULONG *Buffer; 432 433 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 434 Buffer[0] = 0xF9F078B2; 435 Buffer[1] = 0x3F303F30; 436 437 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 438 ok_int(RtlFindSetBits(&BitMapHeader, 0, 0), 0); 439 ok_int(RtlFindSetBits(&BitMapHeader, 0, 3), 0); 440 ok_int(RtlFindSetBits(&BitMapHeader, 1, 0), -1); 441 ok_int(RtlFindSetBits(&BitMapHeader, 1, 1), -1); 442 443 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 444 ok_int(RtlFindSetBits(&BitMapHeader, 0, 3), 0); 445 ok_int(RtlFindSetBits(&BitMapHeader, 1, 0), 1); 446 ok_int(RtlFindSetBits(&BitMapHeader, 1, 1), 1); 447 ok_int(RtlFindSetBits(&BitMapHeader, 1, 2), 4); 448 449 ok_int(RtlFindSetBits(&BitMapHeader, 2, 0), 4); 450 ok_int(RtlFindSetBits(&BitMapHeader, 3, 0), -1); 451 452 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 453 ok_int(RtlFindSetBits(&BitMapHeader, 0, 3), 0); 454 ok_int(RtlFindSetBits(&BitMapHeader, 0, 21), 16); 455 ok_int(RtlFindSetBits(&BitMapHeader, 0, 12), 8); 456 ok_int(RtlFindSetBits(&BitMapHeader, 0, 31), 24); 457 ok_int(RtlFindSetBits(&BitMapHeader, 0, 32), 0); 458 ok_int(RtlFindSetBits(&BitMapHeader, 0, 39), 0); 459 ok_int(RtlFindSetBits(&BitMapHeader, 4, 0), 11); 460 ok_int(RtlFindSetBits(&BitMapHeader, 5, 0), 20); 461 ok_int(RtlFindSetBits(&BitMapHeader, 4, 11), 11); 462 ok_int(RtlFindSetBits(&BitMapHeader, 4, 12), 20); 463 ok_int(RtlFindSetBits(&BitMapHeader, 2, 11), 11); 464 ok_int(RtlFindSetBits(&BitMapHeader, 1, 32), 1); 465 ok_int(RtlFindSetBits(&BitMapHeader, 4, 32), 11); 466 ok_int(RtlFindSetBits(&BitMapHeader, 5, 32), 20); 467 468 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 469 ok_int(RtlFindSetBits(&BitMapHeader, 5, 64), 20); 470 ok_int(RtlFindSetBits(&BitMapHeader, 6, 57), 40); 471 ok_int(RtlFindSetBits(&BitMapHeader, 7, 0), -1); 472 ok_int(RtlFindSetBits(&BitMapHeader, 1, 62), 1); 473 FreeGuarded(Buffer); 474 } 475 476 void 477 Test_RtlFindClearBitsAndSet(void) 478 { 479 RTL_BITMAP BitMapHeader; 480 ULONG *Buffer; 481 482 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 483 Buffer[0] = 0x060F874D; 484 Buffer[1] = 0x3F303F30; 485 486 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 487 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 0, 0), 0); 488 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 0, 3), 0); 489 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 0), -1); 490 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 1), -1); 491 ok_hex(Buffer[0], 0x060F874D); 492 493 Buffer[0] = 0x060F874D; 494 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 495 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 0), 1); 496 ok_hex(Buffer[0], 0x60f874f); 497 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 1), 4); 498 ok_hex(Buffer[0], 0x60f875f); 499 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 2), 5); 500 ok_hex(Buffer[0], 0x60f877f); 501 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 0), -1); 502 ok_hex(Buffer[0], 0x60f877f); 503 504 Buffer[0] = 0x060F874D; 505 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 506 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 0), 11); 507 ok_hex(Buffer[0], 0x60fff4d); 508 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 5, 0), 20); 509 ok_hex(Buffer[0], 0x7ffff4d); 510 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 11), 27); 511 ok_hex(Buffer[0], 0x7fffff4d); 512 513 Buffer[0] = 0x060F874D; 514 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 12), 20); 515 ok_hex(Buffer[0], 0x6ff874d); 516 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 11), 11); 517 ok_hex(Buffer[0], 0x6ff9f4d); 518 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 12), 13); 519 ok_hex(Buffer[0], 0x6ffff4d); 520 FreeGuarded(Buffer); 521 } 522 523 void 524 Test_RtlFindSetBitsAndClear(void) 525 { 526 RTL_BITMAP BitMapHeader; 527 ULONG *Buffer; 528 529 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 530 Buffer[0] = 0xF9F078B2; 531 Buffer[1] = 0x3F303F30; 532 533 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 534 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 0, 0), 0); 535 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 0, 3), 0); 536 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 0), -1); 537 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 1), -1); 538 ok_hex(Buffer[0], 0xF9F078B2); 539 540 Buffer[0] = 0xF9F078B2; 541 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 542 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 0), 1); 543 ok_hex(Buffer[0], 0xf9f078b0); 544 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 1), 4); 545 ok_hex(Buffer[0], 0xf9f078a0); 546 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 2), 5); 547 ok_hex(Buffer[0], 0xf9f07880); 548 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 0), -1); 549 ok_hex(Buffer[0], 0xf9f07880); 550 551 Buffer[0] = 0xF9F078B2; 552 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 553 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 0), 11); 554 ok_hex(Buffer[0], 0xf9f000b2); 555 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 5, 0), 20); 556 ok_hex(Buffer[0], 0xf80000b2); 557 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 11), 27); 558 ok_hex(Buffer[0], 0x800000b2); 559 560 Buffer[0] = 0xF9F078B2; 561 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 12), 20); 562 ok_hex(Buffer[0], 0xf90078b2); 563 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 11), 11); 564 ok_hex(Buffer[0], 0xf90060b2); 565 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 12), 13); 566 ok_hex(Buffer[0], 0xf90000b2); 567 FreeGuarded(Buffer); 568 } 569 570 void 571 Test_RtlFindNextForwardRunClear(void) 572 { 573 RTL_BITMAP BitMapHeader; 574 ULONG *Buffer; 575 ULONG Index; 576 577 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 578 Buffer[0] = 0xF9F078B2; 579 Buffer[1] = 0x3F303F30; 580 581 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 582 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 0, &Index), 0); 583 ok_int(Index, 0); 584 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 1, &Index), 0); 585 ok_int(Index, 1); 586 587 Index = -1; 588 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 589 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 0, &Index), 1); 590 ok_int(Index, 0); 591 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 1, &Index), 2); 592 ok_int(Index, 2); 593 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 7, &Index), 0); 594 ok_int(Index, 8); 595 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 17, &Index), 0); 596 ok_int(Index, 17); 597 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 39, &Index), 0); 598 ok_int(Index, 39); 599 FreeGuarded(Buffer); 600 } 601 602 void 603 Test_RtlFindFirstRunClear(void) 604 { 605 } 606 607 void 608 Test_RtlFindLastBackwardRunClear(void) 609 { 610 } 611 612 void 613 Test_RtlFindClearRuns(void) 614 { 615 } 616 617 void 618 Test_RtlFindLongestRunClear(void) 619 { 620 } 621 622 623 START_TEST(RtlBitmap) 624 { 625 Test_RtlFindMostSignificantBit(); 626 Test_RtlFindLeastSignificantBit(); 627 Test_RtlInitializeBitMap(); 628 Test_RtlClearAllBits(); 629 Test_RtlSetAllBits(); 630 Test_RtlClearBits(); 631 Test_RtlSetBits(); 632 Test_RtlAreBitsClear(); 633 Test_RtlAreBitsSet(); 634 Test_RtlNumberOfSetBits(); 635 Test_RtlNumberOfClearBits(); 636 Test_RtlFindClearBits(); 637 Test_RtlFindSetBits(); 638 Test_RtlFindClearBitsAndSet(); 639 Test_RtlFindSetBitsAndClear(); 640 Test_RtlFindNextForwardRunClear(); 641 Test_RtlFindFirstRunClear(); 642 Test_RtlFindLastBackwardRunClear(); 643 Test_RtlFindClearRuns(); 644 Test_RtlFindLongestRunClear(); 645 } 646 647