From jb@freebsd1.cimlogic.com.au Sat Dec 28 13:15:15 1996 Received: from mira.net.au (eplet.mira.net.au [203.9.190.17]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id NAA25142 for ; Sat, 28 Dec 1996 13:15:08 -0800 (PST) Received: (qmail 3350 invoked from network); 28 Dec 1996 21:15:05 -0000 Received: from melb.werple.net.au (203.9.190.18) by eplet.mira.net.au with SMTP; 28 Dec 1996 21:15:05 -0000 Received: (from uucp@localhost) by melb.werple.net.au (8.7.6/8.7.3/2) with UUCP id IAA26609 for FreeBSD-gnats-submit@freebsd.org; Sun, 29 Dec 1996 08:12:07 +1100 (EST) Received: (from jb@localhost) by freebsd1.cimlogic.com.au (8.7.5/8.7.3) id IAA14097; Sun, 29 Dec 1996 08:14:52 +1100 (EST) Message-Id: <199612282114.IAA14097@freebsd1.cimlogic.com.au> Date: Sun, 29 Dec 1996 08:14:52 +1100 (EST) From: John Birrell Reply-To: jb@cimlogic.com.au To: FreeBSD-gnats-submit@freebsd.org Subject: Thread safe fixes to malloc, localtime, libc_r X-Send-Pr-Version: 3.2 >Number: 2309 >Category: misc >Synopsis: Thread safe fixes to malloc, localtime, libc_r >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Dec 28 13:20:01 PST 1996 >Closed-Date: Sun Mar 22 21:09:25 PST 1998 >Last-Modified: Sun Mar 22 21:10:48 PST 1998 >Originator: John Birrell >Release: FreeBSD 3.0-current (961227) >Organization: CIMlogic Pty Ltd >Environment: >Description: 1. Thread unlocking macro in malloc is broken. 2. pthread_getspecific call in localtime treats NULL as an error. 3. 'tags' has never worked in libc_r/Makefile 4. Thread auto init routine not being linked if static. 5. libc_r makefiles out of sync with libc. >How-To-Repeat: Try to build libc_r. >Fix: Apply the following patch: diff -rc /freebsd1/u/freebsd/src/lib/libc/stdlib/malloc.c /u/freebsd/src/lib/libc/stdlib/malloc.c *** /freebsd1/u/freebsd/src/lib/libc/stdlib/malloc.c Wed Oct 30 07:35:39 1996 --- /u/freebsd/src/lib/libc/stdlib/malloc.c Thu Dec 26 13:59:03 1996 *************** *** 1085,1091 **** #include "pthread_private.h" static int malloc_lock; #define THREAD_LOCK() _thread_kern_sig_block(&malloc_lock); ! #define THREAD_UNLOCK() _thread_kern_sig_unblock(&malloc_lock); #else #define THREAD_LOCK() #define THREAD_UNLOCK() --- 1085,1091 ---- #include "pthread_private.h" static int malloc_lock; #define THREAD_LOCK() _thread_kern_sig_block(&malloc_lock); ! #define THREAD_UNLOCK() _thread_kern_sig_unblock(malloc_lock); #else #define THREAD_LOCK() #define THREAD_UNLOCK() diff -rc /freebsd1/u/freebsd/src/lib/libc/stdtime/localtime.c /u/freebsd/src/lib/libc/stdtime/localtime.c *** /freebsd1/u/freebsd/src/lib/libc/stdtime/localtime.c Mon Nov 11 21:58:37 1996 --- /u/freebsd/src/lib/libc/stdtime/localtime.c Sun Dec 29 08:02:35 1996 *************** *** 1103,1118 **** pthread_mutex_lock(&localtime_mutex); if (localtime_key < 0) { if (pthread_key_create(&localtime_key, free) < 0) { ! pthread_mutex_unlock(&localtime_mutex); ! return(NULL); } } pthread_mutex_unlock(&localtime_mutex); ! if ((p_tm = pthread_getspecific(localtime_key)) != 0) { ! return(NULL); ! } else if (p_tm == NULL) { if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { ! return(NULL); } pthread_setspecific(localtime_key, p_tm); } --- 1103,1115 ---- pthread_mutex_lock(&localtime_mutex); if (localtime_key < 0) { if (pthread_key_create(&localtime_key, free) < 0) { ! PANIC("Cannot create key for localtime"); } } pthread_mutex_unlock(&localtime_mutex); ! if ((p_tm = pthread_getspecific(localtime_key)) == NULL) { if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { ! PANIC("Cannot malloc for localtime"); } pthread_setspecific(localtime_key, p_tm); } diff -rc /freebsd1/u/freebsd/src/lib/libc_r/Makefile /u/freebsd/src/lib/libc_r/Makefile *** /freebsd1/u/freebsd/src/lib/libc_r/Makefile Fri Aug 30 11:43:15 1996 --- /u/freebsd/src/lib/libc_r/Makefile Sun Dec 29 08:03:03 1996 *************** *** 11,17 **** CFLAGS+=-DLIBC_RCS -DSYSLIBC_RCS CFLAGS+=-DPTHREAD_KERNEL -D_THREAD_SAFE -I${.CURDIR}/uthread AINC= -I${.CURDIR}/../libc/${MACHINE} -I${.CURDIR}/uthread - CLEANFILES+=tags PRECIOUSLIB= yes .include "${.CURDIR}/db/Makefile.inc" --- 11,16 ---- *************** *** 37,50 **** .include "${.CURDIR}/yp/Makefile.inc" .endif .include "${.CURDIR}/${MACHINE}/sys/Makefile.inc" - - beforeinstall: tags - ${INSTALL} ${COPY} -o bin -g bin -m 444 tags /var/db/libc_r.tags - - tags: ${SRCS} - ctags ${.ALLSRC:M*.c} - egrep -o "^ENTRY(.*)|^FUNC(.*)|^SYSCALL(.*)" ${.ALLSRC:M*.s} | \ - sed "s;\([^:]*\):\([^(]*\)(\([^, )]*\)\(.*\);\3 \1 /^\2(\3\4$$/;" \ - >> tags; sort -o tags tags .include --- 36,40 ---- diff -rc /freebsd1/u/freebsd/src/lib/libc_r/sys/Makefile.inc /u/freebsd/src/lib/libc_r/sys/Makefile.inc *** /freebsd1/u/freebsd/src/lib/libc_r/sys/Makefile.inc Thu Aug 22 14:25:09 1996 --- /u/freebsd/src/lib/libc_r/sys/Makefile.inc Thu Dec 26 11:32:06 1996 *************** *** 27,33 **** setpgid.o setpriority.o setregid.o setreuid.o setrlimit.o \ setsid.o settimeofday.o setuid.o shmsys.o stat.o statfs.o \ swapon.o symlink.o sync.o sysarch.o umask.o unlink.o \ ! unmount.o utimes.o vadvise.o __syscall.o __sysctl.o # Syscalls renamed as _thread_sys_{syscall}. THREADASM= accept.o bind.o close.o connect.o dup.o dup2.o \ --- 27,33 ---- setpgid.o setpriority.o setregid.o setreuid.o setrlimit.o \ setsid.o settimeofday.o setuid.o shmsys.o stat.o statfs.o \ swapon.o symlink.o sync.o sysarch.o umask.o unlink.o \ ! unmount.o utimes.o utrace.o vadvise.o __syscall.o __sysctl.o # Syscalls renamed as _thread_sys_{syscall}. THREADASM= accept.o bind.o close.o connect.o dup.o dup2.o \ diff -rc /freebsd1/u/freebsd/src/lib/libc_r/uthread/Makefile.inc /u/freebsd/src/lib/libc_r/uthread/Makefile.inc *** /freebsd1/u/freebsd/src/lib/libc_r/uthread/Makefile.inc Mon Nov 11 21:58:53 1996 --- /u/freebsd/src/lib/libc_r/uthread/Makefile.inc Thu Dec 26 12:35:29 1996 *************** *** 7,12 **** --- 7,13 ---- SRCS+= \ uthread_accept.c \ + uthread_attr_destroy.c \ uthread_attr_init.c \ uthread_attr_setcreatesuspend_np.c \ uthread_attr_setstacksize.c \ diff -rc /freebsd1/u/freebsd/src/lib/libc_r/uthread/uthread_init.c /u/freebsd/src/lib/libc_r/uthread/uthread_init.c *** /freebsd1/u/freebsd/src/lib/libc_r/uthread/uthread_init.c Tue Aug 20 18:21:23 1996 --- /u/freebsd/src/lib/libc_r/uthread/uthread_init.c Thu Dec 26 11:44:50 1996 *************** *** 44,49 **** --- 44,50 ---- #include #include #include "pthread_private.h" + extern int _thread_autoinit_dummy_decl; void _thread_init(void) *************** *** 52,57 **** --- 53,59 ---- int i; struct sigaction act; + _thread_autoinit_dummy_decl = 1; /* Check if this function has already been called: */ if (_thread_initial) { /* Only initialise the threaded application once. */ diff -rc /freebsd1/u/freebsd/src/lib/libc_r/yp/Makefile.inc /u/freebsd/src/lib/libc_r/yp/Makefile.inc *** /freebsd1/u/freebsd/src/lib/libc_r/yp/Makefile.inc Mon Jan 22 11:23:58 1996 --- /u/freebsd/src/lib/libc_r/yp/Makefile.inc Thu Dec 26 12:08:07 1996 *************** *** 4,8 **** # yp sources .PATH: ${.CURDIR}/../libc/yp ! SRCS+= xdryp.c yplib.c --- 4,17 ---- # yp sources .PATH: ${.CURDIR}/../libc/yp ! SRCS+= xdryp.c yp_xdr.c yplib.c ! CLEANFILES+= yp_xdr.c yp.h + RPCSRC= ${.DESTDIR}/usr/include/rpcsvc/yp.x + RPCGEN= rpcgen + + yp_xdr.c: ${RPCSRC} yp.h + ${RPCGEN} -c -o ${.TARGET} ${RPCSRC} + + yp.h: ${RPCSRC} + ${RPCGEN} -h -o ${.TARGET} ${RPCSRC} >Release-Note: >Audit-Trail: State-Changed-From-To: open->closed State-Changed-By: hoek State-Changed-When: Sun Mar 22 21:09:25 PST 1998 State-Changed-Why: jb (aka "originator") believes this no longer applies. >Unformatted: