[PATCH] D14288: [tsan] Alternative ThreadState storage for OS X

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 04:55:58 PST 2015


dvyukov added a comment.

Signal handlers call SigCtx to obtain signal handling context:

static ThreadSignalContext *SigCtx(ThreadState *thr) {

  ThreadSignalContext *ctx = (ThreadSignalContext*)thr->signal_ctx;
  if (ctx == 0 && !thr->is_dead) {
    ctx = (ThreadSignalContext*)MmapOrDie(sizeof(*ctx), "ThreadSignalContext");
    MemoryResetRange(thr, (uptr)&SigCtx, (uptr)ctx, sizeof(*ctx));
    thr->signal_ctx = ctx;
  }
  return ctx;

}

If the thread is already considered "dead" (during destruction or destroyed), then we just ignore signals.
This is most likely OK, because we can pretend that the thread just exited before catching the signal.

Add a note to cur_thread_finalize saying that it is not signal-safe (in particular you call unmap first and then clear the fake_tls, if we receive a signal in between, handler will try to access the unmapped ThreadState). We can sort it out later. But this is something to keep in mind (in fact, signals are the most common source of tsan bugs and crashes).


http://reviews.llvm.org/D14288





More information about the llvm-commits mailing list