xref: /illumos-gate/usr/src/head/dlfcn.h (revision bdb9230ac765cb7af3fc1f4119caf2c5720dceb3)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  *	Copyright (c) 1989 AT&T
26  *	  All Rights Reserved
27  *
28  */
29 
30 #ifndef _DLFCN_H
31 #define	_DLFCN_H
32 
33 #include <sys/feature_tests.h>
34 #include <sys/types.h>
35 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
36 #include <sys/auxv.h>
37 #include <sys/mman.h>
38 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Information structures for various dlinfo() requests.
46  */
47 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
48 #ifdef __STDC__
49 typedef struct	dl_info {
50 	const char	*dli_fname;	/* file containing address range */
51 	void		*dli_fbase;	/* base address of file image */
52 	const char	*dli_sname;	/* symbol name */
53 	void		*dli_saddr;	/* symbol address */
54 } Dl_info;
55 #else
56 typedef struct	dl_info {
57 	char		*dli_fname;
58 	void		*dli_fbase;
59 	char		*dli_sname;
60 	void		*dli_saddr;
61 } Dl_info;
62 #endif /* __STDC__ */
63 typedef	Dl_info		Dl_info_t;
64 
65 typedef struct	dl_serpath {
66 	char		*dls_name;	/* library search path name */
67 	uint_t		dls_flags;	/* path information */
68 } Dl_serpath;
69 typedef	Dl_serpath	Dl_serpath_t;
70 
71 typedef struct	dl_serinfo {
72 	size_t		dls_size;	/* total buffer size */
73 	uint_t		dls_cnt;	/* number of path entries */
74 	Dl_serpath	dls_serpath[1];	/* there may be more than one */
75 } Dl_serinfo;
76 typedef	Dl_serinfo	Dl_serinfo_t;
77 
78 typedef struct	dl_argsinfo {
79 	long		dla_argc;	/* process argument count */
80 	char		**dla_argv;	/* process arguments */
81 	char		**dla_envp;	/* process environment variables */
82 	auxv_t		*dla_auxv;	/* process auxv vectors */
83 } Dl_argsinfo;
84 typedef	Dl_argsinfo	Dl_argsinfo_t;
85 
86 typedef struct {
87 	mmapobj_result_t *dlm_maps;	/* mapping information */
88 	uint_t		dlm_acnt;	/* number of dlm_maps mappings */
89 	uint_t		dlm_rcnt;	/* number of returned mappings */
90 } Dl_mapinfo_t;
91 
92 typedef struct {
93 	uint_t		dlui_version;	/* version # */
94 	uint_t		dlui_flags;	/* flags */
95 	char		*dlui_objname;	/* path to object */
96 	void		*dlui_unwindstart; /* star of unwind hdr */
97 	void		*dlui_unwindend; /* end of unwind hdr */
98 	void		*dlui_segstart;	/* start of segment described */
99 					/*  by unwind block */
100 	void		*dlui_segend;	/* end of segment described */
101 					/*  by unwind block */
102 } Dl_amd64_unwindinfo;
103 typedef	Dl_amd64_unwindinfo	Dl_amd64_unwindinfo_t;
104 
105 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
106 
107 
108 typedef ulong_t		Lmid_t;
109 
110 /*
111  * Declarations used for dynamic linking support routines.
112  */
113 #ifdef __STDC__
114 extern void	*dlopen(const char *, int);
115 extern void   	*dlsym(void *_RESTRICT_KYWD, const char *_RESTRICT_KYWD);
116 extern int	dlclose(void *);
117 extern char	*dlerror(void);
118 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
119 extern void	*dlmopen(Lmid_t, const char *, int);
120 extern int	dladdr(void *, Dl_info *);
121 extern int	dladdr1(void *, Dl_info *, void **, int);
122 extern int	dldump(const char *, const char *, int);
123 extern int	dlinfo(void *, int, void *);
124 extern Dl_amd64_unwindinfo  *dlamd64getunwind(void *, Dl_amd64_unwindinfo *);
125 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
126 #else
127 extern void	*dlopen();
128 extern void	*dlsym();
129 extern int	dlclose();
130 extern char	*dlerror();
131 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
132 extern void 	*dlmopen();
133 extern int	dladdr();
134 extern int	dladdr1();
135 extern int	dldump();
136 extern int	dlinfo();
137 extern Dl_amd64_unwindinfo  *dlamd64getunwind();
138 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
139 #endif /* __STDC__ */
140 
141 #pragma unknown_control_flow(dlopen, dlsym, dlclose, dlerror)
142 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
143 #pragma unknown_control_flow(dlmopen, dladdr, dladdr1, dldump, dlinfo)
144 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
145 
146 /*
147  * Valid values for handle argument to dlsym(3x).
148  */
149 #define	RTLD_NEXT		(void *)-1	/* look in `next' dependency */
150 #define	RTLD_DEFAULT		(void *)-2	/* look up symbol from scope */
151 						/*	of current object */
152 #define	RTLD_SELF		(void *)-3	/* look in `ourself' */
153 #define	RTLD_PROBE		(void *)-4	/* look up symbol from scope */
154 						/*	of current object, */
155 						/*	using currently */
156 						/*	loaded objects only. */
157 /*
158  * Valid values for mode argument to dlopen.
159  */
160 #define	RTLD_LAZY		0x00001		/* deferred function binding */
161 #define	RTLD_NOW		0x00002		/* immediate function binding */
162 #define	RTLD_NOLOAD		0x00004		/* don't load object */
163 
164 #define	RTLD_GLOBAL		0x00100		/* export symbols to others */
165 #define	RTLD_LOCAL		0x00000		/* symbols are only available */
166 						/*	to group members */
167 #define	RTLD_PARENT		0x00200		/* add parent (caller) to */
168 						/*	a group dependencies */
169 #define	RTLD_GROUP		0x00400		/* resolve symbols within */
170 						/*	members of the group */
171 #define	RTLD_WORLD		0x00800		/* resolve symbols within */
172 						/*	global objects */
173 #define	RTLD_NODELETE		0x01000		/* do not remove members */
174 #define	RTLD_FIRST		0x02000		/* only first object is */
175 						/*	available for dlsym */
176 #define	RTLD_CONFGEN		0x10000		/* crle(1) config generation */
177 						/*	internal use only */
178 
179 /*
180  * Valid values for flag argument to dldump.
181  */
182 #define	RTLD_REL_RELATIVE	0x00001		/* apply relative relocs */
183 #define	RTLD_REL_EXEC		0x00002		/* apply symbolic relocs that */
184 						/*	bind to main */
185 #define	RTLD_REL_DEPENDS	0x00004		/* apply symbolic relocs that */
186 						/*	bind to dependencies */
187 #define	RTLD_REL_PRELOAD	0x00008		/* apply symbolic relocs that */
188 						/*	bind to preload objs */
189 #define	RTLD_REL_SELF		0x00010		/* apply symbolic relocs that */
190 						/*	bind to ourself */
191 #define	RTLD_REL_WEAK		0x00020		/* apply symbolic weak relocs */
192 						/*	even if unresolved */
193 #define	RTLD_REL_ALL		0x00fff 	/* apply all relocs */
194 
195 #define	RTLD_MEMORY		0x01000		/* use memory sections */
196 #define	RTLD_STRIP		0x02000		/* retain allocable sections */
197 						/*	only */
198 #define	RTLD_NOHEAP		0x04000		/* do no save any heap */
199 #define	RTLD_CONFSET		0x10000		/* crle(1) config generation */
200 						/*	internal use only */
201 
202 /*
203  * Valid values for dladdr1() flags.
204  */
205 #define	RTLD_DL_SYMENT		1		/* return symbol table entry */
206 #define	RTLD_DL_LINKMAP		2		/* return public link-map */
207 #define	RTLD_DL_MASK		0xffff
208 
209 
210 /*
211  * Arguments for dlinfo()
212  */
213 #define	RTLD_DI_LMID		1		/* obtain link-map id */
214 #define	RTLD_DI_LINKMAP		2		/* obtain link-map */
215 #define	RTLD_DI_CONFIGADDR	3		/* obtain config addr */
216 #define	RTLD_DI_SERINFO		4		/* obtain search path info or */
217 #define	RTLD_DI_SERINFOSIZE	5		/*	associated info size */
218 #define	RTLD_DI_ORIGIN		6		/* obtain objects origin */
219 #define	RTLD_DI_PROFILENAME	7		/* obtain profile object name */
220 						/*	internal use only */
221 #define	RTLD_DI_PROFILEOUT	8		/* obtain profile output name */
222 						/*	internal use only */
223 #define	RTLD_DI_GETSIGNAL	9		/* get termination signal */
224 #define	RTLD_DI_SETSIGNAL	10		/* set termination signal */
225 #define	RTLD_DI_ARGSINFO	11		/* get process arguments */
226 						/*	environment and auxv */
227 #define	RTLD_DI_MMAPS		12		/* obtain objects mappings or */
228 #define	RTLD_DI_MMAPCNT		13		/*	mapping count */
229 #define	RTLD_DI_MAX		13
230 
231 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
232 /*
233  * Version information for Dl_amd64_unwindinfo.dlui_version
234  */
235 #define	DLUI_VERS_1		1
236 #define	DLUI_VERS_CURRENT	DLUI_VERS_1
237 
238 /*
239  * Valid flags for Dl_amd64_unwindinfo.dlfi_flags
240  */
241 #define	DLUI_FLG_NOUNWIND	0x0001		/* object has no Unwind info */
242 #define	DLUI_FLG_NOOBJ		0x0002		/* no object was found */
243 						/*  matching the pc provided */
244 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
245 
246 #ifdef	__cplusplus
247 }
248 #endif
249 
250 #endif	/* _DLFCN_H */
251