From: Bart Van Assche Date: Sun, 19 Sep 2010 11:14:31 +0000 (+0000) Subject: DRD: avoid unaligned reads. X-Git-Tag: svn/VALGRIND_3_6_0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecb0c51747e4070d2935dd0041ffb89dc3de3f16;p=thirdparty%2Fvalgrind.git DRD: avoid unaligned reads. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11365 --- diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index f3026edd3d..57e509534a 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -51,6 +51,7 @@ #include /* assert() */ #include /* pthread_mutex_t */ #include /* sem_t */ +#include /* uintptr_t */ #include /* fprintf() */ #include /* malloc(), free() */ #include /* confstr() */ @@ -181,6 +182,8 @@ static MutexT DRD_(pthread_to_drd_mutex_type)(const int kind) } } +#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. @@ -198,19 +201,25 @@ static __always_inline MutexT DRD_(mutex_type)(pthread_mutex_t* mutex) { #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; } /**