From 4b603e5c500c2ae06fca53bd9898fcf492821176 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 14 May 2013 14:04:06 +0000 Subject: [PATCH] [sanitizer] Filtering in GetListOfModules. llvm-svn: 181791 --- compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc | 3 ++- compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h | 7 +++++-- .../lib/sanitizer_common/sanitizer_symbolizer_linux.cc | 8 ++++++-- .../lib/sanitizer_common/sanitizer_symbolizer_mac.cc | 3 ++- .../lib/sanitizer_common/sanitizer_symbolizer_win.cc | 3 ++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc index 07f6cc7c40b9..15fd057774a7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cc @@ -383,7 +383,8 @@ class Symbolizer { modules_ = (LoadedModule*)(symbolizer_allocator.Allocate( kMaxNumberOfModuleContexts * sizeof(LoadedModule))); CHECK(modules_); - n_modules_ = GetListOfModules(modules_, kMaxNumberOfModuleContexts); + n_modules_ = GetListOfModules(modules_, kMaxNumberOfModuleContexts, + /* filter */ 0); // FIXME: Return this check when GetListOfModules is implemented on Mac. // CHECK_GT(n_modules_, 0); CHECK_LT(n_modules_, kMaxNumberOfModuleContexts); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h index 3aeebe9a84f9..91687153926d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h @@ -107,8 +107,11 @@ bool StartSymbolizerSubprocess(const char *path_to_symbolizer, // OS-dependent function that fills array with descriptions of at most // "max_modules" currently loaded modules. Returns the number of -// initialized modules. -uptr GetListOfModules(LoadedModule *modules, uptr max_modules); +// initialized modules. If filter is nonzero, ignores modules for which +// filter(full_name) is false. +typedef bool (*string_predicate_t)(const char *); +uptr GetListOfModules(LoadedModule *modules, uptr max_modules, + string_predicate_t filter); } // namespace __sanitizer diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc index fc3299c0f4e4..6e429207c66f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc @@ -134,6 +134,7 @@ struct DlIteratePhdrData { LoadedModule *modules; uptr current_n; uptr max_n; + string_predicate_t filter; }; static const uptr kMaxPathLength = 512; @@ -161,6 +162,8 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { } if (module_name.data()[0] == '\0') return 0; + if (data->filter && !data->filter(module_name.data())) + return 0; void *mem = &data->modules[data->current_n]; LoadedModule *cur_module = new(mem) LoadedModule(module_name.data(), info->dlpi_addr); @@ -176,9 +179,10 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { return 0; } -uptr GetListOfModules(LoadedModule *modules, uptr max_modules) { +uptr GetListOfModules(LoadedModule *modules, uptr max_modules, + string_predicate_t filter) { CHECK(modules); - DlIteratePhdrData data = {modules, 0, max_modules}; + DlIteratePhdrData data = {modules, 0, max_modules, filter}; dl_iterate_phdr(dl_iterate_phdr_cb, &data); return data.current_n; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cc index d3cd15a0a792..c8a91fdd6c66 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cc @@ -24,7 +24,8 @@ bool StartSymbolizerSubprocess(const char *path_to_symbolizer, UNIMPLEMENTED(); } -uptr GetListOfModules(LoadedModule *modules, uptr max_modules) { +uptr GetListOfModules(LoadedModule *modules, uptr max_modules, + string_predicate_t filter) { // FIXME: Actually implement this on Mac. Just using MemoryMappingLayout // may be enough for this on Mac. return 0; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc index c17b9c2b23a3..d3e69757d45c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc @@ -26,7 +26,8 @@ bool StartSymbolizerSubprocess(const char *path_to_symbolizer, UNIMPLEMENTED(); } -uptr GetListOfModules(LoadedModule *modules, uptr max_modules) { +uptr GetListOfModules(LoadedModule *modules, uptr max_modules, + string_predicate_t filter) { UNIMPLEMENTED(); };