RtlFindSetBits

Hello,

according to DDK help, it returns 0xFFFFFFFF if it cant find number of set bits within the given bitmap (from HintIndex to the end).
os: xpsp1

RtlInitializeBitmap( ) - init for 256 items
RtlClearAllBits( )

RtlSetBits( pBitmap, 0x11, 1 )
RtlSetBits( pBitmap, 0xB0, 1 )

RtlFindSetBits( pBitmap, 1, 0x22 ) - returns 0xB0
RtlFindSetBits( pBitmap, 1, 0xB1 ) - returns 0x11 (!)

why 0x11 instead of -1 ?

thanks, pk

The DDK says:

“The RtlFindSetBits routine searches for a range of set bits of a requested size within a bitmap. […] For a successful call, the returned bit position is not necessarily equivalent to the given HintIndex. If necessary, RtlFindSetBits searches the whole bitmap to locate a set bit range of the requested size.”
In other words, RtlFindSetBits uses HintIndex just as a (as the name implies) hint on where to start the search from, but it will look for set bits in the whole bitmap.

You are probably assuming that RtlFindSetBits searches starting from HintIndex and until the end of the bitmap, which is not correct.

Regards,
Razvan

Petr Kurtin wrote: Hello,

according to DDK help, it returns 0xFFFFFFFF if it cant find number of set bits within the given bitmap (from HintIndex to the end).
os: xpsp1

RtlInitializeBitmap( ) - init for 256 items
RtlClearAllBits( )

RtlSetBits( pBitmap, 0x11, 1 )
RtlSetBits( pBitmap, 0xB0, 1 )

RtlFindSetBits( pBitmap, 1, 0x22 ) - returns 0xB0
RtlFindSetBits( pBitmap, 1, 0xB1 ) - returns 0x11 (!)

why 0x11 instead of -1 ?

thanks, pk


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

---------------------------------
Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

"For a successful call, the returned bit position is not necessarily
equivalent to the given HintIndex. If necessary, RtlFindSetBits searches
the whole bitmap to locate a set bit range of the requested size.
However, it starts searching for the requested range near HintIndex, so
callers can find such a range more quickly when they can supply
appropriate hints about where to start looking. "

The function is working as documented. Hint is the starting index, the
search covers the entire bitmap starting at hint.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Petr Kurtin
Sent: Monday, January 02, 2006 12:07 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RtlFindSetBits

Hello,

according to DDK help, it returns 0xFFFFFFFF if it cant find number
of set bits within the given bitmap (from HintIndex to the end).

os: xpsp1

RtlInitializeBitmap( ) - init for 256 items

RtlClearAllBits( )

RtlSetBits( pBitmap, 0x11, 1 )

RtlSetBits( pBitmap, 0xB0, 1 )

RtlFindSetBits( pBitmap, 1, 0x22 ) - returns 0xB0

RtlFindSetBits( pBitmap, 1, 0xB1 ) - returns 0x11 (!)

why 0x11 instead of -1 ?

thanks, pk


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

>(from HintIndex to the end).

At least in the 5256 WDK, the docs do not say this. That’s your
interpretation. The comments section indicates that the routine searches
the whole bitmap.

  • Dan.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Petr Kurtin
Sent: Monday, January 02, 2006 10:07 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] RtlFindSetBits

Hello,

according to DDK help, it returns 0xFFFFFFFF if it cant find number of
set bits within the given bitmap (from HintIndex to the end).
os: xpsp1

RtlInitializeBitmap( ) - init for 256 items
RtlClearAllBits( )

RtlSetBits( pBitmap, 0x11, 1 )
RtlSetBits( pBitmap, 0xB0, 1 )

RtlFindSetBits( pBitmap, 1, 0x22 ) - returns 0xB0
RtlFindSetBits( pBitmap, 1, 0xB1 ) - returns 0x11 (!)

why 0x11 instead of -1 ?

thanks, pk


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

While on the subject of the bitmap functions, does anybody know if these
things are internally protected across threads? Specifically, can I call
RtlFindClearBitsAndSet from multiple threads/processors and expect correct
atomic updates to the bitmap? I’ve tended to use spinlocks around bitmaps
calls in this case, but wondered if that was unnecessary.

  • Jan

No they are not protected in anyway.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

“Jan Bottorff” wrote in message news:xxxxx@ntdev…
> While on the subject of the bitmap functions, does anybody know if these
> things are internally protected across threads? Specifically, can I call
> RtlFindClearBitsAndSet from multiple threads/processors and expect correct
> atomic updates to the bitmap? I’ve tended to use spinlocks around bitmaps
> calls in this case, but wondered if that was unnecessary.
>
> - Jan
>
>
>
>
>

The locks are necessary. The RTL_BITMAP structure contains no locks by
itself.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Jan Bottorff”
To: “Windows System Software Devs Interest List”
Sent: Monday, January 02, 2006 9:22 PM
Subject: RE: [ntdev] RtlFindSetBits

> While on the subject of the bitmap functions, does anybody know if these
> things are internally protected across threads? Specifically, can I call
> RtlFindClearBitsAndSet from multiple threads/processors and expect correct
> atomic updates to the bitmap? I’ve tended to use spinlocks around bitmaps
> calls in this case, but wondered if that was unnecessary.
>
> - Jan
>
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com