File tree 7 files changed +29
-1
lines changed
test/sanitizer_common/TestCases/Posix
7 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ extern "C" void __lsan_init() {
101
101
InstallDeadlySignalHandlers (LsanOnDeadlySignal);
102
102
InitializeMainThread ();
103
103
InstallAtExitCheckLeaks ();
104
+ InstallAtForkHandler ();
104
105
105
106
InitializeCoverage (common_flags ()->coverage , common_flags ()->coverage_dir );
106
107
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ void InitializeInterceptors();
40
40
void ReplaceSystemMalloc ();
41
41
void LsanOnDeadlySignal (int signo, void *siginfo, void *context);
42
42
void InstallAtExitCheckLeaks ();
43
+ void InstallAtForkHandler ();
43
44
44
45
#define ENSURE_LSAN_INITED \
45
46
do { \
Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ namespace __lsan {
42
42
// also to protect the global list of root regions.
43
43
static Mutex global_mutex;
44
44
45
+ void LockGlobal () SANITIZER_ACQUIRE(global_mutex) { global_mutex.Lock (); }
46
+ void UnlockGlobal () SANITIZER_RELEASE(global_mutex) { global_mutex.Unlock (); }
47
+
45
48
Flags lsan_flags;
46
49
47
50
void DisableCounterUnderflow () {
Original file line number Diff line number Diff line change @@ -120,6 +120,10 @@ void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads);
120
120
void LockAllocator ();
121
121
void UnlockAllocator ();
122
122
123
+ // Lock/unlock global mutext.
124
+ void LockGlobal ();
125
+ void UnlockGlobal ();
126
+
123
127
// Returns the address range occupied by the global allocator object.
124
128
void GetAllocatorGlobalRange (uptr *begin, uptr *end);
125
129
// If p points into a chunk that has been allocated to the user, returns its
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {
80
80
// On Fuchsia, leak detection is done by a special hook after atexit hooks.
81
81
// So this doesn't install any atexit hook like on other platforms.
82
82
void InstallAtExitCheckLeaks () {}
83
+ void InstallAtForkHandler () {}
83
84
84
85
// ASan defines this to check its `halt_on_error` flag.
85
86
bool UseExitcodeOnLeak () { return true ; }
Original file line number Diff line number Diff line change 14
14
#include " sanitizer_common/sanitizer_platform.h"
15
15
16
16
#if SANITIZER_POSIX
17
+ # include < pthread.h>
18
+
17
19
# include " lsan.h"
18
20
# include " lsan_allocator.h"
19
21
# include " lsan_thread.h"
@@ -98,6 +100,22 @@ void InstallAtExitCheckLeaks() {
98
100
Atexit (DoLeakCheck);
99
101
}
100
102
103
+ void InstallAtForkHandler () {
104
+ auto before = []() {
105
+ LockGlobal ();
106
+ LockThreads ();
107
+ LockAllocator ();
108
+ StackDepotLockAll ();
109
+ };
110
+ auto after = []() {
111
+ StackDepotUnlockAll ();
112
+ UnlockAllocator ();
113
+ UnlockThreads ();
114
+ UnlockGlobal ();
115
+ };
116
+ pthread_atfork (before, after, after);
117
+ }
118
+
101
119
} // namespace __lsan
102
120
103
121
#endif // SANITIZER_POSIX
Original file line number Diff line number Diff line change 1
1
// RUN: %clang -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
2
2
3
- // UNSUPPORTED: asan, lsan, hwasan
3
+ // UNSUPPORTED: asan, hwasan
4
4
5
5
// The test uses pthread barriers which are not available on Darwin.
6
6
// UNSUPPORTED: darwin
You can’t perform that action at this time.
0 commit comments