xref: /titanic_44/usr/src/lib/libproc/common/Pservice.c (revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9acbbeafSnn35248  * Common Development and Distribution License (the "License").
6*9acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*9acbbeafSnn35248  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <stdarg.h>
297c478bd9Sstevel@tonic-gate #include <string.h>
307c478bd9Sstevel@tonic-gate #include "Pcontrol.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * This file implements the process services declared in <proc_service.h>.
347c478bd9Sstevel@tonic-gate  * This enables libproc to be used in conjunction with libc_db and
357c478bd9Sstevel@tonic-gate  * librtld_db.  As most of these facilities are already provided by
367c478bd9Sstevel@tonic-gate  * (more elegant) interfaces in <libproc.h>, we can just call those.
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * NOTE: We explicitly do *not* implement the functions ps_kill() and
397c478bd9Sstevel@tonic-gate  * ps_lrolltoaddr() in this library.  The very existence of these functions
407c478bd9Sstevel@tonic-gate  * causes libc_db to create an "agent thread" in the target process.
417c478bd9Sstevel@tonic-gate  * The only way to turn off this behavior is to omit these functions.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #pragma weak ps_pdread = ps_pread
457c478bd9Sstevel@tonic-gate #pragma weak ps_ptread = ps_pread
467c478bd9Sstevel@tonic-gate #pragma weak ps_pdwrite = ps_pwrite
477c478bd9Sstevel@tonic-gate #pragma weak ps_ptwrite = ps_pwrite
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate ps_err_e
507c478bd9Sstevel@tonic-gate ps_pdmodel(struct ps_prochandle *P, int *modelp)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	*modelp = P->status.pr_dmodel;
537c478bd9Sstevel@tonic-gate 	return (PS_OK);
547c478bd9Sstevel@tonic-gate }
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate ps_err_e
577c478bd9Sstevel@tonic-gate ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	if (P->ops->p_pread(P, buf, size, addr) != size)
607c478bd9Sstevel@tonic-gate 		return (PS_BADADDR);
617c478bd9Sstevel@tonic-gate 	return (PS_OK);
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate ps_err_e
657c478bd9Sstevel@tonic-gate ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate 	if (P->ops->p_pwrite(P, buf, size, addr) != size)
687c478bd9Sstevel@tonic-gate 		return (PS_BADADDR);
697c478bd9Sstevel@tonic-gate 	return (PS_OK);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * libc_db calls matched pairs of ps_pstop()/ps_pcontinue()
747c478bd9Sstevel@tonic-gate  * in the belief that the client may have left the process
757c478bd9Sstevel@tonic-gate  * running while calling in to the libc_db interfaces.
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * We interpret the meaning of these functions to be an inquiry
787c478bd9Sstevel@tonic-gate  * as to whether the process is stopped, not an action to be
797c478bd9Sstevel@tonic-gate  * performed to make it stopped.  For similar reasons, we also
807c478bd9Sstevel@tonic-gate  * return PS_OK for core files in order to allow libc_db to
817c478bd9Sstevel@tonic-gate  * operate on these as well.
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate ps_err_e
847c478bd9Sstevel@tonic-gate ps_pstop(struct ps_prochandle *P)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
877c478bd9Sstevel@tonic-gate 		return (PS_ERR);
887c478bd9Sstevel@tonic-gate 	return (PS_OK);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate ps_err_e
927c478bd9Sstevel@tonic-gate ps_pcontinue(struct ps_prochandle *P)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
957c478bd9Sstevel@tonic-gate 		return (PS_ERR);
967c478bd9Sstevel@tonic-gate 	return (PS_OK);
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate  * ps_lstop() and ps_lcontinue() are not called by any code in libc_db
1017c478bd9Sstevel@tonic-gate  * or librtld_db.  We make them behave like ps_pstop() and ps_pcontinue().
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
1047c478bd9Sstevel@tonic-gate ps_err_e
1057c478bd9Sstevel@tonic-gate ps_lstop(struct ps_prochandle *P, lwpid_t lwpid)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1087c478bd9Sstevel@tonic-gate 		return (PS_ERR);
1097c478bd9Sstevel@tonic-gate 	return (PS_OK);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
1137c478bd9Sstevel@tonic-gate ps_err_e
1147c478bd9Sstevel@tonic-gate ps_lcontinue(struct ps_prochandle *P, lwpid_t lwpid)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1177c478bd9Sstevel@tonic-gate 		return (PS_ERR);
1187c478bd9Sstevel@tonic-gate 	return (PS_OK);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate ps_err_e
1227c478bd9Sstevel@tonic-gate ps_lgetregs(struct ps_prochandle *P, lwpid_t lwpid, prgregset_t regs)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1257c478bd9Sstevel@tonic-gate 		return (PS_ERR);
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	if (Plwp_getregs(P, lwpid, regs) == 0)
1287c478bd9Sstevel@tonic-gate 		return (PS_OK);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate ps_err_e
1347c478bd9Sstevel@tonic-gate ps_lsetregs(struct ps_prochandle *P, lwpid_t lwpid, const prgregset_t regs)
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP)
1377c478bd9Sstevel@tonic-gate 		return (PS_ERR);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	if (Plwp_setregs(P, lwpid, regs) == 0)
1407c478bd9Sstevel@tonic-gate 		return (PS_OK);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate ps_err_e
1467c478bd9Sstevel@tonic-gate ps_lgetfpregs(struct ps_prochandle *P, lwpid_t lwpid, prfpregset_t *regs)
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1497c478bd9Sstevel@tonic-gate 		return (PS_ERR);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	if (Plwp_getfpregs(P, lwpid, regs) == 0)
1527c478bd9Sstevel@tonic-gate 		return (PS_OK);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate ps_err_e
1587c478bd9Sstevel@tonic-gate ps_lsetfpregs(struct ps_prochandle *P, lwpid_t lwpid, const prfpregset_t *regs)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP)
1617c478bd9Sstevel@tonic-gate 		return (PS_ERR);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	if (Plwp_setfpregs(P, lwpid, regs) == 0)
1647c478bd9Sstevel@tonic-gate 		return (PS_OK);
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #if defined(sparc) || defined(__sparc)
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate ps_err_e
1727c478bd9Sstevel@tonic-gate ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize)
1737c478bd9Sstevel@tonic-gate {
174*9acbbeafSnn35248 	char fname[PATH_MAX];
1757c478bd9Sstevel@tonic-gate 	struct stat statb;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (P->state == PS_DEAD) {
1787c478bd9Sstevel@tonic-gate 		lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
1797c478bd9Sstevel@tonic-gate 		uint_t i;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 		for (i = 0; i < P->core->core_nlwp; i++, lwp = list_next(lwp)) {
1827c478bd9Sstevel@tonic-gate 			if (lwp->lwp_id == lwpid) {
1837c478bd9Sstevel@tonic-gate 				if (lwp->lwp_xregs != NULL)
1847c478bd9Sstevel@tonic-gate 					*xrsize = sizeof (prxregset_t);
1857c478bd9Sstevel@tonic-gate 				else
1867c478bd9Sstevel@tonic-gate 					*xrsize = 0;
1877c478bd9Sstevel@tonic-gate 				return (PS_OK);
1887c478bd9Sstevel@tonic-gate 			}
1897c478bd9Sstevel@tonic-gate 		}
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 		return (PS_BADLID);
1927c478bd9Sstevel@tonic-gate 	}
1937c478bd9Sstevel@tonic-gate 
194*9acbbeafSnn35248 	(void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/xregs",
195*9acbbeafSnn35248 	    procfs_path, (int)P->status.pr_pid, (int)lwpid);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	if (stat(fname, &statb) != 0)
1987c478bd9Sstevel@tonic-gate 		return (PS_BADLID);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	*xrsize = (int)statb.st_size;
2017c478bd9Sstevel@tonic-gate 	return (PS_OK);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate ps_err_e
2057c478bd9Sstevel@tonic-gate ps_lgetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
2087c478bd9Sstevel@tonic-gate 		return (PS_ERR);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
2117c478bd9Sstevel@tonic-gate 	if (Plwp_getxregs(P, lwpid, (prxregset_t *)xregs) == 0)
2127c478bd9Sstevel@tonic-gate 		return (PS_OK);
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate ps_err_e
2187c478bd9Sstevel@tonic-gate ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP)
2217c478bd9Sstevel@tonic-gate 		return (PS_ERR);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
2247c478bd9Sstevel@tonic-gate 	if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs) == 0)
2257c478bd9Sstevel@tonic-gate 		return (PS_OK);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate #endif	/* sparc */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate ps_err_e
2357c478bd9Sstevel@tonic-gate ps_lgetLDT(struct ps_prochandle *P, lwpid_t lwpid, struct ssd *ldt)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
2387c478bd9Sstevel@tonic-gate 	if (P->status.pr_dmodel != PR_MODEL_NATIVE) {
2397c478bd9Sstevel@tonic-gate #endif
2407c478bd9Sstevel@tonic-gate 	prgregset_t regs;
2417c478bd9Sstevel@tonic-gate 	struct ssd *ldtarray;
2427c478bd9Sstevel@tonic-gate 	ps_err_e error;
2437c478bd9Sstevel@tonic-gate 	uint_t gs;
2447c478bd9Sstevel@tonic-gate 	int nldt;
2457c478bd9Sstevel@tonic-gate 	int i;
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
2487c478bd9Sstevel@tonic-gate 		return (PS_ERR);
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	/*
2517c478bd9Sstevel@tonic-gate 	 * We need to get the ldt entry that matches the
2527c478bd9Sstevel@tonic-gate 	 * value in the lwp's GS register.
2537c478bd9Sstevel@tonic-gate 	 */
2547c478bd9Sstevel@tonic-gate 	if ((error = ps_lgetregs(P, lwpid, regs)) != PS_OK)
2557c478bd9Sstevel@tonic-gate 		return (error);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	gs = regs[GS];
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if ((nldt = Pldt(P, NULL, 0)) <= 0 ||
2607c478bd9Sstevel@tonic-gate 	    (ldtarray = malloc(nldt * sizeof (struct ssd))) == NULL)
2617c478bd9Sstevel@tonic-gate 		return (PS_ERR);
2627c478bd9Sstevel@tonic-gate 	if ((nldt = Pldt(P, ldtarray, nldt)) <= 0) {
2637c478bd9Sstevel@tonic-gate 		free(ldtarray);
2647c478bd9Sstevel@tonic-gate 		return (PS_ERR);
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	for (i = 0; i < nldt; i++) {
2687c478bd9Sstevel@tonic-gate 		if (gs == ldtarray[i].sel) {
2697c478bd9Sstevel@tonic-gate 			*ldt = ldtarray[i];
2707c478bd9Sstevel@tonic-gate 			break;
2717c478bd9Sstevel@tonic-gate 		}
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate 	free(ldtarray);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	if (i < nldt)
2767c478bd9Sstevel@tonic-gate 		return (PS_OK);
2777c478bd9Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate #endif
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	return (PS_ERR);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate /*
2877c478bd9Sstevel@tonic-gate  * Libthread_db doesn't use this function currently, but librtld_db uses
2887c478bd9Sstevel@tonic-gate  * it for its debugging output.  We turn this on via rd_log if our debugging
2897c478bd9Sstevel@tonic-gate  * switch is on, and then echo the messages sent to ps_plog to stderr.
2907c478bd9Sstevel@tonic-gate  */
2917c478bd9Sstevel@tonic-gate void
2927c478bd9Sstevel@tonic-gate ps_plog(const char *fmt, ...)
2937c478bd9Sstevel@tonic-gate {
2947c478bd9Sstevel@tonic-gate 	va_list ap;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	if (_libproc_debug && fmt != NULL && *fmt != '\0') {
2977c478bd9Sstevel@tonic-gate 		va_start(ap, fmt);
2987c478bd9Sstevel@tonic-gate 		(void) vfprintf(stderr, fmt, ap);
2997c478bd9Sstevel@tonic-gate 		va_end(ap);
3007c478bd9Sstevel@tonic-gate 		if (fmt[strlen(fmt) - 1] != '\n')
3017c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stderr);
3027c478bd9Sstevel@tonic-gate 	}
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate  * Store a pointer to our internal copy of the aux vector at the address
3077c478bd9Sstevel@tonic-gate  * specified by the caller.  It should not hold on to this data for too long.
3087c478bd9Sstevel@tonic-gate  */
3097c478bd9Sstevel@tonic-gate ps_err_e
3107c478bd9Sstevel@tonic-gate ps_pauxv(struct ps_prochandle *P, const auxv_t **aux)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate 	if (P->auxv == NULL)
3137c478bd9Sstevel@tonic-gate 		Preadauxvec(P);
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	if (P->auxv == NULL)
3167c478bd9Sstevel@tonic-gate 		return (PS_ERR);
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	*aux = (const auxv_t *)P->auxv;
3197c478bd9Sstevel@tonic-gate 	return (PS_OK);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
322*9acbbeafSnn35248 ps_err_e
323*9acbbeafSnn35248 ps_pbrandname(struct ps_prochandle *P, char *buf, size_t len)
324*9acbbeafSnn35248 {
325*9acbbeafSnn35248 	return (Pbrandname(P, buf, len) ? PS_OK : PS_ERR);
326*9acbbeafSnn35248 }
327*9acbbeafSnn35248 
3287c478bd9Sstevel@tonic-gate /*
3297c478bd9Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding address.
3307c478bd9Sstevel@tonic-gate  */
3317c478bd9Sstevel@tonic-gate ps_err_e
3327c478bd9Sstevel@tonic-gate ps_pglobal_lookup(struct ps_prochandle *P, const char *object_name,
3337c478bd9Sstevel@tonic-gate 	const char *sym_name, psaddr_t *sym_addr)
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
3387c478bd9Sstevel@tonic-gate 		dprintf("pglobal_lookup <%s> -> %p\n",
3397c478bd9Sstevel@tonic-gate 		    sym_name, (void *)(uintptr_t)sym.st_value);
3407c478bd9Sstevel@tonic-gate 		*sym_addr = (psaddr_t)sym.st_value;
3417c478bd9Sstevel@tonic-gate 		return (PS_OK);
3427c478bd9Sstevel@tonic-gate 	}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	return (PS_NOSYM);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding symbol
3497c478bd9Sstevel@tonic-gate  * information.  If we're compiled _LP64, we just call Plookup_by_name
3507c478bd9Sstevel@tonic-gate  * and return because ps_sym_t is defined to be an Elf64_Sym, which
3517c478bd9Sstevel@tonic-gate  * is the same as a GElf_Sym.  In the _ILP32 case, we have to convert
3527c478bd9Sstevel@tonic-gate  * Plookup_by_name's result back to a ps_sym_t (which is an Elf32_Sym).
3537c478bd9Sstevel@tonic-gate  */
3547c478bd9Sstevel@tonic-gate ps_err_e
3557c478bd9Sstevel@tonic-gate ps_pglobal_sym(struct ps_prochandle *P, const char *object_name,
3567c478bd9Sstevel@tonic-gate 	const char *sym_name, ps_sym_t *symp)
3577c478bd9Sstevel@tonic-gate {
3587c478bd9Sstevel@tonic-gate #if defined(_ILP32)
3597c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
3627c478bd9Sstevel@tonic-gate 		symp->st_name = (Elf32_Word)sym.st_name;
3637c478bd9Sstevel@tonic-gate 		symp->st_value = (Elf32_Addr)sym.st_value;
3647c478bd9Sstevel@tonic-gate 		symp->st_size = (Elf32_Word)sym.st_size;
3657c478bd9Sstevel@tonic-gate 		symp->st_info = ELF32_ST_INFO(
3667c478bd9Sstevel@tonic-gate 		    GELF_ST_BIND(sym.st_info), GELF_ST_TYPE(sym.st_info));
3677c478bd9Sstevel@tonic-gate 		symp->st_other = sym.st_other;
3687c478bd9Sstevel@tonic-gate 		symp->st_shndx = sym.st_shndx;
3697c478bd9Sstevel@tonic-gate 		return (PS_OK);
3707c478bd9Sstevel@tonic-gate 	}
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate #elif defined(_LP64)
3737c478bd9Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, symp) == 0)
3747c478bd9Sstevel@tonic-gate 		return (PS_OK);
3757c478bd9Sstevel@tonic-gate #endif
3767c478bd9Sstevel@tonic-gate 	return (PS_NOSYM);
3777c478bd9Sstevel@tonic-gate }
378