#ifndef _NTRTL_H
/**
* The RtlSetBits routine sets all bits in a given range of a given bitmap variable.
*
* \param BitMapHeader A pointer to the RTL_BITMAP structure that describes the bitmap. This structure must have been initialized by the RtlInitializeBitMap routine.
* \param StartingIndex Specifies the start of the bit range to be set. This is a zero-based value indicating the position of the first bit in the range.
* \param NumberToSet Specifies how many bits to set.
* \remarks RtlSetBits simply returns control if the input NumberToSet is zero. StartingIndex plus NumberToSet must be less than or equal to BitMapHeader->SizeOfBitMap.
* \sa https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlsetbits
*/
#ifndef PHNT_NO_INLINE_RTL_BITMAP
FORCEINLINE
VOID
NTAPI_INLINE
RtlSetBits(
_In_ PRTL_BITMAP BitMapHeader,
_In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
_In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet
)
{
PUCHAR buffer;
ULONG offset;
ULONG count;
UCHAR mask;
SIZE_T bytes;
if (NumberToSet == 0)
return;
buffer = (PUCHAR)BitMapHeader->Buffer + (SIZE_T)(StartingIndex >> 3);
offset = (ULONG)(StartingIndex & 7);
if (offset != 0)
{
count = 8 - offset;
if (NumberToSet < count)
count = (ULONG)NumberToSet;
mask = (UCHAR)(((1u << count) - 1) << offset);
*buffer++ |= mask;
NumberToSet -= count;
}
bytes = (SIZE_T)(NumberToSet >> 3);
if (bytes != 0)
{
memset(buffer, 0xff, bytes);
buffer += bytes;
}
count = (ULONG)(NumberToSet & 7);
if (count != 0)
{
mask = (UCHAR)((1u << count) - 1);
*buffer |= mask;
}
}
View code on GitHub#ifndef _NTRTL_H
/**
* The RtlSetBits routine sets all bits in a given range of a given bitmap variable.
*
* \param BitMapHeader A pointer to the RTL_BITMAP structure that describes the bitmap. This structure must have been initialized by the RtlInitializeBitMap routine.
* \param StartingIndex Specifies the start of the bit range to be set. This is a zero-based value indicating the position of the first bit in the range.
* \param NumberToSet Specifies how many bits to set.
* \remarks RtlSetBits simply returns control if the input NumberToSet is zero. StartingIndex plus NumberToSet must be less than or equal to BitMapHeader->SizeOfBitMap.
* \sa https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlsetbits
*/
#ifndef PHNT_NO_INLINE_RTL_BITMAP
// ...
#else
NTSYSAPI
VOID
NTAPI
RtlSetBits(
_In_ PRTL_BITMAP BitMapHeader,
_In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
_In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet
);
View code on GitHub// wdm.h
NTSYSAPI VOID RtlSetBits(
[in] PRTL_BITMAP BitMapHeader,
[in] ULONG StartingIndex,
[in] ULONG NumberToSet
);
View the official Windows Driver Kit DDI referenceThis function is documented in Windows Driver Kit.
The RtlSetBits routine sets all bits in a given range of a given bitmap variable.
BitMapHeader [in]A pointer to the RTL_BITMAP structure that describes the bitmap. This structure must have been initialized by the RtlInitializeBitMap routine.
StartingIndex [in]Specifies the start of the bit range to be set. This is a zero-based value indicating the position of the first bit in the range.
NumberToSet [in]Specifies how many bits to set.
None
RtlSetBits simply returns control if the input NumberToSet is zero. StartingIndex plus NumberToSet must be less than or equal to BitMapHeader->SizeOfBitMap.
Callers of RtlSetBits must be running at IRQL <= APC_LEVEL if the memory that contains the bitmap variable is pageable or the memory at BitMapHeader is pageable. Otherwise, RtlSetBits can be called at any IRQL.