xref: /illumos-gate/usr/src/cmd/sgs/librtld_db/common/_rtld_db.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 #include <proc_service.h>
31 #include <thread.h>
32 #include <synch.h>
33 #include <sgs.h>
34 #include <machdep.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Brand helper libraries must name their ops vector using this macro.
42  */
43 #ifdef _LP64
44 #ifdef _ELF64
45 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops64
46 #else /* !_ELF64 */
47 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops32
48 #endif /* !_ELF64 */
49 #else /* !_LP64 */
50 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops32
51 #endif /* !_LP64 */
52 
53 /*
54  * State kept for brand helper libraries
55  *
56  * All librtld_db brand plugin libraries need to specify a Lmid_t value
57  * that controls how link map ids are assigned to native solaris objects
58  * (as pointed to by the processes aux vectors) which are enumerated by
59  * librtld_db.  In most cases this value will either be LM_ID_NONE or
60  * LM_ID_BRAND.
61  *
62  * If LM_ID_NONE is specified in the structure below, then when native solaris
63  * objects are enumerated by librtld_db, their link map id values will match
64  * the link map ids assigned to those objects by the solaris linker within
65  * the target process.
66  *
67  * If LM_ID_BRAND is specified in the structure below, then when native solaris
68  * objects are enumerated by librtld_db, their link map id value will be
69  * explicity set to LM_ID_BRAND, regardless of the link map ids assigned to
70  * those objects by the solaris linker within the target process.
71  *
72  * In all cases the librtld_db brand plugin library can report any link
73  * map id value that it wants for objects that it enumerates via it's
74  * rho_loadobj_iter() entry point.
75  */
76 typedef struct __rd_helper_data	*rd_helper_data_t;
77 typedef struct rd_helper_ops {
78 	Lmid_t			rho_lmid;
79 	rd_helper_data_t	(*rho_init)(rd_agent_t *,
80 				    struct ps_prochandle *);
81 	void			(*rho_fini)(rd_helper_data_t);
82 	int			(*rho_loadobj_iter)(rd_helper_data_t,
83 				    rl_iter_f *, void *);
84 	rd_err_e		(*rho_get_dyns)(rd_helper_data_t,
85 				    psaddr_t, void **, size_t *);
86 } rd_helper_ops_t;
87 
88 typedef struct rd_helper {
89 	void			*rh_dlhandle;
90 	rd_helper_ops_t		*rh_ops;
91 	rd_helper_data_t	rh_data;
92 } rd_helper_t;
93 
94 struct rd_agent {
95 	mutex_t				rd_mutex;
96 	struct ps_prochandle		*rd_psp;	/* prochandle pointer */
97 	psaddr_t			rd_rdebug;	/* rtld r_debug */
98 	psaddr_t			rd_preinit;	/* rtld_db_preinit */
99 	psaddr_t			rd_postinit;	/* rtld_db_postinit */
100 	psaddr_t			rd_dlact;	/* rtld_db_dlact */
101 	psaddr_t			rd_tbinder;	/* tail of binder */
102 	psaddr_t			rd_rtlddbpriv;	/* rtld rtld_db_priv */
103 	ulong_t				rd_flags;	/* flags */
104 	ulong_t				rd_rdebugvers;	/* rtld_db_priv.vers */
105 	int				rd_dmodel;	/* data model */
106 	rd_helper_t			rd_helper;	/* private to helper */
107 };
108 
109 /*
110  * Values for rd_flags
111  */
112 #define	RDF_FL_COREFILE		0x0001		/* client is core file image */
113 
114 
115 
116 #define	RDAGLOCK(x)	(void) mutex_lock(&(x->rd_mutex));
117 #define	RDAGUNLOCK(x)	(void) mutex_unlock(&(x->rd_mutex));
118 #define	LOG(func)	{						\
119 				(void) mutex_lock(&glob_mutex);		\
120 				if (rtld_db_logging)			\
121 					func;				\
122 				(void) mutex_unlock(&glob_mutex);	\
123 			}
124 
125 extern mutex_t		glob_mutex;
126 extern int		rtld_db_version;
127 extern int		rtld_db_logging;
128 
129 extern rd_err_e		rd_binder_exit_addr(struct rd_agent *, const char *,
130 				psaddr_t *);
131 
132 extern rd_err_e		_rd_event_enable32(rd_agent_t *, int);
133 extern rd_err_e		_rd_event_getmsg32(rd_agent_t *, rd_event_msg_t *);
134 extern rd_err_e		_rd_get_dyns32(struct rd_agent *,
135 			    psaddr_t, Dyn **, size_t *);
136 extern rd_err_e		_rd_get_ehdr32(struct rd_agent *,
137 			    psaddr_t, Ehdr *, uint_t *);
138 extern rd_err_e		_rd_objpad_enable32(struct rd_agent *, size_t);
139 extern rd_err_e		_rd_loadobj_iter32(rd_agent_t *, rl_iter_f *, void *);
140 extern rd_err_e		_rd_reset32(struct rd_agent *);
141 extern rd_err_e		find_dynamic_ent32(struct rd_agent *, psaddr_t,
142 			    Xword, Dyn *);
143 extern rd_err_e		plt32_resolution(rd_agent_t *, psaddr_t, lwpid_t,
144 			    psaddr_t, rd_plt_info_t *);
145 extern rd_err_e		validate_rdebug32(struct rd_agent *rap);
146 #ifdef _LP64
147 extern rd_err_e		_rd_event_enable64(rd_agent_t *, int);
148 extern rd_err_e		_rd_event_getmsg64(rd_agent_t *, rd_event_msg_t *);
149 extern rd_err_e		_rd_get_dyns64(struct rd_agent *,
150 			    psaddr_t, Elf64_Dyn **, size_t *);
151 extern rd_err_e		_rd_get_ehdr64(struct rd_agent *,
152 			    psaddr_t, Elf64_Ehdr *, uint_t *);
153 extern rd_err_e		_rd_objpad_enable64(struct rd_agent *, size_t);
154 extern rd_err_e		_rd_loadobj_iter64(rd_agent_t *, rl_iter_f *, void *);
155 extern rd_err_e		_rd_reset64(struct rd_agent *);
156 extern rd_err_e		find_dynamic_ent64(struct rd_agent *, psaddr_t,
157 			    Xword, Elf64_Dyn *);
158 extern rd_err_e		plt64_resolution(rd_agent_t *, psaddr_t, lwpid_t,
159 			    psaddr_t, rd_plt_info_t *);
160 extern rd_err_e		validate_rdebug64(struct rd_agent *rap);
161 #endif
162 
163 #ifdef	__cplusplus
164 }
165 #endif
166 
167 #endif /* __RTLD_DB_H */
168