diff options
author | kib <kib@FreeBSD.org> | 2011-01-10 16:10:25 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2011-01-10 16:10:25 +0000 |
commit | 2325865369c1fbead81ec6db367b2ae00f57ff20 (patch) | |
tree | 7b3832f55586523f0e163291a10e86e5c25bdbe1 /lib/libthr/thread/thr_stack.c | |
parent | 8106498fdd7b4a4f16bbab0b2f852b59f9dd6a6f (diff) | |
download | FreeBSD-src-2325865369c1fbead81ec6db367b2ae00f57ff20.zip FreeBSD-src-2325865369c1fbead81ec6db367b2ae00f57ff20.tar.gz |
For the process that already loaded libthr but still not initialized
threading, fall back to libc method of performing
__pthread_map_stacks_exec() job.
Reported and tested by: Mykola Dzham <i levsha me>
Diffstat (limited to 'lib/libthr/thread/thr_stack.c')
-rw-r--r-- | lib/libthr/thread/thr_stack.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_stack.c b/lib/libthr/thread/thr_stack.c index cb390cc..15a9c82 100644 --- a/lib/libthr/thread/thr_stack.c +++ b/lib/libthr/thread/thr_stack.c @@ -30,6 +30,8 @@ #include <sys/types.h> #include <sys/mman.h> #include <sys/queue.h> +#include <sys/resource.h> +#include <sys/sysctl.h> #include <stdlib.h> #include <pthread.h> #include <link.h> @@ -139,6 +141,26 @@ _thr_stack_fix_protection(struct pthread *thrd) _rtld_get_stack_prot()); } +static void +singlethread_map_stacks_exec(void) +{ + int mib[2]; + struct rlimit rlim; + u_long usrstack; + size_t len; + + mib[0] = CTL_KERN; + mib[1] = KERN_USRSTACK; + len = sizeof(usrstack); + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0) + == -1) + return; + if (getrlimit(RLIMIT_STACK, &rlim) == -1) + return; + mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur), + rlim.rlim_cur, _rtld_get_stack_prot()); +} + void __pthread_map_stacks_exec(void); void __pthread_map_stacks_exec(void) @@ -146,6 +168,10 @@ __pthread_map_stacks_exec(void) struct pthread *curthread, *thrd; struct stack *st; + if (!_thr_is_inited()) { + singlethread_map_stacks_exec(); + return; + } curthread = _get_curthread(); THREAD_LIST_RDLOCK(curthread); LIST_FOREACH(st, &mstackq, qe) |