[compiler-rt] adfefa5 - [NFC] Extract ForEachDVT

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 1 16:15:49 PST 2020


Author: Vitaly Buka
Date: 2020-12-01T16:15:32-08:00
New Revision: adfefa555333b6e276150f6d9adb6f5bb910b103

URL: https://github.com/llvm/llvm-project/commit/adfefa555333b6e276150f6d9adb6f5bb910b103
DIFF: https://github.com/llvm/llvm-project/commit/adfefa555333b6e276150f6d9adb6f5bb910b103.diff

LOG: [NFC] Extract ForEachDVT

Added: 
    

Modified: 
    compiler-rt/lib/lsan/lsan_common.cpp
    compiler-rt/lib/msan/msan_thread.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index 9e23aa9997ac..30c154a4fc94 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -315,15 +315,15 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
       __libc_iterate_dynamic_tls(os_id, cb, frontier);
 #else
       if (dtls && !DTLSInDestruction(dtls)) {
-        for (uptr j = 0; j < dtls->dtv_size; ++j) {
-          uptr dtls_beg = dtls->dtv[j].beg;
-          uptr dtls_end = dtls_beg + dtls->dtv[j].size;
+        ForEachDVT(dtls, [&](const DTLS::DTV &dtv, int id) {
+          uptr dtls_beg = dtv.beg;
+          uptr dtls_end = dtls_beg + dtv.size;
           if (dtls_beg < dtls_end) {
-            LOG_THREADS("DTLS %zu at %p-%p.\n", j, dtls_beg, dtls_end);
+            LOG_THREADS("DTLS %zu at %p-%p.\n", id, dtls_beg, dtls_end);
             ScanRangeForPointers(dtls_beg, dtls_end, frontier, "DTLS",
                                  kReachable);
           }
-        }
+        });
       } else {
         // We are handling a thread with DTLS under destruction. Log about
         // this and continue.

diff  --git a/compiler-rt/lib/msan/msan_thread.cpp b/compiler-rt/lib/msan/msan_thread.cpp
index 456901c6789b..6ae012acd9a2 100644
--- a/compiler-rt/lib/msan/msan_thread.cpp
+++ b/compiler-rt/lib/msan/msan_thread.cpp
@@ -37,8 +37,9 @@ void MsanThread::ClearShadowForThreadStackAndTLS() {
     __msan_unpoison((void *)tls_begin_, tls_end_ - tls_begin_);
   DTLS *dtls = DTLS_Get();
   CHECK_NE(dtls, 0);
-  for (uptr i = 0; i < dtls->dtv_size; ++i)
-    __msan_unpoison((void *)(dtls->dtv[i].beg), dtls->dtv[i].size);
+  ForEachDVT(dtls, [](const DTLS::DTV &dtv, int id) {
+    __msan_unpoison((void *)(dtv.beg), dtv.size);
+  });
 }
 
 void MsanThread::Init() {

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
index c7cd5a8bffcf..cfdef4a2cd4b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
@@ -47,6 +47,11 @@ struct DTLS {
   uptr last_memalign_ptr;
 };
 
+template <typename Fn>
+void ForEachDVT(DTLS *dtls, const Fn &fn) {
+  for (uptr j = 0; j < dtls->dtv_size; ++j) fn(dtls->dtv[j], j);
+}
+
 // Returns pointer and size of a linker-allocated TLS block.
 // Each block is returned exactly once.
 DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res, uptr static_tls_begin,


        


More information about the llvm-commits mailing list