1 /* ltdl.h -- generic dlopen functions
2 Copyright (C) 1998-2000 Free Software Foundation, Inc.
3 Originally by Thomas Tanner <tanner@ffii.org>
4 This file is part of GNU Libtool.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 As a special exception to the GNU Lesser General Public License,
12 if you distribute this file as part of a program or library that
13 is built using GNU libtool, you may include it under the same
14 distribution terms that you use for the rest of that program.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free
23 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 /* Only include this header file once. */
31 /* Canonicalise Windows and Cygwin recognition macros. */
34 # define __CYGWIN__ __CYGWIN32__
43 /* __BEGIN_DECLS should be used at the beginning of your declarations,
44 so that C++ compilers don't mangle their names. Use __END_DECLS at
45 the end of C declarations. */
49 # define __BEGIN_DECLS extern "C" {
50 # define __END_DECLS }
52 # define __BEGIN_DECLS /* empty */
53 # define __END_DECLS /* empty */
56 /* LTDL_PARAMS is a macro used to wrap function prototypes, so that compilers
57 that don't understand ANSI C prototypes still work, and ANSI C
58 compilers can issue warnings about type mismatches. */
61 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
62 # define LTDL_PARAMS(protos) protos
63 # define lt_ptr_t void*
65 # define LTDL_PARAMS(protos) ()
66 # define lt_ptr_t char*
69 /* LTDL_STMT_START/END are used to create macros which expand to a
70 a single compound statement in a portable way. */
71 #undef LTDL_STMT_START
73 #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
74 # define LTDL_STMT_START (void)(
75 # define LTDL_STMT_END )
77 # if (defined (sun) || defined (__sun__))
78 # define LTDL_STMT_START if (1)
79 # define LTDL_STMT_END else (void)0
81 # define LTDL_STMT_START do
82 # define LTDL_STMT_END while (0)
88 /* LTDL_DIRSEP_CHAR is accepted *in addition* to '/' as a directory
89 separator when it is set. */
90 # define LTDL_DIRSEP_CHAR '\\'
91 # define LTDL_PATHSEP_CHAR ';'
94 #ifndef LTDL_PATHSEP_CHAR
95 # define LTDL_PATHSEP_CHAR ':'
98 /* DLL building support on win32 hosts; mostly to workaround their
99 ridiculous implementation of data symbol exporting. */
102 # ifdef DLL_EXPORT /* defined by libtool (if required) */
103 # define LTDL_SCOPE __declspec(dllexport)
105 # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */
106 # define LTDL_SCOPE extern __declspec(dllimport)
109 # ifndef LTDL_SCOPE /* static linking or !_WIN32 */
110 # define LTDL_SCOPE extern
117 /* Defining error strings alongside their symbolic names in a macro in
118 this way allows us to expand the macro in different contexts with
119 confidence that the enumeration of symbolic names will map correctly
120 onto the table of error strings. */
121 #define ltdl_error_table \
122 LTDL_ERROR(UNKNOWN, "unknown error") \
123 LTDL_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available")\
124 LTDL_ERROR(INVALID_LOADER, "invalid loader") \
125 LTDL_ERROR(INIT_LOADER, "loader initialization failed") \
126 LTDL_ERROR(REMOVE_LOADER, "loader removal failed") \
127 LTDL_ERROR(FILE_NOT_FOUND, "file not found") \
128 LTDL_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \
129 LTDL_ERROR(NO_SYMBOLS, "no symbols defined") \
130 LTDL_ERROR(CANNOT_OPEN, "can't open the module") \
131 LTDL_ERROR(CANNOT_CLOSE, "can't close the module") \
132 LTDL_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \
133 LTDL_ERROR(NO_MEMORY, "not enough memory") \
134 LTDL_ERROR(INVALID_HANDLE, "invalid module handle") \
135 LTDL_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \
136 LTDL_ERROR(INVALID_ERRORCODE, "invalid errorcode") \
137 LTDL_ERROR(SHUTDOWN, "library already shutdown")
139 /* Enumerate the symbolic error names. */
141 # define LTDL_ERROR(name, diagnostic) LTDL_ERROR_##name,
143 # define LTDL_ERROR(name, diagnostic) LTDL_ERROR_/**/name,
152 /* An opaque handle for a successfully lt_dlopened module instance. */
153 #ifdef _LTDL_COMPILE_
154 typedef struct lt_dlhandle_t *lt_dlhandle;
156 typedef lt_ptr_t lt_dlhandle;
159 /* A preopened symbol. Arrays of this type comprise the exported
160 symbols for a dlpreopened module. */
166 /* Read only information pertaining to a loaded module. */
168 char *filename; /* file name */
169 char *name; /* module name */
170 int ref_count; /* number of times lt_dlopened minus
171 number of times lt_dlclosed. */
174 /* An opaque handle for a module loaded by a system call. This is only
175 used internally by ltdl loaders, and by user module loaders. */
176 typedef lt_ptr_t lt_module_t;
178 /* An opaque handle for a module loader. */
179 #ifdef _LTDL_COMPILE_
180 typedef struct lt_dlloader_t lt_dlloader_t;
182 typedef lt_ptr_t lt_dlloader_t;
185 typedef lt_ptr_t lt_dlloader_data_t;
187 /* Function pointer types for creating user defined module loaders. */
188 typedef lt_module_t lt_module_open_t LTDL_PARAMS((lt_dlloader_data_t loader_data, const char *filename));
189 typedef int lt_module_close_t LTDL_PARAMS((lt_dlloader_data_t loader_data, lt_module_t handle));
190 typedef lt_ptr_t lt_find_sym_t LTDL_PARAMS((lt_dlloader_data_t loader_data, lt_module_t handle, const char *symbol));
191 typedef int lt_dlloader_exit_t LTDL_PARAMS((lt_dlloader_data_t loader_data));
194 /* Initialisation and finalisation functions for libltdl. */
195 extern int lt_dlinit LTDL_PARAMS((void));
196 extern int lt_dlexit LTDL_PARAMS((void));
198 /* Module search path manipultation. */
199 extern int lt_dladdsearchdir LTDL_PARAMS((const char *search_dir));
200 extern int lt_dlsetsearchpath LTDL_PARAMS((const char *search_path));
201 extern const char *lt_dlgetsearchpath LTDL_PARAMS((void));
203 /* Portable libltdl versions of the system dlopen() API. */
204 extern lt_dlhandle lt_dlopen LTDL_PARAMS((const char *filename));
205 extern lt_dlhandle lt_dlopenext LTDL_PARAMS((const char *filename));
206 extern lt_ptr_t lt_dlsym LTDL_PARAMS((lt_dlhandle handle, const char *name));
207 extern const char *lt_dlerror LTDL_PARAMS((void));
208 extern int lt_dlclose LTDL_PARAMS((lt_dlhandle handle));
210 /* Support for preloaded modules through lt_dlopen() API. */
211 extern int lt_dlpreload LTDL_PARAMS((const lt_dlsymlist *preloaded));
212 extern int lt_dlpreload_default LTDL_PARAMS((const lt_dlsymlist *preloaded));
214 #define LTDL_SET_PRELOADED_SYMBOLS() LTDL_STMT_START{ \
215 extern const lt_dlsymlist lt_preloaded_symbols[]; \
216 lt_dlpreload_default(lt_preloaded_symbols); \
219 /* Managing user data associated with a loaded modules. */
220 extern const lt_dlinfo *lt_dlgetinfo LTDL_PARAMS((lt_dlhandle handle));
221 extern int lt_dlforeach LTDL_PARAMS((
222 int (*func)(lt_dlhandle handle, lt_ptr_t data), lt_ptr_t data));
225 /* User module loader API. */
226 struct lt_user_dlloader {
227 const char *sym_prefix;
228 lt_module_open_t *module_open;
229 lt_module_close_t *module_close;
230 lt_find_sym_t *find_sym;
231 lt_dlloader_exit_t *dlloader_exit;
232 lt_dlloader_data_t dlloader_data;
235 extern lt_dlloader_t *lt_next_dlloader LTDL_PARAMS((lt_dlloader_t *place));
236 extern const char *lt_dlloader_name LTDL_PARAMS((lt_dlloader_t *place));
237 extern lt_dlloader_data_t *lt_dlloader_data LTDL_PARAMS((lt_dlloader_t *place));
238 extern lt_dlloader_t *lt_find_dlloader LTDL_PARAMS((const char *loader_name));
239 extern int lt_add_dlloader LTDL_PARAMS((lt_dlloader_t *place, const struct lt_user_dlloader *dlloader, const char *loader_name));
241 /* Integrated lt_dlerror() messages for user loaders. */
242 extern int lt_dladderror LTDL_PARAMS((const char *diagnostic));
243 extern int lt_dlseterror LTDL_PARAMS((int errorcode));
245 /* Pointers to memory management functions to be used by libltdl. */
246 LTDL_SCOPE lt_ptr_t (*lt_dlmalloc)LTDL_PARAMS((size_t size));
247 LTDL_SCOPE void (*lt_dlfree)LTDL_PARAMS((lt_ptr_t ptr));
251 #endif /* !_LTDL_H_ */