xref: /titanic_50/usr/src/lib/libproc/common/Pservice.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
30*7c478bd9Sstevel@tonic-gate #include <string.h>
31*7c478bd9Sstevel@tonic-gate #include "Pcontrol.h"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * This file implements the process services declared in <proc_service.h>.
35*7c478bd9Sstevel@tonic-gate  * This enables libproc to be used in conjunction with libc_db and
36*7c478bd9Sstevel@tonic-gate  * librtld_db.  As most of these facilities are already provided by
37*7c478bd9Sstevel@tonic-gate  * (more elegant) interfaces in <libproc.h>, we can just call those.
38*7c478bd9Sstevel@tonic-gate  *
39*7c478bd9Sstevel@tonic-gate  * NOTE: We explicitly do *not* implement the functions ps_kill() and
40*7c478bd9Sstevel@tonic-gate  * ps_lrolltoaddr() in this library.  The very existence of these functions
41*7c478bd9Sstevel@tonic-gate  * causes libc_db to create an "agent thread" in the target process.
42*7c478bd9Sstevel@tonic-gate  * The only way to turn off this behavior is to omit these functions.
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #pragma weak ps_pdread = ps_pread
46*7c478bd9Sstevel@tonic-gate #pragma weak ps_ptread = ps_pread
47*7c478bd9Sstevel@tonic-gate #pragma weak ps_pdwrite = ps_pwrite
48*7c478bd9Sstevel@tonic-gate #pragma weak ps_ptwrite = ps_pwrite
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate ps_err_e
51*7c478bd9Sstevel@tonic-gate ps_pdmodel(struct ps_prochandle *P, int *modelp)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	*modelp = P->status.pr_dmodel;
54*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate ps_err_e
58*7c478bd9Sstevel@tonic-gate ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
59*7c478bd9Sstevel@tonic-gate {
60*7c478bd9Sstevel@tonic-gate 	if (P->ops->p_pread(P, buf, size, addr) != size)
61*7c478bd9Sstevel@tonic-gate 		return (PS_BADADDR);
62*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
63*7c478bd9Sstevel@tonic-gate }
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate ps_err_e
66*7c478bd9Sstevel@tonic-gate ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
67*7c478bd9Sstevel@tonic-gate {
68*7c478bd9Sstevel@tonic-gate 	if (P->ops->p_pwrite(P, buf, size, addr) != size)
69*7c478bd9Sstevel@tonic-gate 		return (PS_BADADDR);
70*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate  * libc_db calls matched pairs of ps_pstop()/ps_pcontinue()
75*7c478bd9Sstevel@tonic-gate  * in the belief that the client may have left the process
76*7c478bd9Sstevel@tonic-gate  * running while calling in to the libc_db interfaces.
77*7c478bd9Sstevel@tonic-gate  *
78*7c478bd9Sstevel@tonic-gate  * We interpret the meaning of these functions to be an inquiry
79*7c478bd9Sstevel@tonic-gate  * as to whether the process is stopped, not an action to be
80*7c478bd9Sstevel@tonic-gate  * performed to make it stopped.  For similar reasons, we also
81*7c478bd9Sstevel@tonic-gate  * return PS_OK for core files in order to allow libc_db to
82*7c478bd9Sstevel@tonic-gate  * operate on these as well.
83*7c478bd9Sstevel@tonic-gate  */
84*7c478bd9Sstevel@tonic-gate ps_err_e
85*7c478bd9Sstevel@tonic-gate ps_pstop(struct ps_prochandle *P)
86*7c478bd9Sstevel@tonic-gate {
87*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
88*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
89*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate ps_err_e
93*7c478bd9Sstevel@tonic-gate ps_pcontinue(struct ps_prochandle *P)
94*7c478bd9Sstevel@tonic-gate {
95*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
96*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
97*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate /*
101*7c478bd9Sstevel@tonic-gate  * ps_lstop() and ps_lcontinue() are not called by any code in libc_db
102*7c478bd9Sstevel@tonic-gate  * or librtld_db.  We make them behave like ps_pstop() and ps_pcontinue().
103*7c478bd9Sstevel@tonic-gate  */
104*7c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
105*7c478bd9Sstevel@tonic-gate ps_err_e
106*7c478bd9Sstevel@tonic-gate ps_lstop(struct ps_prochandle *P, lwpid_t lwpid)
107*7c478bd9Sstevel@tonic-gate {
108*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
109*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
110*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
111*7c478bd9Sstevel@tonic-gate }
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
114*7c478bd9Sstevel@tonic-gate ps_err_e
115*7c478bd9Sstevel@tonic-gate ps_lcontinue(struct ps_prochandle *P, lwpid_t lwpid)
116*7c478bd9Sstevel@tonic-gate {
117*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
118*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
119*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate ps_err_e
123*7c478bd9Sstevel@tonic-gate ps_lgetregs(struct ps_prochandle *P, lwpid_t lwpid, prgregset_t regs)
124*7c478bd9Sstevel@tonic-gate {
125*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
126*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	if (Plwp_getregs(P, lwpid, regs) == 0)
129*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
132*7c478bd9Sstevel@tonic-gate }
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate ps_err_e
135*7c478bd9Sstevel@tonic-gate ps_lsetregs(struct ps_prochandle *P, lwpid_t lwpid, const prgregset_t regs)
136*7c478bd9Sstevel@tonic-gate {
137*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP)
138*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	if (Plwp_setregs(P, lwpid, regs) == 0)
141*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
144*7c478bd9Sstevel@tonic-gate }
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate ps_err_e
147*7c478bd9Sstevel@tonic-gate ps_lgetfpregs(struct ps_prochandle *P, lwpid_t lwpid, prfpregset_t *regs)
148*7c478bd9Sstevel@tonic-gate {
149*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
150*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	if (Plwp_getfpregs(P, lwpid, regs) == 0)
153*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate ps_err_e
159*7c478bd9Sstevel@tonic-gate ps_lsetfpregs(struct ps_prochandle *P, lwpid_t lwpid, const prfpregset_t *regs)
160*7c478bd9Sstevel@tonic-gate {
161*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP)
162*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	if (Plwp_setfpregs(P, lwpid, regs) == 0)
165*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate #if defined(sparc) || defined(__sparc)
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate ps_err_e
173*7c478bd9Sstevel@tonic-gate ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize)
174*7c478bd9Sstevel@tonic-gate {
175*7c478bd9Sstevel@tonic-gate 	char fname[64];
176*7c478bd9Sstevel@tonic-gate 	struct stat statb;
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	if (P->state == PS_DEAD) {
179*7c478bd9Sstevel@tonic-gate 		lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
180*7c478bd9Sstevel@tonic-gate 		uint_t i;
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < P->core->core_nlwp; i++, lwp = list_next(lwp)) {
183*7c478bd9Sstevel@tonic-gate 			if (lwp->lwp_id == lwpid) {
184*7c478bd9Sstevel@tonic-gate 				if (lwp->lwp_xregs != NULL)
185*7c478bd9Sstevel@tonic-gate 					*xrsize = sizeof (prxregset_t);
186*7c478bd9Sstevel@tonic-gate 				else
187*7c478bd9Sstevel@tonic-gate 					*xrsize = 0;
188*7c478bd9Sstevel@tonic-gate 				return (PS_OK);
189*7c478bd9Sstevel@tonic-gate 			}
190*7c478bd9Sstevel@tonic-gate 		}
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 		return (PS_BADLID);
193*7c478bd9Sstevel@tonic-gate 	}
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	(void) snprintf(fname, sizeof (fname), "/proc/%d/lwp/%d/xregs",
196*7c478bd9Sstevel@tonic-gate 	    (int)P->status.pr_pid, (int)lwpid);
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 	if (stat(fname, &statb) != 0)
199*7c478bd9Sstevel@tonic-gate 		return (PS_BADLID);
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 	*xrsize = (int)statb.st_size;
202*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate ps_err_e
206*7c478bd9Sstevel@tonic-gate ps_lgetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
207*7c478bd9Sstevel@tonic-gate {
208*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
209*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
212*7c478bd9Sstevel@tonic-gate 	if (Plwp_getxregs(P, lwpid, (prxregset_t *)xregs) == 0)
213*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate ps_err_e
219*7c478bd9Sstevel@tonic-gate ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
220*7c478bd9Sstevel@tonic-gate {
221*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP)
222*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 	/* LINTED - alignment */
225*7c478bd9Sstevel@tonic-gate 	if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs) == 0)
226*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate 	return (PS_BADLID);
229*7c478bd9Sstevel@tonic-gate }
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate #endif	/* sparc */
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate ps_err_e
236*7c478bd9Sstevel@tonic-gate ps_lgetLDT(struct ps_prochandle *P, lwpid_t lwpid, struct ssd *ldt)
237*7c478bd9Sstevel@tonic-gate {
238*7c478bd9Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
239*7c478bd9Sstevel@tonic-gate 	if (P->status.pr_dmodel != PR_MODEL_NATIVE) {
240*7c478bd9Sstevel@tonic-gate #endif
241*7c478bd9Sstevel@tonic-gate 	prgregset_t regs;
242*7c478bd9Sstevel@tonic-gate 	struct ssd *ldtarray;
243*7c478bd9Sstevel@tonic-gate 	ps_err_e error;
244*7c478bd9Sstevel@tonic-gate 	uint_t gs;
245*7c478bd9Sstevel@tonic-gate 	int nldt;
246*7c478bd9Sstevel@tonic-gate 	int i;
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	if (P->state != PS_STOP && P->state != PS_DEAD)
249*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	/*
252*7c478bd9Sstevel@tonic-gate 	 * We need to get the ldt entry that matches the
253*7c478bd9Sstevel@tonic-gate 	 * value in the lwp's GS register.
254*7c478bd9Sstevel@tonic-gate 	 */
255*7c478bd9Sstevel@tonic-gate 	if ((error = ps_lgetregs(P, lwpid, regs)) != PS_OK)
256*7c478bd9Sstevel@tonic-gate 		return (error);
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	gs = regs[GS];
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 	if ((nldt = Pldt(P, NULL, 0)) <= 0 ||
261*7c478bd9Sstevel@tonic-gate 	    (ldtarray = malloc(nldt * sizeof (struct ssd))) == NULL)
262*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
263*7c478bd9Sstevel@tonic-gate 	if ((nldt = Pldt(P, ldtarray, nldt)) <= 0) {
264*7c478bd9Sstevel@tonic-gate 		free(ldtarray);
265*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
266*7c478bd9Sstevel@tonic-gate 	}
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < nldt; i++) {
269*7c478bd9Sstevel@tonic-gate 		if (gs == ldtarray[i].sel) {
270*7c478bd9Sstevel@tonic-gate 			*ldt = ldtarray[i];
271*7c478bd9Sstevel@tonic-gate 			break;
272*7c478bd9Sstevel@tonic-gate 		}
273*7c478bd9Sstevel@tonic-gate 	}
274*7c478bd9Sstevel@tonic-gate 	free(ldtarray);
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate 	if (i < nldt)
277*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
278*7c478bd9Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
279*7c478bd9Sstevel@tonic-gate 	}
280*7c478bd9Sstevel@tonic-gate #endif
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 	return (PS_ERR);
283*7c478bd9Sstevel@tonic-gate }
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate /*
288*7c478bd9Sstevel@tonic-gate  * Libthread_db doesn't use this function currently, but librtld_db uses
289*7c478bd9Sstevel@tonic-gate  * it for its debugging output.  We turn this on via rd_log if our debugging
290*7c478bd9Sstevel@tonic-gate  * switch is on, and then echo the messages sent to ps_plog to stderr.
291*7c478bd9Sstevel@tonic-gate  */
292*7c478bd9Sstevel@tonic-gate void
293*7c478bd9Sstevel@tonic-gate ps_plog(const char *fmt, ...)
294*7c478bd9Sstevel@tonic-gate {
295*7c478bd9Sstevel@tonic-gate 	va_list ap;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	if (_libproc_debug && fmt != NULL && *fmt != '\0') {
298*7c478bd9Sstevel@tonic-gate 		va_start(ap, fmt);
299*7c478bd9Sstevel@tonic-gate 		(void) vfprintf(stderr, fmt, ap);
300*7c478bd9Sstevel@tonic-gate 		va_end(ap);
301*7c478bd9Sstevel@tonic-gate 		if (fmt[strlen(fmt) - 1] != '\n')
302*7c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stderr);
303*7c478bd9Sstevel@tonic-gate 	}
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate /*
307*7c478bd9Sstevel@tonic-gate  * Store a pointer to our internal copy of the aux vector at the address
308*7c478bd9Sstevel@tonic-gate  * specified by the caller.  It should not hold on to this data for too long.
309*7c478bd9Sstevel@tonic-gate  */
310*7c478bd9Sstevel@tonic-gate ps_err_e
311*7c478bd9Sstevel@tonic-gate ps_pauxv(struct ps_prochandle *P, const auxv_t **aux)
312*7c478bd9Sstevel@tonic-gate {
313*7c478bd9Sstevel@tonic-gate 	if (P->auxv == NULL)
314*7c478bd9Sstevel@tonic-gate 		Preadauxvec(P);
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate 	if (P->auxv == NULL)
317*7c478bd9Sstevel@tonic-gate 		return (PS_ERR);
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate 	*aux = (const auxv_t *)P->auxv;
320*7c478bd9Sstevel@tonic-gate 	return (PS_OK);
321*7c478bd9Sstevel@tonic-gate }
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate /*
324*7c478bd9Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding address.
325*7c478bd9Sstevel@tonic-gate  */
326*7c478bd9Sstevel@tonic-gate ps_err_e
327*7c478bd9Sstevel@tonic-gate ps_pglobal_lookup(struct ps_prochandle *P, const char *object_name,
328*7c478bd9Sstevel@tonic-gate 	const char *sym_name, psaddr_t *sym_addr)
329*7c478bd9Sstevel@tonic-gate {
330*7c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
333*7c478bd9Sstevel@tonic-gate 		dprintf("pglobal_lookup <%s> -> %p\n",
334*7c478bd9Sstevel@tonic-gate 		    sym_name, (void *)(uintptr_t)sym.st_value);
335*7c478bd9Sstevel@tonic-gate 		*sym_addr = (psaddr_t)sym.st_value;
336*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
337*7c478bd9Sstevel@tonic-gate 	}
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 	return (PS_NOSYM);
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate /*
343*7c478bd9Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding symbol
344*7c478bd9Sstevel@tonic-gate  * information.  If we're compiled _LP64, we just call Plookup_by_name
345*7c478bd9Sstevel@tonic-gate  * and return because ps_sym_t is defined to be an Elf64_Sym, which
346*7c478bd9Sstevel@tonic-gate  * is the same as a GElf_Sym.  In the _ILP32 case, we have to convert
347*7c478bd9Sstevel@tonic-gate  * Plookup_by_name's result back to a ps_sym_t (which is an Elf32_Sym).
348*7c478bd9Sstevel@tonic-gate  */
349*7c478bd9Sstevel@tonic-gate ps_err_e
350*7c478bd9Sstevel@tonic-gate ps_pglobal_sym(struct ps_prochandle *P, const char *object_name,
351*7c478bd9Sstevel@tonic-gate 	const char *sym_name, ps_sym_t *symp)
352*7c478bd9Sstevel@tonic-gate {
353*7c478bd9Sstevel@tonic-gate #if defined(_ILP32)
354*7c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, &sym) == 0) {
357*7c478bd9Sstevel@tonic-gate 		symp->st_name = (Elf32_Word)sym.st_name;
358*7c478bd9Sstevel@tonic-gate 		symp->st_value = (Elf32_Addr)sym.st_value;
359*7c478bd9Sstevel@tonic-gate 		symp->st_size = (Elf32_Word)sym.st_size;
360*7c478bd9Sstevel@tonic-gate 		symp->st_info = ELF32_ST_INFO(
361*7c478bd9Sstevel@tonic-gate 		    GELF_ST_BIND(sym.st_info), GELF_ST_TYPE(sym.st_info));
362*7c478bd9Sstevel@tonic-gate 		symp->st_other = sym.st_other;
363*7c478bd9Sstevel@tonic-gate 		symp->st_shndx = sym.st_shndx;
364*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
365*7c478bd9Sstevel@tonic-gate 	}
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate #elif defined(_LP64)
368*7c478bd9Sstevel@tonic-gate 	if (Plookup_by_name(P, object_name, sym_name, symp) == 0)
369*7c478bd9Sstevel@tonic-gate 		return (PS_OK);
370*7c478bd9Sstevel@tonic-gate #endif
371*7c478bd9Sstevel@tonic-gate 	return (PS_NOSYM);
372*7c478bd9Sstevel@tonic-gate }
373