Date: Mon, 10 Jan 2011 16:10:25 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r217224 - head/lib/libthr/thread Message-ID: <201101101610.p0AGAPpW085410@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Mon Jan 10 16:10:25 2011 New Revision: 217224 URL: http://svn.freebsd.org/changeset/base/217224 Log: 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> Modified: head/lib/libthr/thread/thr_stack.c Modified: head/lib/libthr/thread/thr_stack.c ============================================================================== --- head/lib/libthr/thread/thr_stack.c Mon Jan 10 16:09:35 2011 (r217223) +++ head/lib/libthr/thread/thr_stack.c Mon Jan 10 16:10:25 2011 (r217224) @@ -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 _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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101101610.p0AGAPpW085410>