[compiler-rt] r191149 - tsan: allow to obtain code range for a particular module

Dmitry Vyukov dvyukov at google.com
Sat Sep 21 14:41:09 PDT 2013


Author: dvyukov
Date: Sat Sep 21 16:41:08 2013
New Revision: 191149

URL: http://llvm.org/viewvc/llvm-project?rev=191149&view=rev
Log:
tsan: allow to obtain code range for a particular module
this is required to ignore interceptors when called from the module


Added:
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=191149&r1=191148&r2=191149&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Sat Sep 21 16:41:08 2013
@@ -228,6 +228,22 @@ void RawWrite(const char *buffer) {
   }
 }
 
+bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end) {
+  uptr s, e, off, prot;
+  InternalMmapVector<char> fn(4096);
+  fn.push_back(0);
+  MemoryMappingLayout proc_maps(/*cache_enabled*/false);
+  while (proc_maps.Next(&s, &e, &off, &fn[0], fn.capacity(), &prot)) {
+    if ((prot & MemoryMappingLayout::kProtectionExecute) != 0
+        && internal_strcmp(module, &fn[0]) == 0) {
+      *start = s;
+      *end = e;
+      return true;
+    }
+  }
+  return false;
+}
+
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_LINUX || SANITIZER_MAC

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h?rev=191149&r1=191148&r2=191149&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h Sat Sep 21 16:41:08 2013
@@ -126,6 +126,9 @@ typedef void (*fill_profile_f)(uptr star
 // |stats_size| elements.
 void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size);
 
+// Returns code range for the specified module.
+bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
+
 #endif  // SANITIZER_WINDOWS
 
 }  // namespace __sanitizer

Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc?rev=191149&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc Sat Sep 21 16:41:08 2013
@@ -0,0 +1,30 @@
+//===-- sanitizer_procmaps_test.cc ----------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
+//
+//===----------------------------------------------------------------------===//
+#include "sanitizer_common/sanitizer_procmaps.h"
+//#include "sanitizer_common/sanitizer_internal_defs.h"
+//#include "sanitizer_common/sanitizer_libc.h"
+#include "gtest/gtest.h"
+
+namespace __sanitizer {
+
+#ifdef SANITIZER_LINUX
+TEST(ProcMaps, CodeRange) {
+  uptr start, end;
+  bool res = GetCodeRangeForFile("[vdso]", &start, &end);
+  EXPECT_EQ(res, true);
+  EXPECT_GT(start, (uptr)0);
+  EXPECT_LT(start, end);
+}
+#endif
+
+}  // namespace __sanitizer





More information about the llvm-commits mailing list