diff --git a/xtoskrnl/includes/rtli.h b/xtoskrnl/includes/rtli.h index 618aa8a..34f8efd 100644 --- a/xtoskrnl/includes/rtli.h +++ b/xtoskrnl/includes/rtli.h @@ -33,6 +33,16 @@ LONG_PTR RtlAtomicAnd64(IN VOLATILE PLONG_PTR Address, IN LONG_PTR Mask); +XTFASTCALL +UCHAR +RtlAtomicBitTestAndSet(IN VOLATILE PLONG Base, + IN LONG Offset); + +XTFASTCALL +UCHAR +RtlAtomicBitTestAndSet64(IN VOLATILE PLONGLONG Base, + IN LONGLONG Offset); + XTFASTCALL CHAR RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address, diff --git a/xtoskrnl/rtl/atomic.c b/xtoskrnl/rtl/atomic.c index d2d99b4..46b2fe8 100644 --- a/xtoskrnl/rtl/atomic.c +++ b/xtoskrnl/rtl/atomic.c @@ -93,6 +93,48 @@ RtlAtomicAnd64(IN VOLATILE PLONG_PTR Address, return __sync_fetch_and_and(Address, Mask); } +/** + * Performs an atomic test of the specified bit of the specified long value and sets it to 1. + * + * @param Base + * Specifies a pointer to the variable. + * + * @param Offset + * Specifies the bit position to be tested. + * + * @return Returns a value of the specified bit. + * + * @since XT 1.0 + */ +XTFASTCALL +UCHAR +RtlAtomicBitTestAndSet(IN VOLATILE PLONG Base, + IN LONG Offset) +{ + return (__atomic_fetch_or(Base, 1l << Offset, __ATOMIC_SEQ_CST) >> Offset) & 1; +} + +/** + * Performs an atomic test of the specified bit of the specified 64-bit long value and sets it to 1. + * + * @param Base + * Specifies a pointer to the variable. + * + * @param Offset + * Specifies the bit position to be tested. + * + * @return Returns a value of the specified bit. + * + * @since XT 1.0 + */ +XTFASTCALL +UCHAR +RtlAtomicBitTestAndSet64(IN VOLATILE PLONGLONG Base, + IN LONGLONG Offset) +{ + return (__atomic_fetch_or(Base, 1ll << Offset, __ATOMIC_SEQ_CST) >> Offset) & 1; +} + /** * Performs atomically compare exchange operation on the 8-bit value. *