[compiler-rt] r200310 - [ASan] Move the sigaltstack() bits to sanitizer_common.
Alexey Samsonov
samsonov at google.com
Tue Jan 28 06:08:39 PST 2014
On Tue, Jan 28, 2014 at 3:12 PM, Alexander Potapenko <glider at google.com>wrote:
> Author: glider
> Date: Tue Jan 28 05:12:29 2014
> New Revision: 200310
>
> URL: http://llvm.org/viewvc/llvm-project?rev=200310&view=rev
> Log:
> [ASan] Move the sigaltstack() bits to sanitizer_common.
> This change is a part of refactoring intended to have common signal
> handling behavior in all tools.
> Note that this particular change doesn't enable use_sigaltstack support in
> every tool.
>
>
> Modified:
> compiler-rt/trunk/lib/asan/asan_internal.h
> compiler-rt/trunk/lib/asan/asan_posix.cc
> compiler-rt/trunk/lib/asan/asan_win.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
>
> Modified: compiler-rt/trunk/lib/asan/asan_internal.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_internal.h (original)
> +++ compiler-rt/trunk/lib/asan/asan_internal.h Tue Jan 28 05:12:29 2014
> @@ -74,8 +74,6 @@ void GetPcSpBp(void *context, uptr *pc,
>
> void MaybeReexec();
> bool AsanInterceptsSignal(int signum);
> -void SetAlternateSignalStack();
> -void UnsetAlternateSignalStack();
> void InstallSignalHandlers();
> void ReadContextStack(void *context, uptr *stack, uptr *ssize);
> void AsanPlatformThreadInit();
>
> Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_posix.cc Tue Jan 28 05:12:29 2014
> @@ -56,33 +56,6 @@ static void ASAN_OnSIGSEGV(int, sigi
> ReportSIGSEGV(pc, sp, bp, addr);
> }
>
> -void SetAlternateSignalStack() {
> - stack_t altstack, oldstack;
> - CHECK_EQ(0, sigaltstack(0, &oldstack));
> - // If the alternate stack is already in place, do nothing.
> - if ((oldstack.ss_flags & SS_DISABLE) == 0) return;
> - // TODO(glider): the mapped stack should have the MAP_STACK flag in the
> - // future. It is not required by man 2 sigaltstack now (they're using
> - // malloc()).
> - void* base = MmapOrDie(kAltStackSize, __FUNCTION__);
> - altstack.ss_sp = base;
> - altstack.ss_flags = 0;
> - altstack.ss_size = kAltStackSize;
> - CHECK_EQ(0, sigaltstack(&altstack, 0));
> - VReport(1, "Alternative stack for T%d set: [%p,%p)\n",
> - GetCurrentTidOrInvalid(), altstack.ss_sp,
> - (char *)altstack.ss_sp + altstack.ss_size);
> -}
> -
> -void UnsetAlternateSignalStack() {
> - stack_t altstack, oldstack;
> - altstack.ss_sp = 0;
> - altstack.ss_flags = SS_DISABLE;
> - altstack.ss_size = 0;
> - CHECK_EQ(0, sigaltstack(&altstack, &oldstack));
> - UnmapOrDie(oldstack.ss_sp, oldstack.ss_size);
> -}
> -
> void InstallSignalHandlers() {
> // Set the alternate signal stack for the main thread.
> // This will cause SetAlternateSignalStack to be called twice, but the
> stack
>
> Modified: compiler-rt/trunk/lib/asan/asan_win.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_win.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_win.cc Tue Jan 28 05:12:29 2014
> @@ -70,14 +70,6 @@ void *AsanDoesNotSupportStaticLinkage()
> return 0;
> }
>
> -void SetAlternateSignalStack() {
> - // FIXME: Decide what to do on Windows.
> -}
> -
> -void UnsetAlternateSignalStack() {
> - // FIXME: Decide what to do on Windows.
> -}
> -
> void InstallSignalHandlers() {
> // FIXME: Decide what to do on Windows.
> }
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Jan 28
> 05:12:29 2014
> @@ -213,6 +213,10 @@ typedef void (*CheckFailedCallbackType)(
> u64, u64);
> void SetCheckFailedCallback(CheckFailedCallbackType callback);
>
> +// Functions related to signal handling.
> +void SetAlternateSignalStack();
> +void UnsetAlternateSignalStack();
> +
> // We don't want a summary too long.
> const int kMaxSummaryLength = 1024;
> // Construct a one-line string:
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Tue Jan 28
> 05:12:29 2014
> @@ -21,6 +21,7 @@
> #include "sanitizer_stacktrace.h"
>
> #include <sys/mman.h>
> +#include <signal.h>
>
why this include?
>
> namespace __sanitizer {
>
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Tue
> Jan 28 05:12:29 2014
> @@ -20,6 +20,7 @@
>
> #include <errno.h>
> #include <pthread.h>
> +#include <signal.h>
> #include <stdlib.h>
> #include <sys/mman.h>
> #include <sys/resource.h>
> @@ -89,6 +90,33 @@ int internal_isatty(fd_t fd) {
> return isatty(fd);
> }
>
> +// TODO(glider): different tools may require different altstack size.
> +static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not
> enough.
> +
> +void SetAlternateSignalStack() {
> + stack_t altstack, oldstack;
> + CHECK_EQ(0, sigaltstack(0, &oldstack));
> + // If the alternate stack is already in place, do nothing.
> + if ((oldstack.ss_flags & SS_DISABLE) == 0) return;
> + // TODO(glider): the mapped stack should have the MAP_STACK flag in the
> + // future. It is not required by man 2 sigaltstack now (they're using
> + // malloc()).
> + void* base = MmapOrDie(kAltStackSize, __FUNCTION__);
> + altstack.ss_sp = base;
> + altstack.ss_flags = 0;
> + altstack.ss_size = kAltStackSize;
> + CHECK_EQ(0, sigaltstack(&altstack, 0));
> +}
> +
> +void UnsetAlternateSignalStack() {
> + stack_t altstack, oldstack;
> + altstack.ss_sp = 0;
> + altstack.ss_flags = SS_DISABLE;
> + altstack.ss_size = 0;
> + CHECK_EQ(0, sigaltstack(&altstack, &oldstack));
> + UnmapOrDie(oldstack.ss_sp, oldstack.ss_size);
> +}
> +
> } // namespace __sanitizer
>
> #endif
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=200310&r1=200309&r2=200310&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Tue Jan 28
> 05:12:29 2014
> @@ -413,6 +413,14 @@ void RawWrite(const char *buffer) {
> }
> }
>
> +void SetAlternateSignalStack() {
> + // FIXME: Decide what to do on Windows.
> +}
> +
> +void UnsetAlternateSignalStack() {
> + // FIXME: Decide what to do on Windows.
> +}
> +
> } // namespace __sanitizer
>
> #endif // _WIN32
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140128/05e1dd11/attachment.html>
More information about the llvm-commits
mailing list