forked from OSchip/llvm-project
[sanitizer] Intercept pthread_*attr_get*.
llvm-svn: 211166
This commit is contained in:
parent
29e254f849
commit
b87f1efc5f
|
@ -3294,19 +3294,26 @@ INTERCEPTOR(int, random_r, void *buf, u32 *result) {
|
|||
// FIXME: under ASan the REAL() call below may write to freed memory and corrupt
|
||||
// its metadata. See
|
||||
// https://code.google.com/p/address-sanitizer/issues/detail?id=321.
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET || \
|
||||
SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSSCHED
|
||||
#define INTERCEPTOR_PTHREAD_ATTR_GET(what, sz) \
|
||||
INTERCEPTOR(int, pthread_attr_get##what, void *attr, void *r) { \
|
||||
void *ctx; \
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, pthread_attr_get##what, attr, r); \
|
||||
int res = REAL(pthread_attr_get##what)(attr, r); \
|
||||
if (!res && r) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, r, sz); \
|
||||
return res; \
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET || \
|
||||
SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSSCHED || \
|
||||
SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GET || \
|
||||
SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GET || \
|
||||
SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GET || \
|
||||
SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GET
|
||||
#define INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(fn, sz) \
|
||||
INTERCEPTOR(int, fn, void *attr, void *r) { \
|
||||
void *ctx; \
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, fn, attr, r); \
|
||||
int res = REAL(fn)(attr, r); \
|
||||
if (!res && r) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, r, sz); \
|
||||
return res; \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET
|
||||
#define INTERCEPTOR_PTHREAD_ATTR_GET(what, sz) \
|
||||
INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_attr_get##what, sz)
|
||||
INTERCEPTOR_PTHREAD_ATTR_GET(detachstate, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_ATTR_GET(guardsize, sizeof(SIZE_T))
|
||||
INTERCEPTOR_PTHREAD_ATTR_GET(schedparam, struct_sched_param_sz)
|
||||
|
@ -3380,6 +3387,60 @@ INTERCEPTOR(int, pthread_attr_getaffinity_np, void *attr, SIZE_T cpusetsize,
|
|||
#define INIT_PTHREAD_ATTR_GETAFFINITY_NP
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GET
|
||||
#define INTERCEPTOR_PTHREAD_MUTEXATTR_GET(what, sz) \
|
||||
INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_mutexattr_get##what, sz)
|
||||
INTERCEPTOR_PTHREAD_MUTEXATTR_GET(pshared, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_MUTEXATTR_GET(type, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_MUTEXATTR_GET(protocol, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_MUTEXATTR_GET(prioceiling, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_MUTEXATTR_GET(robust, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_MUTEXATTR_GET(robust_np, sizeof(int))
|
||||
#define INIT_PTHREAD_MUTEXATTR_GET \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getpshared); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_gettype); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getprotocol); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getprioceiling); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getrobust); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getrobust_np);
|
||||
#else
|
||||
#define INIT_PTHREAD_MUTEXATTR_GET
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GET
|
||||
#define INTERCEPTOR_PTHREAD_RWLOCKATTR_GET(what, sz) \
|
||||
INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_rwlockattr_get##what, sz)
|
||||
INTERCEPTOR_PTHREAD_RWLOCKATTR_GET(pshared, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_RWLOCKATTR_GET(kind_np, sizeof(int))
|
||||
#define INIT_PTHREAD_RWLOCKATTR_GET \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_rwlockattr_getpshared); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_rwlockattr_getkind_np);
|
||||
#else
|
||||
#define INIT_PTHREAD_RWLOCKATTR_GET
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GET
|
||||
#define INTERCEPTOR_PTHREAD_CONDATTR_GET(what, sz) \
|
||||
INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_condattr_get##what, sz)
|
||||
INTERCEPTOR_PTHREAD_CONDATTR_GET(pshared, sizeof(int))
|
||||
INTERCEPTOR_PTHREAD_CONDATTR_GET(clock, sizeof(__sanitizer_clockid_t))
|
||||
#define INIT_PTHREAD_CONDATTR_GET \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_condattr_getpshared); \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_condattr_getclock);
|
||||
#else
|
||||
#define INIT_PTHREAD_CONDATTR_GET
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GET
|
||||
#define INTERCEPTOR_PTHREAD_BARRIERATTR_GET(what, sz) \
|
||||
INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_barrierattr_get##what, sz)
|
||||
INTERCEPTOR_PTHREAD_BARRIERATTR_GET(pshared, sizeof(int))
|
||||
#define INIT_PTHREAD_BARRIERATTR_GET \
|
||||
COMMON_INTERCEPT_FUNCTION(pthread_barrierattr_getpshared);
|
||||
#else
|
||||
#define INIT_PTHREAD_BARRIERATTR_GET
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT_TMPNAM
|
||||
INTERCEPTOR(char *, tmpnam, char *s) {
|
||||
void *ctx;
|
||||
|
@ -4606,6 +4667,10 @@ static void InitializeCommonInterceptors() {
|
|||
INIT_PTHREAD_ATTR_GET;
|
||||
INIT_PTHREAD_ATTR_GETINHERITSCHED;
|
||||
INIT_PTHREAD_ATTR_GETAFFINITY_NP;
|
||||
INIT_PTHREAD_MUTEXATTR_GET;
|
||||
INIT_PTHREAD_RWLOCKATTR_GET;
|
||||
INIT_PTHREAD_CONDATTR_GET;
|
||||
INIT_PTHREAD_BARRIERATTR_GET;
|
||||
INIT_TMPNAM;
|
||||
INIT_TMPNAM_R;
|
||||
INIT_TEMPNAM;
|
||||
|
|
|
@ -163,6 +163,10 @@
|
|||
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
|
||||
SI_MAC || SI_LINUX_NOT_ANDROID
|
||||
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
|
||||
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GET SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GET SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GET SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GET SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT_TMPNAM SI_NOT_WINDOWS
|
||||
#define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID
|
||||
#define SANITIZER_INTERCEPT_TEMPNAM SI_NOT_WINDOWS
|
||||
|
|
|
@ -1058,6 +1058,7 @@ CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch);
|
|||
#endif
|
||||
|
||||
CHECK_TYPE_SIZE(clock_t);
|
||||
CHECK_TYPE_SIZE(clockid_t);
|
||||
|
||||
#if !SANITIZER_ANDROID
|
||||
CHECK_TYPE_SIZE(ifaddrs);
|
||||
|
|
|
@ -440,6 +440,8 @@ namespace __sanitizer {
|
|||
typedef long __sanitizer_clock_t;
|
||||
#endif
|
||||
|
||||
typedef int __sanitizer_clockid_t;
|
||||
|
||||
#if SANITIZER_LINUX || SANITIZER_FREEBSD
|
||||
#if defined(_LP64) || defined(__x86_64__) || defined(__powerpc__)
|
||||
typedef unsigned __sanitizer___kernel_uid_t;
|
||||
|
|
|
@ -47,7 +47,7 @@ DECLARE_REAL(int, pthread_attr_getdetachstate, void *, void *)
|
|||
extern "C" int pthread_attr_setstacksize(void *attr, uptr stacksize);
|
||||
extern "C" int pthread_key_create(unsigned *key, void (*destructor)(void* v));
|
||||
extern "C" int pthread_setspecific(unsigned key, const void *v);
|
||||
extern "C" int pthread_mutexattr_gettype(void *a, int *type);
|
||||
DECLARE_REAL(int, pthread_mutexattr_gettype, void *, void *)
|
||||
extern "C" int pthread_yield();
|
||||
extern "C" int pthread_sigmask(int how, const __sanitizer_sigset_t *set,
|
||||
__sanitizer_sigset_t *oldset);
|
||||
|
@ -1029,7 +1029,7 @@ TSAN_INTERCEPTOR(int, pthread_mutex_init, void *m, void *a) {
|
|||
bool recursive = false;
|
||||
if (a) {
|
||||
int type = 0;
|
||||
if (pthread_mutexattr_gettype(a, &type) == 0)
|
||||
if (REAL(pthread_mutexattr_gettype)(a, &type) == 0)
|
||||
recursive = (type == PTHREAD_MUTEX_RECURSIVE
|
||||
|| type == PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// RUN: %clangxx -O0 %s -o %t && %run %t
|
||||
// XFAIL: arm-linux-gnueabi
|
||||
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int main(void) {
|
||||
pthread_mutexattr_t ma;
|
||||
int res = pthread_mutexattr_init(&ma);
|
||||
assert(res == 0);
|
||||
res = pthread_mutexattr_setpshared(&ma, 1);
|
||||
assert(res == 0);
|
||||
int pshared;
|
||||
res = pthread_mutexattr_getpshared(&ma, &pshared);
|
||||
assert(res == 0);
|
||||
assert(pshared == 1);
|
||||
res = pthread_mutexattr_destroy(&ma);
|
||||
assert(res == 0);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue