tsan: allow to obtain code range for a particular module

this is required to ignore interceptors when called from the module

llvm-svn: 191149
This commit is contained in:
Dmitry Vyukov 2013-09-21 21:41:08 +00:00
parent 12bfc4fef1
commit 4e9c091dd7
3 changed files with 49 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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