tsan: use pthread_equal instead of direct pthread_t comparison
authorDmitry Vyukov <dvyukov@google.com>
Mon, 15 Nov 2021 18:44:34 +0000 (19:44 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 16 Nov 2021 06:51:24 +0000 (07:51 +0100)
man pthread_equal:
  The pthread_equal() function is necessary because thread IDs
  should be considered opaque: there is no portable way for
  applications to directly compare two pthread_t values.

Depends on D113916.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D113919

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

index 2f04cd2..25dbe48 100644 (file)
@@ -2134,11 +2134,11 @@ TSAN_INTERCEPTOR(int, pthread_kill, void *tid, int sig) {
   ThreadSignalContext *sctx = SigCtx(thr);
   CHECK_NE(sctx, 0);
   int prev = sctx->int_signal_send;
-  if (tid == pthread_self()) {
+  bool self = pthread_equal(tid, pthread_self());
+  if (self)
     sctx->int_signal_send = sig;
-  }
   int res = REAL(pthread_kill)(tid, sig);
-  if (tid == pthread_self()) {
+  if (self) {
     CHECK_EQ(sctx->int_signal_send, sig);
     sctx->int_signal_send = prev;
   }