Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Dec 1996 08:14:52 +1100 (EST)
From:      John Birrell <jb@cimlogic.com.au>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   misc/2309: Thread safe fixes to malloc, localtime, libc_r
Message-ID:  <199612282114.IAA14097@freebsd1.cimlogic.com.au>
Resent-Message-ID: <199612282120.NAA25274@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         2309
>Category:       misc
>Synopsis:       Thread safe fixes to malloc, localtime, libc_r
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 28 13:20:01 PST 1996
>Last-Modified:
>Originator:     John Birrell
>Organization:
CIMlogic Pty Ltd
>Release:        FreeBSD 3.0-current (961227)
>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 <bsd.lib.mk>
--- 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 <machine/reg.h>
  #include <pthread.h>
  #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}
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612282114.IAA14097>