Skip to content

Commit 87e9333

Browse files
vitalybukaDanielCChen
authored andcommitted
[sanitizer] VReport BeforeFork/AfterFork (llvm#111900)
Forks are common suspects for unusual sanitizer behavior. It can be handy to see them without rebuild.
1 parent 0baa8f2 commit 87e9333

File tree

6 files changed

+12
-0
lines changed

6 files changed

+12
-0
lines changed

compiler-rt/lib/asan/asan_posix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void PlatformTSDDtor(void *tsd) {
149149
# endif
150150

151151
static void BeforeFork() {
152+
VReport(2, "BeforeFork tid: %llu\n", GetTid());
152153
if (CAN_SANITIZE_LEAKS) {
153154
__lsan::LockGlobal();
154155
}
@@ -168,6 +169,7 @@ static void AfterFork(bool fork_child) {
168169
if (CAN_SANITIZE_LEAKS) {
169170
__lsan::UnlockGlobal();
170171
}
172+
VReport(2, "AfterFork tid: %llu\n", GetTid());
171173
}
172174

173175
void InstallAtForkHandler() {

compiler-rt/lib/dfsan/dfsan_custom.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,13 +2859,15 @@ WRAPPER_ALIAS(__isoc99_sscanf, sscanf)
28592859
WRAPPER_ALIAS(__isoc23_sscanf, sscanf)
28602860

28612861
static void BeforeFork() {
2862+
VReport(2, "BeforeFork tid: %llu\n", GetTid());
28622863
StackDepotLockBeforeFork();
28632864
ChainedOriginDepotLockBeforeFork();
28642865
}
28652866

28662867
static void AfterFork(bool fork_child) {
28672868
ChainedOriginDepotUnlockAfterFork(fork_child);
28682869
StackDepotUnlockAfterFork(fork_child);
2870+
VReport(2, "AfterFork tid: %llu\n", GetTid());
28692871
}
28702872

28712873
SANITIZER_INTERFACE_ATTRIBUTE

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
528528
}
529529

530530
static void BeforeFork() {
531+
VReport(2, "BeforeFork tid: %llu\n", GetTid());
531532
if (CAN_SANITIZE_LEAKS) {
532533
__lsan::LockGlobal();
533534
}
@@ -547,6 +548,7 @@ static void AfterFork(bool fork_child) {
547548
if (CAN_SANITIZE_LEAKS) {
548549
__lsan::UnlockGlobal();
549550
}
551+
VReport(2, "AfterFork tid: %llu\n", GetTid());
550552
}
551553

552554
void HwasanInstallAtForkHandler() {

compiler-rt/lib/lsan/lsan_posix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void InstallAtExitCheckLeaks() {
9797
}
9898

9999
static void BeforeFork() {
100+
VReport(2, "BeforeFork tid: %llu\n", GetTid());
100101
LockGlobal();
101102
LockThreads();
102103
LockAllocator();
@@ -108,6 +109,7 @@ static void AfterFork(bool fork_child) {
108109
UnlockAllocator();
109110
UnlockThreads();
110111
UnlockGlobal();
112+
VReport(2, "AfterFork tid: %llu\n", GetTid());
111113
}
112114

113115
void InstallAtForkHandler() {

compiler-rt/lib/msan/msan_linux.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ void MsanTSDDtor(void *tsd) {
302302
# endif
303303

304304
static void BeforeFork() {
305+
VReport(2, "BeforeFork tid: %llu\n", GetTid());
305306
// Usually we lock ThreadRegistry, but msan does not have one.
306307
LockAllocator();
307308
StackDepotLockBeforeFork();
@@ -313,6 +314,7 @@ static void AfterFork(bool fork_child) {
313314
StackDepotUnlockAfterFork(fork_child);
314315
UnlockAllocator();
315316
// Usually we unlock ThreadRegistry, but msan does not have one.
317+
VReport(2, "AfterFork tid: %llu\n", GetTid());
316318
}
317319

318320
void InstallAtForkHandler() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ int Finalize(ThreadState *thr) {
806806

807807
#if !SANITIZER_GO
808808
void ForkBefore(ThreadState* thr, uptr pc) SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
809+
VReport(2, "BeforeFork tid: %llu\n", GetTid());
809810
GlobalProcessorLock();
810811
// Detaching from the slot makes OnUserFree skip writing to the shadow.
811812
// The slot will be locked so any attempts to use it will deadlock anyway.
@@ -847,6 +848,7 @@ static void ForkAfter(ThreadState* thr,
847848
SlotAttachAndLock(thr);
848849
SlotUnlock(thr);
849850
GlobalProcessorUnlock();
851+
VReport(2, "AfterFork tid: %llu\n", GetTid());
850852
}
851853

852854
void ForkParentAfter(ThreadState* thr, uptr pc) { ForkAfter(thr, false); }

0 commit comments

Comments
 (0)