From owner-svn-src-all@FreeBSD.ORG Mon Jan 10 16:10:25 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 56E5E1065672; Mon, 10 Jan 2011 16:10:25 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 45E308FC1C; Mon, 10 Jan 2011 16:10:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p0AGAPjq085412; Mon, 10 Jan 2011 16:10:25 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0AGAPpW085410; Mon, 10 Jan 2011 16:10:25 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201101101610.p0AGAPpW085410@svn.freebsd.org> From: Konstantin Belousov Date: Mon, 10 Jan 2011 16:10:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r217224 - head/lib/libthr/thread X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jan 2011 16:10:25 -0000 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 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 #include #include +#include +#include #include #include #include @@ -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)