xref: /titanic_44/usr/src/cmd/sgs/liblddbg/common/audit.c (revision 4d0eb50e691de4c20b1dd9976ad6839fede8a42d)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #include	<dlfcn.h>
27 #include	<stdio.h>
28 #include	"_debug.h"
29 #include	"msg.h"
30 #include	"libld.h"
31 
32 void
33 Dbg_audit_lib(Rt_map *clmp, const char *lib, int type)
34 {
35 	Lm_list		*clml = LIST(clmp);
36 	const char	*str;
37 
38 	if (DBG_NOTCLASS(DBG_C_AUDITING))
39 		return;
40 
41 	Dbg_util_nl(clml, DBG_NL_STD);
42 	switch (type) {
43 	case DBG_AUD_PRELOAD:
44 		str = MSG_ORIG(MSG_AUD_PRELOAD);
45 		break;
46 	case DBG_AUD_GLOBAL:
47 		str = MSG_ORIG(MSG_AUD_GLOBAL);
48 		break;
49 	case DBG_AUD_LOCAL:
50 		/* FALLTHROUGH */
51 	default:
52 		str = MSG_ORIG(MSG_STR_EMPTY);
53 	}
54 
55 	dbg_print(clml, MSG_INTL(MSG_AUD_LIB), lib, NAME(clmp), str);
56 }
57 
58 void
59 Dbg_audit_interface(Lm_list *lml, const char *lib, const char *interface)
60 {
61 	if (DBG_NOTCLASS(DBG_C_AUDITING))
62 		return;
63 
64 	dbg_print(lml, MSG_INTL(MSG_AUD_INTERFACE), lib, interface);
65 }
66 
67 void
68 Dbg_audit_version(Lm_list *lml, const char *lib, uint_t overs, uint_t nvers)
69 {
70 	if (DBG_NOTCLASS(DBG_C_AUDITING))
71 		return;
72 
73 	dbg_print(lml, MSG_INTL(MSG_AUD_VERSION), lib, overs, nvers);
74 }
75 
76 void
77 Dbg_audit_activity(Lm_list *lml, const char *lib, const char *obj, uint_t flags)
78 {
79 	Conv_inv_buf_t	inv_buf;
80 
81 	if (DBG_NOTCLASS(DBG_C_AUDITING))
82 		return;
83 
84 	Dbg_util_nl(lml, DBG_NL_STD);
85 	dbg_print(lml, MSG_INTL(MSG_AUD_ACTIVITY), lib, obj,
86 	    conv_la_activity(flags, CONV_FMT_ALT_DEFAULT, &inv_buf));
87 }
88 
89 void
90 Dbg_audit_preinit(Lm_list *lml, const char *lib, const char *obj)
91 {
92 	if (DBG_NOTCLASS(DBG_C_AUDITING))
93 		return;
94 
95 	Dbg_util_nl(lml, DBG_NL_STD);
96 	dbg_print(lml, MSG_INTL(MSG_AUD_PREINIT), lib, obj);
97 }
98 
99 void
100 Dbg_audit_objsearch(Lm_list *lml, int call, const char *lib,
101     const char *oobj, uint_t flags, const char *nobj)
102 {
103 	Conv_la_search_buf_t	la_search_buf;
104 
105 	if (DBG_NOTCLASS(DBG_C_AUDITING))
106 		return;
107 
108 	if (call == DBG_AUD_CALL) {
109 		Dbg_util_nl(lml, DBG_NL_STD);
110 		dbg_print(lml, MSG_INTL(MSG_AUD_OBJSEARCH), lib, oobj,
111 		    conv_la_search(flags, &la_search_buf));
112 	} else {
113 		if (nobj)
114 			dbg_print(lml, MSG_INTL(MSG_AUD_OBJSEARCH_R), lib,
115 			    oobj, nobj);
116 		else
117 			dbg_print(lml, MSG_INTL(MSG_AUD_OBJSEARCH_S), lib,
118 			    oobj);
119 	}
120 }
121 
122 void
123 Dbg_audit_objfilter(Lm_list *lml, int call, const char *lib,
124     const char *filter, const char *filtee, const char *ref)
125 {
126 	if (DBG_NOTCLASS(DBG_C_AUDITING))
127 		return;
128 
129 	if (call == DBG_AUD_CALL) {
130 		Dbg_util_nl(lml, DBG_NL_STD);
131 		dbg_print(lml, MSG_INTL(MSG_AUD_OBJFILTER), lib, filter,
132 		    filtee, ref);
133 	} else
134 		dbg_print(lml, MSG_INTL(MSG_AUD_OBJFILTER_R), lib, filter);
135 }
136 
137 void
138 Dbg_audit_objopen(Lm_list *lml, int call, const char *lib, const char *obj,
139     uint_t flags, Boolean ignore)
140 {
141 	Conv_la_bind_buf_t	la_bind_buf;
142 
143 	if (DBG_NOTCLASS(DBG_C_AUDITING))
144 		return;
145 
146 	if (call == DBG_AUD_CALL) {
147 		Dbg_util_nl(lml, DBG_NL_STD);
148 		dbg_print(lml, MSG_INTL(MSG_AUD_OBJOPEN), lib, obj);
149 	} else {
150 		if (ignore)
151 			dbg_print(lml, MSG_INTL(MSG_AUD_OBJOPEN_RI), lib, obj,
152 			    conv_la_bind(flags, &la_bind_buf));
153 		else
154 			dbg_print(lml, MSG_INTL(MSG_AUD_OBJOPEN_R), lib, obj,
155 			    conv_la_bind(flags, &la_bind_buf));
156 	}
157 }
158 
159 void
160 Dbg_audit_objclose(Lm_list *lml, const char *lib, const char *obj)
161 {
162 	if (DBG_NOTCLASS(DBG_C_AUDITING))
163 		return;
164 
165 	Dbg_util_nl(lml, DBG_NL_STD);
166 	dbg_print(lml, MSG_INTL(MSG_AUD_OBJCLOSE), lib, obj);
167 }
168 
169 void
170 Dbg_audit_symbind(Lm_list *lml, int call, const char *lib, const char *name,
171     Addr value, uint_t flags)
172 {
173 	Conv_la_symbind_buf_t	la_symbind_buf;
174 
175 	if (DBG_NOTCLASS(DBG_C_AUDITING))
176 		return;
177 
178 	if (call == DBG_AUD_CALL) {
179 		Dbg_util_nl(lml, DBG_NL_STD);
180 		dbg_print(lml, MSG_INTL(MSG_AUD_SYMBIND), lib, name,
181 		    EC_XWORD(value), conv_la_symbind(flags, &la_symbind_buf));
182 	} else {
183 		dbg_print(lml, MSG_INTL(MSG_AUD_SYMBIND_R), lib, name,
184 		    EC_XWORD(value), conv_la_symbind(flags, &la_symbind_buf));
185 	}
186 }
187 
188 void
189 Dbg_audit_pltenter(Lm_list *lml, int call, const char *lib, const char *name,
190     Addr value)
191 {
192 	if (DBG_NOTCLASS(DBG_C_AUDITING))
193 		return;
194 
195 	if (call == DBG_AUD_CALL) {
196 		Dbg_util_nl(lml, DBG_NL_STD);
197 		dbg_print(lml, MSG_INTL(MSG_AUD_PLTENTER), lib, name,
198 		    EC_XWORD(value));
199 	} else {
200 		dbg_print(lml, MSG_INTL(MSG_AUD_PLTENTER_R), lib, name,
201 		    EC_XWORD(value));
202 	}
203 }
204 
205 void
206 Dbg_audit_pltexit(Lm_list *lml, const char *lib, const char *name)
207 {
208 	if (DBG_NOTCLASS(DBG_C_AUDITING))
209 		return;
210 
211 	dbg_print(lml, MSG_INTL(MSG_AUD_PLTEXIT), lib, name);
212 }
213 
214 void
215 Dbg_audit_skip(Lm_list *lml, const char *name, const char *lmid)
216 {
217 	if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES))
218 		return;
219 
220 	dbg_print(lml, MSG_INTL(MSG_AUD_SKIP), name, lmid);
221 }
222 
223 void
224 Dbg_audit_terminate(Lm_list *lml, const char *name)
225 {
226 	if (DBG_NOTCLASS(DBG_C_FILES))
227 		return;
228 
229 	dbg_print(lml, MSG_INTL(MSG_AUD_TERM), name);
230 }
231 
232 void
233 Dbg_audit_ignore(Rt_map *lmp)
234 {
235 	if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES))
236 		return;
237 
238 	dbg_print(LIST(lmp), MSG_INTL(MSG_AUD_IGNORE), NAME(lmp));
239 }
240