[PATCH] Run the callback on a separate stack in StopTheWorld.
Sergey Matveev
earthdok at google.com
Mon Apr 1 07:17:08 PDT 2013
- Factored out TidySigaction to a separate CL.
Hi kcc, glider, samsonov,
http://llvm-reviews.chandlerc.com/D592
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D592?vs=1452&id=1461#toc
Files:
lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
Index: lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
+++ lib/sanitizer_common/sanitizer_stoptheworld_linux.cc
@@ -248,6 +248,30 @@
return exit_code;
}
+class ScopedStackSpaceWithGuard {
+ public:
+ explicit ScopedStackSpaceWithGuard(uptr stack_size) {
+ stack_size_ = stack_size;
+ guard_size_ = GetPageSizeCached();
+ // XXX: Omitting MAP_STACK here works in current kernels but might break in
+ // the future.
+ guard_start_ = (uptr)MmapOrDie(stack_size_ + guard_size_,
+ "ScopedStackWithGuard");
+ CHECK_EQ(guard_start_, (uptr)Mprotect((uptr)guard_start_, guard_size_));
+ }
+ ~ScopedStackSpaceWithGuard() {
+ UnmapOrDie((void *)guard_start_, stack_size_ + guard_size_);
+ }
+ void *Bottom() const {
+ return (void *)(guard_start_ + stack_size_ + guard_size_);
+ }
+
+ private:
+ uptr stack_size_;
+ uptr guard_size_;
+ uptr guard_start_;
+};
+
static sigset_t blocked_sigset;
static sigset_t old_sigset;
static struct sigaction old_sigactions[ARRAY_SIZE(kUnblockedSignals)];
@@ -282,16 +306,12 @@
struct TracerThreadArgument tracer_thread_argument;
tracer_thread_argument.callback = callback;
tracer_thread_argument.callback_argument = argument;
+ const uptr kTracerStackSize = 2 * 1024 * 1024;
+ ScopedStackSpaceWithGuard tracer_stack(kTracerStackSize);
// Block the execution of TracerThread until after we have set ptrace
// permissions.
tracer_thread_argument.mutex.Lock();
- // The tracer thread will run on the same stack, so we must reserve some
- // stack space for the caller thread to run in as it waits on the tracer.
- const uptr kReservedStackSize = 4096;
- // Get a 16-byte aligned pointer for stack.
- int a_local_variable __attribute__((__aligned__(16)));
- pid_t tracer_pid = clone(TracerThread,
- (char *)&a_local_variable - kReservedStackSize,
+ pid_t tracer_pid = clone(TracerThread, tracer_stack.Bottom(),
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_UNTRACED,
&tracer_thread_argument, 0, 0, 0);
if (tracer_pid < 0) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D592.3.patch
Type: text/x-patch
Size: 2257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130401/dd1d50b8/attachment.bin>
More information about the llvm-commits
mailing list