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