From: Joerg Sonnenberger Date: Tue, 3 May 2005 07:29:04 +0000 (+0000) Subject: Make errno a thread-local variable and remove the __error function. X-Git-Tag: v2.0.1~7509 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/9d315dd3ee66baf246138c2666983bb271a7418e Make errno a thread-local variable and remove the __error function. The handling of ceiling violations on mutexes can be improved, it currently needs two syscalls. --- diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 3202a2003e..fb0d655b2e 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,6 +1,6 @@ # @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # $FreeBSD: src/lib/libc/gen/Makefile.inc,v 1.62.2.19 2003/02/21 13:46:16 phantom Exp $ -# $DragonFly: src/lib/libc/gen/Makefile.inc,v 1.12 2005/04/27 19:00:46 asmodai Exp $ +# $DragonFly: src/lib/libc/gen/Makefile.inc,v 1.13 2005/05/03 07:29:04 joerg Exp $ # machine-independent gen sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/gen ${.CURDIR}/../libc/gen @@ -28,11 +28,15 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ shmat.c shmctl.c shmdt.c shmget.c siginterrupt.c siglist.c signal.c \ sigsetops.c sigwait.c sleep.c srand48.c stringlist.c strtofflags.c \ sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ - syslog.c telldir.c termios.c time.c times.c timezone.c tls.c \ + syslog.c telldir.c termios.c time.c times.c timezone.c \ tolower.c toupper.c ttyname.c ttyslot.c ualarm.c ulimit.c \ uname.c unvis.c usleep.c utime.c valloc.c vis.c \ wait.c wait3.c waitpid.c +.if ${LIB} != {c_rtld} +SRCS+= tls.c +.endif + # machine-dependent gen sources .include "${.CURDIR}/../libc/${MACHINE_ARCH}/gen/Makefile.inc" diff --git a/lib/libc/gen/errlst.c b/lib/libc/gen/errlst.c index 39a15d7b94..8a0330676d 100644 --- a/lib/libc/gen/errlst.c +++ b/lib/libc/gen/errlst.c @@ -31,6 +31,7 @@ * SUCH DAMAGE. * * @(#)errlst.c 8.2 (Berkeley) 11/16/93 + * $DragonFly: src/lib/libc/gen/errlst.c,v 1.3 2005/05/03 07:29:04 joerg Exp $ */ #include @@ -142,5 +143,5 @@ const char *const sys_errlist[] = { "Operation canceled", /* 85 - ECANCELED */ "Illegal byte sequence", /* 86 - EILSEQ */ }; -int errno; +__thread int errno; const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); diff --git a/lib/libc/i386/sys/cerror.S b/lib/libc/i386/sys/cerror.S index 90429692f6..cc7fb963d5 100644 --- a/lib/libc/i386/sys/cerror.S +++ b/lib/libc/i386/sys/cerror.S @@ -34,32 +34,34 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/sys/cerror.S,v 1.10 1999/08/27 23:59:38 peter Exp $ - * $DragonFly: src/lib/libc/i386/sys/cerror.S,v 1.3 2003/12/06 03:11:36 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/sys/cerror.S,v 1.4 2005/05/03 07:29:04 joerg Exp $ */ #include "SYS.h" .globl HIDENAME(cerror) - /* - * The __error() function is thread aware. For non-threaded - * programs and the initial threaded in threaded programs, - * it returns a pointer to the global errno variable. - */ - .globl CNAME(__error) - .type CNAME(__error),@function HIDENAME(cerror): - pushl %eax #ifdef PIC /* The caller must execute the PIC prologue before jumping to cerror. */ - call PIC_PLT(CNAME(__error)) +# ifdef __thread + movl %eax, PIC_GOT(CNAME(errno)) +# else + pushl %eax + leal errno@TLSGD(,%ebx,1), %eax + call ___tls_get_addr@PLT popl %ecx + movl %ecx, (%eax) +# endif PIC_EPILOGUE #else - call CNAME(__error) - popl %ecx +# ifdef __thread + movl %eax, errno +# else + movl %gs:0, %ecx + movl %eax, errno@NTPOFF(%ecx) +# endif #endif - movl %ecx,(%eax) movl $-1,%eax movl $-1,%edx ret diff --git a/lib/libc/i386/sys/ptrace.S b/lib/libc/i386/sys/ptrace.S index 713a3eee0e..0a76087d3c 100644 --- a/lib/libc/i386/sys/ptrace.S +++ b/lib/libc/i386/sys/ptrace.S @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/sys/ptrace.S,v 1.6 1999/08/27 23:59:43 peter Exp $ - * $DragonFly: src/lib/libc/i386/sys/ptrace.S,v 1.3 2003/12/06 03:11:36 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/sys/ptrace.S,v 1.4 2005/05/03 07:29:04 joerg Exp $ */ #include "SYS.h" @@ -43,11 +43,24 @@ ENTRY(ptrace) xorl %eax,%eax #ifdef PIC PIC_PROLOGUE - movl PIC_GOT(CNAME(errno)),%edx - movl %eax,(%edx) +# ifdef __thread + movl PIC_GOT(CNAME(errno)), %edx +# else + pushl %eax + leal errno@TLSGD(,%ebx,1), %eax + call ___tls_get_addr@PLT + movl %eax, %ecx + popl %eax +# endif + movl %eax, (%ecx) PIC_EPILOGUE #else - movl %eax,CNAME(errno) +# ifdef __thread + movl %eax, errno +# else + movl %gs:0, %ecx + movl %eax, errno@NTPOFF(%ecx) +# endif #endif lea SYS_ptrace,%eax KERNCALL diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 98c19acd62..21e49a6a26 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,6 +1,6 @@ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # $FreeBSD: src/lib/libc/sys/Makefile.inc,v 1.75.2.7 2003/04/22 17:31:18 trhodes Exp $ -# $DragonFly: src/lib/libc/sys/Makefile.inc,v 1.12 2005/05/01 18:38:11 joerg Exp $ +# $DragonFly: src/lib/libc/sys/Makefile.inc,v 1.13 2005/05/03 07:29:04 joerg Exp $ # sys sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/sys ${.CURDIR}/../libc/sys @@ -19,11 +19,6 @@ # Sources common to both syscall interfaces: SRCS+= ftruncate.c lseek.c mmap.c pread.c pwrite.c truncate.c -# Build __error() into libc, but not libc_r which has its own: -.if ${LIB} == "c" || ${LIB} == "c_rtld" -SRCS+= __error.c -.endif - # Add machine dependent asm sources: SRCS+=${MDASM} diff --git a/lib/libc/sys/__error.c b/lib/libc/sys/__error.c deleted file mode 100644 index 0731e095a2..0000000000 --- a/lib/libc/sys/__error.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 1997 John Birrell . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc/sys/__error.c,v 1.1.8.1 2001/03/05 11:45:51 obrien Exp $ - * $DragonFly: src/lib/libc/sys/Attic/__error.c,v 1.4 2005/02/01 22:35:19 joerg Exp $ - */ - -#include - -extern int errno; - -/* - * Declare a weak reference in case the application is not linked - * with libpthread. - */ -__weak_reference(__error_unthreaded,__error); - -int * -__error_unthreaded(void) -{ - return(&errno); -} diff --git a/lib/libc_r/sys/Makefile.inc b/lib/libc_r/sys/Makefile.inc index 65f0543485..c7d667a374 100644 --- a/lib/libc_r/sys/Makefile.inc +++ b/lib/libc_r/sys/Makefile.inc @@ -1,7 +1,7 @@ # $FreeBSD: src/lib/libc_r/sys/Makefile.inc,v 1.10 1999/08/28 00:03:13 peter Exp $ -# $DragonFly: src/lib/libc_r/sys/Makefile.inc,v 1.2 2003/06/17 04:26:48 dillon Exp $ +# $DragonFly: src/lib/libc_r/sys/Makefile.inc,v 1.3 2005/05/03 07:29:04 joerg Exp $ .PATH: ${.CURDIR}/sys ${.CURDIR}/arch/${MACHINE_ARCH} -SRCS+= uthread_error.c _atomic_lock.S +SRCS+= _atomic_lock.S diff --git a/lib/libc_r/sys/uthread_error.c b/lib/libc_r/sys/uthread_error.c deleted file mode 100644 index 1548063163..0000000000 --- a/lib/libc_r/sys/uthread_error.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1995 John Birrell . - * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell - * and Chris Provenzano. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc_r/sys/uthread_error.c,v 1.3 1999/08/28 00:03:14 peter Exp $ - * $DragonFly: src/lib/libc_r/sys/Attic/uthread_error.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ - */ -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -extern int errno; - -int * __error() -{ - int *p_errno; - if (_thread_run == _thread_initial) { - p_errno = &errno; - } else { - p_errno = &_thread_run->error; - } - return(p_errno); -} -#endif diff --git a/lib/libc_r/uthread/Makefile.inc b/lib/libc_r/uthread/Makefile.inc index a80ff49c38..2fbc1291ee 100644 --- a/lib/libc_r/uthread/Makefile.inc +++ b/lib/libc_r/uthread/Makefile.inc @@ -1,5 +1,5 @@ # $FreeBSD: src/lib/libc_r/uthread/Makefile.inc,v 1.23.2.8 2003/05/27 18:18:01 jdp Exp $ -# $DragonFly: src/lib/libc_r/uthread/Makefile.inc,v 1.5 2005/05/02 19:52:58 joerg Exp $ +# $DragonFly: src/lib/libc_r/uthread/Makefile.inc,v 1.6 2005/05/03 07:29:04 joerg Exp $ # uthread sources .PATH: ${.CURDIR}/uthread @@ -104,7 +104,6 @@ SRCS+= \ uthread_sendfile.c \ uthread_sendmsg.c \ uthread_sendto.c \ - uthread_seterrno.c \ uthread_setprio.c \ uthread_setschedparam.c \ uthread_setsockopt.c \ diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index 46e4ff32e1..2794fa1de7 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -32,7 +32,7 @@ * Private thread definitions for the uthread kernel. * * $FreeBSD: src/lib/libc_r/uthread/pthread_private.h,v 1.36.2.21 2002/10/22 14:44:02 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/pthread_private.h,v 1.7 2005/05/02 20:40:50 joerg Exp $ + * $DragonFly: src/lib/libc_r/uthread/pthread_private.h,v 1.8 2005/05/03 07:29:04 joerg Exp $ */ #ifndef _PTHREAD_PRIVATE_H @@ -693,12 +693,6 @@ struct pthread { /* TRUE if operation has timed out. */ int timeout; - /* - * Error variable used instead of errno. The function __error() - * returns a pointer to this. - */ - int error; - /* * The joiner is the thread that is joining to this thread. The * join status keeps track of a join operation to another thread. @@ -1224,7 +1218,6 @@ void _thread_sig_wrapper(void); void _thread_sigframe_restore(struct pthread *thread, struct pthread_signal_frame *psf); void _thread_start(void); -void _thread_seterrno(pthread_t, int); pthread_addr_t _thread_gc(pthread_addr_t); void _thread_enter_cancellation_point(void); void _thread_leave_cancellation_point(void); @@ -1322,6 +1315,7 @@ int __sys_sigreturn(ucontext_t *); #ifdef _UNISTD_H_ void __sys__exit(int); int __sys_close(int); +int __sys_closefrom(int); int __sys_dup(int); int __sys_dup2(int, int); int __sys_execve(const char *, char * const *, char * const *); diff --git a/lib/libc_r/uthread/uthread_init.c b/lib/libc_r/uthread/uthread_init.c index aa71b4e34b..6118ca63ea 100644 --- a/lib/libc_r/uthread/uthread_init.c +++ b/lib/libc_r/uthread/uthread_init.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_init.c,v 1.23.2.11 2003/02/24 23:27:32 das Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_init.c,v 1.7 2005/05/03 07:21:45 joerg Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_init.c,v 1.8 2005/05/03 07:29:04 joerg Exp $ */ /* Allocate space for global thread variables here: */ @@ -289,7 +289,6 @@ _thread_init(void) _thread_initial->specific_data = NULL; _thread_initial->cleanup = NULL; _thread_initial->flags = 0; - _thread_initial->error = 0; TAILQ_INIT(&_thread_list); TAILQ_INSERT_HEAD(&_thread_list, _thread_initial, tle); _set_curthread(_thread_initial); diff --git a/lib/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c index aa6415cea7..fa211ed6f8 100644 --- a/lib/libc_r/uthread/uthread_mutex.c +++ b/lib/libc_r/uthread/uthread_mutex.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_mutex.c,v 1.20.2.8 2002/10/22 14:44:03 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_mutex.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_mutex.c,v 1.3 2005/05/03 07:29:04 joerg Exp $ */ #include #include @@ -600,7 +600,7 @@ _pthread_mutex_lock(pthread_mutex_t * mutex) curthread->data.mutex = *mutex; /* Clear any previous error: */ - curthread->error = 0; + errno = 0; /* * Unlock the mutex structure and schedule the @@ -617,8 +617,8 @@ _pthread_mutex_lock(pthread_mutex_t * mutex) * waiting for the mutex causing a ceiling * violation. */ - ret = curthread->error; - curthread->error = 0; + ret = errno; + errno = 0; } break; @@ -990,7 +990,9 @@ mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) * to this thread being queued on the * waiting list. */ - (*mutex)->m_owner->error = EINVAL; + tls_set_tcb((*mutex)->m_owner->tcb); + errno = EINVAL; + tls_set_tcb(curthread->tcb); PTHREAD_NEW_STATE((*mutex)->m_owner, PS_RUNNING); /* diff --git a/lib/libc_r/uthread/uthread_seterrno.c b/lib/libc_r/uthread/uthread_seterrno.c deleted file mode 100644 index 764420bd20..0000000000 --- a/lib/libc_r/uthread/uthread_seterrno.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1995 John Birrell . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libc_r/uthread/uthread_seterrno.c,v 1.4.2.1 2002/10/22 14:44:03 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/Attic/uthread_seterrno.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ - */ -#include -#include "pthread_private.h" - -/* - * This function needs to reference the global error variable which is - * normally hidden from the user. - */ -#ifdef errno -#undef errno; -#endif -extern int errno; - -void -_thread_seterrno(pthread_t thread, int error) -{ - /* Check for the initial thread: */ - if (thread == _thread_initial) - /* The initial thread always uses the global error variable: */ - errno = error; - else - /* - * Threads other than the initial thread always use the error - * field in the thread structureL - */ - thread->error = error; -} diff --git a/lib/libthread_xu/Makefile b/lib/libthread_xu/Makefile index b9e334bc88..f728e9d934 100644 --- a/lib/libthread_xu/Makefile +++ b/lib/libthread_xu/Makefile @@ -1,5 +1,5 @@ # $FreeBSD: src/lib/libpthread/Makefile,v 1.53 2004/10/24 15:32:32 ru Exp $ -# $DragonFly: src/lib/libthread_xu/Makefile,v 1.3 2005/04/21 13:42:34 joerg Exp $ +# $DragonFly: src/lib/libthread_xu/Makefile,v 1.4 2005/05/03 07:29:04 joerg 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 @@ -14,7 +14,6 @@ CFLAGS+=-DPTHREAD_KERNEL -D_THREAD_SAFE CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}/thread \ -I${.CURDIR}/../../include CFLAGS+=-I${.CURDIR}/arch/${MACHINE_ARCH}/include -CFLAGS+=-I${.CURDIR}/sys CFLAGS+=-Winline CFLAGS+= -g @@ -29,7 +28,6 @@ CFLAGS+=-D_PTHREADS_INVARIANTS -Wall PRECIOUSLIB= yes .include "${.CURDIR}/arch/${MACHINE_ARCH}/Makefile.inc" -.include "${.CURDIR}/sys/Makefile.inc" .include "${.CURDIR}/thread/Makefile.inc" .include diff --git a/lib/libthread_xu/pthread.map b/lib/libthread_xu/pthread.map index 69d60db207..92dc8b3324 100644 --- a/lib/libthread_xu/pthread.map +++ b/lib/libthread_xu/pthread.map @@ -1,5 +1,5 @@ # $FreeBSD: src/lib/libpthread/pthread.map,v 1.13 2004/09/26 06:50:14 deischen Exp $ -# $DragonFly: src/lib/libthread_xu/pthread.map,v 1.2 2005/03/29 19:26:20 joerg Exp $ +# $DragonFly: src/lib/libthread_xu/pthread.map,v 1.3 2005/05/03 07:29:04 joerg Exp $ LIBTHREAD_1_0 { global: @@ -7,7 +7,6 @@ global: __accept; __close; __connect; - __error; __fcntl; __fsync; __msync; diff --git a/lib/libthread_xu/sys/Makefile.inc b/lib/libthread_xu/sys/Makefile.inc deleted file mode 100644 index 712fbb19f7..0000000000 --- a/lib/libthread_xu/sys/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# $DragonFly: src/lib/libthread_xu/sys/Attic/Makefile.inc,v 1.1 2005/02/01 12:38:27 davidxu Exp $ - -.PATH: ${.CURDIR}/sys - -SRCS+= thr_error.c diff --git a/lib/libthread_xu/sys/thr_error.c b/lib/libthread_xu/sys/thr_error.c deleted file mode 100644 index 90cf48b96b..0000000000 --- a/lib/libthread_xu/sys/thr_error.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1995 John Birrell . - * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell - * and Chris Provenzano. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libpthread/sys/thr_error.c,v 1.7 2003/04/23 21:46:50 deischen Exp $ - * $DragonFly: src/lib/libthread_xu/sys/Attic/thr_error.c,v 1.2 2005/03/29 19:26:20 joerg Exp $ - */ -#include -#include -#include "libc_private.h" -#include "thr_private.h" - -#undef errno -extern int errno; - -int * -__error(void) -{ - struct pthread *curthread = tls_get_curthread(); - - if (curthread != _thr_initial) - return (&curthread->error); - else - return (&errno); -} diff --git a/lib/libthread_xu/thread/Makefile.inc b/lib/libthread_xu/thread/Makefile.inc index 011306e921..853c6fb80c 100644 --- a/lib/libthread_xu/thread/Makefile.inc +++ b/lib/libthread_xu/thread/Makefile.inc @@ -1,4 +1,4 @@ -# $DragonFly: src/lib/libthread_xu/thread/Makefile.inc,v 1.2 2005/02/26 02:26:32 davidxu Exp $ +# $DragonFly: src/lib/libthread_xu/thread/Makefile.inc,v 1.3 2005/05/03 07:29:04 joerg Exp $ # thr sources .PATH: ${.CURDIR}/thread @@ -37,7 +37,6 @@ SRCS+= \ thr_rwlockattr.c \ thr_self.c \ thr_sem.c \ - thr_seterrno.c \ thr_setprio.c \ thr_setschedparam.c \ thr_sig.c \ diff --git a/lib/libthread_xu/thread/thr_mutex.c b/lib/libthread_xu/thread/thr_mutex.c index ef54a96a24..4b9f351d2b 100644 --- a/lib/libthread_xu/thread/thr_mutex.c +++ b/lib/libthread_xu/thread/thr_mutex.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libpthread/thread/thr_mutex.c,v 1.46 2004/10/31 05:03:50 green Exp $ - * $DragonFly: src/lib/libthread_xu/thread/thr_mutex.c,v 1.4 2005/04/05 23:04:22 davidxu Exp $ + * $DragonFly: src/lib/libthread_xu/thread/thr_mutex.c,v 1.5 2005/05/03 07:29:04 joerg Exp $ */ #include @@ -696,7 +696,7 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m, curthread->data.mutex = *m; /* Clear any previous error: */ - curthread->error = 0; + errno = 0; THR_LOCK(curthread); cycle = curthread->cycle; @@ -729,8 +729,8 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m, * waiting for the mutex causing a ceiling * violation. */ - ret = curthread->error; - curthread->error = 0; + ret = errno; + errno = 0; } break; @@ -1566,7 +1566,9 @@ mutex_handoff(struct pthread *curthread, struct pthread_mutex *mutex) * has been raised subsequent to the thread * being queued on the waiting list. */ - pthread->error = EINVAL; + tls_set_tcb(pthread->tcb); + errno = EINVAL; + tls_set_tcb(curthread->tcb); } else { /* diff --git a/lib/libthread_xu/thread/thr_seterrno.c b/lib/libthread_xu/thread/thr_seterrno.c deleted file mode 100644 index 613b0722fb..0000000000 --- a/lib/libthread_xu/thread/thr_seterrno.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1995 John Birrell . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libpthread/thread/thr_seterrno.c,v 1.7 2003/04/18 05:04:16 deischen Exp $ - * $DragonFly: src/lib/libthread_xu/thread/Attic/thr_seterrno.c,v 1.1 2005/02/01 12:38:27 davidxu Exp $ - */ -#include -#include "thr_private.h" - -/* - * This function needs to reference the global error variable which is - * normally hidden from the user. - */ -#undef errno -extern int errno; - -void -_thread_seterrno(pthread_t thread, int error) -{ - /* Check for the initial thread: */ - if (thread == NULL || thread == _thr_initial) - /* The initial thread always uses the global error variable: */ - errno = error; - else - /* - * Threads other than the initial thread always use the error - * field in the thread structureL - */ - thread->error = error; -} diff --git a/sys/sys/errno.h b/sys/sys/errno.h index 64f3c5b5b1..28949b1f12 100644 --- a/sys/sys/errno.h +++ b/sys/sys/errno.h @@ -37,18 +37,19 @@ * * @(#)errno.h 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/sys/errno.h,v 1.14.2.2 2002/01/22 10:46:56 keramida Exp $ - * $DragonFly: src/sys/sys/errno.h,v 1.5 2003/08/27 02:03:22 dillon Exp $ + * $DragonFly: src/sys/sys/errno.h,v 1.6 2005/05/03 07:29:04 joerg Exp $ */ #ifndef _SYS_ERRNO_H_ #define _SYS_ERRNO_H_ #ifndef _KERNEL -#include -__BEGIN_DECLS -int * __error (void); -__END_DECLS -#define errno (* __error()) +extern __thread int errno; +/* + * A lot of programs want to define errno as normal int, if + * it isn't a macro. Work around this to prevent even more breakage. + */ +#define errno errno #endif #define EPERM 1 /* Operation not permitted */