summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_posix.cc16
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h3
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc30
3 files changed, 49 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
index a73e7419a42..ffe91df1a59 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
+++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h
index ed281997f1a..65bcac6338d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h
+++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
new file mode 100644
index 00000000000..d16e2eebf98
--- /dev/null
+++ b/compiler-rt/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
OpenPOWER on IntegriCloud