summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2013-09-21 21:41:08 +0000
committerDmitry Vyukov <dvyukov@google.com>2013-09-21 21:41:08 +0000
commit821acfaccc7d11b987e2882b022e8d167b0c8a54 (patch)
tree7531d3ca18a6a33b70d08c3051abc76622aa62b2 /lib
parent6c21e11b36bb5ebf625463ca6724cf936ef0dc39 (diff)
downloadcompiler-rt-821acfaccc7d11b987e2882b022e8d167b0c8a54.tar.gz
tsan: allow to obtain code range for a particular module
this is required to ignore interceptors when called from the module git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@191149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/sanitizer_common/sanitizer_posix.cc16
-rw-r--r--lib/sanitizer_common/sanitizer_procmaps.h3
-rw-r--r--lib/sanitizer_common/tests/sanitizer_procmaps_test.cc30
3 files changed, 49 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_posix.cc b/lib/sanitizer_common/sanitizer_posix.cc
index a73e7419a..ffe91df1a 100644
--- a/lib/sanitizer_common/sanitizer_posix.cc
+++ b/lib/sanitizer_common/sanitizer_posix.cc
@@ -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
diff --git a/lib/sanitizer_common/sanitizer_procmaps.h b/lib/sanitizer_common/sanitizer_procmaps.h
index ed281997f..65bcac633 100644
--- a/lib/sanitizer_common/sanitizer_procmaps.h
+++ b/lib/sanitizer_common/sanitizer_procmaps.h
@@ -126,6 +126,9 @@ typedef void (*fill_profile_f)(uptr start, uptr rss, bool file,
// |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
diff --git a/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc b/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
new file mode 100644
index 000000000..d16e2eebf
--- /dev/null
+++ b/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
@@ -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