#include <assert.h> /* assert() */
#include <pthread.h> /* pthread_mutex_t */
#include <semaphore.h> /* sem_t */
+#include <stdint.h> /* uintptr_t */
#include <stdio.h> /* fprintf() */
#include <stdlib.h> /* malloc(), free() */
#include <unistd.h> /* confstr() */
}
}
+#define IS_ALIGNED(p) (((uintptr_t)(p) & (sizeof(*(p)) - 1)) == 0)
+
/**
* Read the mutex type stored in the client memory used for the mutex
* implementation.
{
#if defined(HAVE_PTHREAD_MUTEX_T__M_KIND)
/* glibc + LinuxThreads. */
- const int kind = mutex->__m_kind & 3;
- return DRD_(pthread_to_drd_mutex_type)(kind);
+ if (IS_ALIGNED(&mutex->__m_kind))
+ {
+ const int kind = mutex->__m_kind & 3;
+ return DRD_(pthread_to_drd_mutex_type)(kind);
+ }
#elif defined(HAVE_PTHREAD_MUTEX_T__DATA__KIND)
/* glibc + NPTL. */
- const int kind = mutex->__data.__kind & 3;
- return DRD_(pthread_to_drd_mutex_type)(kind);
+ if (IS_ALIGNED(&mutex->__data.__kind))
+ {
+ const int kind = mutex->__data.__kind & 3;
+ return DRD_(pthread_to_drd_mutex_type)(kind);
+ }
#else
/*
* Another POSIX threads implementation. The mutex type won't be printed
* when enabling --trace-mutex=yes.
*/
- return mutex_type_unknown;
#endif
+ return mutex_type_unknown;
}
/**