diff options
author | Elliott Hughes <enh@google.com> | 2014-10-09 14:01:47 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-10-09 14:01:47 -0700 |
commit | 9afb2f2106a5d659854c175c574c1c31e0e205a2 (patch) | |
tree | cbcc21f633b85ff022827d5e2c3ac87db3a5e2c4 | |
parent | d0944d9ed38be0d74c3d8876f0f36b9ddc0ce38c (diff) | |
download | bionic-9afb2f2106a5d659854c175c574c1c31e0e205a2.zip bionic-9afb2f2106a5d659854c175c574c1c31e0e205a2.tar.gz bionic-9afb2f2106a5d659854c175c574c1c31e0e205a2.tar.bz2 |
Fix pthread_attr_getstack under valgrind.
valgrind seems to mess with the stack enough that the kernel will
report "[stack:pid]" rather than "[stack]" in /proc/self/maps, so
switch to the task-specific file instead to force "[stack]". (There
are two conditions in the kernel code that decides which form to
output.)
Bug: 17897476
Change-Id: Iff85ceb6d52e8716251fab4e45d95a27184c5529
-rw-r--r-- | libc/bionic/pthread_attr.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp index c93970a..c65ccc1 100644 --- a/libc/bionic/pthread_attr.cpp +++ b/libc/bionic/pthread_attr.cpp @@ -31,6 +31,7 @@ #include <inttypes.h> #include <stdio.h> #include <sys/resource.h> +#include <unistd.h> #include "private/bionic_string_utils.h" #include "private/ErrnoRestorer.h" @@ -126,8 +127,12 @@ static int __pthread_attr_getstack_main_thread(void** stack_base, size_t* stack_ 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"); + // It shouldn't matter which thread we are because we're just looking for "[stack]", but + // valgrind seems to mess with the stack enough that the kernel will report "[stack:pid]" + // instead if you look in /proc/self/maps, so we need to look in /proc/pid/task/pid/maps. + char path[64]; + snprintf(path, sizeof(path), "/proc/self/task/%d/maps", getpid()); + FILE* fp = fopen(path, "re"); if (fp == NULL) { return errno; } @@ -143,7 +148,7 @@ static int __pthread_attr_getstack_main_thread(void** stack_base, size_t* stack_ } } } - __libc_fatal("No [stack] line found in /proc/self/maps!"); + __libc_fatal("No [stack] line found in \"%s\"!", path); } int pthread_attr_getstack(const pthread_attr_t* attr, void** stack_base, size_t* stack_size) { |