llvm-project/compiler-rt/lib/tsan
Julian Lettner 858eb8fc11 [TSan][Darwin] Avoid crashes due to interpreting non-zero shadow content as a pointer
We would like to use TLS to store the ThreadState object (or at least a
reference ot it), but on Darwin accessing TLS via __thread or manually
by using pthread_key_* is problematic, because there are several places
where interceptors are called when TLS is not accessible (early process
startup, thread cleanup, ...).

Previously, we used a "poor man's TLS" implementation, where we use the
shadow memory of the pointer returned by pthread_self() to store a
pointer to the ThreadState object.

The problem with that was that certain operations can populate shadow
bytes unbeknownst to TSan, and we later interpret these non-zero bytes
as the pointer to our ThreadState object and crash on when dereferencing
the pointer.

This patch changes the storage location of our reference to the
ThreadState object to "real" TLS.  We make this work by artificially
keeping this reference alive in the pthread_key destructor by resetting
the key value with pthread_setspecific().

This change also fixes the issue were the ThreadState object is
re-allocated after DestroyThreadState() because intercepted functions
can still get called on the terminating thread after the
THREAD_TERMINATE event.

Radar-Id: rdar://problem/72010355

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D110236
2021-11-30 14:49:23 -08:00
..
benchmarks compiler-rt: Rename .cc file in lib/tsan/{benchmarks,dd,go} to .cpp 2019-08-01 14:30:49 +00:00
dd tsan/dd: fix format strings 2021-08-13 17:45:29 +02:00
go tsan: new runtime (v3) 2021-11-25 18:32:04 +01:00
rtl [TSan][Darwin] Avoid crashes due to interpreting non-zero shadow content as a pointer 2021-11-30 14:49:23 -08:00
tests tsan: new runtime (v3) 2021-11-25 18:32:04 +01:00
.clang-format Revert "sanitizers: increase .clang-format columns to 100" 2021-07-28 09:40:21 +02:00
CMakeLists.txt tsan: new runtime (v3) 2021-11-25 18:32:04 +01:00
analyze_libtsan.sh [compiler-rt] Use portable "#!/usr/bin/env bash" shebang for tests. 2021-09-24 19:10:07 +05:30
check_analyze.sh tsan: new runtime (v3) 2021-11-25 18:32:04 +01:00
check_cmake.sh [compiler-rt] Use portable "#!/usr/bin/env bash" shebang for tests. 2021-09-24 19:10:07 +05:30