Skip to content

Commit

Permalink
[tsan] Lock/Unlock allocator and stacks on fork (llvm#96600)
Browse files Browse the repository at this point in the history
We do that for other Sanitizers, and we
should do the same for TSAN.
There are know deadlocks reports here.
  • Loading branch information
vitalybuka authored and AlexisPerry committed Jun 27, 2024
1 parent bff2ffe commit b32c1d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 10 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_mman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_errno.h"
#include "sanitizer_common/sanitizer_placement_new.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
#include "tsan_flags.h"
#include "tsan_interface.h"
#include "tsan_report.h"
Expand Down Expand Up @@ -119,9 +120,18 @@ ScopedGlobalProcessor::~ScopedGlobalProcessor() {
void AllocatorLockBeforeFork() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
global_proc()->internal_alloc_mtx.Lock();
InternalAllocatorLock();
#if !SANITIZER_APPLE
// OS X allocates from hooks, see 6a3958247a.
allocator()->ForceLock();
StackDepotLockBeforeFork();
#endif
}

void AllocatorUnlockAfterFork(bool child) SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
#if !SANITIZER_APPLE
StackDepotUnlockAfterFork(child);
allocator()->ForceUnlock();
#endif
InternalAllocatorUnlock();
global_proc()->internal_alloc_mtx.Unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
// FIXME: It probably hangs on this platform.
// UNSUPPORTED: ppc

// FIXME: TSAN does not lock allocator.
// UNSUPPORTED: tsan

// FIXME: False stack overflow report
// UNSUPPORTED: android && asan

Expand Down

0 comments on commit b32c1d6

Please sign in to comment.