|
From: <sv...@va...> - 2010-09-19 11:14:39
|
Author: bart
Date: 2010-09-19 12:14:31 +0100 (Sun, 19 Sep 2010)
New Revision: 11365
Log:
DRD: avoid unaligned reads.
Modified:
trunk/drd/drd_pthread_intercepts.c
Modified: trunk/drd/drd_pthread_intercepts.c
===================================================================
--- trunk/drd/drd_pthread_intercepts.c 2010-09-18 13:34:23 UTC (rev 11364)
+++ trunk/drd/drd_pthread_intercepts.c 2010-09-19 11:14:31 UTC (rev 11365)
@@ -51,6 +51,7 @@
#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() */
@@ -181,6 +182,8 @@
}
}
+#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 @@
{
#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.
*/
+#endif
return mutex_type_unknown;
-#endif
}
/**
|