aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/pthread_attr.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-07-16 13:14:24 -0700
committerElliott Hughes <enh@google.com>2013-07-16 13:14:24 -0700
commitaa754dca90487356cabf07ade0e8d88c2630b784 (patch)
treeb4cda0d4fa3935abd85b3ee178d35d0738e8a744 /libc/bionic/pthread_attr.cpp
parent9562d38df1e4aba941b3433cfd0922fee5ea258b (diff)
downloadandroid_bionic-aa754dca90487356cabf07ade0e8d88c2630b784.tar.gz
android_bionic-aa754dca90487356cabf07ade0e8d88c2630b784.tar.bz2
android_bionic-aa754dca90487356cabf07ade0e8d88c2630b784.zip
Improve stack overflow diagnostics.
We notify debuggerd of problems by installing signal handlers. That's fine except for when the signal is caused by us running off the end of a thread's stack and into the guard page. Bug: 8557703 Change-Id: I1ef65b4bb3bbca7e9a9743056177094921e60ed3
Diffstat (limited to 'libc/bionic/pthread_attr.cpp')
-rw-r--r--libc/bionic/pthread_attr.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index fe1ed4a98..d7c6c1396 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -30,12 +30,16 @@
#include "pthread_internal.h"
-#define DEFAULT_STACK_SIZE (1024 * 1024)
+// Traditionally we give threads a 1MiB stack. When we started allocating per-thread
+// alternate signal stacks to ease debugging of stack overflows, we subtracted the
+// same amount we were using there from the default thread stack size. This should
+// keep memory usage roughly constant.
+#define DEFAULT_THREAD_STACK_SIZE ((1 * 1024 * 1024) - SIGSTKSZ)
int pthread_attr_init(pthread_attr_t* attr) {
attr->flags = 0;
attr->stack_base = NULL;
- attr->stack_size = DEFAULT_STACK_SIZE;
+ attr->stack_size = DEFAULT_THREAD_STACK_SIZE;
attr->guard_size = PAGE_SIZE;
attr->sched_policy = SCHED_NORMAL;
attr->sched_priority = 0;