xref: /onnv-gate/usr/src/cmd/sgs/librtld_db/common/_rtld_db.h (revision 6830:296b2ea3c777)
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
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * 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  */
211618Srie 
220Sstevel@tonic-gate /*
23*6830Sedp  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	__RTLD_DB_H
280Sstevel@tonic-gate #define	__RTLD_DB_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <proc_service.h>
330Sstevel@tonic-gate #include <thread.h>
340Sstevel@tonic-gate #include <synch.h>
350Sstevel@tonic-gate #include <sgs.h>
360Sstevel@tonic-gate #include <machdep.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
42*6830Sedp /*
43*6830Sedp  * Brand helper libraries must name their ops vector using this macro.
44*6830Sedp  */
45*6830Sedp #ifdef _LP64
46*6830Sedp #ifdef _ELF64
47*6830Sedp #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops64
48*6830Sedp #else /* !_ELF64 */
49*6830Sedp #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops32
50*6830Sedp #endif /* !_ELF64 */
51*6830Sedp #else /* !_LP64 */
52*6830Sedp #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops32
53*6830Sedp #endif /* !_LP64 */
54*6830Sedp 
55*6830Sedp /*
56*6830Sedp  * State kept for brand helper libraries
57*6830Sedp  *
58*6830Sedp  * All librtld_db brand plugin libraries need to specify a Lmid_t value
59*6830Sedp  * that controls how link map ids are assigned to native solaris objects
60*6830Sedp  * (as pointed to by the processes aux vectors) which are enumerated by
61*6830Sedp  * librtld_db.  In most cases this value will either be LM_ID_NONE or
62*6830Sedp  * LM_ID_BRAND.
63*6830Sedp  *
64*6830Sedp  * If LM_ID_NONE is specified in the structure below, then when native solaris
65*6830Sedp  * objects are enumerated by librtld_db, their link map id values will match
66*6830Sedp  * the link map ids assigned to those objects by the solaris linker within
67*6830Sedp  * the target process.
68*6830Sedp  *
69*6830Sedp  * If LM_ID_BRAND is specified in the structure below, then when native solaris
70*6830Sedp  * objects are enumerated by librtld_db, their link map id value will be
71*6830Sedp  * explicity set to LM_ID_BRAND, regardless of the link map ids assigned to
72*6830Sedp  * those objects by the solaris linker within the target process.
73*6830Sedp  *
74*6830Sedp  * In all cases the librtld_db brand plugin library can report any link
75*6830Sedp  * map id value that it wants for objects that it enumerates via it's
76*6830Sedp  * rho_loadobj_iter() entry point.
77*6830Sedp  */
78*6830Sedp typedef struct __rd_helper_data	*rd_helper_data_t;
79*6830Sedp typedef struct rd_helper_ops {
80*6830Sedp 	Lmid_t			rho_lmid;
81*6830Sedp 	rd_helper_data_t	(*rho_init)(rd_agent_t *,
82*6830Sedp 				    struct ps_prochandle *);
83*6830Sedp 	void			(*rho_fini)(rd_helper_data_t);
84*6830Sedp 	int			(*rho_loadobj_iter)(rd_helper_data_t,
85*6830Sedp 				    rl_iter_f *, void *);
86*6830Sedp 	rd_err_e		(*rho_get_dyns)(rd_helper_data_t,
87*6830Sedp 				    psaddr_t, void **, size_t *);
88*6830Sedp } rd_helper_ops_t;
89*6830Sedp 
90*6830Sedp typedef struct rd_helper {
91*6830Sedp 	void			*rh_dlhandle;
92*6830Sedp 	rd_helper_ops_t		*rh_ops;
93*6830Sedp 	rd_helper_data_t	rh_data;
94*6830Sedp } rd_helper_t;
95*6830Sedp 
960Sstevel@tonic-gate struct rd_agent {
970Sstevel@tonic-gate 	mutex_t				rd_mutex;
980Sstevel@tonic-gate 	struct ps_prochandle		*rd_psp;	/* prochandle pointer */
990Sstevel@tonic-gate 	psaddr_t			rd_rdebug;	/* rtld r_debug */
1000Sstevel@tonic-gate 	psaddr_t			rd_preinit;	/* rtld_db_preinit */
1010Sstevel@tonic-gate 	psaddr_t			rd_postinit;	/* rtld_db_postinit */
1020Sstevel@tonic-gate 	psaddr_t			rd_dlact;	/* rtld_db_dlact */
1030Sstevel@tonic-gate 	psaddr_t			rd_tbinder;	/* tail of binder */
1040Sstevel@tonic-gate 	psaddr_t			rd_rtlddbpriv;	/* rtld rtld_db_priv */
1050Sstevel@tonic-gate 	ulong_t				rd_flags;	/* flags */
1060Sstevel@tonic-gate 	ulong_t				rd_rdebugvers;	/* rtld_db_priv.vers */
1070Sstevel@tonic-gate 	int				rd_dmodel;	/* data model */
1082712Snn35248 	rd_helper_t			rd_helper;	/* private to helper */
1090Sstevel@tonic-gate };
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate  * Values for rd_flags
1130Sstevel@tonic-gate  */
1140Sstevel@tonic-gate #define	RDF_FL_COREFILE		0x0001		/* client is core file image */
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate #define	RDAGLOCK(x)	(void) mutex_lock(&(x->rd_mutex));
1190Sstevel@tonic-gate #define	RDAGUNLOCK(x)	(void) mutex_unlock(&(x->rd_mutex));
1202712Snn35248 #define	LOG(func)	{						\
1212712Snn35248 				(void) mutex_lock(&glob_mutex);		\
1222712Snn35248 				if (rtld_db_logging)			\
1232712Snn35248 					func;				\
1242712Snn35248 				(void) mutex_unlock(&glob_mutex);	\
1252712Snn35248 			}
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate extern mutex_t		glob_mutex;
1280Sstevel@tonic-gate extern int		rtld_db_version;
1290Sstevel@tonic-gate extern int		rtld_db_logging;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate extern rd_err_e		rd_binder_exit_addr(struct rd_agent *, const char *,
1320Sstevel@tonic-gate 				psaddr_t *);
133*6830Sedp 
1340Sstevel@tonic-gate extern rd_err_e		_rd_event_enable32(rd_agent_t *, int);
1350Sstevel@tonic-gate extern rd_err_e		_rd_event_getmsg32(rd_agent_t *, rd_event_msg_t *);
136*6830Sedp extern rd_err_e		_rd_get_dyns32(struct rd_agent *,
137*6830Sedp 			    psaddr_t, Dyn **, size_t *);
138*6830Sedp extern rd_err_e		_rd_get_ehdr32(struct rd_agent *,
139*6830Sedp 			    psaddr_t, Ehdr *, uint_t *);
1400Sstevel@tonic-gate extern rd_err_e		_rd_objpad_enable32(struct rd_agent *, size_t);
1410Sstevel@tonic-gate extern rd_err_e		_rd_loadobj_iter32(rd_agent_t *, rl_iter_f *, void *);
142*6830Sedp extern rd_err_e		_rd_reset32(struct rd_agent *);
1430Sstevel@tonic-gate extern rd_err_e		find_dynamic_ent32(struct rd_agent *, psaddr_t,
1441618Srie 			    Xword, Dyn *);
1450Sstevel@tonic-gate extern rd_err_e		plt32_resolution(rd_agent_t *, psaddr_t, lwpid_t,
1460Sstevel@tonic-gate 			    psaddr_t, rd_plt_info_t *);
147*6830Sedp extern rd_err_e		validate_rdebug32(struct rd_agent *rap);
1480Sstevel@tonic-gate #ifdef _LP64
1490Sstevel@tonic-gate extern rd_err_e		_rd_event_enable64(rd_agent_t *, int);
1500Sstevel@tonic-gate extern rd_err_e		_rd_event_getmsg64(rd_agent_t *, rd_event_msg_t *);
151*6830Sedp extern rd_err_e		_rd_get_dyns64(struct rd_agent *,
152*6830Sedp 			    psaddr_t, Elf64_Dyn **, size_t *);
153*6830Sedp extern rd_err_e		_rd_get_ehdr64(struct rd_agent *,
154*6830Sedp 			    psaddr_t, Elf64_Ehdr *, uint_t *);
1550Sstevel@tonic-gate extern rd_err_e		_rd_objpad_enable64(struct rd_agent *, size_t);
1560Sstevel@tonic-gate extern rd_err_e		_rd_loadobj_iter64(rd_agent_t *, rl_iter_f *, void *);
157*6830Sedp extern rd_err_e		_rd_reset64(struct rd_agent *);
1580Sstevel@tonic-gate extern rd_err_e		find_dynamic_ent64(struct rd_agent *, psaddr_t,
1590Sstevel@tonic-gate 			    Xword, Elf64_Dyn *);
1600Sstevel@tonic-gate extern rd_err_e		plt64_resolution(rd_agent_t *, psaddr_t, lwpid_t,
1610Sstevel@tonic-gate 			    psaddr_t, rd_plt_info_t *);
162*6830Sedp extern rd_err_e		validate_rdebug64(struct rd_agent *rap);
1630Sstevel@tonic-gate #endif
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #ifdef	__cplusplus
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate #endif
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #endif /* __RTLD_DB_H */
170