1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc.
24*7c478bd9Sstevel@tonic-gate */
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate * Functions to sync up library list with that of the run time linker
30*7c478bd9Sstevel@tonic-gate */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #ifndef DEBUG
33*7c478bd9Sstevel@tonic-gate #define NDEBUG 1
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate #include <assert.h>
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate #include "tnfctl_int.h"
39*7c478bd9Sstevel@tonic-gate #include "kernel_int.h"
40*7c478bd9Sstevel@tonic-gate #include "dbg.h"
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_check_libs(tnfctl_handle_t * hndl)43*7c478bd9Sstevel@tonic-gate tnfctl_check_libs(tnfctl_handle_t *hndl)
44*7c478bd9Sstevel@tonic-gate {
45*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t prexstat;
46*7c478bd9Sstevel@tonic-gate enum event_op_t dl_evt;
47*7c478bd9Sstevel@tonic-gate boolean_t lmap_ok;
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate if (hndl->mode == KERNEL_MODE) {
50*7c478bd9Sstevel@tonic-gate prexstat = _tnfctl_refresh_kernel(hndl);
51*7c478bd9Sstevel@tonic-gate return (prexstat);
52*7c478bd9Sstevel@tonic-gate }
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate /* hndl refers to a process */
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate /* return value of lmap_ok, dl_evt ignored */
57*7c478bd9Sstevel@tonic-gate prexstat = _tnfctl_refresh_process(hndl, &lmap_ok, &dl_evt);
58*7c478bd9Sstevel@tonic-gate assert(lmap_ok == B_TRUE);
59*7c478bd9Sstevel@tonic-gate return (prexstat);
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate * _tnfctl_lock_libs() locks the library list maintained in the prex
64*7c478bd9Sstevel@tonic-gate * handle against it changing by a dlopen or dlclose.
65*7c478bd9Sstevel@tonic-gate *
66*7c478bd9Sstevel@tonic-gate * This locking code is between the thread that owns the handle and
67*7c478bd9Sstevel@tonic-gate * another thread that may be doing a dlopen/dlclose. We do not support
68*7c478bd9Sstevel@tonic-gate * the situation of having multiple threads operating on the same
69*7c478bd9Sstevel@tonic-gate * handle - in effect the code per tnfctl_handle can be thought of as
70*7c478bd9Sstevel@tonic-gate * being single-threaded - that is why we can check "hndl->in_objlist"
71*7c478bd9Sstevel@tonic-gate * without first obtaining a lock. "in_objlist" is the re-entrancy
72*7c478bd9Sstevel@tonic-gate * protector on the lock i.e. we can call _tnfctl_lock_libs() safely even if
73*7c478bd9Sstevel@tonic-gate * this thread has the lock held. The return value "release_lock" indicates
74*7c478bd9Sstevel@tonic-gate * whether the lock should be released or not. It can be passed into
75*7c478bd9Sstevel@tonic-gate * _tnfctl_unlock_libs() which will do the right thing.
76*7c478bd9Sstevel@tonic-gate *
77*7c478bd9Sstevel@tonic-gate * All of this is a bit too complex for warlock. Here we give warlock a
78*7c478bd9Sstevel@tonic-gate * simpler view, that these routines have the side effect of acquiring and
79*7c478bd9Sstevel@tonic-gate * releasing the lock, period.
80*7c478bd9Sstevel@tonic-gate */
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_lock_libs(tnfctl_handle_t * hndl,boolean_t * release_lock)83*7c478bd9Sstevel@tonic-gate _tnfctl_lock_libs(tnfctl_handle_t *hndl, boolean_t *release_lock)
84*7c478bd9Sstevel@tonic-gate {
85*7c478bd9Sstevel@tonic-gate #if defined(__lock_lint)
86*7c478bd9Sstevel@tonic-gate
87*7c478bd9Sstevel@tonic-gate NOTE(MUTEX_ACQUIRED_AS_SIDE_EFFECT(&warlock_kludge->lmap_lock))
88*7c478bd9Sstevel@tonic-gate mutex_lock(&warlock_kludge->lmap_lock);
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate #else
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate /* this interface is only for INTERNAL_MODE clients */
93*7c478bd9Sstevel@tonic-gate assert(hndl->mode == INTERNAL_MODE);
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate if (hndl->in_objlist == B_TRUE) {
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate * already have _tnfctl_lmap_lock held which implies that
98*7c478bd9Sstevel@tonic-gate * the library list has been sync'ed up
99*7c478bd9Sstevel@tonic-gate */
100*7c478bd9Sstevel@tonic-gate *release_lock = B_FALSE;
101*7c478bd9Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate /* lock is not currently held, so lock it */
105*7c478bd9Sstevel@tonic-gate mutex_lock(&_tnfctl_lmap_lock);
106*7c478bd9Sstevel@tonic-gate hndl->in_objlist = B_TRUE;
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate *release_lock = B_TRUE;
109*7c478bd9Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate #endif
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate
114*7c478bd9Sstevel@tonic-gate void
_tnfctl_unlock_libs(tnfctl_handle_t * hndl,boolean_t release_lock)115*7c478bd9Sstevel@tonic-gate _tnfctl_unlock_libs(tnfctl_handle_t *hndl, boolean_t release_lock)
116*7c478bd9Sstevel@tonic-gate {
117*7c478bd9Sstevel@tonic-gate #if defined(__lock_lint)
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate NOTE(LOCK_RELEASED_AS_SIDE_EFFECT(&warlock_kludge->lmap_lock))
120*7c478bd9Sstevel@tonic-gate mutex_unlock(&warlock_kludge->lmap_lock);
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate #else
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate /* this interface is only for INTERNAL_MODE clients */
125*7c478bd9Sstevel@tonic-gate assert(hndl->mode == INTERNAL_MODE);
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate if (release_lock) {
128*7c478bd9Sstevel@tonic-gate hndl->in_objlist = B_FALSE;
129*7c478bd9Sstevel@tonic-gate mutex_unlock(&_tnfctl_lmap_lock);
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate #endif
133*7c478bd9Sstevel@tonic-gate }
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate * _tnfctl_syn_lib_list() syncs up the library list maintained
137*7c478bd9Sstevel@tonic-gate * in the prex handle with the libraries in the process (if needed)
138*7c478bd9Sstevel@tonic-gate * NOTE: Assumes _tnfctl_lmap_lock is held.
139*7c478bd9Sstevel@tonic-gate *
140*7c478bd9Sstevel@tonic-gate */
141*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_sync_lib_list(tnfctl_handle_t * hndl)142*7c478bd9Sstevel@tonic-gate _tnfctl_sync_lib_list(tnfctl_handle_t *hndl)
143*7c478bd9Sstevel@tonic-gate {
144*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t prexstat = TNFCTL_ERR_NONE;
145*7c478bd9Sstevel@tonic-gate enum event_op_t dl_evt;
146*7c478bd9Sstevel@tonic-gate boolean_t lmap_ok;
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate /* this interface is only for INTERNAL_MODE clients */
149*7c478bd9Sstevel@tonic-gate assert(hndl->mode == INTERNAL_MODE);
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate /* lmap_lock held and in_objlist marked as B_TRUE */
152*7c478bd9Sstevel@tonic-gate if (_tnfctl_libs_changed == B_TRUE) {
153*7c478bd9Sstevel@tonic-gate prexstat = _tnfctl_refresh_process(hndl, &lmap_ok, &dl_evt);
154*7c478bd9Sstevel@tonic-gate if (prexstat) {
155*7c478bd9Sstevel@tonic-gate return (prexstat);
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
159*7c478bd9Sstevel@tonic-gate }
160