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
116 /* Defining error strings alongside their symbolic names in a macro in
117 this way allows us to expand the macro in different contexts with
118 confidence that the enumeration of symbolic names will map correctly
119 onto the table of error strings. */
120 #define ltdl_error_table \
121 LTDL_ERROR(UNKNOWN, "unknown error") \
122 LTDL_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available")\
123 LTDL_ERROR(INVALID_LOADER, "invalid loader") \
124 LTDL_ERROR(INIT_LOADER, "loader initialization failed") \
125 LTDL_ERROR(REMOVE_LOADER, "loader removal failed") \
126 LTDL_ERROR(FILE_NOT_FOUND, "file not found") \
127 LTDL_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \
128 LTDL_ERROR(NO_SYMBOLS, "no symbols defined") \
129 LTDL_ERROR(CANNOT_OPEN, "can't open the module") \
130 LTDL_ERROR(CANNOT_CLOSE, "can't close the module") \
131 LTDL_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \
132 LTDL_ERROR(NO_MEMORY, "not enough memory") \
133 LTDL_ERROR(INVALID_HANDLE, "invalid module handle") \
134 LTDL_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \
135 LTDL_ERROR(INVALID_ERRORCODE, "invalid errorcode") \
136 LTDL_ERROR(SHUTDOWN, "library already shutdown")
138 /* Enumerate the symbolic error names. */
139 #if defined(__STDC__) || defined(__cplusplus)
140 # define LTDL_ERROR(name, diagnostic) LTDL_ERROR_##name,
142 # define LTDL_ERROR(name, diagnostic) LTDL_ERROR_/**/name,
150 /* An opaque handle for a successfully lt_dlopened module instance. */
151 #ifdef _LTDL_COMPILE_
152 typedef struct lt_dlhandle_t
*lt_dlhandle
;
154 typedef lt_ptr_t lt_dlhandle
;
157 /* A preopened symbol. Arrays of this type comprise the exported
158 symbols for a dlpreopened module. */
164 /* Read only information pertaining to a loaded module. */
166 char *filename
; /* file name */
167 char *name
; /* module name */
168 int ref_count
; /* number of times lt_dlopened minus
169 number of times lt_dlclosed. */
172 /* An opaque handle for a module loaded by a system call. This is only
173 used internally by ltdl loaders, and by user module loaders. */
174 typedef lt_ptr_t lt_module_t
;
176 /* An opaque handle for a module loader. */
177 #ifdef _LTDL_COMPILE_
178 typedef struct lt_dlloader_t lt_dlloader_t
;
180 typedef lt_ptr_t lt_dlloader_t
;
183 typedef lt_ptr_t lt_dlloader_data_t
;
185 /* Function pointer types for creating user defined module loaders. */
186 typedef lt_module_t lt_module_open_t
LTDL_PARAMS((lt_dlloader_data_t loader_data
, const char *filename
));
187 typedef int lt_module_close_t
LTDL_PARAMS((lt_dlloader_data_t loader_data
, lt_module_t handle
));
188 typedef lt_ptr_t lt_find_sym_t
LTDL_PARAMS((lt_dlloader_data_t loader_data
, lt_module_t handle
, const char *symbol
));
189 typedef int lt_dlloader_exit_t
LTDL_PARAMS((lt_dlloader_data_t loader_data
));
192 /* Initialisation and finalisation functions for libltdl. */
193 extern int lt_dlinit
LTDL_PARAMS((void));
194 extern int lt_dlexit
LTDL_PARAMS((void));
196 /* Module search path manipultation. */
197 extern int lt_dladdsearchdir
LTDL_PARAMS((const char *search_dir
));
198 extern int lt_dlsetsearchpath
LTDL_PARAMS((const char *search_path
));
199 extern const char *lt_dlgetsearchpath
LTDL_PARAMS((void));
201 /* Portable libltdl versions of the system dlopen() API. */
202 extern lt_dlhandle lt_dlopen
LTDL_PARAMS((const char *filename
));
203 extern lt_dlhandle lt_dlopenext
LTDL_PARAMS((const char *filename
));
204 extern lt_ptr_t lt_dlsym
LTDL_PARAMS((lt_dlhandle handle
, const char *name
));
205 extern const char *lt_dlerror
LTDL_PARAMS((void));
206 extern int lt_dlclose
LTDL_PARAMS((lt_dlhandle handle
));
208 /* Support for preloaded modules through lt_dlopen() API. */
209 extern int lt_dlpreload
LTDL_PARAMS((const lt_dlsymlist
*preloaded
));
210 extern int lt_dlpreload_default
LTDL_PARAMS((const lt_dlsymlist
*preloaded
));
212 #define LTDL_SET_PRELOADED_SYMBOLS() LTDL_STMT_START{ \
213 extern const lt_dlsymlist lt_preloaded_symbols[]; \
214 lt_dlpreload_default(lt_preloaded_symbols); \
217 /* Managing user data associated with a loaded modules. */
218 extern const lt_dlinfo
*lt_dlgetinfo
LTDL_PARAMS((lt_dlhandle handle
));
219 extern int lt_dlforeach
LTDL_PARAMS((
220 int (*func
)(lt_dlhandle handle
, lt_ptr_t data
), lt_ptr_t data
));
222 /* User module loader API. */
223 struct lt_user_dlloader
{
224 const char *sym_prefix
;
225 lt_module_open_t
*module_open
;
226 lt_module_close_t
*module_close
;
227 lt_find_sym_t
*find_sym
;
228 lt_dlloader_exit_t
*dlloader_exit
;
229 lt_dlloader_data_t dlloader_data
;
232 extern lt_dlloader_t
*lt_dlloader_next
LTDL_PARAMS((lt_dlloader_t
*place
));
233 extern lt_dlloader_t
*lt_dlloader_find
LTDL_PARAMS((const char *loader_name
));
234 extern const char *lt_dlloader_name
LTDL_PARAMS((lt_dlloader_t
*place
));
235 extern lt_dlloader_data_t
*lt_dlloader_data
LTDL_PARAMS((lt_dlloader_t
*place
));
236 extern lt_dlloader_t
*lt_find_dlloader
LTDL_PARAMS((const char *loader_name
));
237 extern int lt_dlloader_add
LTDL_PARAMS((lt_dlloader_t
*place
, const struct lt_user_dlloader
*dlloader
, const char *loader_name
));
238 extern int lt_dlloader_remove
LTDL_PARAMS((const char *loader_name
));
240 /* Integrated lt_dlerror() messages for user loaders. */
241 extern int lt_dladderror
LTDL_PARAMS((const char *diagnostic
));
242 extern int lt_dlseterror
LTDL_PARAMS((int errorcode
));
244 /* Pointers to memory management functions to be used by libltdl. */
245 LTDL_SCOPE
lt_ptr_t (*lt_dlmalloc
)LTDL_PARAMS((size_t size
));
246 LTDL_SCOPE
void (*lt_dlfree
)LTDL_PARAMS((lt_ptr_t ptr
));
250 #endif /* !_LTDL_H_ */