Skip to content

Commit 0458fba

Browse files
committed
bsdkm: add atomic_fcmpset_ptr.
1 parent 551f904 commit 0458fba

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

wolfcrypt/src/wc_port.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,20 @@ int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c, int *expected_i,
13521352
int wolfSSL_Atomic_Uint_CompareExchange(
13531353
wolfSSL_Atomic_Uint* c, unsigned int *expected_i, unsigned int new_i)
13541354
{
1355-
u_int exp = (u_int) *expected_i;
1355+
u_int exp = (u_int)*expected_i;
13561356
int ret = atomic_fcmpset_int(c, &exp, new_i);
13571357
*expected_i = (unsigned int)exp;
13581358
return ret;
13591359
}
13601360

1361+
int wolfSSL_Atomic_Ptr_CompareExchange(
1362+
void **c, void **expected_ptr, void *new_ptr)
1363+
{
1364+
uintptr_t exp = (uintptr_t)*expected_ptr;
1365+
int ret = atomic_fcmpset_ptr((uintptr_t *)c, &exp, (uintptr_t)new_ptr);
1366+
*expected_ptr = (void *)exp;
1367+
return ret;
1368+
}
13611369

13621370
#elif defined(HAVE_C___ATOMIC) && defined(WOLFSSL_HAVE_ATOMIC_H) && \
13631371
!defined(__cplusplus)

wolfcrypt/test/test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20061,6 +20061,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
2006120061
#endif
2006220062
int int_expected;
2006320063
unsigned int uint_expected;
20064+
void * a_ptr = NULL;
20065+
void * ptr_expected = NULL;
2006420066

2006520067
if (WOLFSSL_ATOMIC_LOAD(a_int) != -2)
2006620068
return WC_TEST_RET_ENC_NC;
@@ -20131,6 +20133,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
2013120133
return WC_TEST_RET_ENC_NC;
2013220134
if (WOLFSSL_ATOMIC_LOAD(a_uint) != 7)
2013320135
return WC_TEST_RET_ENC_NC;
20136+
20137+
a_ptr = NULL;
20138+
ptr_expected = NULL;
20139+
if (! wolfSSL_Atomic_Ptr_CompareExchange(&a_ptr, &ptr_expected, &ret))
20140+
return WC_TEST_RET_ENC_NC;
20141+
if (a_ptr != &ret)
20142+
return WC_TEST_RET_ENC_NC;
2013420143
}
2013520144

2013620145
return ret;

0 commit comments

Comments
 (0)