From cf7c467637d139d12486a31dc0211c9cbdd4d3a0 Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 29 Oct 2023 11:48:31 +0100 Subject: [PATCH] Implement RtlInterlockedExchangePointer() routine --- xtoskrnl/includes/rtl.h | 5 +++++ xtoskrnl/rtl/intrin.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/xtoskrnl/includes/rtl.h b/xtoskrnl/includes/rtl.h index b4bad2c..fb66e69 100644 --- a/xtoskrnl/includes/rtl.h +++ b/xtoskrnl/includes/rtl.h @@ -233,6 +233,11 @@ XTFASTCALL LONG_PTR RtlInterlockedDecrementLongPtr(IN VOLATILE PLONG_PTR Addend); +XTFASTCALL +PVOID +RtlInterlockedExchangePointer(IN VOLATILE PVOID *Destination, + IN PVOID Value); + XTCDECL BOOLEAN RtlListEmpty(PLIST_ENTRY ListHead); diff --git a/xtoskrnl/rtl/intrin.c b/xtoskrnl/rtl/intrin.c index 4b9df3c..d5413f8 100644 --- a/xtoskrnl/rtl/intrin.c +++ b/xtoskrnl/rtl/intrin.c @@ -50,3 +50,25 @@ RtlInterlockedDecrementLongPtr(IN VOLATILE PLONG_PTR Addend) { return (LONG_PTR)__sync_sub_and_fetch(Addend, 1); } + +/** + * Performs an atomic assignment of the value to the pointer variable. + * + * @param Destination + * Supplies a pointer to the variable to be set. + * + * @param Value + * Supplies a value to set. + * + * @return This routine returns the initial value of the pointer variable. + * + * @since XT 1.0 + */ +XTFASTCALL +PVOID +RtlInterlockedExchangePointer(IN VOLATILE PVOID *Destination, + IN PVOID Value) +{ + __sync_synchronize(); + return (void *)__sync_lock_test_and_set(Destination, Value); +}