xref: /onnv-gate/usr/src/lib/libproc/common/Pservice.c (revision 2712:f74a135872bc)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2712Snn35248  * Common Development and Distribution License (the "License").
6*2712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2712Snn35248  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdarg.h>
290Sstevel@tonic-gate #include <string.h>
300Sstevel@tonic-gate #include "Pcontrol.h"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * This file implements the process services declared in <proc_service.h>.
340Sstevel@tonic-gate  * This enables libproc to be used in conjunction with libc_db and
350Sstevel@tonic-gate  * librtld_db.  As most of these facilities are already provided by
360Sstevel@tonic-gate  * (more elegant) interfaces in <libproc.h>, we can just call those.
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * NOTE: We explicitly do *not* implement the functions ps_kill() and
390Sstevel@tonic-gate  * ps_lrolltoaddr() in this library.  The very existence of these functions
400Sstevel@tonic-gate  * causes libc_db to create an "agent thread" in the target process.
410Sstevel@tonic-gate  * The only way to turn off this behavior is to omit these functions.
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #pragma weak ps_pdread = ps_pread
450Sstevel@tonic-gate #pragma weak ps_ptread = ps_pread
460Sstevel@tonic-gate #pragma weak ps_pdwrite = ps_pwrite
470Sstevel@tonic-gate #pragma weak ps_ptwrite = ps_pwrite
480Sstevel@tonic-gate 
490Sstevel@tonic-gate ps_err_e
ps_pdmodel(struct ps_prochandle * P,int * modelp)500Sstevel@tonic-gate ps_pdmodel(struct ps_prochandle *P, int *modelp)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate 	*modelp = P->status.pr_dmodel;
530Sstevel@tonic-gate 	return (PS_OK);
540Sstevel@tonic-gate }
550Sstevel@tonic-gate 
560Sstevel@tonic-gate ps_err_e
ps_pread(struct ps_prochandle * P,psaddr_t addr,void * buf,size_t size)570Sstevel@tonic-gate ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	if (P->ops->p_pread(P, buf, size, addr) != size)
600Sstevel@tonic-gate 		return (PS_BADADDR);
610Sstevel@tonic-gate 	return (PS_OK);
620Sstevel@tonic-gate }
630Sstevel@tonic-gate 
640Sstevel@tonic-gate ps_err_e
ps_pwrite(struct ps_prochandle * P,psaddr_t addr,const void * buf,size_t size)650Sstevel@tonic-gate ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
660Sstevel@tonic-gate {
670Sstevel@tonic-gate 	if (P->ops->p_pwrite(P, buf, size, addr) != size)
680Sstevel@tonic-gate 		return (PS_BADADDR);
690Sstevel@tonic-gate 	return (PS_OK);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * libc_db calls matched pairs of ps_pstop()/ps_pcontinue()
740Sstevel@tonic-gate  * in the belief that the client may have left the process
750Sstevel@tonic-gate  * running while calling in to the libc_db interfaces.
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  * We interpret the meaning of these functions to be an inquiry
780Sstevel@tonic-gate  * as to whether the process is stopped, not an action to be
790Sstevel@tonic-gate  * performed to make it stopped.  For similar reasons, we also
800Sstevel@tonic-gate  * return PS_OK for core files in order to allow libc_db to
810Sstevel@tonic-gate  * operate on these as well.
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate ps_err_e
ps_pstop(struct ps_prochandle * P)840Sstevel@tonic-gate ps_pstop(struct ps_prochandle *P)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
870Sstevel@tonic-gate 		return (PS_ERR);
880Sstevel@tonic-gate 	return (PS_OK);
890Sstevel@tonic-gate }
900Sstevel@tonic-gate 
910Sstevel@tonic-gate ps_err_e
ps_pcontinue(struct ps_prochandle * P)920Sstevel@tonic-gate ps_pcontinue(struct ps_prochandle *P)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
950Sstevel@tonic-gate 		return (PS_ERR);
960Sstevel@tonic-gate 	return (PS_OK);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * ps_lstop() and ps_lcontinue() are not called by any code in libc_db
1010Sstevel@tonic-gate  * or librtld_db.  We make them behave like ps_pstop() and ps_pcontinue().
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate /* ARGSUSED1 */
1040Sstevel@tonic-gate ps_err_e
ps_lstop(struct ps_prochandle * P,lwpid_t lwpid)1050Sstevel@tonic-gate ps_lstop(struct ps_prochandle *P, lwpid_t lwpid)
1060Sstevel@tonic-gate {
1070Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1080Sstevel@tonic-gate 		return (PS_ERR);
1090Sstevel@tonic-gate 	return (PS_OK);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /* ARGSUSED1 */
1130Sstevel@tonic-gate ps_err_e
ps_lcontinue(struct ps_prochandle * P,lwpid_t lwpid)1140Sstevel@tonic-gate ps_lcontinue(struct ps_prochandle *P, lwpid_t lwpid)
1150Sstevel@tonic-gate {
1160Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1170Sstevel@tonic-gate 		return (PS_ERR);
1180Sstevel@tonic-gate 	return (PS_OK);
1190Sstevel@tonic-gate }
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate ps_err_e
ps_lgetregs(struct ps_prochandle * P,lwpid_t lwpid,prgregset_t regs)1220Sstevel@tonic-gate ps_lgetregs(struct ps_prochandle *P, lwpid_t lwpid, prgregset_t regs)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1250Sstevel@tonic-gate 		return (PS_ERR);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	if (Plwp_getregs(P, lwpid, regs) == 0)
1280Sstevel@tonic-gate 		return (PS_OK);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	return (PS_BADLID);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate ps_err_e
ps_lsetregs(struct ps_prochandle * P,lwpid_t lwpid,const prgregset_t regs)1340Sstevel@tonic-gate ps_lsetregs(struct ps_prochandle *P, lwpid_t lwpid, const prgregset_t regs)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate 	if (P->state != PS_STOP)
1370Sstevel@tonic-gate 		return (PS_ERR);
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	if (Plwp_setregs(P, lwpid, regs) == 0)
1400Sstevel@tonic-gate 		return (PS_OK);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	return (PS_BADLID);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate ps_err_e
ps_lgetfpregs(struct ps_prochandle * P,lwpid_t lwpid,prfpregset_t * regs)1460Sstevel@tonic-gate ps_lgetfpregs(struct ps_prochandle *P, lwpid_t lwpid, prfpregset_t *regs)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
1490Sstevel@tonic-gate 		return (PS_ERR);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	if (Plwp_getfpregs(P, lwpid, regs) == 0)
1520Sstevel@tonic-gate 		return (PS_OK);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	return (PS_BADLID);
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate ps_err_e
ps_lsetfpregs(struct ps_prochandle * P,lwpid_t lwpid,const prfpregset_t * regs)1580Sstevel@tonic-gate ps_lsetfpregs(struct ps_prochandle *P, lwpid_t lwpid, const prfpregset_t *regs)
1590Sstevel@tonic-gate {
1600Sstevel@tonic-gate 	if (P->state != PS_STOP)
1610Sstevel@tonic-gate 		return (PS_ERR);
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	if (Plwp_setfpregs(P, lwpid, regs) == 0)
1640Sstevel@tonic-gate 		return (PS_OK);
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	return (PS_BADLID);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #if defined(sparc) || defined(__sparc)
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate ps_err_e
ps_lgetxregsize(struct ps_prochandle * P,lwpid_t lwpid,int * xrsize)1720Sstevel@tonic-gate ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize)
1730Sstevel@tonic-gate {
174*2712Snn35248 	char fname[PATH_MAX];
1750Sstevel@tonic-gate 	struct stat statb;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	if (P->state == PS_DEAD) {
1780Sstevel@tonic-gate 		lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
1790Sstevel@tonic-gate 		uint_t i;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 		for (i = 0; i < P->core->core_nlwp; i++, lwp = list_next(lwp)) {
1820Sstevel@tonic-gate 			if (lwp->lwp_id == lwpid) {
1830Sstevel@tonic-gate 				if (lwp->lwp_xregs != NULL)
1840Sstevel@tonic-gate 					*xrsize = sizeof (prxregset_t);
1850Sstevel@tonic-gate 				else
1860Sstevel@tonic-gate 					*xrsize = 0;
1870Sstevel@tonic-gate 				return (PS_OK);
1880Sstevel@tonic-gate 			}
1890Sstevel@tonic-gate 		}
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 		return (PS_BADLID);
1920Sstevel@tonic-gate 	}
1930Sstevel@tonic-gate 
194*2712Snn35248 	(void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/xregs",
195*2712Snn35248 	    procfs_path, (int)P->status.pr_pid, (int)lwpid);
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	if (stat(fname, &statb) != 0)
1980Sstevel@tonic-gate 		return (PS_BADLID);
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate 	*xrsize = (int)statb.st_size;
2010Sstevel@tonic-gate 	return (PS_OK);
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate ps_err_e
ps_lgetxregs(struct ps_prochandle * P,lwpid_t lwpid,caddr_t xregs)2050Sstevel@tonic-gate ps_lgetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
2080Sstevel@tonic-gate 		return (PS_ERR);
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 	/* LINTED - alignment */
2110Sstevel@tonic-gate 	if (Plwp_getxregs(P, lwpid, (prxregset_t *)xregs) == 0)
2120Sstevel@tonic-gate 		return (PS_OK);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	return (PS_BADLID);
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate ps_err_e
ps_lsetxregs(struct ps_prochandle * P,lwpid_t lwpid,caddr_t xregs)2180Sstevel@tonic-gate ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate 	if (P->state != PS_STOP)
2210Sstevel@tonic-gate 		return (PS_ERR);
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	/* LINTED - alignment */
2240Sstevel@tonic-gate 	if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs) == 0)
2250Sstevel@tonic-gate 		return (PS_OK);
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 	return (PS_BADLID);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate #endif	/* sparc */
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate ps_err_e
ps_lgetLDT(struct ps_prochandle * P,lwpid_t lwpid,struct ssd * ldt)2350Sstevel@tonic-gate ps_lgetLDT(struct ps_prochandle *P, lwpid_t lwpid, struct ssd *ldt)
2360Sstevel@tonic-gate {
2370Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
2380Sstevel@tonic-gate 	if (P->status.pr_dmodel != PR_MODEL_NATIVE) {
2390Sstevel@tonic-gate #endif
2400Sstevel@tonic-gate 	prgregset_t regs;
2410Sstevel@tonic-gate 	struct ssd *ldtarray;
2420Sstevel@tonic-gate 	ps_err_e error;
2430Sstevel@tonic-gate 	uint_t gs;
2440Sstevel@tonic-gate 	int nldt;
2450Sstevel@tonic-gate 	int i;
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
2480Sstevel@tonic-gate 		return (PS_ERR);
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 	/*
2510Sstevel@tonic-gate 	 * We need to get the ldt entry that matches the
2520Sstevel@tonic-gate 	 * value in the lwp's GS register.
2530Sstevel@tonic-gate 	 */
2540Sstevel@tonic-gate 	if ((error = ps_lgetregs(P, lwpid, regs)) != PS_OK)
2550Sstevel@tonic-gate 		return (error);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	gs = regs[GS];
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate 	if ((nldt = Pldt(P, NULL, 0)) <= 0 ||
2600Sstevel@tonic-gate 	    (ldtarray = malloc(nldt * sizeof (struct ssd))) == NULL)
2610Sstevel@tonic-gate 		return (PS_ERR);
2620Sstevel@tonic-gate 	if ((nldt = Pldt(P, ldtarray, nldt)) <= 0) {
2630Sstevel@tonic-gate 		free(ldtarray);
2640Sstevel@tonic-gate 		return (PS_ERR);
2650Sstevel@tonic-gate 	}
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	for (i = 0; i < nldt; i++) {
2680Sstevel@tonic-gate 		if (gs == ldtarray[i].sel) {
2690Sstevel@tonic-gate 			*ldt = ldtarray[i];
2700Sstevel@tonic-gate 			break;
2710Sstevel@tonic-gate 		}
2720Sstevel@tonic-gate 	}
2730Sstevel@tonic-gate 	free(ldtarray);
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	if (i < nldt)
2760Sstevel@tonic-gate 		return (PS_OK);
2770Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
2780Sstevel@tonic-gate 	}
2790Sstevel@tonic-gate #endif
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	return (PS_ERR);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate  * Libthread_db doesn't use this function currently, but librtld_db uses
2880Sstevel@tonic-gate  * it for its debugging output.  We turn this on via rd_log if our debugging
2890Sstevel@tonic-gate  * switch is on, and then echo the messages sent to ps_plog to stderr.
2900Sstevel@tonic-gate  */
2910Sstevel@tonic-gate void
ps_plog(const char * fmt,...)2920Sstevel@tonic-gate ps_plog(const char *fmt, ...)
2930Sstevel@tonic-gate {
2940Sstevel@tonic-gate 	va_list ap;
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	if (_libproc_debug && fmt != NULL && *fmt != '\0') {
2970Sstevel@tonic-gate 		va_start(ap, fmt);
2980Sstevel@tonic-gate 		(void) vfprintf(stderr, fmt, ap);
2990Sstevel@tonic-gate 		va_end(ap);
3000Sstevel@tonic-gate 		if (fmt[strlen(fmt) - 1] != '\n')
3010Sstevel@tonic-gate 			(void) fputc('\n', stderr);
3020Sstevel@tonic-gate 	}
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate  * Store a pointer to our internal copy of the aux vector at the address
3070Sstevel@tonic-gate  * specified by the caller.  It should not hold on to this data for too long.
3080Sstevel@tonic-gate  */
3090Sstevel@tonic-gate ps_err_e
ps_pauxv(struct ps_prochandle * P,const auxv_t ** aux)3100Sstevel@tonic-gate ps_pauxv(struct ps_prochandle *P, const auxv_t **aux)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate 	if (P->auxv == NULL)
3130Sstevel@tonic-gate 		Preadauxvec(P);
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 	if (P->auxv == NULL)
3160Sstevel@tonic-gate 		return (PS_ERR);
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 	*aux = (const auxv_t *)P->auxv;
3190Sstevel@tonic-gate 	return (PS_OK);
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate 
322*2712Snn35248 ps_err_e
ps_pbrandname(struct ps_prochandle * P,char * buf,size_t len)323*2712Snn35248 ps_pbrandname(struct ps_prochandle *P, char *buf, size_t len)
324*2712Snn35248 {
325*2712Snn35248 	return (Pbrandname(P, buf, len) ? PS_OK : PS_ERR);
326*2712Snn35248 }
327*2712Snn35248 
3280Sstevel@tonic-gate /*
3290Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding address.
3300Sstevel@tonic-gate  */
3310Sstevel@tonic-gate ps_err_e
ps_pglobal_lookup(struct ps_prochandle * P,const char * object_name,const char * sym_name,psaddr_t * sym_addr)3320Sstevel@tonic-gate ps_pglobal_lookup(struct ps_prochandle *P, const char *object_name,
3330Sstevel@tonic-gate 	const char *sym_name, psaddr_t *sym_addr)
3340Sstevel@tonic-gate {
3350Sstevel@tonic-gate 	GElf_Sym sym;
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
3380Sstevel@tonic-gate 		dprintf("pglobal_lookup <%s> -> %p\n",
3390Sstevel@tonic-gate 		    sym_name, (void *)(uintptr_t)sym.st_value);
3400Sstevel@tonic-gate 		*sym_addr = (psaddr_t)sym.st_value;
3410Sstevel@tonic-gate 		return (PS_OK);
3420Sstevel@tonic-gate 	}
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	return (PS_NOSYM);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate /*
3480Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding symbol
3490Sstevel@tonic-gate  * information.  If we're compiled _LP64, we just call Plookup_by_name
3500Sstevel@tonic-gate  * and return because ps_sym_t is defined to be an Elf64_Sym, which
3510Sstevel@tonic-gate  * is the same as a GElf_Sym.  In the _ILP32 case, we have to convert
3520Sstevel@tonic-gate  * Plookup_by_name's result back to a ps_sym_t (which is an Elf32_Sym).
3530Sstevel@tonic-gate  */
3540Sstevel@tonic-gate ps_err_e
ps_pglobal_sym(struct ps_prochandle * P,const char * object_name,const char * sym_name,ps_sym_t * symp)3550Sstevel@tonic-gate ps_pglobal_sym(struct ps_prochandle *P, const char *object_name,
3560Sstevel@tonic-gate 	const char *sym_name, ps_sym_t *symp)
3570Sstevel@tonic-gate {
3580Sstevel@tonic-gate #if defined(_ILP32)
3590Sstevel@tonic-gate 	GElf_Sym sym;
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
3620Sstevel@tonic-gate 		symp->st_name = (Elf32_Word)sym.st_name;
3630Sstevel@tonic-gate 		symp->st_value = (Elf32_Addr)sym.st_value;
3640Sstevel@tonic-gate 		symp->st_size = (Elf32_Word)sym.st_size;
3650Sstevel@tonic-gate 		symp->st_info = ELF32_ST_INFO(
3660Sstevel@tonic-gate 		    GELF_ST_BIND(sym.st_info), GELF_ST_TYPE(sym.st_info));
3670Sstevel@tonic-gate 		symp->st_other = sym.st_other;
3680Sstevel@tonic-gate 		symp->st_shndx = sym.st_shndx;
3690Sstevel@tonic-gate 		return (PS_OK);
3700Sstevel@tonic-gate 	}
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate #elif defined(_LP64)
3730Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, symp) == 0)
3740Sstevel@tonic-gate 		return (PS_OK);
3750Sstevel@tonic-gate #endif
3760Sstevel@tonic-gate 	return (PS_NOSYM);
3770Sstevel@tonic-gate }
378