Static assert that CRYPTO_MUTEX is sufficiently aligned.
Bug: 325
Change-Id: I55d4d7fcb91602c8d2a371be5011e1a5df157819
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40364
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/thread_pthread.c b/crypto/thread_pthread.c
index 832e90e..2cb1000 100644
--- a/crypto/thread_pthread.c
+++ b/crypto/thread_pthread.c
@@ -26,6 +26,10 @@
OPENSSL_STATIC_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(pthread_rwlock_t),
"CRYPTO_MUTEX is too small");
+#if defined(__GNUC__) || defined(__clang__)
+OPENSSL_STATIC_ASSERT(alignof(CRYPTO_MUTEX) >= alignof(pthread_rwlock_t),
+ "CRYPTO_MUTEX has insufficient alignment");
+#endif
void CRYPTO_MUTEX_init(CRYPTO_MUTEX *lock) {
if (pthread_rwlock_init((pthread_rwlock_t *) lock, NULL) != 0) {
diff --git a/crypto/thread_win.c b/crypto/thread_win.c
index c8e19f5..49ecc12 100644
--- a/crypto/thread_win.c
+++ b/crypto/thread_win.c
@@ -29,6 +29,10 @@
OPENSSL_STATIC_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(SRWLOCK),
"CRYPTO_MUTEX is too small");
+#if defined(__GNUC__) || defined(__clang__)
+OPENSSL_STATIC_ASSERT(alignof(CRYPTO_MUTEX) >= alignof(SRWLOCK),
+ "CRYPTO_MUTEX has insufficient alignment");
+#endif
static BOOL CALLBACK call_once_init(INIT_ONCE *once, void *arg, void **out) {
void (**init)(void) = (void (**)(void))arg;