| 1 |
From: Alessandro Astone <[email protected]> |
| 2 |
Date: Thu, 19 Mar 2026 10:13:34 +0100 |
| 3 |
Subject: Bug 2024326 - Mutex,ConditionVariable: Ensure alignment of |
| 4 |
platformData r=jandem,glandium |
| 5 |
|
| 6 |
Declaring the variable as (void*)[] does not guarantee proper alignment to |
| 7 |
hold a pthread_mutex_t/pthread_cond_t. |
| 8 |
Since we're already including pthread.h, make the variable actually hold the |
| 9 |
wanted type. Here we keep using an array of size 1 to satisfy existing |
| 10 |
expectations that the name platformData_ is an array. |
| 11 |
|
| 12 |
Forwarded: https://phabricator.services.mozilla.com/D288470 |
| 13 |
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2024326 |
| 14 |
Bug-Ubuntu: https://launchpad.net/bugs/2144310 |
| 15 |
--- |
| 16 |
mozglue/misc/PlatformConditionVariable.h | 5 +---- |
| 17 |
mozglue/misc/PlatformMutex.h | 5 +---- |
| 18 |
2 files changed, 2 insertions(+), 8 deletions(-) |
| 19 |
|
| 20 |
diff --git a/mozglue/misc/PlatformConditionVariable.h b/mozglue/misc/PlatformConditionVariable.h |
| 21 |
index 61fb06a..70a14b8 100644 |
| 22 |
--- a/mozglue/misc/PlatformConditionVariable.h |
| 23 |
+++ b/mozglue/misc/PlatformConditionVariable.h |
| 24 |
@@ -55,10 +55,7 @@ class ConditionVariableImpl { |
| 25 |
PlatformData* platformData(); |
| 26 |
|
| 27 |
#if !defined(XP_WIN) && !defined(__wasi__) |
| 28 |
- void* platformData_[sizeof(pthread_cond_t) / sizeof(void*)]; |
| 29 |
- static_assert(sizeof(pthread_cond_t) / sizeof(void*) != 0 && |
| 30 |
- sizeof(pthread_cond_t) % sizeof(void*) == 0, |
| 31 |
- "pthread_cond_t must have pointer alignment"); |
| 32 |
+ pthread_cond_t platformData_[1]; |
| 33 |
#else |
| 34 |
void* platformData_[4]; |
| 35 |
#endif |
| 36 |
diff --git a/mozglue/misc/PlatformMutex.h b/mozglue/misc/PlatformMutex.h |
| 37 |
index ac5459c..9066dec 100644 |
| 38 |
--- a/mozglue/misc/PlatformMutex.h |
| 39 |
+++ b/mozglue/misc/PlatformMutex.h |
| 40 |
@@ -49,10 +49,7 @@ class MutexImpl { |
| 41 |
PlatformData* platformData(); |
| 42 |
|
| 43 |
#if !defined(XP_WIN) && !defined(__wasi__) |
| 44 |
- void* platformData_[sizeof(pthread_mutex_t) / sizeof(void*)]; |
| 45 |
- static_assert(sizeof(pthread_mutex_t) / sizeof(void*) != 0 && |
| 46 |
- sizeof(pthread_mutex_t) % sizeof(void*) == 0, |
| 47 |
- "pthread_mutex_t must have pointer alignment"); |
| 48 |
+ pthread_mutex_t platformData_[1]; |
| 49 |
#else |
| 50 |
void* platformData_[6]; |
| 51 |
#endif |