Skip to content

Commit c0dc134

Browse files
authored
[tsan] Lock/Unlock allocator and stacks on fork (#96600)
We do that for other Sanitizers, and we should do the same for TSAN. There are know deadlocks reports here.
1 parent 70fb1e3 commit c0dc134

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

compiler-rt/lib/tsan/rtl/tsan_mman.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "sanitizer_common/sanitizer_common.h"
1818
#include "sanitizer_common/sanitizer_errno.h"
1919
#include "sanitizer_common/sanitizer_placement_new.h"
20+
#include "sanitizer_common/sanitizer_stackdepot.h"
2021
#include "tsan_flags.h"
2122
#include "tsan_interface.h"
2223
#include "tsan_report.h"
@@ -119,9 +120,18 @@ ScopedGlobalProcessor::~ScopedGlobalProcessor() {
119120
void AllocatorLockBeforeFork() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
120121
global_proc()->internal_alloc_mtx.Lock();
121122
InternalAllocatorLock();
123+
#if !SANITIZER_APPLE
124+
// OS X allocates from hooks, see 6a3958247a.
125+
allocator()->ForceLock();
126+
StackDepotLockBeforeFork();
127+
#endif
122128
}
123129

124130
void AllocatorUnlockAfterFork(bool child) SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
131+
#if !SANITIZER_APPLE
132+
StackDepotUnlockAfterFork(child);
133+
allocator()->ForceUnlock();
134+
#endif
125135
InternalAllocatorUnlock();
126136
global_proc()->internal_alloc_mtx.Unlock();
127137
}

compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
// FIXME: It probably hangs on this platform.
77
// UNSUPPORTED: ppc
88

9-
// FIXME: TSAN does not lock allocator.
10-
// UNSUPPORTED: tsan
11-
129
// FIXME: False stack overflow report
1310
// UNSUPPORTED: android && asan
1411

0 commit comments

Comments
 (0)