xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_pservice.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 /*
22*7b9b3bf3Sedp  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Proc Service API Interposition Layer
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * In order to allow multiple MDB targets to make use of librtld_db, we
307c478bd9Sstevel@tonic-gate  * provide an interposition layer for functions in the proc_service.h API
317c478bd9Sstevel@tonic-gate  * that are used by librtld_db.  Each of the functions used by librtld_db
327c478bd9Sstevel@tonic-gate  * can be conveniently expressed in terms of the MDB target API, so this
337c478bd9Sstevel@tonic-gate  * layer simply selects the appropriate target, invokes the corresponding
347c478bd9Sstevel@tonic-gate  * target API function, and then translates the error codes appropriately.
357c478bd9Sstevel@tonic-gate  * We expect that each proc_service entry point will be invoked with a
367c478bd9Sstevel@tonic-gate  * cookie (struct ps_prochandle *) which matches either a known MDB target,
377c478bd9Sstevel@tonic-gate  * or the value of a target's t->t_pshandle.  This allows us to re-vector
387c478bd9Sstevel@tonic-gate  * calls to the proc service API around libproc (which also contains an
397c478bd9Sstevel@tonic-gate  * implementation of the proc_service API) like this:
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * Linker map:
427c478bd9Sstevel@tonic-gate  * +---------+   +---------+   +------------+      Legend:
437c478bd9Sstevel@tonic-gate  * |   MDB   | ->| libproc | ->| librtld_db |      <1> function in this file
447c478bd9Sstevel@tonic-gate  * +---------+   +---------+   +------------+      <2> function in libproc
457c478bd9Sstevel@tonic-gate  * ps_pread<1>   ps_pread<2>   call ps_pread() --+
467c478bd9Sstevel@tonic-gate  *                                               |
477c478bd9Sstevel@tonic-gate  * +---------------------------------------------+
487c478bd9Sstevel@tonic-gate  * |
497c478bd9Sstevel@tonic-gate  * +-> ps_pread<1>(P, ...)
507c478bd9Sstevel@tonic-gate  *       t = mdb_tgt_from_pshandle(P);
517c478bd9Sstevel@tonic-gate  *       mdb_tgt_vread(t, ...);
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * If we are debugging a user process, we then make these calls (which form
547c478bd9Sstevel@tonic-gate  * the equivalent of libproc's proc_service implementation):
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * mdb_tgt_vread() -> proc target t->t_vread() -> libproc.so`Pread()
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * If we are debugging a user process through a kernel crash dump (kproc
597c478bd9Sstevel@tonic-gate  * target), we make these calls:
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * mdb_tgt_vread() -> kproc target t->t_vread() -> mdb_tgt_aread(kvm target) ->
627c478bd9Sstevel@tonic-gate  * 	kvm target t->t_aread() -> libkvm.so`kvm_aread()
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * This design allows us to support both kproc's use of librtld_db, as well
657c478bd9Sstevel@tonic-gate  * as libproc's use of librtld_db, but it does lead to one unfortunate problem
667c478bd9Sstevel@tonic-gate  * in the creation of a proc target: when the proc target invokes libproc to
677c478bd9Sstevel@tonic-gate  * construct a ps_prochandle, and libproc in turn invokes librtld_db, MDB does
687c478bd9Sstevel@tonic-gate  * not yet know what ps_prochandle has been allocated inside of libproc since
697c478bd9Sstevel@tonic-gate  * this call has not yet returned.  We also can't translate this ps_prochandle
707c478bd9Sstevel@tonic-gate  * to the target itself, since that target isn't ready to handle requests yet;
717c478bd9Sstevel@tonic-gate  * we actually need to pass the call back through to libproc.  In order to
727c478bd9Sstevel@tonic-gate  * do that, we use libdl to lookup the address of libproc's definition of the
737c478bd9Sstevel@tonic-gate  * various functions (RTLD_NEXT on the link map chain) and store these in the
747c478bd9Sstevel@tonic-gate  * ps_ops structure below.  If we ever fail to translate a ps_prochandle to
757c478bd9Sstevel@tonic-gate  * an MDB target, we simply pass the call through to libproc.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #include <proc_service.h>
797c478bd9Sstevel@tonic-gate #include <dlfcn.h>
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #include <mdb/mdb_target_impl.h>
827c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h>
837c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate static struct {
867c478bd9Sstevel@tonic-gate 	ps_err_e (*ps_pread)(struct ps_prochandle *,
877c478bd9Sstevel@tonic-gate 	    psaddr_t, void *, size_t);
887c478bd9Sstevel@tonic-gate 	ps_err_e (*ps_pwrite)(struct ps_prochandle *,
897c478bd9Sstevel@tonic-gate 	    psaddr_t, const void *, size_t);
907c478bd9Sstevel@tonic-gate 	ps_err_e (*ps_pglobal_lookup)(struct ps_prochandle *,
917c478bd9Sstevel@tonic-gate 	    const char *, const char *, psaddr_t *);
927c478bd9Sstevel@tonic-gate 	ps_err_e (*ps_pglobal_sym)(struct ps_prochandle *P,
937c478bd9Sstevel@tonic-gate 	    const char *, const char *, ps_sym_t *);
947c478bd9Sstevel@tonic-gate 	ps_err_e (*ps_pauxv)(struct ps_prochandle *,
957c478bd9Sstevel@tonic-gate 	    const auxv_t **);
96*7b9b3bf3Sedp 	ps_err_e (*ps_pbrandname)(struct ps_prochandle *,
97*7b9b3bf3Sedp 	    char *, size_t);
987c478bd9Sstevel@tonic-gate 	ps_err_e (*ps_pdmodel)(struct ps_prochandle *,
997c478bd9Sstevel@tonic-gate 	    int *);
1007c478bd9Sstevel@tonic-gate } ps_ops;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate static mdb_tgt_t *
mdb_tgt_from_pshandle(void * P)1037c478bd9Sstevel@tonic-gate mdb_tgt_from_pshandle(void *P)
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	for (t = mdb_list_next(&mdb.m_tgtlist); t; t = mdb_list_next(t)) {
1087c478bd9Sstevel@tonic-gate 		if (t == P || t->t_pshandle == P)
1097c478bd9Sstevel@tonic-gate 			return (t);
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	return (NULL);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * Read from the specified target virtual address.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate ps_err_e
ps_pread(struct ps_prochandle * P,psaddr_t addr,void * buf,size_t size)1197c478bd9Sstevel@tonic-gate ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	if (t == NULL)
1247c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pread(P, addr, buf, size));
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	if (mdb_tgt_vread(t, buf, size, addr) != size)
1277c478bd9Sstevel@tonic-gate 		return (PS_BADADDR);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	return (PS_OK);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Write to the specified target virtual address.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate ps_err_e
ps_pwrite(struct ps_prochandle * P,psaddr_t addr,const void * buf,size_t size)1367c478bd9Sstevel@tonic-gate ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	if (t == NULL)
1417c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pwrite(P, addr, buf, size));
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	if (mdb_tgt_vwrite(t, buf, size, addr) != size)
1447c478bd9Sstevel@tonic-gate 		return (PS_BADADDR);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	return (PS_OK);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding address.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate ps_err_e
ps_pglobal_lookup(struct ps_prochandle * P,const char * object,const char * name,psaddr_t * symp)1537c478bd9Sstevel@tonic-gate ps_pglobal_lookup(struct ps_prochandle *P, const char *object,
1547c478bd9Sstevel@tonic-gate     const char *name, psaddr_t *symp)
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
1577c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	if (t == NULL)
1607c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pglobal_lookup(P, object, name, symp));
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (mdb_tgt_lookup_by_name(t, object, name, &sym, NULL) == 0) {
1637c478bd9Sstevel@tonic-gate 		*symp = (psaddr_t)sym.st_value;
1647c478bd9Sstevel@tonic-gate 		return (PS_OK);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	return (PS_NOSYM);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * Search for a symbol by name and return the corresponding symbol data.
1727c478bd9Sstevel@tonic-gate  * If we're compiled _LP64, we just call mdb_tgt_lookup_by_name and return
1737c478bd9Sstevel@tonic-gate  * because ps_sym_t is defined to be an Elf64_Sym, which is the same as a
1747c478bd9Sstevel@tonic-gate  * GElf_Sym.  In the _ILP32 case, we have to convert mdb_tgt_lookup_by_name's
1757c478bd9Sstevel@tonic-gate  * result back to a ps_sym_t (which is an Elf32_Sym).
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate ps_err_e
ps_pglobal_sym(struct ps_prochandle * P,const char * object,const char * name,ps_sym_t * symp)1787c478bd9Sstevel@tonic-gate ps_pglobal_sym(struct ps_prochandle *P, const char *object,
1797c478bd9Sstevel@tonic-gate     const char *name, ps_sym_t *symp)
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
1827c478bd9Sstevel@tonic-gate #if defined(_ILP32)
1837c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (t == NULL)
1867c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pglobal_sym(P, object, name, symp));
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	if (mdb_tgt_lookup_by_name(t, object, name, &sym, NULL) == 0) {
1897c478bd9Sstevel@tonic-gate 		symp->st_name = (Elf32_Word)sym.st_name;
1907c478bd9Sstevel@tonic-gate 		symp->st_value = (Elf32_Addr)sym.st_value;
1917c478bd9Sstevel@tonic-gate 		symp->st_size = (Elf32_Word)sym.st_size;
1927c478bd9Sstevel@tonic-gate 		symp->st_info = ELF32_ST_INFO(
1937c478bd9Sstevel@tonic-gate 		    GELF_ST_BIND(sym.st_info), GELF_ST_TYPE(sym.st_info));
1947c478bd9Sstevel@tonic-gate 		symp->st_other = sym.st_other;
1957c478bd9Sstevel@tonic-gate 		symp->st_shndx = sym.st_shndx;
1967c478bd9Sstevel@tonic-gate 		return (PS_OK);
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #elif defined(_LP64)
2007c478bd9Sstevel@tonic-gate 	if (t == NULL)
2017c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pglobal_sym(P, object, name, symp));
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (mdb_tgt_lookup_by_name(t, object, name, symp, NULL) == 0)
2047c478bd9Sstevel@tonic-gate 		return (PS_OK);
2057c478bd9Sstevel@tonic-gate #endif
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	return (PS_NOSYM);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * Report a debug message.  We allow proc_service API clients to report
2127c478bd9Sstevel@tonic-gate  * messages via our debug stream if the MDB_DBG_PSVC token is enabled.
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate void
ps_plog(const char * format,...)2157c478bd9Sstevel@tonic-gate ps_plog(const char *format, ...)
2167c478bd9Sstevel@tonic-gate {
2177c478bd9Sstevel@tonic-gate 	va_list alist;
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	va_start(alist, format);
2207c478bd9Sstevel@tonic-gate 	mdb_dvprintf(MDB_DBG_PSVC, format, alist);
2217c478bd9Sstevel@tonic-gate 	va_end(alist);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Return the auxv structure from the process being examined.
2267c478bd9Sstevel@tonic-gate  */
2277c478bd9Sstevel@tonic-gate ps_err_e
ps_pauxv(struct ps_prochandle * P,const auxv_t ** auxvp)2287c478bd9Sstevel@tonic-gate ps_pauxv(struct ps_prochandle *P, const auxv_t **auxvp)
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	if (t == NULL)
2337c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pauxv(P, auxvp));
2347c478bd9Sstevel@tonic-gate 
2359acbbeafSnn35248 	if (mdb_tgt_auxv(t, auxvp) != 0)
2369acbbeafSnn35248 		return (PS_ERR);
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	return (PS_OK);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate 
241*7b9b3bf3Sedp ps_err_e
ps_pbrandname(struct ps_prochandle * P,char * buf,size_t len)242*7b9b3bf3Sedp ps_pbrandname(struct ps_prochandle *P, char *buf, size_t len)
243*7b9b3bf3Sedp {
244*7b9b3bf3Sedp 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
245*7b9b3bf3Sedp 	const auxv_t *auxv;
246*7b9b3bf3Sedp 
247*7b9b3bf3Sedp 	if (t == NULL)
248*7b9b3bf3Sedp 		return (ps_ops.ps_pbrandname(P, buf, len));
249*7b9b3bf3Sedp 
250*7b9b3bf3Sedp 	if (mdb_tgt_auxv(t, &auxv) != 0)
251*7b9b3bf3Sedp 		return (PS_ERR);
252*7b9b3bf3Sedp 
253*7b9b3bf3Sedp 	while (auxv->a_type != AT_NULL) {
254*7b9b3bf3Sedp 		if (auxv->a_type == AT_SUN_BRANDNAME)
255*7b9b3bf3Sedp 			break;
256*7b9b3bf3Sedp 		auxv++;
257*7b9b3bf3Sedp 	}
258*7b9b3bf3Sedp 	if (auxv->a_type == AT_NULL)
259*7b9b3bf3Sedp 		return (PS_ERR);
260*7b9b3bf3Sedp 
261*7b9b3bf3Sedp 	if (mdb_tgt_readstr(t, MDB_TGT_AS_VIRT,
262*7b9b3bf3Sedp 	    buf, len, auxv->a_un.a_val) <= 0)
263*7b9b3bf3Sedp 		return (PS_ERR);
264*7b9b3bf3Sedp 
265*7b9b3bf3Sedp 	return (PS_OK);
266*7b9b3bf3Sedp }
267*7b9b3bf3Sedp 
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate  * Return the data model of the target.
2707c478bd9Sstevel@tonic-gate  */
2717c478bd9Sstevel@tonic-gate ps_err_e
ps_pdmodel(struct ps_prochandle * P,int * dm)2727c478bd9Sstevel@tonic-gate ps_pdmodel(struct ps_prochandle *P, int *dm)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb_tgt_from_pshandle(P);
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	if (t == NULL)
2777c478bd9Sstevel@tonic-gate 		return (ps_ops.ps_pdmodel(P, dm));
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	switch (mdb_tgt_dmodel(t)) {
2807c478bd9Sstevel@tonic-gate 	case MDB_TGT_MODEL_LP64:
2817c478bd9Sstevel@tonic-gate 		*dm = PR_MODEL_LP64;
2827c478bd9Sstevel@tonic-gate 		return (PS_OK);
2837c478bd9Sstevel@tonic-gate 	case MDB_TGT_MODEL_ILP32:
2847c478bd9Sstevel@tonic-gate 		*dm = PR_MODEL_ILP32;
2857c478bd9Sstevel@tonic-gate 		return (PS_OK);
2867c478bd9Sstevel@tonic-gate 	}
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	return (PS_ERR);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate  * Stub function in case we cannot find the necessary symbols from libproc.
2937c478bd9Sstevel@tonic-gate  */
2947c478bd9Sstevel@tonic-gate static ps_err_e
ps_fail(struct ps_prochandle * P)2957c478bd9Sstevel@tonic-gate ps_fail(struct ps_prochandle *P)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	mdb_dprintf(MDB_DBG_PSVC, "failing call to pshandle %p\n", (void *)P);
2987c478bd9Sstevel@tonic-gate 	return (PS_BADPID);
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate /*
3027c478bd9Sstevel@tonic-gate  * Initialization function for the proc service interposition layer: we use
3037c478bd9Sstevel@tonic-gate  * libdl to look up the next definition of each function in the link map.
3047c478bd9Sstevel@tonic-gate  */
3057c478bd9Sstevel@tonic-gate void
mdb_pservice_init(void)3067c478bd9Sstevel@tonic-gate mdb_pservice_init(void)
3077c478bd9Sstevel@tonic-gate {
3087c478bd9Sstevel@tonic-gate 	if ((ps_ops.ps_pread = (ps_err_e (*)())
3097c478bd9Sstevel@tonic-gate 	    dlsym(RTLD_NEXT, "ps_pread")) == NULL)
3107c478bd9Sstevel@tonic-gate 		ps_ops.ps_pread = (ps_err_e (*)())ps_fail;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	if ((ps_ops.ps_pwrite = (ps_err_e (*)())
3137c478bd9Sstevel@tonic-gate 	    dlsym(RTLD_NEXT, "ps_pwrite")) == NULL)
3147c478bd9Sstevel@tonic-gate 		ps_ops.ps_pwrite = (ps_err_e (*)())ps_fail;
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	if ((ps_ops.ps_pglobal_lookup = (ps_err_e (*)())
3177c478bd9Sstevel@tonic-gate 	    dlsym(RTLD_NEXT, "ps_pglobal_lookup")) == NULL)
3187c478bd9Sstevel@tonic-gate 		ps_ops.ps_pglobal_lookup = (ps_err_e (*)())ps_fail;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	if ((ps_ops.ps_pglobal_sym = (ps_err_e (*)())
3217c478bd9Sstevel@tonic-gate 	    dlsym(RTLD_NEXT, "ps_pglobal_sym")) == NULL)
3227c478bd9Sstevel@tonic-gate 		ps_ops.ps_pglobal_sym = (ps_err_e (*)())ps_fail;
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	if ((ps_ops.ps_pauxv = (ps_err_e (*)())
3257c478bd9Sstevel@tonic-gate 	    dlsym(RTLD_NEXT, "ps_pauxv")) == NULL)
3267c478bd9Sstevel@tonic-gate 		ps_ops.ps_pauxv = (ps_err_e (*)())ps_fail;
3277c478bd9Sstevel@tonic-gate 
328*7b9b3bf3Sedp 	if ((ps_ops.ps_pbrandname = (ps_err_e (*)())
329*7b9b3bf3Sedp 	    dlsym(RTLD_NEXT, "ps_pbrandname")) == NULL)
330*7b9b3bf3Sedp 		ps_ops.ps_pbrandname = (ps_err_e (*)())ps_fail;
331*7b9b3bf3Sedp 
3327c478bd9Sstevel@tonic-gate 	if ((ps_ops.ps_pdmodel = (ps_err_e (*)())
3337c478bd9Sstevel@tonic-gate 	    dlsym(RTLD_NEXT, "ps_pdmodel")) == NULL)
3347c478bd9Sstevel@tonic-gate 		ps_ops.ps_pdmodel = (ps_err_e (*)())ps_fail;
3357c478bd9Sstevel@tonic-gate }
336