-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tsan] Lock/Unlock allocator and stacks on fork #96600
[tsan] Lock/Unlock allocator and stacks on fork #96600
Conversation
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) ChangesWe do that for other Sanitizers, and we Full diff: https://github.com/llvm/llvm-project/pull/96600.diff 2 Files Affected:
diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
index 1e579c6a020e9..e129e9af272f5 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cpp
@@ -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"
@@ -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();
}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
index 13240234a1c79..27b67db0c0a38 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
@@ -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
|
Created using spr 1.3.4 [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that tsan simply disables itself after multithreaded fork, so it produces false sense to operation with die_after_fork=0. And it still can deadlock on mutex/atomic operations and maybe more.
nit: and stack depot? "and stacks" is confusing a bit. |
Created using spr 1.3.4 [skip ci]
We do that for other Sanitizers, and we should do the same for TSAN. There are know deadlocks reports here.
We do that for other Sanitizers, and we
should do the same for TSAN.
There are know deadlocks reports here.