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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <proc_service.h>
29 #include <link.h>
30 #include <rtld_db.h>
31 #include <rtld.h>
32 #include <alist.h>
33 #include <list.h>
34 #include <_rtld_db.h>
35 #include <msg.h>
36 #include <limits.h>
37 #include <string.h>
38 #include <sys/param.h>
39
40 /*
41 * 64-bit builds are going to compile this module twice, the
42 * second time with _ELF64 defined. These defines should make
43 * all the necessary adjustments to the code.
44 */
45 #ifdef _LP64
46 #ifdef _ELF64
47 #define _rd_event_enable32 _rd_event_enable64
48 #define _rd_event_getmsg32 _rd_event_getmsg64
49 #define _rd_get_dyns32 _rd_get_dyns64
50 #define _rd_get_ehdr32 _rd_get_ehdr64
51 #define _rd_objpad_enable32 _rd_objpad_enable64
52 #define _rd_loadobj_iter32 _rd_loadobj_iter64
53 #define _rd_reset32 _rd_reset64
54 #define find_dynamic_ent32 find_dynamic_ent64
55 #define validate_rdebug32 validate_rdebug64
56 #define TAPlist APlist
57 #define TLm_list Lm_list
58 #define TList List
59 #define TListnode Listnode
60 #define MSG_SYM_BRANDOPS MSG_SYM_BRANDOPS_64
266 LOG(ps_plog(MSG_ORIG(MSG_DB_INITFAILED)));
267 return (rc);
268 }
269 rc = find_dynamic_ent32(rap, symaddr, DT_DEBUG, &dyn);
270 if (rc != RD_OK) {
271 LOG(ps_plog(MSG_ORIG(MSG_DB_INITFAILED)));
272 return (rc);
273 }
274 rap->rd_rdebug = dyn.d_un.d_ptr;
275 rc = validate_rdebug32(rap);
276 if (rc != RD_OK) {
277 LOG(ps_plog(MSG_ORIG(MSG_DB_INITFAILED)));
278 return (rc);
279 }
280 }
281
282 /*
283 * If we are debugging a branded executable, load the appropriate
284 * helper library, and call its initialization routine. Being unable
285 * to load the helper library is not a critical error. (Hopefully
286 * we'll still be able to access some objects in the target.)
287 */
288 ps_pbrandname = (ps_pbrandname_fp_t)dlsym(RTLD_PROBE, "ps_pbrandname");
289 while ((ps_pbrandname != NULL) &&
290 (ps_pbrandname(php, brandname, MAXPATHLEN) == PS_OK)) {
291 const char *isa = "";
292
293 #ifdef _LP64
294 isa = MSG_ORIG(MSG_DB_64BIT_PREFIX);
295 #endif /* _LP64 */
296
297 if (rtld_db_helper_path[0] != '\0')
298 (void) snprintf(brandlib, MAXPATHLEN,
299 MSG_ORIG(MSG_DB_BRAND_HELPERPATH_PREFIX),
300 rtld_db_helper_path,
301 MSG_ORIG(MSG_DB_HELPER_PREFIX), brandname, isa,
302 brandname);
303 else
304 (void) snprintf(brandlib, MAXPATHLEN,
305 MSG_ORIG(MSG_DB_BRAND_HELPERPATH),
306 MSG_ORIG(MSG_DB_HELPER_PREFIX), brandname, isa,
307 brandname);
308
309 rap->rd_helper.rh_dlhandle = dlopen(brandlib,
310 RTLD_LAZY | RTLD_LOCAL);
311 if (rap->rd_helper.rh_dlhandle == NULL) {
312 LOG(ps_plog(MSG_ORIG(MSG_DB_HELPERLOADFAILED),
313 brandlib));
314 break;
315 }
316
317 rap->rd_helper.rh_ops = dlsym(rap->rd_helper.rh_dlhandle,
318 MSG_ORIG(MSG_SYM_BRANDOPS));
319 if (rap->rd_helper.rh_ops == NULL) {
320 LOG(ps_plog(MSG_ORIG(MSG_DB_HELPERNOOPS),
321 brandlib));
322 (void) dlclose(rap->rd_helper.rh_dlhandle);
323 rap->rd_helper.rh_dlhandle = NULL;
324 break;
325 }
326
327 rap->rd_helper.rh_data = rap->rd_helper.rh_ops->rho_init(rap,
|
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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright (c) 2014 Joyent, Inc. All rights reserved.
28 */
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <proc_service.h>
33 #include <link.h>
34 #include <rtld_db.h>
35 #include <rtld.h>
36 #include <alist.h>
37 #include <list.h>
38 #include <_rtld_db.h>
39 #include <msg.h>
40 #include <limits.h>
41 #include <string.h>
42 #include <sys/param.h>
43
44 /*
45 * We want to include zone.h to pull in the prototype for zone_get_nroot(),
46 * but we need to avoid pulling in <sys/stream.h>, which has a definition
47 * of M_DATA that conflicts with the ELF-related definition in machdep_*.h.
48 */
49 #define _SYS_STREAM_H
50 #include <zone.h>
51
52 /*
53 * 64-bit builds are going to compile this module twice, the
54 * second time with _ELF64 defined. These defines should make
55 * all the necessary adjustments to the code.
56 */
57 #ifdef _LP64
58 #ifdef _ELF64
59 #define _rd_event_enable32 _rd_event_enable64
60 #define _rd_event_getmsg32 _rd_event_getmsg64
61 #define _rd_get_dyns32 _rd_get_dyns64
62 #define _rd_get_ehdr32 _rd_get_ehdr64
63 #define _rd_objpad_enable32 _rd_objpad_enable64
64 #define _rd_loadobj_iter32 _rd_loadobj_iter64
65 #define _rd_reset32 _rd_reset64
66 #define find_dynamic_ent32 find_dynamic_ent64
67 #define validate_rdebug32 validate_rdebug64
68 #define TAPlist APlist
69 #define TLm_list Lm_list
70 #define TList List
71 #define TListnode Listnode
72 #define MSG_SYM_BRANDOPS MSG_SYM_BRANDOPS_64
278 LOG(ps_plog(MSG_ORIG(MSG_DB_INITFAILED)));
279 return (rc);
280 }
281 rc = find_dynamic_ent32(rap, symaddr, DT_DEBUG, &dyn);
282 if (rc != RD_OK) {
283 LOG(ps_plog(MSG_ORIG(MSG_DB_INITFAILED)));
284 return (rc);
285 }
286 rap->rd_rdebug = dyn.d_un.d_ptr;
287 rc = validate_rdebug32(rap);
288 if (rc != RD_OK) {
289 LOG(ps_plog(MSG_ORIG(MSG_DB_INITFAILED)));
290 return (rc);
291 }
292 }
293
294 /*
295 * If we are debugging a branded executable, load the appropriate
296 * helper library, and call its initialization routine. Being unable
297 * to load the helper library is not a critical error. (Hopefully
298 * we'll still be able to access some objects in the target.) Note
299 * that we pull in the native root here to allow for helper libraries
300 * to be properly found from within the branded zone.
301 */
302 ps_pbrandname = (ps_pbrandname_fp_t)dlsym(RTLD_PROBE, "ps_pbrandname");
303 while ((ps_pbrandname != NULL) &&
304 (ps_pbrandname(php, brandname, MAXPATHLEN) == PS_OK)) {
305 const char *isa = "";
306
307 #ifdef _LP64
308 isa = MSG_ORIG(MSG_DB_64BIT_PREFIX);
309 #endif /* _LP64 */
310
311 if (rtld_db_helper_path[0] != '\0') {
312 (void) snprintf(brandlib, MAXPATHLEN,
313 MSG_ORIG(MSG_DB_BRAND_HELPERPATH_PREFIX),
314 rtld_db_helper_path,
315 MSG_ORIG(MSG_DB_HELPER_PREFIX), brandname, isa,
316 brandname);
317 } else {
318 const char *nroot = zone_get_nroot();
319
320 if (nroot == NULL)
321 nroot = "";
322
323 (void) snprintf(brandlib, MAXPATHLEN,
324 MSG_ORIG(MSG_DB_BRAND_HELPERPATH), nroot,
325 MSG_ORIG(MSG_DB_HELPER_PREFIX), brandname, isa,
326 brandname);
327 }
328
329 rap->rd_helper.rh_dlhandle = dlopen(brandlib,
330 RTLD_LAZY | RTLD_LOCAL);
331 if (rap->rd_helper.rh_dlhandle == NULL) {
332 LOG(ps_plog(MSG_ORIG(MSG_DB_HELPERLOADFAILED),
333 brandlib));
334 break;
335 }
336
337 rap->rd_helper.rh_ops = dlsym(rap->rd_helper.rh_dlhandle,
338 MSG_ORIG(MSG_SYM_BRANDOPS));
339 if (rap->rd_helper.rh_ops == NULL) {
340 LOG(ps_plog(MSG_ORIG(MSG_DB_HELPERNOOPS),
341 brandlib));
342 (void) dlclose(rap->rd_helper.rh_dlhandle);
343 rap->rd_helper.rh_dlhandle = NULL;
344 break;
345 }
346
347 rap->rd_helper.rh_data = rap->rd_helper.rh_ops->rho_init(rap,
|