Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
[ASan] Move the sigaltstack() bits to sanitizer_common.
Browse files Browse the repository at this point in the history
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.



git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200310 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ramosian-glider committed Jan 28, 2014
1 parent dfec81c commit 222bbfa
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
2 changes: 0 additions & 2 deletions lib/asan/asan_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);

void MaybeReexec();
bool AsanInterceptsSignal(int signum);
void SetAlternateSignalStack();
void UnsetAlternateSignalStack();
void InstallSignalHandlers();
void ReadContextStack(void *context, uptr *stack, uptr *ssize);
void AsanPlatformThreadInit();
Expand Down
27 changes: 0 additions & 27 deletions lib/asan/asan_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,6 @@ static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
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
Expand Down
8 changes: 0 additions & 8 deletions lib/asan/asan_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
4 changes: 4 additions & 0 deletions lib/sanitizer_common/sanitizer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ typedef void (*CheckFailedCallbackType)(const char *, int, const char *,
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:
Expand Down
1 change: 1 addition & 0 deletions lib/sanitizer_common/sanitizer_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "sanitizer_stacktrace.h"

#include <sys/mman.h>
#include <signal.h>

namespace __sanitizer {

Expand Down
28 changes: 28 additions & 0 deletions lib/sanitizer_common/sanitizer_posix_libcdep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions lib/sanitizer_common/sanitizer_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 222bbfa

Please sign in to comment.