From 9e5fb84412fc11210d93c80146c9a27f956fc5e4 Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 12 Feb 2023 23:11:23 +0100 Subject: [PATCH] More routines for performing atomic bitwise AND/OR/XOR operations --- sdk/xtdk/rtlfuncs.h | 60 ++++++++++ xtoskrnl/rtl/atomic.c | 252 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 312 insertions(+) diff --git a/sdk/xtdk/rtlfuncs.h b/sdk/xtdk/rtlfuncs.h index 455db2c..0e61e2c 100644 --- a/sdk/xtdk/rtlfuncs.h +++ b/sdk/xtdk/rtlfuncs.h @@ -14,6 +14,26 @@ #include +XTFASTCALL +CHAR +RtlAtomicAnd8(IN VOLATILE PCHAR Address, + IN CHAR Mask); + +XTFASTCALL +SHORT +RtlAtomicAnd16(IN VOLATILE PSHORT Address, + IN SHORT Mask); + +XTFASTCALL +LONG +RtlAtomicAnd32(IN VOLATILE PLONG Address, + IN LONG Mask); + +XTFASTCALL +LONGLONG +RtlAtomicAnd64(IN VOLATILE PLONGLONG Address, + IN LONGLONG Mask); + XTFASTCALL CHAR RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address, @@ -121,6 +141,46 @@ XTFASTCALL LONGLONG RtlAtomicIncrement64(IN VOLATILE PLONGLONG Address); +XTFASTCALL +CHAR +RtlAtomicOr8(IN VOLATILE PCHAR Address, + IN CHAR Mask); + +XTFASTCALL +SHORT +RtlAtomicOr16(IN VOLATILE PSHORT Address, + IN SHORT Mask); + +XTFASTCALL +LONG +RtlAtomicOr32(IN VOLATILE PLONG Address, + IN LONG Mask); + +XTFASTCALL +LONGLONG +RtlAtomicOr64(IN VOLATILE PLONGLONG Address, + IN LONGLONG Mask); + +XTFASTCALL +CHAR +RtlAtomicXor8(IN VOLATILE PCHAR Address, + IN CHAR Mask); + +XTFASTCALL +SHORT +RtlAtomicXor16(IN VOLATILE PSHORT Address, + IN SHORT Mask); + +XTFASTCALL +LONG +RtlAtomicXor32(IN VOLATILE PLONG Address, + IN LONG Mask); + +XTFASTCALL +LONGLONG +RtlAtomicXor64(IN VOLATILE PLONGLONG Address, + IN LONGLONG Mask); + XTAPI SIZE_T RtlCompareMemory(IN PCVOID LeftBuffer, diff --git a/xtoskrnl/rtl/atomic.c b/xtoskrnl/rtl/atomic.c index 8a71420..9558ba8 100644 --- a/xtoskrnl/rtl/atomic.c +++ b/xtoskrnl/rtl/atomic.c @@ -9,6 +9,90 @@ #include +/** + * Performs an atomic bitwise AND operation on the 8-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise AND operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise AND operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +CHAR +RtlAtomicAnd8(IN VOLATILE PCHAR Address, + IN CHAR Mask) +{ + return __sync_fetch_and_and(Address, Mask); +} + +/** + * Performs an atomic bitwise AND operation on the 16-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise AND operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise AND operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +SHORT +RtlAtomicAnd16(IN VOLATILE PSHORT Address, + IN SHORT Mask) +{ + return __sync_fetch_and_and(Address, Mask); +} + +/** + * Performs an atomic bitwise AND operation on the 32-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise AND operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise AND operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +LONG +RtlAtomicAnd32(IN VOLATILE PLONG Address, + IN LONG Mask) +{ + return __sync_fetch_and_and(Address, Mask); +} + +/** + * Performs an atomic bitwise AND operation on the 64-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise AND operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise AND operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +LONGLONG +RtlAtomicAnd64(IN VOLATILE PLONGLONG Address, + IN LONGLONG Mask) +{ + return __sync_fetch_and_and(Address, Mask); +} + /** * Performs atomically compare exchange operation on the 8-bit value. * @@ -458,3 +542,171 @@ RtlAtomicIncrement64(IN VOLATILE PLONGLONG Address) { return __sync_add_and_fetch(Address, 1); } + +/** + * Performs an atomic bitwise OR operation on the 8-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise OR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise OR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +CHAR +RtlAtomicOr8(IN VOLATILE PCHAR Address, + IN CHAR Mask) +{ + return __sync_fetch_and_or(Address, Mask); +} + +/** + * Performs an atomic bitwise OR operation on the 16-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise OR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise OR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +SHORT +RtlAtomicOr16(IN VOLATILE PSHORT Address, + IN SHORT Mask) +{ + return __sync_fetch_and_or(Address, Mask); +} + +/** + * Performs an atomic bitwise OR operation on the 32-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise OR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise OR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +LONG +RtlAtomicOr32(IN VOLATILE PLONG Address, + IN LONG Mask) +{ + return __sync_fetch_and_or(Address, Mask); +} + +/** + * Performs an atomic bitwise OR operation on the 64-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise OR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise OR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +LONGLONG +RtlAtomicOr64(IN VOLATILE PLONGLONG Address, + IN LONGLONG Mask) +{ + return __sync_fetch_and_or(Address, Mask); +} + +/** + * Performs an atomic bitwise XOR operation on the 8-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise XOR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise XOR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +CHAR +RtlAtomicXor8(IN VOLATILE PCHAR Address, + IN CHAR Mask) +{ + return __sync_fetch_and_xor(Address, Mask); +} + +/** + * Performs an atomic bitwise XOR operation on the 16-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise XOR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise XOR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +SHORT +RtlAtomicXor16(IN VOLATILE PSHORT Address, + IN SHORT Mask) +{ + return __sync_fetch_and_xor(Address, Mask); +} + +/** + * Performs an atomic bitwise XOR operation on the 32-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise XOR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise XOR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +LONG +RtlAtomicXor32(IN VOLATILE PLONG Address, + IN LONG Mask) +{ + return __sync_fetch_and_xor(Address, Mask); +} + +/** + * Performs an atomic bitwise XOR operation on the 64-bit value. + * + * @param Address + * Supplies the address of the value on which the bitwise XOR operation is to be performed. + * + * @param Mask + * Supplies the mask with which the bitwise XOR operation is to be performed + * + * @return This routine returns the initial value at the given address. + * + * @since XT 1.0 + */ +XTFASTCALL +LONGLONG +RtlAtomicXor64(IN VOLATILE PLONGLONG Address, + IN LONGLONG Mask) +{ + return __sync_fetch_and_xor(Address, Mask); +}