[lsan] Avoid segfaults during threads destruction under high load
authorMaxim Ostapenko <chefmax7@gmail.com>
Thu, 6 Apr 2017 07:42:27 +0000 (07:42 +0000)
committerMaxim Ostapenko <chefmax7@gmail.com>
Thu, 6 Apr 2017 07:42:27 +0000 (07:42 +0000)
commitfe863a65105c75cbb16c91500958f9b97f2d7114
tree4db5a24f857996e0339f876bd579953eacfe513d
parent895171e6eea4ffc9d2b25ca4151dfef268bc8148
[lsan] Avoid segfaults during threads destruction under high load

This patch addresses two issues:

* It turned out that suspended thread may have dtls->dtv_size == kDestroyedThread (-1)
and LSan wrongly assumes that DTV is available. This leads to SEGV when LSan tries to
iterate through DTV that is invalid.
* In some rare cases GetRegistersAndSP can fail with errno 3 (ESRCH). In this case LSan
assumes that the whole stack of a given thread is available. This is wrong because ESRCH
can indicate that suspended thread was destroyed and its stack was unmapped. This patch
properly handles ESRCH from GetRegistersAndSP in order to avoid invalid accesses to already
unpapped threads stack.

Differential Revision: https://reviews.llvm.org/D30818

llvm-svn: 299630
compiler-rt/lib/lsan/lsan_common.cc
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld.h
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cc
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h