[compiler-rt] r192453 - [sanitizer] Define kPthreadDestructorIterations on POSIX systems.
Sergey Matveev
earthdok at google.com
Fri Oct 11 07:19:14 PDT 2013
Author: smatveev
Date: Fri Oct 11 09:19:14 2013
New Revision: 192453
URL: http://llvm.org/viewvc/llvm-project?rev=192453&view=rev
Log:
[sanitizer] Define kPthreadDestructorIterations on POSIX systems.
Added:
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=192453&r1=192452&r2=192453&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri Oct 11 09:19:14 2013
@@ -440,6 +440,12 @@ typedef bool (*string_predicate_t)(const
uptr GetListOfModules(LoadedModule *modules, uptr max_modules,
string_predicate_t filter);
+#if SANITIZER_POSIX
+const uptr kPthreadDestructorIterations = 4;
+#else
+// Unused on Windows.
+const uptr kPthreadDestructorIterations = 0;
+#endif
} // namespace __sanitizer
#endif // SANITIZER_COMMON_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h?rev=192453&r1=192452&r2=192453&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h Fri Oct 11 09:19:14 2013
@@ -76,9 +76,6 @@ void CacheBinaryName();
// Call cb for each region mapped by map.
void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
-
-// PTHREAD_DESTRUCTOR_ITERATIONS from glibc.
-const uptr kPthreadDestructorIterations = 4;
} // namespace __sanitizer
#endif // SANITIZER_LINUX
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=192453&r1=192452&r2=192453&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Fri Oct 11 09:19:14 2013
@@ -15,6 +15,7 @@
#ifndef SANITIZER_PLATFORM_LIMITS_POSIX_H
#define SANITIZER_PLATFORM_LIMITS_POSIX_H
+#include "sanitizer_internal_defs.h"
#include "sanitizer_platform.h"
namespace __sanitizer {
@@ -821,6 +822,7 @@ namespace __sanitizer {
extern unsigned IOCTL_TIOCSERSETMULTI;
extern unsigned IOCTL_TIOCSSERIAL;
#endif
+
} // namespace __sanitizer
#endif
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=192453&r1=192452&r2=192453&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Fri Oct 11 09:19:14 2013
@@ -11,6 +11,7 @@ set(SANITIZER_UNITTESTS
sanitizer_list_test.cc
sanitizer_mutex_test.cc
sanitizer_nolibc_test.cc
+ sanitizer_posix_test.cc
sanitizer_printf_test.cc
sanitizer_scanf_interceptor_test.cc
sanitizer_stackdepot_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc?rev=192453&r1=192452&r2=192453&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc Fri Oct 11 09:19:14 2013
@@ -255,42 +255,6 @@ TEST(SanitizerCommon, LibraryNameIs) {
}
}
-static pthread_key_t key;
-static bool destructor_executed;
-
-extern "C"
-void destructor(void *arg) {
- uptr iter = reinterpret_cast<uptr>(arg);
- if (iter > 1) {
- ASSERT_EQ(0, pthread_setspecific(key, reinterpret_cast<void *>(iter - 1)));
- return;
- }
- destructor_executed = true;
-}
-
-extern "C"
-void *thread_func(void *arg) {
- return reinterpret_cast<void*>(pthread_setspecific(key, arg));
-}
-
-static void SpawnThread(uptr iteration) {
- destructor_executed = false;
- pthread_t tid;
- ASSERT_EQ(0, pthread_create(&tid, 0, &thread_func,
- reinterpret_cast<void *>(iteration)));
- void *retval;
- ASSERT_EQ(0, pthread_join(tid, &retval));
- ASSERT_EQ(0, retval);
-}
-
-TEST(SanitizerCommon, PthreadDestructorIterations) {
- ASSERT_EQ(0, pthread_key_create(&key, &destructor));
- SpawnThread(kPthreadDestructorIterations);
- EXPECT_TRUE(destructor_executed);
- SpawnThread(kPthreadDestructorIterations + 1);
- EXPECT_FALSE(destructor_executed);
-}
-
} // namespace __sanitizer
#endif // SANITIZER_LINUX
Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc?rev=192453&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc Fri Oct 11 09:19:14 2013
@@ -0,0 +1,62 @@
+//===-- sanitizer_posix_test.cc -------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Tests for POSIX-specific code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_platform.h"
+#if SANITIZER_POSIX
+
+#include "sanitizer_common/sanitizer_common.h"
+#include "gtest/gtest.h"
+
+#include <pthread.h>
+
+namespace __sanitizer {
+
+static pthread_key_t key;
+static bool destructor_executed;
+
+extern "C"
+void destructor(void *arg) {
+ uptr iter = reinterpret_cast<uptr>(arg);
+ if (iter > 1) {
+ ASSERT_EQ(0, pthread_setspecific(key, reinterpret_cast<void *>(iter - 1)));
+ return;
+ }
+ destructor_executed = true;
+}
+
+extern "C"
+void *thread_func(void *arg) {
+ return reinterpret_cast<void*>(pthread_setspecific(key, arg));
+}
+
+static void SpawnThread(uptr iteration) {
+ destructor_executed = false;
+ pthread_t tid;
+ ASSERT_EQ(0, pthread_create(&tid, 0, &thread_func,
+ reinterpret_cast<void *>(iteration)));
+ void *retval;
+ ASSERT_EQ(0, pthread_join(tid, &retval));
+ ASSERT_EQ(0, retval);
+}
+
+TEST(SanitizerCommon, PthreadDestructorIterations) {
+ ASSERT_EQ(0, pthread_key_create(&key, &destructor));
+ SpawnThread(kPthreadDestructorIterations);
+ EXPECT_TRUE(destructor_executed);
+ SpawnThread(kPthreadDestructorIterations + 1);
+ EXPECT_FALSE(destructor_executed);
+}
+
+} // namespace __sanitizer
+
+#endif // SANITIZER_POSIX
More information about the llvm-commits
mailing list