diff options
author | Josh Gao <jmgao@google.com> | 2017-03-06 17:45:33 -0800 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2017-03-08 16:43:59 -0800 |
commit | 415daa8cca875d348c003a95cf7c44c9231eae75 (patch) | |
tree | 0846b1476c61bb7d870fc8e031099d634c0c2e3c | |
parent | e429bf2f696282537efb577feb7cb9fd534e7ace (diff) |
Increase signal stack size on 32-bit to 16kB.
snprintf to a buffer of length PATH_MAX consumes about 7kB of stack.
Bug: http://b/35858739
Test: bionic-unit-tests --gtest_filter="*big_enough*"
Change-Id: I34a7f42c1fd2582ca0d0a9b7e7a5290bc1cc19b1
-rw-r--r-- | libc/bionic/pthread_internal.h | 10 | ||||
-rwxr-xr-x | tests/pthread_test.cpp | 27 |
2 files changed, 22 insertions, 15 deletions
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h index b17029968..6faf5a4ff 100644 --- a/libc/bionic/pthread_internal.h +++ b/libc/bionic/pthread_internal.h @@ -141,13 +141,11 @@ static inline __always_inline bionic_tls& __get_bionic_tls() { __LIBC_HIDDEN__ void pthread_key_clean_all(void); -#if defined(__LP64__) -// SIGSTKSZ is not big enough for 64-bit arch. -// See https://code.google.com/p/android/issues/detail?id=187064. +// SIGSTKSZ (8kB) is not big enough. +// snprintf to a stack buffer of size PATH_MAX consumes ~7kB of stack. +// Also, on 64-bit, logging uses more than 8kB by itself: +// https://code.google.com/p/android/issues/detail?id=187064 #define SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE (16 * 1024) -#else -#define SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE SIGSTKSZ -#endif /* * Traditionally we gave threads a 1MiB stack. When we started diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp index 024a6754e..4fb15ad8a 100755 --- a/tests/pthread_test.cpp +++ b/tests/pthread_test.cpp @@ -1888,17 +1888,26 @@ static volatile bool signal_handler_on_altstack_done; static void SignalHandlerOnAltStack(int signo, siginfo_t*, void*) { ASSERT_EQ(SIGUSR1, signo); - // Check if we have enough stack space for unwinding. - int count = 0; - _Unwind_Backtrace(FrameCounter, &count); - ASSERT_GT(count, 0); - // Check if we have enough stack space for logging. - std::string s(2048, '*'); - GTEST_LOG_(INFO) << s; - signal_handler_on_altstack_done = true; + { + // Check if we have enough stack space for unwinding. + int count = 0; + _Unwind_Backtrace(FrameCounter, &count); + ASSERT_GT(count, 0); + } + { + // Check if we have enough stack space for logging. + std::string s(2048, '*'); + GTEST_LOG_(INFO) << s; + signal_handler_on_altstack_done = true; + } + { + // Check if we have enough stack space for snprintf to a PATH_MAX buffer, plus some extra. + char buf[PATH_MAX + 2048]; + ASSERT_GT(snprintf(buf, sizeof(buf), "/proc/%d/status", getpid()), 0); + } } -TEST(pthread, big_enough_signal_stack_for_64bit_arch) { +TEST(pthread, big_enough_signal_stack) { signal_handler_on_altstack_done = false; ScopedSignalHandler handler(SIGUSR1, SignalHandlerOnAltStack, SA_SIGINFO | SA_ONSTACK); kill(getpid(), SIGUSR1); |