aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/pthread_attr.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-08-27 15:32:01 -0700
committerElliott Hughes <enh@google.com>2014-08-27 15:32:01 -0700
commit9e4ffa7032eaab308876b8e3da86b05c3c613878 (patch)
tree83e23ad0b0ba82c017cbf292abd7594d2148f316 /libc/bionic/pthread_attr.cpp
parent34da32e7dd00270e98b845f8a810a6f12ffffb9b (diff)
downloadandroid_bionic-9e4ffa7032eaab308876b8e3da86b05c3c613878.tar.gz
android_bionic-9e4ffa7032eaab308876b8e3da86b05c3c613878.tar.bz2
android_bionic-9e4ffa7032eaab308876b8e3da86b05c3c613878.zip
Have pthread_attr_getstack for the main thread report RLIMIT_STACK...
...rather than just what's already mapped in. This seems somewhat contrary to POSIX's "All pages within the stack described by stackaddr and stacksize shall be both readable and writable by the thread", but it's what glibc does. Bug: 17111575 Change-Id: If9e2dfad9a603c0d0615a8123aacda4946e95b2c
Diffstat (limited to 'libc/bionic/pthread_attr.cpp')
-rw-r--r--libc/bionic/pthread_attr.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index 8df3bffac..c93970a19 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -116,6 +116,16 @@ int pthread_attr_setstack(pthread_attr_t* attr, void* stack_base, size_t stack_s
static int __pthread_attr_getstack_main_thread(void** stack_base, size_t* stack_size) {
ErrnoRestorer errno_restorer;
+ rlimit stack_limit;
+ if (getrlimit(RLIMIT_STACK, &stack_limit) == -1) {
+ return errno;
+ }
+
+ // If the current RLIMIT_STACK is RLIM_INFINITY, only admit to an 8MiB stack for sanity's sake.
+ if (stack_limit.rlim_cur == RLIM_INFINITY) {
+ stack_limit.rlim_cur = 8 * 1024 * 1024;
+ }
+
// It doesn't matter which thread we are; we're just looking for "[stack]".
FILE* fp = fopen("/proc/self/maps", "re");
if (fp == NULL) {
@@ -126,17 +136,8 @@ static int __pthread_attr_getstack_main_thread(void** stack_base, size_t* stack_
if (ends_with(line, " [stack]\n")) {
uintptr_t lo, hi;
if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &lo, &hi) == 2) {
- *stack_base = reinterpret_cast<void*>(lo);
- *stack_size = hi - lo;
-
- // Does our current RLIMIT_STACK mean we won't actually get everything /proc/maps promises?
- rlimit stack_limit;
- if (getrlimit(RLIMIT_STACK, &stack_limit) != -1) {
- if (*stack_size > stack_limit.rlim_cur) {
- *stack_size = stack_limit.rlim_cur;
- }
- }
-
+ *stack_size = stack_limit.rlim_cur;
+ *stack_base = reinterpret_cast<void*>(hi - *stack_size);
fclose(fp);
return 0;
}