summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2013-09-12 21:47:20 -0700
committerBrian Carlstrom <bdc@google.com>2013-09-13 16:25:25 -0700
commit322e7bce235ec6e3f82f65669423a1d9e997b51e (patch)
tree17a4d755030ee77fb1773eb570efcb157ea9113a
parent98c726ec9b40e75efdd3ea027cd9cc627329f85e (diff)
downloadbionic-322e7bce235ec6e3f82f65669423a1d9e997b51e.zip
bionic-322e7bce235ec6e3f82f65669423a1d9e997b51e.tar.gz
bionic-322e7bce235ec6e3f82f65669423a1d9e997b51e.tar.bz2
Use kernel default for initial thread size
Bug: 10697851 Change-Id: I8d980f5e0b584799536f6e6b891056c968d26cdf
-rw-r--r--libc/bionic/libc_init_common.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 1fc490e..c10abad 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -37,6 +37,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/auxv.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include <unistd.h>
#include "atexit.h"
@@ -62,6 +64,21 @@ uintptr_t __stack_chk_guard = 0;
unsigned int __page_size = PAGE_SIZE;
unsigned int __page_shift = PAGE_SHIFT;
+static size_t get_stack_size() {
+ const size_t minimal_stack_size = 128 * 1024;
+ size_t stack_size = minimal_stack_size;
+ struct rlimit stack_limit;
+ int rlimit_result = getrlimit(RLIMIT_STACK, &stack_limit);
+ if ((rlimit_result == 0) && (stack_limit.rlim_cur != RLIM_INFINITY)) {
+ stack_size = stack_limit.rlim_cur;
+ stack_size = (stack_size & ~(PAGE_SIZE - 1));
+ if (stack_size < minimal_stack_size) {
+ stack_size = minimal_stack_size;
+ }
+ }
+ return stack_size;
+}
+
/* Init TLS for the initial thread. Called by the linker _before_ libc is mapped
* in memory. Beware: all writes to libc globals from this function will
* apply to linker-private copies and will not be visible from libc later on.
@@ -76,9 +93,9 @@ unsigned int __page_shift = PAGE_SHIFT;
void __libc_init_tls(KernelArgumentBlock& args) {
__libc_auxv = args.auxv;
- unsigned stack_top = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
- unsigned stack_size = 128 * 1024;
- unsigned stack_bottom = stack_top - stack_size;
+ uintptr_t stack_top = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
+ size_t stack_size = get_stack_size();
+ uintptr_t stack_bottom = stack_top - stack_size;
static void* tls[BIONIC_TLS_SLOTS];
static pthread_internal_t thread;