crypto/threads_pthread.c: refactor all atomics fallbacks for type safety
authorRichard Levitte <levitte@openssl.org>
Fri, 12 Apr 2024 08:03:21 +0000 (10:03 +0200)
committerTomas Mraz <tomas@openssl.org>
Tue, 16 Apr 2024 07:18:01 +0000 (09:18 +0200)
commita02077d4d7aeb0c99cc88cdfc7c131e48f98c4de
tree0cb20a53f841c23c4934f8f8ad4518de51a39d24
parent81f393498b333534111e320a33e3b244db06bbe9
crypto/threads_pthread.c: refactor all atomics fallbacks for type safety

The atomics fallbacks were using 'void *' as a generic transport for all
possible scalar and pointer types, with the hypothesis that a pointer is
as large as the largest possible scalar type that we would use.

Then enters the use of uint64_t, which is larger than a pointer on any
32-bit system (or any system that has 32-bit pointer configurations).

We could of course choose a larger type as a generic transport.  However,
that only pushes the problem forward in time...  and it's still a hack.
It's therefore safer to reimplement the fallbacks per type that atomics
are used for, and deal with missing per type fallbacks when the need
arrises in the future.

For test build purposes, the macro USE_ATOMIC_FALLBACKS is introduced.
If OpenSSL is configured with '-DUSE_ATOMIC_FALLBACKS', the fallbacks
will be used, unconditionally.

Fixes #24096

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24123)
crypto/threads_pthread.c