From 0458fba3940cef21612dce7440a653eeedc73d43 Mon Sep 17 00:00:00 2001 From: jordan Date: Tue, 18 Nov 2025 10:12:28 -0600 Subject: [PATCH] bsdkm: add atomic_fcmpset_ptr. --- wolfcrypt/src/wc_port.c | 10 +++++++++- wolfcrypt/test/test.c | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 83242873f..d37be2370 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -1352,12 +1352,20 @@ int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i, int wolfSSL_Atomic_Uint_CompareExchange( wolfSSL_Atomic_Uint* c, unsigned int *expected_i, unsigned int new_i) { - u_int exp = (u_int) *expected_i; + u_int exp = (u_int)*expected_i; int ret = atomic_fcmpset_int(c, &exp, new_i); *expected_i = (unsigned int)exp; return ret; } +int wolfSSL_Atomic_Ptr_CompareExchange( + void **c, void **expected_ptr, void *new_ptr) +{ + uintptr_t exp = (uintptr_t)*expected_ptr; + int ret = atomic_fcmpset_ptr((uintptr_t *)c, &exp, (uintptr_t)new_ptr); + *expected_ptr = (void *)exp; + return ret; +} #elif defined(HAVE_C___ATOMIC) && defined(WOLFSSL_HAVE_ATOMIC_H) && \ !defined(__cplusplus) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 996e47f43..ab67d8c1a 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -20061,6 +20061,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void) #endif int int_expected; unsigned int uint_expected; + void * a_ptr = NULL; + void * ptr_expected = NULL; if (WOLFSSL_ATOMIC_LOAD(a_int) != -2) return WC_TEST_RET_ENC_NC; @@ -20131,6 +20133,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void) return WC_TEST_RET_ENC_NC; if (WOLFSSL_ATOMIC_LOAD(a_uint) != 7) return WC_TEST_RET_ENC_NC; + + a_ptr = NULL; + ptr_expected = NULL; + if (! wolfSSL_Atomic_Ptr_CompareExchange(&a_ptr, &ptr_expected, &ret)) + return WC_TEST_RET_ENC_NC; + if (a_ptr != &ret) + return WC_TEST_RET_ENC_NC; } return ret;