Print this page
10100 Illumos is confused about calloc() arguments
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/librtld_db/common/rtld_db.c
+++ new/usr/src/cmd/sgs/librtld_db/common/rtld_db.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
26 +/*
27 + * Copyright (c) 2018, Joyent, Inc.
28 + */
27 29
28 -
29 30 #include <stdlib.h>
30 31 #include <stdio.h>
31 32 #include <string.h>
32 33 #include <proc_service.h>
33 34 #include <link.h>
34 35 #include <rtld_db.h>
35 36 #include <rtld.h>
36 37 #include <_rtld_db.h>
37 38 #include <msg.h>
38 39 #include <sys/param.h>
39 40
40 41 /*
41 42 * Mutex to protect global data
42 43 */
43 44 mutex_t glob_mutex = DEFAULTMUTEX;
44 45 int rtld_db_version = RD_VERSION1;
45 46 int rtld_db_logging = 0;
46 47 char rtld_db_helper_path[MAXPATHLEN];
47 48
48 49
49 50 void
50 51 rd_log(const int on_off)
51 52 {
52 53 (void) mutex_lock(&glob_mutex);
53 54 rtld_db_logging = on_off;
54 55 (void) mutex_unlock(&glob_mutex);
55 56 LOG(ps_plog(MSG_ORIG(MSG_DB_LOGENABLE)));
56 57 }
57 58
58 59 /*
59 60 * Versioning Notes.
60 61 *
61 62 * The following have been added as the versions of librtld_db
62 63 * have grown:
63 64 *
64 65 * RD_VERSION1:
65 66 * o baseline version
66 67 *
67 68 * RD_VERSION2:
68 69 * o added support for the use of the AT_SUN_LDBASE auxvector
69 70 * to find the initialial debugging (r_debug) structures
70 71 * in ld.so.1
71 72 * o added the rl_dynamic field to rd_loadobj_t
72 73 * o added the RD_FLG_MEM_OBJECT to be used with the
73 74 * rl_dynamic->rl_flags field.
74 75 *
75 76 * RD_VERSION3:
76 77 * o added the following fields/flags to the rd_plt_info_t
77 78 * type:
78 79 * pi_baddr - bound address of PLT (if bound)
79 80 * pi_flags - flag field
80 81 * RD_FLG_PI_PLTBOUND (flag for pi_flags)
81 82 * if set - the PLT is bound and pi_baddr
82 83 * is filled in with the destination of the PLT.
83 84 *
84 85 * RD_VERSION4:
85 86 * o added the following field to the rd_loadobj_t structure:
86 87 * rl_tlsmodid - module ID for TLS references
87 88 */
88 89 rd_err_e
89 90 rd_init(int version)
90 91 {
91 92 if ((version < RD_VERSION1) ||
92 93 (version > RD_VERSION))
93 94 return (RD_NOCAPAB);
94 95 rtld_db_version = version;
95 96 LOG(ps_plog(MSG_ORIG(MSG_DB_RDINIT), rtld_db_version));
96 97
97 98 return (RD_OK);
98 99 }
99 100
100 101 rd_err_e
101 102 rd_ctl(int cmd, void *arg)
102 103 {
103 104 if (cmd != RD_CTL_SET_HELPPATH || arg == NULL ||
104 105 strlen((char *)arg) >= MAXPATHLEN)
105 106 return (RD_ERR);
106 107
107 108 (void) strcpy(rtld_db_helper_path, (char *)arg);
108 109
109 110 return (RD_OK);
110 111 }
111 112
112 113 rd_err_e
113 114 rd_get_dyns(rd_agent_t *rap, psaddr_t addr, void **dynpp, size_t *dynpp_sz)
114 115 {
115 116 if (rap->rd_helper.rh_ops != NULL)
116 117 return (rap->rd_helper.rh_ops->rho_get_dyns(
117 118 rap->rd_helper.rh_data, addr, dynpp, dynpp_sz));
118 119
119 120 #ifdef _LP64
120 121 if (rap->rd_dmodel == PR_MODEL_LP64)
121 122 return (_rd_get_dyns64(rap,
122 123 addr, (Elf64_Dyn **)dynpp, dynpp_sz));
123 124 else
124 125 #endif
125 126 return (_rd_get_dyns32(rap,
126 127 addr, (Dyn **)dynpp, dynpp_sz));
127 128 }
128 129
129 130 rd_err_e
130 131 rd_reset(struct rd_agent *rap)
131 132 {
132 133 rd_err_e err;
133 134
134 135 RDAGLOCK(rap);
135 136
136 137 rap->rd_flags = 0;
137 138
138 139 #ifdef _LP64
139 140 /*
140 141 * Determine if client is 32-bit or 64-bit.
141 142 */
142 143 if (ps_pdmodel(rap->rd_psp, &rap->rd_dmodel) != PS_OK) {
143 144 LOG(ps_plog(MSG_ORIG(MSG_DB_DMLOOKFAIL)));
144 145 RDAGUNLOCK(rap);
145 146 return (RD_DBERR);
146 147 }
147 148
148 149 if (rap->rd_dmodel == PR_MODEL_LP64)
149 150 err = _rd_reset64(rap);
150 151 else
151 152 #endif
152 153 err = _rd_reset32(rap);
153 154
154 155 RDAGUNLOCK(rap);
↓ open down ↓ |
116 lines elided |
↑ open up ↑ |
155 156 return (err);
156 157 }
157 158
158 159
159 160 rd_agent_t *
160 161 rd_new(struct ps_prochandle *php)
161 162 {
162 163 rd_agent_t *rap;
163 164
164 165 LOG(ps_plog(MSG_ORIG(MSG_DB_RDNEW), php));
165 - if ((rap = (rd_agent_t *)calloc(sizeof (rd_agent_t), 1)) == NULL)
166 + if ((rap = (rd_agent_t *)calloc(1, sizeof (rd_agent_t))) == NULL)
166 167 return (0);
167 168
168 169 rap->rd_psp = php;
169 170 (void) mutex_init(&rap->rd_mutex, USYNC_THREAD, 0);
170 171 if (rd_reset(rap) != RD_OK) {
171 172 if (rap->rd_helper.rh_dlhandle != NULL) {
172 173 rap->rd_helper.rh_ops->rho_fini(rap->rd_helper.rh_data);
173 174 (void) dlclose(rap->rd_helper.rh_dlhandle);
174 175 }
175 176 free(rap);
176 177 LOG(ps_plog(MSG_ORIG(MSG_DB_RESETFAIL)));
177 178 return ((rd_agent_t *)0);
178 179 }
179 180
180 181 return (rap);
181 182 }
182 183
183 184
184 185 void
185 186 rd_delete(rd_agent_t *rap)
186 187 {
187 188 LOG(ps_plog(MSG_ORIG(MSG_DB_RDDELETE), rap));
188 189 if (rap->rd_helper.rh_dlhandle != NULL) {
189 190 rap->rd_helper.rh_ops->rho_fini(rap->rd_helper.rh_data);
190 191 (void) dlclose(rap->rd_helper.rh_dlhandle);
191 192 }
192 193 free(rap);
193 194 }
194 195
195 196
196 197 rd_err_e
197 198 rd_loadobj_iter(rd_agent_t *rap, rl_iter_f *cb, void *client_data)
198 199 {
199 200 rd_err_e err;
200 201
201 202 RDAGLOCK(rap);
202 203
203 204 #ifdef _LP64
204 205 if (rap->rd_dmodel == PR_MODEL_LP64)
205 206 err = _rd_loadobj_iter64(rap, cb, client_data);
206 207 else
207 208 #endif
208 209 err = _rd_loadobj_iter32(rap, cb, client_data);
209 210
210 211 RDAGUNLOCK(rap);
211 212 return (err);
212 213 }
213 214
214 215
215 216 rd_err_e
216 217 rd_plt_resolution(rd_agent_t *rap, psaddr_t pc, lwpid_t lwpid,
217 218 psaddr_t pltbase, rd_plt_info_t *rpi)
218 219 {
219 220 rd_err_e err;
220 221 RDAGLOCK(rap);
221 222 #ifdef _LP64
222 223 if (rap->rd_dmodel == PR_MODEL_LP64)
223 224 err = plt64_resolution(rap, pc, lwpid, pltbase,
224 225 rpi);
225 226 else
226 227 #endif
227 228 err = plt32_resolution(rap, pc, lwpid, pltbase,
228 229 rpi);
229 230 RDAGUNLOCK(rap);
230 231 return (err);
231 232 }
232 233
233 234 rd_err_e
234 235 rd_event_addr(rd_agent_t *rap, rd_event_e num, rd_notify_t *np)
235 236 {
236 237 rd_err_e rc = RD_OK;
237 238
238 239 RDAGLOCK(rap);
239 240 switch (num) {
240 241 case RD_NONE:
241 242 break;
242 243 case RD_PREINIT:
243 244 np->type = RD_NOTIFY_BPT;
244 245 np->u.bptaddr = rap->rd_preinit;
245 246 break;
246 247 case RD_POSTINIT:
247 248 np->type = RD_NOTIFY_BPT;
248 249 np->u.bptaddr = rap->rd_postinit;
249 250 break;
250 251 case RD_DLACTIVITY:
251 252 np->type = RD_NOTIFY_BPT;
252 253 np->u.bptaddr = rap->rd_dlact;
253 254 break;
254 255 default:
255 256 LOG(ps_plog(MSG_ORIG(MSG_DB_UNEXPEVENT), num));
256 257 rc = RD_ERR;
257 258 break;
258 259 }
259 260 if (rc == RD_OK) {
260 261 LOG(ps_plog(MSG_ORIG(MSG_DB_RDEVENTADDR), num,
261 262 EC_ADDR(np->u.bptaddr)));
262 263 }
263 264
264 265 RDAGUNLOCK(rap);
265 266 return (rc);
266 267 }
267 268
268 269
269 270 /* ARGSUSED 0 */
270 271 rd_err_e
271 272 rd_event_enable(rd_agent_t *rap, int onoff)
272 273 {
273 274 rd_err_e err;
274 275
275 276 RDAGLOCK(rap);
276 277
277 278 #ifdef _LP64
278 279 if (rap->rd_dmodel == PR_MODEL_LP64)
279 280 err = _rd_event_enable64(rap, onoff);
280 281 else
281 282 #endif
282 283 err = _rd_event_enable32(rap, onoff);
283 284
284 285 RDAGUNLOCK(rap);
285 286 return (err);
286 287 }
287 288
288 289
289 290 rd_err_e
290 291 rd_event_getmsg(rd_agent_t *rap, rd_event_msg_t *emsg)
291 292 {
292 293 rd_err_e err;
293 294
294 295 RDAGLOCK(rap);
295 296
296 297 #ifdef _LP64
297 298 if (rap->rd_dmodel == PR_MODEL_LP64)
298 299 err = _rd_event_getmsg64(rap, emsg);
299 300 else
300 301 #endif
301 302 err = _rd_event_getmsg32(rap, emsg);
302 303
303 304 RDAGUNLOCK(rap);
304 305 return (err);
305 306 }
306 307
307 308
308 309 rd_err_e
309 310 rd_binder_exit_addr(struct rd_agent *rap, const char *bname, psaddr_t *beaddr)
310 311 {
311 312 ps_sym_t sym;
312 313
313 314 if (rap->rd_tbinder) {
314 315 *beaddr = rap->rd_tbinder;
315 316 return (RD_OK);
316 317 }
317 318 if (ps_pglobal_sym(rap->rd_psp, PS_OBJ_LDSO, bname, &sym) != PS_OK) {
318 319 LOG(ps_plog(MSG_ORIG(MSG_DB_UNFNDSYM),
319 320 bname));
320 321 return (RD_ERR);
321 322 }
322 323
323 324 rap->rd_tbinder = *beaddr = sym.st_value + sym.st_size - M_BIND_ADJ;
324 325
325 326 return (RD_OK);
326 327 }
327 328
328 329
329 330 rd_err_e
330 331 rd_objpad_enable(struct rd_agent *rap, size_t padsize)
331 332 {
332 333 rd_err_e err;
333 334
334 335 RDAGLOCK(rap);
335 336
336 337 #ifdef _LP64
337 338 if (rap->rd_dmodel == PR_MODEL_LP64)
338 339 err = _rd_objpad_enable64(rap, padsize);
339 340 else
340 341 #endif
341 342 err = _rd_objpad_enable32(rap, padsize);
342 343
343 344 RDAGUNLOCK(rap);
344 345 return (err);
345 346 }
346 347
347 348
348 349 char *
349 350 rd_errstr(rd_err_e rderr)
350 351 {
351 352 /*
352 353 * Convert an 'rd_err_e' to a string
353 354 */
354 355 switch (rderr) {
355 356 case RD_OK:
356 357 return ((char *)MSG_ORIG(MSG_ER_OK));
357 358 case RD_ERR:
358 359 return ((char *)MSG_ORIG(MSG_ER_ERR));
359 360 case RD_DBERR:
360 361 return ((char *)MSG_ORIG(MSG_ER_DBERR));
361 362 case RD_NOCAPAB:
362 363 return ((char *)MSG_ORIG(MSG_ER_NOCAPAB));
363 364 case RD_NODYNAM:
364 365 return ((char *)MSG_ORIG(MSG_ER_NODYNAM));
365 366 case RD_NOBASE:
366 367 return ((char *)MSG_ORIG(MSG_ER_NOBASE));
367 368 case RD_NOMAPS:
368 369 return ((char *)MSG_ORIG(MSG_ER_NOMAPS));
369 370 default:
370 371 return ((char *)MSG_ORIG(MSG_ER_DEFAULT));
371 372 }
372 373 }
↓ open down ↓ |
197 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX