Date: Sun, 1 May 2005 02:40:05 GMT From: Peter Wemm <peter@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 76312 for review Message-ID: <200505010240.j412e5Cq011928@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=76312 Change 76312 by peter@peter_daintree on 2005/05/01 02:40:00 IFC @76311 Affected files ... .. //depot/projects/hammer/lib/libthr/Makefile#10 integrate .. //depot/projects/hammer/lib/libthr/arch/i386/i386/pthread_md.c#4 integrate .. //depot/projects/hammer/lib/libthr/arch/i386/include/pthread_md.h#3 integrate .. //depot/projects/hammer/lib/libthr/support/Makefile.inc#1 branch .. //depot/projects/hammer/lib/libthr/thread/thr_create.c#16 integrate Differences ... ==== //depot/projects/hammer/lib/libthr/Makefile#10 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/lib/libthr/Makefile,v 1.11 2005/04/12 03:00:28 davidxu Exp $ +# $FreeBSD: src/lib/libthr/Makefile,v 1.12 2005/04/23 02:48:58 davidxu Exp $ # # All library objects contain FreeBSD revision strings by default; they may be # excluded as a space-saving measure. To produce a library that does @@ -30,6 +30,7 @@ PRECIOUSLIB= .include "${.CURDIR}/arch/${MACHINE_ARCH}/Makefile.inc" +.include "${.CURDIR}/support/Makefile.inc" .include "${.CURDIR}/sys/Makefile.inc" .include "${.CURDIR}/thread/Makefile.inc" ==== //depot/projects/hammer/lib/libthr/arch/i386/i386/pthread_md.c#4 (text+ko) ==== @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libthr/arch/i386/i386/pthread_md.c,v 1.3 2005/04/23 02:14:38 davidxu Exp $ + * $FreeBSD: src/lib/libthr/arch/i386/i386/pthread_md.c,v 1.5 2005/04/23 03:34:43 davidxu Exp $ */ #include <sys/types.h> @@ -35,18 +35,11 @@ #include "pthread_md.h" -int _thr_using_setbase; - struct tcb * _tcb_ctor(struct pthread *thread, int initial) { -#ifndef COMPAT_32BIT - union descriptor ldt; - void *base; -#endif struct tcb *tcb; void *oldtls; - int error; if (initial) __asm __volatile("movl %%gs:0, %0" : "=r" (oldtls)); @@ -54,51 +47,15 @@ oldtls = NULL; tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); - if (tcb) { + if (tcb) tcb->tcb_thread = thread; -#ifndef COMPAT_32BIT - tcb->tcb_ldt = -1; - switch (_thr_using_setbase) { - case 1: /* use i386_set_gsbase() in _kcb_set */ - break; - case 0: /* Untested, try the get/set_gsbase routines once */ - error = i386_get_gsbase(&base); - if (error == 0) { - _thr_using_setbase = 1; - break; - } - /* fall through */ - case 2: /* Use the user_ldt code, we must have an old kernel */ - _thr_using_setbase = 2; - ldt.sd.sd_hibase = (unsigned int)tcb >> 24; - ldt.sd.sd_lobase = (unsigned int)tcb & 0xFFFFFF; - ldt.sd.sd_hilimit = (sizeof(struct tcb) >> 16) & 0xF; - ldt.sd.sd_lolimit = sizeof(struct tcb) & 0xFFFF; - ldt.sd.sd_type = SDT_MEMRWA; - ldt.sd.sd_dpl = SEL_UPL; - ldt.sd.sd_p = 1; - ldt.sd.sd_xx = 0; - ldt.sd.sd_def32 = 1; - ldt.sd.sd_gran = 0; /* no more than 1M */ - tcb->tcb_ldt = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1); - if (tcb->tcb_ldt < 0) { - _rtld_free_tls(tcb, sizeof(struct tcb), 16); - tcb = NULL; - } - break; - } -#endif - } return (tcb); } void _tcb_dtor(struct tcb *tcb) { -#ifndef COMPAT_32BIT - if (tcb->tcb_ldt >= 0) - i386_set_ldt(tcb->tcb_ldt, NULL, 1); -#endif + _rtld_free_tls(tcb, sizeof(struct tcb), 16); } ==== //depot/projects/hammer/lib/libthr/arch/i386/include/pthread_md.h#3 (text+ko) ==== @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libthr/arch/i386/include/pthread_md.h,v 1.2 2005/04/14 00:44:07 peter Exp $ + * $FreeBSD: src/lib/libthr/arch/i386/include/pthread_md.h,v 1.4 2005/04/27 01:29:03 davidxu Exp $ */ /* @@ -49,7 +49,6 @@ struct tcb *tcb_self; /* required by rtld */ void *tcb_dtv; /* required by rtld */ struct pthread *tcb_thread; - int tcb_ldt; }; /* @@ -87,19 +86,7 @@ static __inline void _tcb_set(struct tcb *tcb) { -#ifndef COMPAT_32BIT - int val; - - if (_thr_using_setbase == 1) { - i386_set_gsbase(tcb); - } else { - val = (tcb->tcb_ldt << 3) | 7; - __asm __volatile("movl %0, %%gs" : : "r" (val)); - } -#else - _amd64_set_gsbase(tcb); -#endif - + i386_set_gsbase(tcb); } /* Get the current kcb. */ ==== //depot/projects/hammer/lib/libthr/thread/thr_create.c#16 (text+ko) ==== @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libthr/thread/thr_create.c,v 1.21 2005/04/12 03:00:28 davidxu Exp $ + * $FreeBSD: src/lib/libthr/thread/thr_create.c,v 1.22 2005/04/23 02:48:59 davidxu Exp $ */ #include <errno.h> @@ -53,9 +53,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, void *(*start_routine) (void *), void *arg) { - ucontext_t uc; - sigset_t sigmask, oldsigmask; struct pthread *curthread, *new_thread; + struct thr_param param; int ret = 0, locked; _thr_check_init(); @@ -70,6 +69,8 @@ if ((new_thread = _thr_alloc(curthread)) == NULL) return (EAGAIN); + memset(¶m, 0, sizeof(param)); + if (attr == NULL || *attr == NULL) /* Use the default thread attributes: */ new_thread->attr = _pthread_attr_default; @@ -108,12 +109,6 @@ new_thread->arg = arg; new_thread->cancelflags = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED; - getcontext(&uc); - SIGFILLSET(uc.uc_sigmask); - uc.uc_stack.ss_sp = new_thread->attr.stackaddr_attr; - uc.uc_stack.ss_size = new_thread->attr.stacksize_attr; - makecontext(&uc, (void (*)(void))thread_start, 1, new_thread); - /* * Check if this thread is to inherit the scheduling * attributes from its parent: @@ -146,15 +141,7 @@ if (new_thread->attr.suspend == THR_CREATE_SUSPENDED) new_thread->flags = THR_FLAGS_SUSPENDED; new_thread->state = PS_RUNNING; - /* - * Thread created by thr_create() inherits currrent thread - * sigmask, however, before new thread setup itself correctly, - * it can not handle signal, so we should masks all signals here. - */ - SIGFILLSET(sigmask); - SIGDELSET(sigmask, SIGTRAP); - __sys_sigprocmask(SIG_SETMASK, &sigmask, &oldsigmask); - new_thread->sigmask = oldsigmask; + /* Add the new thread. */ _thr_link(curthread, new_thread); /* Return thread pointer eariler so that new thread can use it. */ @@ -164,9 +151,19 @@ locked = 1; } else locked = 0; + param.start_func = (void (*)(void *)) thread_start; + param.arg = new_thread; + param.stack_base = new_thread->attr.stackaddr_attr; + param.stack_size = new_thread->attr.stacksize_attr; + param.tls_base = (char *)new_thread->tcb; + param.tls_size = sizeof(struct tcb); + param.child_tid = &new_thread->tid; + param.parent_tid = &new_thread->tid; + param.flags = 0; + if (new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) + param.flags |= THR_SYSTEM_SCOPE; /* Schedule the new thread. */ - ret = thr_create(&uc, &new_thread->tid, 0); - __sys_sigprocmask(SIG_SETMASK, &oldsigmask, NULL); + ret = thr_new(¶m, sizeof(param)); if (ret != 0) { if (locked) THR_THREAD_UNLOCK(curthread, new_thread); @@ -219,11 +216,6 @@ static void thread_start(struct pthread *curthread) { - _tcb_set(curthread->tcb); - - /* Thread was created with all signals blocked, unblock them. */ - __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); - if (curthread->flags & THR_FLAGS_NEED_SUSPEND) _thr_suspend_check(curthread);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200505010240.j412e5Cq011928>