xref: /titanic_44/usr/src/cmd/sgs/librtld_db/common/_rtld_db.h (revision 22872efb9462b28180d11ea401344608e641a5aa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	__RTLD_DB_H
28 #define	__RTLD_DB_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <proc_service.h>
33 #include <thread.h>
34 #include <synch.h>
35 #include <sgs.h>
36 #include <machdep.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Brand helper libraries must name their ops vector using this macro.
44  */
45 #ifdef _LP64
46 #ifdef _ELF64
47 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops64
48 #else /* !_ELF64 */
49 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops32
50 #endif /* !_ELF64 */
51 #else /* !_LP64 */
52 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops32
53 #endif /* !_LP64 */
54 
55 /*
56  * State kept for brand helper libraries
57  *
58  * All librtld_db brand plugin libraries need to specify a Lmid_t value
59  * that controls how link map ids are assigned to native solaris objects
60  * (as pointed to by the processes aux vectors) which are enumerated by
61  * librtld_db.  In most cases this value will either be LM_ID_NONE or
62  * LM_ID_BRAND.
63  *
64  * If LM_ID_NONE is specified in the structure below, then when native solaris
65  * objects are enumerated by librtld_db, their link map id values will match
66  * the link map ids assigned to those objects by the solaris linker within
67  * the target process.
68  *
69  * If LM_ID_BRAND is specified in the structure below, then when native solaris
70  * objects are enumerated by librtld_db, their link map id value will be
71  * explicity set to LM_ID_BRAND, regardless of the link map ids assigned to
72  * those objects by the solaris linker within the target process.
73  *
74  * In all cases the librtld_db brand plugin library can report any link
75  * map id value that it wants for objects that it enumerates via it's
76  * rho_loadobj_iter() entry point.
77  */
78 typedef struct __rd_helper_data	*rd_helper_data_t;
79 typedef struct rd_helper_ops {
80 	Lmid_t			rho_lmid;
81 	rd_helper_data_t	(*rho_init)(rd_agent_t *,
82 				    struct ps_prochandle *);
83 	void			(*rho_fini)(rd_helper_data_t);
84 	int			(*rho_loadobj_iter)(rd_helper_data_t,
85 				    rl_iter_f *, void *);
86 	rd_err_e		(*rho_get_dyns)(rd_helper_data_t,
87 				    psaddr_t, void **, size_t *);
88 } rd_helper_ops_t;
89 
90 typedef struct rd_helper {
91 	void			*rh_dlhandle;
92 	rd_helper_ops_t		*rh_ops;
93 	rd_helper_data_t	rh_data;
94 } rd_helper_t;
95 
96 struct rd_agent {
97 	mutex_t				rd_mutex;
98 	struct ps_prochandle		*rd_psp;	/* prochandle pointer */
99 	psaddr_t			rd_rdebug;	/* rtld r_debug */
100 	psaddr_t			rd_preinit;	/* rtld_db_preinit */
101 	psaddr_t			rd_postinit;	/* rtld_db_postinit */
102 	psaddr_t			rd_dlact;	/* rtld_db_dlact */
103 	psaddr_t			rd_tbinder;	/* tail of binder */
104 	psaddr_t			rd_rtlddbpriv;	/* rtld rtld_db_priv */
105 	ulong_t				rd_flags;	/* flags */
106 	ulong_t				rd_rdebugvers;	/* rtld_db_priv.vers */
107 	int				rd_dmodel;	/* data model */
108 	rd_helper_t			rd_helper;	/* private to helper */
109 };
110 
111 /*
112  * Values for rd_flags
113  */
114 #define	RDF_FL_COREFILE		0x0001		/* client is core file image */
115 
116 
117 
118 #define	RDAGLOCK(x)	(void) mutex_lock(&(x->rd_mutex));
119 #define	RDAGUNLOCK(x)	(void) mutex_unlock(&(x->rd_mutex));
120 #define	LOG(func)	{						\
121 				(void) mutex_lock(&glob_mutex);		\
122 				if (rtld_db_logging)			\
123 					func;				\
124 				(void) mutex_unlock(&glob_mutex);	\
125 			}
126 
127 extern mutex_t		glob_mutex;
128 extern int		rtld_db_version;
129 extern int		rtld_db_logging;
130 
131 extern rd_err_e		rd_binder_exit_addr(struct rd_agent *, const char *,
132 				psaddr_t *);
133 
134 extern rd_err_e		_rd_event_enable32(rd_agent_t *, int);
135 extern rd_err_e		_rd_event_getmsg32(rd_agent_t *, rd_event_msg_t *);
136 extern rd_err_e		_rd_get_dyns32(struct rd_agent *,
137 			    psaddr_t, Dyn **, size_t *);
138 extern rd_err_e		_rd_get_ehdr32(struct rd_agent *,
139 			    psaddr_t, Ehdr *, uint_t *);
140 extern rd_err_e		_rd_objpad_enable32(struct rd_agent *, size_t);
141 extern rd_err_e		_rd_loadobj_iter32(rd_agent_t *, rl_iter_f *, void *);
142 extern rd_err_e		_rd_reset32(struct rd_agent *);
143 extern rd_err_e		find_dynamic_ent32(struct rd_agent *, psaddr_t,
144 			    Xword, Dyn *);
145 extern rd_err_e		plt32_resolution(rd_agent_t *, psaddr_t, lwpid_t,
146 			    psaddr_t, rd_plt_info_t *);
147 extern rd_err_e		validate_rdebug32(struct rd_agent *rap);
148 #ifdef _LP64
149 extern rd_err_e		_rd_event_enable64(rd_agent_t *, int);
150 extern rd_err_e		_rd_event_getmsg64(rd_agent_t *, rd_event_msg_t *);
151 extern rd_err_e		_rd_get_dyns64(struct rd_agent *,
152 			    psaddr_t, Elf64_Dyn **, size_t *);
153 extern rd_err_e		_rd_get_ehdr64(struct rd_agent *,
154 			    psaddr_t, Elf64_Ehdr *, uint_t *);
155 extern rd_err_e		_rd_objpad_enable64(struct rd_agent *, size_t);
156 extern rd_err_e		_rd_loadobj_iter64(rd_agent_t *, rl_iter_f *, void *);
157 extern rd_err_e		_rd_reset64(struct rd_agent *);
158 extern rd_err_e		find_dynamic_ent64(struct rd_agent *, psaddr_t,
159 			    Xword, Elf64_Dyn *);
160 extern rd_err_e		plt64_resolution(rd_agent_t *, psaddr_t, lwpid_t,
161 			    psaddr_t, rd_plt_info_t *);
162 extern rd_err_e		validate_rdebug64(struct rd_agent *rap);
163 #endif
164 
165 #ifdef	__cplusplus
166 }
167 #endif
168 
169 #endif /* __RTLD_DB_H */
170