4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
39 * This file provides the LD_AUDIT interfaces for libcrle.so.1, which are
40 * called for one of two reasons:
43 * under this mode, the dependencies of the application are
44 * gathered (similar to ldd(1)) and written back to the calling
48 * under this mode, the LD_CONFIG file is read to determine which
49 * objects are to be dldump()'ed. The memory range occupied by
50 * the dumped images is written back to the calling process.
52 * Both of these interfaces are invoked via the crle(1) calling process. The
53 * following environment variables are used to communicate between the two:
55 * CRLE_FD the file descriptor on which to communicate to the calling
56 * process (used for CRLE_AUD_DEPENDS and CRLE_AUD_DUMP).
58 * CRLE_FLAGS this signals CRLE_AUD_DLDUMP mode, and indicates the required
59 * flags for the dldump(3x) calls.
65 int dlflag
= RTLD_CONFSET
;
68 * Initial audit handshake, establish audit mode.
72 la_version(uint_t version
)
77 * Establish the file desciptor to communicate with the calling process,
78 * If there are any errors terminate the process.
80 if ((str
= getenv(MSG_ORIG(MSG_ENV_AUD_FD
))) == NULL
)
85 * Determine which audit mode is required based on the existance of
88 if ((str
= getenv(MSG_ORIG(MSG_ENV_AUD_FLAGS
))) == NULL
) {
89 auflag
= CRLE_AUD_DEPENDS
;
91 auflag
= CRLE_AUD_DLDUMP
;
95 * Fill any memory holes before anything gets mapped.
102 * We need the audit interface containing la_objfilter().
104 return (LAV_VERSION3
);
108 * Audit interface called for each dependency. If in CRLE_AUD_DEPENDS mode,
109 * return each dependency of the primary link-map to the caller.
113 la_objopen(Link_map
* lmp
, Lmid_t lmid
, uintptr_t *cookie
)
115 if (auflag
== CRLE_AUD_DLDUMP
)
118 if ((lmid
== LM_ID_BASE
) &&
119 !(FLAGS(LINKMAP_TO_RTMAP(lmp
)) & FLG_RT_ISMAIN
)) {
120 char buffer
[PATH_MAX
];
122 (void) snprintf(buffer
, PATH_MAX
, MSG_ORIG(MSG_AUD_DEPEND
),
124 (void) write(pfd
, buffer
, strlen(buffer
));
125 *cookie
= (uintptr_t)lmp
->l_name
;
127 *cookie
= (uintptr_t)0;
133 * Audit interface called for any filter/filtee pairs. If in CRLE_AUD_DEPENDS
134 * mode, return the filter/filtee association to the caller.
138 la_objfilter(uintptr_t *fltrcook
, const char *fltestr
, uintptr_t *fltecook
,
141 if (auflag
== CRLE_AUD_DLDUMP
)
144 if (*fltrcook
&& *fltestr
&& *fltecook
) {
145 char buffer
[PATH_MAX
];
147 (void) snprintf(buffer
, PATH_MAX
, MSG_ORIG(MSG_AUD_FILTER
),
148 (char *)(*fltrcook
), fltestr
, (char *)(*fltecook
));
149 (void) write(pfd
, buffer
, strlen(buffer
));
155 * Audit interface called before transfer of control to application. If in
156 * CRLE_AUD_DLDUMP mode read the configuration file and dldump() all necessary
161 la_preinit(uintptr_t *cookie
)
163 if (auflag
== CRLE_AUD_DLDUMP
) {
164 if (dumpconfig() != 0)