xref: /onnv-gate/usr/src/lib/libc/port/gen/sh_locks.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52186Sraf  * Common Development and Distribution License (the "License").
62186Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
212186Sraf 
220Sstevel@tonic-gate /*
236515Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include <mtlib.h>
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <synch.h>
330Sstevel@tonic-gate #include <thread.h>
346515Sraf #include <pthread.h>
350Sstevel@tonic-gate #include "libc.h"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * fork1-safety.
390Sstevel@tonic-gate  * These three routines were used to make some libc interfaces fork1-safe.
400Sstevel@tonic-gate  * With the merge of libthread into libc, almost all libc internal-only
410Sstevel@tonic-gate  * locks are acquired via lmutex_lock() or lrw_rdlock()/lrw_wrlock(),
420Sstevel@tonic-gate  * which makes them automatically fork1-safe (as well as async-signal
430Sstevel@tonic-gate  * safe), so these functions are now used only for the locks that cannot
440Sstevel@tonic-gate  * be used with lmutex_lock or lrw_rdlock()/lrw_wrlock().
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate extern void atexit_locks(void);
480Sstevel@tonic-gate extern void atexit_unlocks(void);
490Sstevel@tonic-gate 
500Sstevel@tonic-gate extern void stdio_locks(void);
510Sstevel@tonic-gate extern void stdio_unlocks(void);
520Sstevel@tonic-gate 
532186Sraf extern void malloc_locks(void);
542186Sraf extern void malloc_unlocks(void);
552186Sraf 
560Sstevel@tonic-gate static void
libc_prepare_atfork(void)570Sstevel@tonic-gate libc_prepare_atfork(void)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	atexit_locks();
600Sstevel@tonic-gate 	stdio_locks();
612186Sraf 	malloc_locks();
620Sstevel@tonic-gate }
630Sstevel@tonic-gate 
640Sstevel@tonic-gate static void
libc_child_atfork(void)650Sstevel@tonic-gate libc_child_atfork(void)
660Sstevel@tonic-gate {
672186Sraf 	malloc_unlocks();
680Sstevel@tonic-gate 	stdio_unlocks();
690Sstevel@tonic-gate 	atexit_unlocks();
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate static void
libc_parent_atfork(void)730Sstevel@tonic-gate libc_parent_atfork(void)
740Sstevel@tonic-gate {
752186Sraf 	malloc_unlocks();
760Sstevel@tonic-gate 	stdio_unlocks();
770Sstevel@tonic-gate 	atexit_unlocks();
780Sstevel@tonic-gate }
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /* called from libc_init() */
810Sstevel@tonic-gate void
atfork_init(void)820Sstevel@tonic-gate atfork_init(void)
830Sstevel@tonic-gate {
846515Sraf 	(void) pthread_atfork(libc_prepare_atfork,
856515Sraf 	    libc_parent_atfork, libc_child_atfork);
860Sstevel@tonic-gate }
87