SignalContext *sctx = SigCtx(thr);
if (sctx == 0 || sctx->pending_signal_count == 0 || thr->in_signal_handler)
return;
+ Context *ctx = CTX();
thr->in_signal_handler = true;
sctx->pending_signal_count = 0;
// These are too big for stack.
(uptr)sigactions[sig].sa_handler;
stack.Init(&pc, 1);
ScopedReport rep(ReportTypeErrnoInSignal);
- rep.AddStack(&stack);
- OutputReport(rep, rep.GetReport()->stacks[0]);
+ if (!IsFiredSuppression(ctx, rep, stack)) {
+ rep.AddStack(&stack);
+ OutputReport(ctx, rep, rep.GetReport()->stacks[0]);
+ }
}
errno = saved_errno;
}
static void SignalUnsafeCall(ThreadState *thr, uptr pc) {
if (!thr->in_signal_handler || !flags()->report_signal_unsafe)
return;
+ Context *ctx = CTX();
StackTrace stack;
stack.ObtainCurrent(thr, pc);
ScopedReport rep(ReportTypeSignalUnsafe);
- rep.AddStack(&stack);
- OutputReport(rep, rep.GetReport()->stacks[0]);
+ if (!IsFiredSuppression(ctx, rep, stack)) {
+ rep.AddStack(&stack);
+ OutputReport(ctx, rep, rep.GetReport()->stacks[0]);
+ }
}
void *user_alloc(ThreadState *thr, uptr pc, uptr sz, uptr align) {
, nmissed_expected()
, thread_mtx(MutexTypeThreads, StatMtxThreads)
, racy_stacks(MBlockRacyStacks)
- , racy_addresses(MBlockRacyAddresses) {
+ , racy_addresses(MBlockRacyAddresses)
+ , fired_suppressions(MBlockRacyAddresses) {
}
// The objects are allocated in TLS, so one may rely on zero-initialization.
uptr addr_max;
};
+struct FiredSuppression {
+ ReportType type;
+ uptr pc;
+};
+
struct Context {
Context();
Vector<RacyStacks> racy_stacks;
Vector<RacyAddress> racy_addresses;
+ Vector<FiredSuppression> fired_suppressions;
Flags flags;
void InitializeDynamicAnnotations();
void ReportRace(ThreadState *thr);
-bool OutputReport(const ScopedReport &srep,
+bool OutputReport(Context *ctx,
+ const ScopedReport &srep,
const ReportStack *suppress_stack = 0);
+bool IsFiredSuppression(Context *ctx,
+ const ScopedReport &srep,
+ const StackTrace &trace);
bool IsExpectedReport(uptr addr, uptr size);
#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 1
RestoreStack(last.tid(), last.epoch(), &trace);
rep.AddStack(&trace);
rep.AddLocation(s->addr, 1);
- OutputReport(rep);
+ OutputReport(ctx, rep);
}
DestroyAndFree(s);
}
}
}
-bool OutputReport(const ScopedReport &srep, const ReportStack *suppress_stack) {
+bool OutputReport(Context *ctx,
+ const ScopedReport &srep,
+ const ReportStack *suppress_stack) {
const ReportDesc *rep = srep.GetReport();
- bool suppressed = IsSuppressed(rep->typ, suppress_stack);
- suppressed = OnReport(rep, suppressed);
- if (suppressed)
+ const uptr suppress_pc = IsSuppressed(rep->typ, suppress_stack);
+ if (suppress_pc != 0) {
+ FiredSuppression supp = {srep.GetReport()->typ, suppress_pc};
+ ctx->fired_suppressions.PushBack(supp);
+ }
+ if (OnReport(rep, suppress_pc != 0))
return false;
PrintReport(rep);
CTX()->nreported++;
return true;
}
+bool IsFiredSuppression(Context *ctx,
+ const ScopedReport &srep,
+ const StackTrace &trace) {
+ for (uptr k = 0; k < ctx->fired_suppressions.Size(); k++) {
+ if (ctx->fired_suppressions[k].type != srep.GetReport()->typ)
+ continue;
+ for (uptr j = 0; j < trace.Size(); j++) {
+ if (trace.Get(j) == ctx->fired_suppressions[k].pc)
+ return true;
+ }
+ }
+ return false;
+}
+
void ReportRace(ThreadState *thr) {
ScopedInRtl in_rtl;
ScopedReport rep(freed ? ReportTypeUseAfterFree : ReportTypeRace);
const uptr kMop = 2;
StackTrace traces[kMop];
- for (uptr i = 0; i < kMop; i++) {
- Shadow s(thr->racy_state[i]);
- RestoreStack(s.tid(), s.epoch(), &traces[i]);
- }
- // Failure to restore stack of the current thread
- // was observed on free() interceptor called from pthread.
- // Just get the current shadow stack instead.
- if (traces[0].IsEmpty())
- traces[0].ObtainCurrent(thr, 0);
+ const uptr toppc = thr->trace.events[thr->fast_state.epoch() % kTraceSize]
+ & ((1ull << 61) - 1);
+ traces[0].ObtainCurrent(thr, toppc);
+ if (IsFiredSuppression(ctx, rep, traces[0]))
+ return;
+ Shadow s2(thr->racy_state[1]);
+ RestoreStack(s2.tid(), s2.epoch(), &traces[1]);
if (HandleRacyStacks(thr, traces, addr_min, addr_max))
return;
}
#endif
- if (!OutputReport(rep, rep.GetReport()->mops[0]->stack))
+ if (!OutputReport(ctx, rep, rep.GetReport()->mops[0]->stack))
return;
AddRacyStacks(thr, traces, addr_min, addr_max);
return;
ScopedReport rep(ReportTypeThreadLeak);
rep.AddThread(tctx);
- OutputReport(rep);
+ OutputReport(CTX(), rep);
}
void ThreadFinalize(ThreadState *thr) {
g_suppressions = SuppressionParse(supp);
}
-bool IsSuppressed(ReportType typ, const ReportStack *stack) {
+uptr IsSuppressed(ReportType typ, const ReportStack *stack) {
if (g_suppressions == 0 || stack == 0)
- return false;
+ return 0;
SuppressionType stype;
if (typ == ReportTypeRace)
stype = SuppressionRace;
else if (typ == ReportTypeSignalUnsafe)
stype = SuppressionSignal;
else
- return false;
+ return 0;
for (const ReportStack *frame = stack; frame; frame = frame->next) {
for (Suppression *supp = g_suppressions; supp; supp = supp->next) {
if (stype == supp->type &&
(SuppressionMatch(supp->templ, frame->func) ||
SuppressionMatch(supp->templ, frame->file))) {
DPrintf("ThreadSanitizer: matched suppression '%s'\n", supp->templ);
- return true;
+ return frame->pc;
}
}
}
- return false;
+ return 0;
}
} // namespace __tsan
void InitializeSuppressions();
void FinalizeSuppressions();
-bool IsSuppressed(ReportType typ, const ReportStack *stack);
+uptr IsSuppressed(ReportType typ, const ReportStack *stack);
// Exposed for testing.
enum SuppressionType {