Skip to content

Commit 9766ce4

Browse files
committed
[lsan] Add thread_suspend_fail flag
1 parent 9e862ae commit 9766ce4

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ static void ReportUnsuspendedThreads(const SuspendedThreadsList &) {}
702702

703703
# else // !SANITIZER_FUCHSIA
704704

705-
static void ReportUnsuspendedThreads(
705+
static bool ReportUnsuspendedThreads(
706706
const SuspendedThreadsList &suspended_threads) {
707707
InternalMmapVector<tid_t> threads(suspended_threads.ThreadCount());
708708
for (uptr i = 0; i < suspended_threads.ThreadCount(); ++i)
@@ -713,13 +713,17 @@ static void ReportUnsuspendedThreads(
713713
InternalMmapVector<tid_t> unsuspended;
714714
GetRunningThreadsLocked(&unsuspended);
715715

716+
bool succeded = true;
716717
for (auto os_id : unsuspended) {
717718
uptr i = InternalLowerBound(threads, os_id);
718-
if (i >= threads.size() || threads[i] != os_id)
719+
if (i >= threads.size() || threads[i] != os_id) {
720+
succeded = false;
719721
Report(
720722
"Running thread %zu was not suspended. False leaks are possible.\n",
721723
os_id);
724+
}
722725
}
726+
return succeded;
723727
}
724728

725729
# endif // !SANITIZER_FUCHSIA
@@ -729,7 +733,18 @@ static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads,
729733
CheckForLeaksParam *param = reinterpret_cast<CheckForLeaksParam *>(arg);
730734
CHECK(param);
731735
CHECK(!param->success);
732-
ReportUnsuspendedThreads(suspended_threads);
736+
if (!ReportUnsuspendedThreads(suspended_threads)) {
737+
switch (flags()->thread_suspend_fail) {
738+
case 0:
739+
param->success = true;
740+
return;
741+
case 1:
742+
break;
743+
case 2:
744+
// Will crash on return.
745+
return;
746+
}
747+
}
733748
ClassifyAllChunks(suspended_threads, &param->frontier, param->caller_tid,
734749
param->caller_sp);
735750
ForEachChunk(CollectLeaksCb, &param->leaks);

compiler-rt/lib/lsan/lsan_flags.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ LSAN_FLAG(bool, use_poisoned, false,
4444
LSAN_FLAG(bool, log_pointers, false, "Debug logging")
4545
LSAN_FLAG(bool, log_threads, false, "Debug logging")
4646
LSAN_FLAG(const char *, suppressions, "", "Suppressions file name.")
47+
LSAN_FLAG(int, thread_suspend_fail, 1,
48+
"Behaviour if thread suspendion all thread (0 - "
49+
"abandon leak checking, 1 - continue with leak checking (reported "
50+
"leaks can be false), 2 - crash (for debugging LSAN)).")

0 commit comments

Comments
 (0)