usr/src/lib/libc/port/gen/sh_locks.c
author Jon Tibble <meths@btinternet.com>
Thu, 09 Dec 2010 22:32:39 +0100
changeset 13255 4afa820d78b9
parent 6812 febeba71273d
permissions -rw-r--r--
298 SPARC build fails in smt_pause.o 478 Build needs fixing for pkgdepend flag day Reviewed by: [email protected] Reviewed by: [email protected] Reviewed by: [email protected] Approved by: [email protected]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
2186
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
     5
 * Common Development and Distribution License (the "License").
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
2186
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
6515
10dab2b883e0 6678310 using LD_AUDIT, ld.so.1 calls shared library's .init before library is fully relocated
raf
parents: 2186
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
#pragma ident	"%Z%%M%	%I%	%E% SMI"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
6812
febeba71273d PSARC 2008/309 expunge synonyms.h
raf
parents: 6515
diff changeset
    29
#include "lint.h"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
#include <mtlib.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
#include <sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
#include <synch.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
#include <thread.h>
6515
10dab2b883e0 6678310 using LD_AUDIT, ld.so.1 calls shared library's .init before library is fully relocated
raf
parents: 2186
diff changeset
    34
#include <pthread.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
#include "libc.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
 * fork1-safety.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    39
 * These three routines were used to make some libc interfaces fork1-safe.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
 * With the merge of libthread into libc, almost all libc internal-only
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
 * locks are acquired via lmutex_lock() or lrw_rdlock()/lrw_wrlock(),
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
 * which makes them automatically fork1-safe (as well as async-signal
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
 * safe), so these functions are now used only for the locks that cannot
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
 * be used with lmutex_lock or lrw_rdlock()/lrw_wrlock().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    47
extern void atexit_locks(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    48
extern void atexit_unlocks(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    49
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
extern void stdio_locks(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
extern void stdio_unlocks(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
2186
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    53
extern void malloc_locks(void);
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    54
extern void malloc_unlocks(void);
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    55
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    56
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
libc_prepare_atfork(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    58
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
	atexit_locks();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    60
	stdio_locks();
2186
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    61
	malloc_locks();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    64
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    65
libc_child_atfork(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    66
{
2186
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    67
	malloc_unlocks();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    68
	stdio_unlocks();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    69
	atexit_unlocks();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    70
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    71
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    72
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
libc_parent_atfork(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
{
2186
7b18ba5d9cfe 6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
raf
parents: 0
diff changeset
    75
	malloc_unlocks();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    76
	stdio_unlocks();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    77
	atexit_unlocks();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    78
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    79
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
/* called from libc_init() */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    81
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    82
atfork_init(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    83
{
6515
10dab2b883e0 6678310 using LD_AUDIT, ld.so.1 calls shared library's .init before library is fully relocated
raf
parents: 2186
diff changeset
    84
	(void) pthread_atfork(libc_prepare_atfork,
10dab2b883e0 6678310 using LD_AUDIT, ld.so.1 calls shared library's .init before library is fully relocated
raf
parents: 2186
diff changeset
    85
	    libc_parent_atfork, libc_child_atfork);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
}