From f483a8a9d055bc834cd163f8edaee73194005497 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Tue, 28 Apr 2015 18:50:32 +0000 Subject: [PATCH] [asan] Use dl_iterate_phdr on Android. It's available on Android/ARM starting with API 21 (L). llvm-svn: 236014 --- .../sanitizer_common/sanitizer_linux_libcdep.cc | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index ab9f0ab..7db7ce4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -28,6 +28,7 @@ #include // for dlsym() #endif +#include #include #include #include @@ -42,9 +43,12 @@ #include #endif +#if SANITIZER_ANDROID +#include +#endif + #if !SANITIZER_ANDROID #include -#include #include #endif @@ -397,13 +401,6 @@ void AdjustStackSize(void *attr_) { } } -#if SANITIZER_ANDROID -uptr GetListOfModules(LoadedModule *modules, uptr max_modules, - string_predicate_t filter) { - MemoryMappingLayout memory_mapping(false); - return memory_mapping.DumpListOfModules(modules, max_modules, filter); -} -#else // SANITIZER_ANDROID # if !SANITIZER_FREEBSD typedef ElfW(Phdr) Elf_Phdr; # elif SANITIZER_WORDSIZE == 32 && __FreeBSD_version <= 902001 // v9.2 @@ -451,14 +448,27 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { return 0; } +#if SANITIZER_ANDROID && __ANDROID_API__ < 21 +extern "C" __attribute__((weak)) int dl_iterate_phdr( + int (*)(struct dl_phdr_info *, size_t, void *), void *); +#endif + uptr GetListOfModules(LoadedModule *modules, uptr max_modules, string_predicate_t filter) { +#if SANITIZER_ANDROID && __ANDROID_API__ < 21 + // Fall back to /proc/maps if dl_iterate_phdr is not available. + // The runtime check allows the same library to work with + // both K and L (and future) Android releases. + if (!dl_iterate_phdr) { + MemoryMappingLayout memory_mapping(false); + return memory_mapping.DumpListOfModules(modules, max_modules, filter); + } +#endif CHECK(modules); DlIteratePhdrData data = {modules, 0, true, max_modules, filter}; dl_iterate_phdr(dl_iterate_phdr_cb, &data); return data.current_n; } -#endif // SANITIZER_ANDROID // getrusage does not give us the current RSS, only the max RSS. // Still, this is better than nothing if /proc/self/statm is not available -- 2.7.4