[msan] Intercept pthread_key_create.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@185693 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc
index 13d1033..aa3342c 100644
--- a/lib/msan/msan_interceptors.cc
+++ b/lib/msan/msan_interceptors.cc
@@ -979,6 +979,14 @@
return res;
}
+INTERCEPTOR(int, pthread_key_create, __sanitizer_pthread_key_t *key, void (*dtor) (void *)) {
+ ENSURE_MSAN_INITED();
+ int res = REAL(pthread_key_create)(key, dtor);
+ if (!res && key)
+ __msan_unpoison(key, sizeof(*key));
+ return res;
+}
+
struct MSanInterceptorContext {
bool in_interceptor_scope;
};
@@ -1220,6 +1228,7 @@
INTERCEPT_FUNCTION(sigaction);
INTERCEPT_FUNCTION(signal);
INTERCEPT_FUNCTION(pthread_create);
+ INTERCEPT_FUNCTION(pthread_key_create);
inited = 1;
}
} // namespace __msan
diff --git a/lib/msan/tests/msan_test.cc b/lib/msan/tests/msan_test.cc
index a400b16..baf7956 100644
--- a/lib/msan/tests/msan_test.cc
+++ b/lib/msan/tests/msan_test.cc
@@ -2050,6 +2050,15 @@
EXPECT_NOT_POISONED(param.sched_priority);
}
+TEST(MemorySanitizer, pthread_key_create) {
+ pthread_key_t key;
+ int res = pthread_key_create(&key, NULL);
+ assert(!res);
+ EXPECT_NOT_POISONED(key);
+ res = pthread_key_delete(key);
+ assert(!res);
+}
+
TEST(MemorySanitizer, posix_memalign) {
void *p;
EXPECT_POISONED(p);
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
index 4bf2565..45218fc 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -727,6 +727,7 @@
sizeof(__sanitizer::struct_sigaction_sz));
COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));
+CHECK_TYPE_SIZE(pthread_key_t);
#if SANITIZER_LINUX
// There are more undocumented fields in dl_phdr_info that we are not interested
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 3e1b318..24a2ef5 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -55,6 +55,8 @@
uptr iov_len;
};
+ typedef unsigned __sanitizer_pthread_key_t;
+
#if SANITIZER_ANDROID || SANITIZER_MAC
struct __sanitizer_msghdr {
void *msg_name;