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