]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fallback implementation of tsan_add now returns value before addition to be consisten...
authorFrederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Wed, 25 Feb 2026 19:06:07 +0000 (20:06 +0100)
committerNeil Horman <nhorman@openssl.org>
Sat, 28 Feb 2026 14:10:22 +0000 (09:10 -0500)
Fixes #28410

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
MergeDate: Sat Feb 28 14:10:25 2026
(Merged from https://github.com/openssl/openssl/pull/30180)

include/internal/tsan_assist.h

index 998c45170e5890805191f3c5ee8ac9381837f04e..42953371cc5f4513134fe16865fb42bd9de36161 100644 (file)
 
 #define tsan_load(ptr) (*(ptr))
 #define tsan_store(ptr, val) (*(ptr) = (val))
-#define tsan_add(ptr, n) (*(ptr) += (n))
+
+static ossl_inline ossl_unused int64_t tsan_add_fallback64(int64_t *ptr, int64_t n)
+{
+    int64_t old = *ptr;
+    *ptr = old + n;
+    return old;
+}
+
+static ossl_inline ossl_unused int32_t tsan_add_fallback32(int32_t *ptr, int32_t n)
+{
+    int32_t old = *ptr;
+    *ptr = old + n;
+    return old;
+}
+
+#define tsan_add(ptr, n)                                              \
+    (sizeof(*(ptr)) == 8 ? tsan_add_fallback64((int64_t *)(ptr), (n)) \
+                         : tsan_add_fallback32((int32_t *)(ptr), (n)))
+
 /*
  * Lack of tsan_ld_acq and tsan_ld_rel means that compiler support is not
  * sophisticated enough to support them. Code that relies on them should be