Lines Matching refs:thr

79 static TracePart* TracePartAlloc(ThreadState* thr) {  in TracePartAlloc()  argument
84 Trace* trace = &thr->tctx->trace; in TracePartAlloc()
88 DPrintf("#%d: TracePartAlloc: part=%p\n", thr->tid, part); in TracePartAlloc()
151 bool attached = tctx->thr && tctx->thr->slot; in DoResetImpl()
171 &tctx->thr->trace_pos, in DoResetImpl()
180 if (tctx->thr && !tctx->thr->slot) { in DoResetImpl()
181 atomic_store_relaxed(&tctx->thr->trace_pos, 0); in DoResetImpl()
182 tctx->thr->trace_prev_pc = 0; in DoResetImpl()
195 slot.thr = nullptr; in DoResetImpl()
229 void DoReset(ThreadState* thr, uptr epoch) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { in DoReset() argument
241 DPrintf("#%d: DoReset epoch=%lu\n", thr ? thr->tid : -1, epoch); in DoReset()
248 static TidSlot* FindSlotAndLock(ThreadState* thr) in FindSlotAndLock() argument
249 SANITIZER_ACQUIRE(thr->slot->mtx) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { in FindSlotAndLock()
250 CHECK(!thr->slot); in FindSlotAndLock()
261 thr->slot_locked = false; in FindSlotAndLock()
275 DoReset(thr, epoch); in FindSlotAndLock()
279 CHECK(!thr->slot_locked); in FindSlotAndLock()
280 thr->slot_locked = true; in FindSlotAndLock()
281 if (slot->thr) { in FindSlotAndLock()
282 DPrintf("#%d: preempting sid=%d tid=%d\n", thr->tid, (u32)slot->sid, in FindSlotAndLock()
283 slot->thr->tid); in FindSlotAndLock()
284 slot->SetEpoch(slot->thr->fast_state.epoch()); in FindSlotAndLock()
285 slot->thr = nullptr; in FindSlotAndLock()
292 void SlotAttachAndLock(ThreadState* thr) { in SlotAttachAndLock() argument
293 TidSlot* slot = FindSlotAndLock(thr); in SlotAttachAndLock()
294 DPrintf("#%d: SlotAttach: slot=%u\n", thr->tid, static_cast<int>(slot->sid)); in SlotAttachAndLock()
295 CHECK(!slot->thr); in SlotAttachAndLock()
296 CHECK(!thr->slot); in SlotAttachAndLock()
297 slot->thr = thr; in SlotAttachAndLock()
298 thr->slot = slot; in SlotAttachAndLock()
302 thr->fast_state.SetSid(slot->sid); in SlotAttachAndLock()
303 thr->fast_state.SetEpoch(epoch); in SlotAttachAndLock()
304 if (thr->slot_epoch != ctx->global_epoch) { in SlotAttachAndLock()
305 thr->slot_epoch = ctx->global_epoch; in SlotAttachAndLock()
306 thr->clock.Reset(); in SlotAttachAndLock()
308 thr->last_sleep_stack_id = kInvalidStackID; in SlotAttachAndLock()
309 thr->last_sleep_clock.Reset(); in SlotAttachAndLock()
312 thr->clock.Set(slot->sid, epoch); in SlotAttachAndLock()
313 slot->journal.PushBack({thr->tid, epoch}); in SlotAttachAndLock()
316 static void SlotDetachImpl(ThreadState* thr, bool exiting) { in SlotDetachImpl() argument
317 TidSlot* slot = thr->slot; in SlotDetachImpl()
318 thr->slot = nullptr; in SlotDetachImpl()
319 if (thr != slot->thr) { in SlotDetachImpl()
321 if (thr->slot_epoch != ctx->global_epoch) { in SlotDetachImpl()
323 auto* trace = &thr->tctx->trace; in SlotDetachImpl()
332 thr->tctx->trace.local_head = nullptr; in SlotDetachImpl()
333 atomic_store_relaxed(&thr->trace_pos, 0); in SlotDetachImpl()
334 thr->trace_prev_pc = 0; in SlotDetachImpl()
343 CHECK(exiting || thr->fast_state.epoch() == kEpochLast); in SlotDetachImpl()
344 slot->SetEpoch(thr->fast_state.epoch()); in SlotDetachImpl()
345 slot->thr = nullptr; in SlotDetachImpl()
348 void SlotDetach(ThreadState* thr) { in SlotDetach() argument
349 Lock lock(&thr->slot->mtx); in SlotDetach()
350 SlotDetachImpl(thr, true); in SlotDetach()
353 void SlotLock(ThreadState* thr) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { in SlotLock() argument
354 DCHECK(!thr->slot_locked); in SlotLock()
362 TidSlot* slot = thr->slot; in SlotLock()
364 thr->slot_locked = true; in SlotLock()
365 if (LIKELY(thr == slot->thr && thr->fast_state.epoch() != kEpochLast)) in SlotLock()
367 SlotDetachImpl(thr, false); in SlotLock()
368 thr->slot_locked = false; in SlotLock()
370 SlotAttachAndLock(thr); in SlotLock()
373 void SlotUnlock(ThreadState* thr) { in SlotUnlock() argument
374 DCHECK(thr->slot_locked); in SlotUnlock()
375 thr->slot_locked = false; in SlotUnlock()
376 thr->slot->mtx.Unlock(); in SlotUnlock()
565 void UnmapShadow(ThreadState *thr, uptr addr, uptr size) { in UnmapShadow() argument
570 SlotLocker locker(thr, true); in UnmapShadow()
571 ctx->metamap.ResetRange(thr->proc(), addr, size, true); in UnmapShadow()
666 ThreadState* thr = cur_thread(); in CheckUnwind() local
667 thr->nomalloc = false; in CheckUnwind()
668 thr->ignore_sync++; in CheckUnwind()
669 thr->ignore_reads_and_writes++; in CheckUnwind()
670 atomic_store_relaxed(&thr->in_signal_handler, 0); in CheckUnwind()
677 void Initialize(ThreadState *thr) { in Initialize() argument
705 ProcWire(proc, thr); in Initialize()
728 ThreadStart(thr, tid, GetTid(), ThreadType::Regular); in Initialize()
764 int Finalize(ThreadState *thr) { in Finalize() argument
772 if (flags()->atexit_sleep_ms > 0 && ThreadCount(thr) > 1) in Finalize()
784 ThreadFinalize(thr); in Finalize()
804 void ForkBefore(ThreadState* thr, uptr pc) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { in ForkBefore() argument
808 SlotDetach(thr); in ForkBefore()
819 thr->suppress_reports++; in ForkBefore()
824 thr->ignore_interceptors++; in ForkBefore()
826 thr->ignore_reads_and_writes++; in ForkBefore()
831 static void ForkAfter(ThreadState* thr) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { in ForkAfter() argument
832 thr->suppress_reports--; // Enabled in ForkBefore. in ForkAfter()
833 thr->ignore_interceptors--; in ForkAfter()
834 thr->ignore_reads_and_writes--; in ForkAfter()
840 SlotAttachAndLock(thr); in ForkAfter()
841 SlotUnlock(thr); in ForkAfter()
845 void ForkParentAfter(ThreadState* thr, uptr pc) { ForkAfter(thr); } in ForkParentAfter() argument
847 void ForkChildAfter(ThreadState* thr, uptr pc, bool start_thread) { in ForkChildAfter() argument
848 ForkAfter(thr); in ForkChildAfter()
849 u32 nthread = ctx->thread_registry.OnFork(thr->tid); in ForkChildAfter()
862 thr->ignore_interceptors++; in ForkChildAfter()
863 thr->suppress_reports++; in ForkChildAfter()
864 ThreadIgnoreBegin(thr, pc); in ForkChildAfter()
865 ThreadIgnoreSyncBegin(thr, pc); in ForkChildAfter()
872 void GrowShadowStack(ThreadState *thr) { in GrowShadowStack() argument
873 const int sz = thr->shadow_stack_end - thr->shadow_stack; in GrowShadowStack()
876 internal_memcpy(newstack, thr->shadow_stack, sz * sizeof(uptr)); in GrowShadowStack()
877 Free(thr->shadow_stack); in GrowShadowStack()
878 thr->shadow_stack = newstack; in GrowShadowStack()
879 thr->shadow_stack_pos = newstack + sz; in GrowShadowStack()
880 thr->shadow_stack_end = newstack + newsz; in GrowShadowStack()
884 StackID CurrentStackId(ThreadState *thr, uptr pc) { in CurrentStackId() argument
886 if (!thr->is_inited) // May happen during bootstrap. in CurrentStackId()
891 DCHECK_LT(thr->shadow_stack_pos, thr->shadow_stack_end); in CurrentStackId()
893 if (thr->shadow_stack_pos == thr->shadow_stack_end) in CurrentStackId()
894 GrowShadowStack(thr); in CurrentStackId()
896 thr->shadow_stack_pos[0] = pc; in CurrentStackId()
897 thr->shadow_stack_pos++; in CurrentStackId()
900 StackTrace(thr->shadow_stack, thr->shadow_stack_pos - thr->shadow_stack)); in CurrentStackId()
902 thr->shadow_stack_pos--; in CurrentStackId()
906 static bool TraceSkipGap(ThreadState* thr) { in TraceSkipGap() argument
907 Trace *trace = &thr->tctx->trace; in TraceSkipGap()
908 Event *pos = reinterpret_cast<Event *>(atomic_load_relaxed(&thr->trace_pos)); in TraceSkipGap()
911 DPrintf("#%d: TraceSwitchPart enter trace=%p parts=%p-%p pos=%p\n", thr->tid, in TraceSkipGap()
928 atomic_store_relaxed(&thr->trace_pos, reinterpret_cast<uptr>(pos)); in TraceSkipGap()
937 void TraceSwitchPart(ThreadState* thr) { in TraceSwitchPart() argument
938 if (TraceSkipGap(thr)) in TraceSwitchPart()
943 TracePart* part = thr->tctx->trace.parts.Back(); in TraceSwitchPart()
945 atomic_store_relaxed(&thr->trace_pos, in TraceSwitchPart()
951 TraceSwitchPartImpl(thr); in TraceSwitchPart()
954 void TraceSwitchPartImpl(ThreadState* thr) { in TraceSwitchPartImpl() argument
955 SlotLocker locker(thr, true); in TraceSwitchPartImpl()
956 Trace* trace = &thr->tctx->trace; in TraceSwitchPartImpl()
957 TracePart* part = TracePartAlloc(thr); in TraceSwitchPartImpl()
959 thr->trace_prev_pc = 0; in TraceSwitchPartImpl()
973 atomic_store_relaxed(&thr->trace_pos, in TraceSwitchPartImpl()
978 TraceTime(thr); in TraceSwitchPartImpl()
985 uptr* pos = Max(&thr->shadow_stack[0], thr->shadow_stack_pos - kMaxFrames); in TraceSwitchPartImpl()
986 for (; pos < thr->shadow_stack_pos; pos++) { in TraceSwitchPartImpl()
987 if (TryTraceFunc(thr, *pos)) in TraceSwitchPartImpl()
989 CHECK(TraceSkipGap(thr)); in TraceSwitchPartImpl()
990 CHECK(TryTraceFunc(thr, *pos)); in TraceSwitchPartImpl()
993 for (uptr i = 0; i < thr->mset.Size(); i++) { in TraceSwitchPartImpl()
994 MutexSet::Desc d = thr->mset.Get(i); in TraceSwitchPartImpl()
996 TraceMutexLock(thr, d.write ? EventType::kLock : EventType::kRLock, 0, in TraceSwitchPartImpl()
1004 if (!TraceAcquire(thr, &ev)) { in TraceSwitchPartImpl()
1005 CHECK(TraceSkipGap(thr)); in TraceSwitchPartImpl()
1006 CHECK(TraceAcquire(thr, &ev)); in TraceSwitchPartImpl()
1018 if (ctx->slot_queue.Queued(thr->slot)) { in TraceSwitchPartImpl()
1019 ctx->slot_queue.Remove(thr->slot); in TraceSwitchPartImpl()
1020 ctx->slot_queue.PushBack(thr->slot); in TraceSwitchPartImpl()
1025 DPrintf("#%d: TraceSwitchPart exit parts=%p-%p pos=0x%zx\n", thr->tid, in TraceSwitchPartImpl()
1027 atomic_load_relaxed(&thr->trace_pos)); in TraceSwitchPartImpl()
1030 void ThreadIgnoreBegin(ThreadState* thr, uptr pc) { in ThreadIgnoreBegin() argument
1031 DPrintf("#%d: ThreadIgnoreBegin\n", thr->tid); in ThreadIgnoreBegin()
1032 thr->ignore_reads_and_writes++; in ThreadIgnoreBegin()
1033 CHECK_GT(thr->ignore_reads_and_writes, 0); in ThreadIgnoreBegin()
1034 thr->fast_state.SetIgnoreBit(); in ThreadIgnoreBegin()
1037 thr->mop_ignore_set.Add(CurrentStackId(thr, pc)); in ThreadIgnoreBegin()
1041 void ThreadIgnoreEnd(ThreadState *thr) { in ThreadIgnoreEnd() argument
1042 DPrintf("#%d: ThreadIgnoreEnd\n", thr->tid); in ThreadIgnoreEnd()
1043 CHECK_GT(thr->ignore_reads_and_writes, 0); in ThreadIgnoreEnd()
1044 thr->ignore_reads_and_writes--; in ThreadIgnoreEnd()
1045 if (thr->ignore_reads_and_writes == 0) { in ThreadIgnoreEnd()
1046 thr->fast_state.ClearIgnoreBit(); in ThreadIgnoreEnd()
1048 thr->mop_ignore_set.Reset(); in ThreadIgnoreEnd()
1056 ThreadState *thr = cur_thread(); in __tsan_testonly_shadow_stack_current_size() local
1057 return thr->shadow_stack_pos - thr->shadow_stack; in __tsan_testonly_shadow_stack_current_size()
1061 void ThreadIgnoreSyncBegin(ThreadState *thr, uptr pc) { in ThreadIgnoreSyncBegin() argument
1062 DPrintf("#%d: ThreadIgnoreSyncBegin\n", thr->tid); in ThreadIgnoreSyncBegin()
1063 thr->ignore_sync++; in ThreadIgnoreSyncBegin()
1064 CHECK_GT(thr->ignore_sync, 0); in ThreadIgnoreSyncBegin()
1067 thr->sync_ignore_set.Add(CurrentStackId(thr, pc)); in ThreadIgnoreSyncBegin()
1071 void ThreadIgnoreSyncEnd(ThreadState *thr) { in ThreadIgnoreSyncEnd() argument
1072 DPrintf("#%d: ThreadIgnoreSyncEnd\n", thr->tid); in ThreadIgnoreSyncEnd()
1073 CHECK_GT(thr->ignore_sync, 0); in ThreadIgnoreSyncEnd()
1074 thr->ignore_sync--; in ThreadIgnoreSyncEnd()
1076 if (thr->ignore_sync == 0) in ThreadIgnoreSyncEnd()
1077 thr->sync_ignore_set.Reset(); in ThreadIgnoreSyncEnd()