[hwasan] Support malloc in atfork.
authorEvgenii Stepanov <eugenis@google.com>
Sat, 14 Aug 2021 00:09:10 +0000 (17:09 -0700)
committerEvgenii Stepanov <eugenis@google.com>
Tue, 17 Aug 2021 22:29:49 +0000 (15:29 -0700)
commit8a570a873b25af4c718a16caa214b4f7bc14e6d6
tree72c6b6289780ef6fe591d68355c75cac9530cff3
parent4018d25da8ab7d2392ef444e1134fe262d47dad8
[hwasan] Support malloc in atfork.

Before this change we were locking the StackDepot in the fork()
interceptor. This results in a deadlock when allocator functions are
used in a pthread_atfork() callback.

Instead, set up a pthread_atfork() callback at init that locks/unlocks
both StackDepot and the allocator. Since our callback is set up very
early, the pre-fork callback is executed late, and both post-fork ones
are executed early, which works perfect for us.

Differential Revision: https://reviews.llvm.org/D108063
compiler-rt/lib/hwasan/hwasan.cpp
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_allocator.cpp
compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
compiler-rt/lib/hwasan/hwasan_interceptors.cpp
compiler-rt/lib/hwasan/hwasan_linux.cpp
compiler-rt/test/hwasan/TestCases/Linux/atfork.cpp [new file with mode: 0644]