[RFC][BZ #16549] Add sanity check for condvar alignment.
Ondřej Bílka
neleai@seznam.cz
Tue Feb 11 12:43:00 GMT 2014
Hi,
In this bug using misaligned condition variable causes a silent failure.
There are two possibilities how to fix it. First one would be not lie
about requirements and add attribute ((aligned)) to header. That could
break programs by changing sizes of structures but these were broken in
first place.
A more conservative solution is add assert in initialization to check
alignment. Following patch does that, should be same check added for
mutex/semaphores?
* nptl/pthread_cond_init.c (__pthread_cond_init): Add assert that
input is aligned.
diff --git a/nptl/pthread_cond_init.c b/nptl/pthread_cond_init.c
index 27efc9c..53d6170 100644
--- a/nptl/pthread_cond_init.c
+++ b/nptl/pthread_cond_init.c
@@ -16,6 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <assert.h>
#include <shlib-compat.h>
#include "pthreadP.h"
#include <stap-probe.h>
@@ -28,6 +29,7 @@ __pthread_cond_init (cond, cond_attr)
{
struct pthread_condattr *icond_attr = (struct pthread_condattr *) cond_attr;
+ assert (((uintptr_t) cond) % sizeof (long) == 0);
cond->__data.__lock = LLL_LOCK_INITIALIZER;
cond->__data.__futex = 0;
cond->__data.__nwaiters = (icond_attr != NULL
More information about the Libc-alpha
mailing list