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