From aac36b345a27b0f939fe3d7c242defa53ccd16c0 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 23 Nov 2012 10:14:44 +0000 Subject: [PATCH] [ASan] intercept swapcontext on Linux only llvm-svn: 168509 --- compiler-rt/lib/asan/asan_intercepted_functions.h | 14 ++++++-------- compiler-rt/lib/asan/asan_linux.cc | 17 +++++++++++++++++ compiler-rt/lib/asan/asan_mac.cc | 4 ++++ compiler-rt/lib/asan/asan_posix.cc | 12 ------------ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/compiler-rt/lib/asan/asan_intercepted_functions.h b/compiler-rt/lib/asan/asan_intercepted_functions.h index 1f174fb..5abc3f4 100644 --- a/compiler-rt/lib/asan/asan_intercepted_functions.h +++ b/compiler-rt/lib/asan/asan_intercepted_functions.h @@ -51,12 +51,16 @@ using __sanitizer::uptr; # define ASAN_INTERCEPT_STRNLEN 0 #endif +#if defined(__linux__) && !defined(ANDROID) +# define ASAN_INTERCEPT_SWAPCONTEXT 1 +#else +# define ASAN_INTERCEPT_SWAPCONTEXT 0 +#endif + #if !defined(ANDROID) && !defined(_WIN32) # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 1 -# define ASAN_INTERCEPT_SWAPCONTEXT 1 #else # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 0 -# define ASAN_INTERCEPT_SWAPCONTEXT 0 #endif // On Darwin siglongjmp tailcalls longjmp, so we don't want to intercept it @@ -90,12 +94,6 @@ DECLARE_FUNCTION_AND_WRAPPER(int, sigaction, int sig, DECLARE_FUNCTION_AND_WRAPPER(void*, signal, int signum, void *handler); # endif -// ucontext.h -# if ASAN_INTERCEPT_SWAPCONTEXT -DECLARE_FUNCTION_AND_WRAPPER(int, swapcontext, struct ucontext_t *oucp, - struct ucontext_t *ucp); -# endif - // setjmp.h DECLARE_FUNCTION_AND_WRAPPER(void, longjmp, void *env, int value); # if ASAN_INTERCEPT__LONGJMP diff --git a/compiler-rt/lib/asan/asan_linux.cc b/compiler-rt/lib/asan/asan_linux.cc index 2e6934e..a70adee 100644 --- a/compiler-rt/lib/asan/asan_linux.cc +++ b/compiler-rt/lib/asan/asan_linux.cc @@ -170,6 +170,23 @@ void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) { } } +#if !ASAN_ANDROID +void ClearShadowMemoryForContext(void *context) { + ucontext_t *ucp = (ucontext_t*)context; + uptr sp = (uptr)ucp->uc_stack.ss_sp; + uptr size = ucp->uc_stack.ss_size; + // Align to page size. + uptr bottom = sp & ~(kPageSize - 1); + size += sp - bottom; + size = RoundUpTo(size, kPageSize); + PoisonShadow(bottom, size, 0); +} +#else +void ClearShadowMemoryForContext(void *context) { + UNIMPLEMENTED(); +} +#endif + } // namespace __asan #endif // __linux__ diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index 771b8b28..e4e897e 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -171,6 +171,10 @@ void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) { } } +void ClearShadowMemoryForContext(void *context) { + UNIMPLEMENTED(); +} + // The range of pages to be used for escape islands. // TODO(glider): instead of mapping a fixed range we must find a range of // unmapped pages in vmmap and take them. diff --git a/compiler-rt/lib/asan/asan_posix.cc b/compiler-rt/lib/asan/asan_posix.cc index 699af68..ceaf120 100644 --- a/compiler-rt/lib/asan/asan_posix.cc +++ b/compiler-rt/lib/asan/asan_posix.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough. @@ -96,17 +95,6 @@ void InstallSignalHandlers() { MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV); } -void ClearShadowMemoryForContext(void *context) { - ucontext_t *ucp = (ucontext_t*)context; - uptr sp = (uptr)ucp->uc_stack.ss_sp; - uptr size = ucp->uc_stack.ss_size; - // Align to page size. - uptr bottom = sp & ~(kPageSize - 1); - size += sp - bottom; - size = RoundUpTo(size, kPageSize); - PoisonShadow(bottom, size, 0); -} - // ---------------------- TSD ---------------- {{{1 static pthread_key_t tsd_key; -- 2.7.4