From: Neil Horman Date: Thu, 13 Feb 2025 20:52:16 +0000 (-0500) Subject: Don't use __ATOMIC_ACQ_REL on older compilers X-Git-Tag: openssl-3.3.4~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74a52ca9b7934c100a055cf4a67782244568d36b;p=thirdparty%2Fopenssl.git Don't use __ATOMIC_ACQ_REL on older compilers Older compilers don't always support __ATOMIC_ACQ_REL, use a lock where they don't Reviewed-by: Tomas Mraz Reviewed-by: Bernd Edlinger (Merged from https://github.com/openssl/openssl/pull/26747) (cherry picked from commit 7d284560a0624206356d46a948ab3a0b6f670c0e) --- diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index 8af2a504a3a..2e2e6121214 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -68,7 +68,6 @@ * fallback function names. */ typedef void *pvoid; -typedef struct rcu_cb_item *prcu_cb_item; # if defined(__GNUC__) && defined(__ATOMIC_ACQUIRE) && !defined(BROKEN_CLANG_ATOMICS) \ && !defined(USE_ATOMIC_FALLBACKS) @@ -168,7 +167,6 @@ IMPL_fallback_atomic_store(pvoid) return ret; \ } IMPL_fallback_atomic_exchange_n(uint64_t) -IMPL_fallback_atomic_exchange_n(prcu_cb_item) # define ATOMIC_EXCHANGE_N(t, p, v, o) fallback_atomic_exchange_n_##t(p, v) @@ -555,6 +553,10 @@ void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock) } } +/* + * Note: This call assumes its made under the protection of + * ossl_rcu_write_lock + */ int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data) { struct rcu_cb_item *new = @@ -565,13 +567,9 @@ int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data) new->data = data; new->fn = cb; - /* - * Use __ATOMIC_ACQ_REL here to indicate that any prior writes to this - * list are visible to us prior to reading, and publish the new value - * immediately - */ - new->next = ATOMIC_EXCHANGE_N(prcu_cb_item, &lock->cb_items, new, - __ATOMIC_ACQ_REL); + + new->next = lock->cb_items; + lock->cb_items = new; return 1; } diff --git a/crypto/threads_win.c b/crypto/threads_win.c index 81fc4e80a00..0c2e5a6ff74 100644 --- a/crypto/threads_win.c +++ b/crypto/threads_win.c @@ -312,7 +312,10 @@ void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock) struct rcu_cb_item *cb_items, *tmpcb; /* before we do anything else, lets grab the cb list */ - cb_items = InterlockedExchangePointer((void * volatile *)&lock->cb_items, NULL); + ossl_crypto_mutex_lock(lock->write_lock); + cb_items = lock->cb_items; + lock->cb_items = NULL; + ossl_crypto_mutex_unlock(lock->write_lock); qp = update_qp(lock, &curr_id); @@ -345,6 +348,9 @@ void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock) } +/* + * Note, must be called under the protection of ossl_rcu_write_lock + */ int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data) { struct rcu_cb_item *new; @@ -357,8 +363,9 @@ int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data) new->data = data; new->fn = cb; - InterlockedExchangePointer((void * volatile *)&lock->cb_items, prev); - new->next = prev; + new->next = lock->cb_items; + lock->cb_items = new; + return 1; }