1 /* ltdl.h -- generic dlopen functions
2 Copyright (C) 1998-2000, 2002 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 #include "guile-ltdl.h"
33 #include <sys/types.h> /* for size_t declaration */
36 /* --- MACROS FOR PORTABILITY --- */
38 /* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations,
39 so that C++ compilers don't mangle their names. Use LTDL_END_C_DECLS at
40 the end of C declarations. */
42 # define LT_BEGIN_C_DECLS extern "C" {
43 # define LT_END_C_DECLS }
45 # define LT_BEGIN_C_DECLS /* empty */
46 # define LT_END_C_DECLS /* empty */
52 /* LT_PARAMS is a macro used to wrap function prototypes, so that compilers
53 that don't understand ANSI C prototypes still work, and ANSI C
54 compilers can issue warnings about type mismatches. */
55 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
56 # define LT_PARAMS(protos) protos
59 # define LT_PARAMS(protos) ()
63 /* LT_STMT_START/END are used to create macros which expand to a
64 a single compound statement in a portable way. */
65 #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
66 # define LT_STMT_START (void)(
67 # define LT_STMT_END )
69 # if (defined (sun) || defined (__sun__))
70 # define LT_STMT_START if (1)
71 # define LT_STMT_END else (void)0
73 # define LT_STMT_START do
74 # define LT_STMT_END while (0)
78 /* LT_CONC creates a new concatenated symbol for the compiler
80 #if defined(__STDC__) || defined(__cplusplus)
81 # define LT_CONC(s,t) s##t
83 # define LT_CONC(s,t) s/**/t
86 /* LT_STRLEN can be used safely on NULL pointers. */
87 #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0)
91 /* --- WINDOWS SUPPORT --- */
94 /* Canonicalise Windows and Cygwin recognition macros. */
97 # define __CYGWIN__ __CYGWIN32__
100 #if defined(_WIN32) || defined(WIN32)
103 # define __WINDOWS__ _WIN32
106 # define __WINDOWS__ WIN32
114 /* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory
115 separator when it is set. */
116 # define LT_DIRSEP_CHAR '\\'
117 # define LT_PATHSEP_CHAR ';'
120 #ifndef LT_PATHSEP_CHAR
121 # define LT_PATHSEP_CHAR ':'
124 /* DLL building support on win32 hosts; mostly to workaround their
125 ridiculous implementation of data symbol exporting. */
128 # ifdef DLL_EXPORT /* defined by libtool (if required) */
129 # define LT_SCOPE __declspec(dllexport)
131 # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */
132 # define LT_SCOPE extern __declspec(dllimport)
135 # ifndef LT_SCOPE /* static linking or !__WINDOWS__ */
136 # define LT_SCOPE extern
143 /* --- DYNAMIC MODULE LOADING API --- */
146 typedef struct lt_dlhandle_struct
*lt_dlhandle
; /* A loaded module. */
148 /* Initialisation and finalisation functions for libltdl. */
149 SCMLTXT
int lt_dlinit
LT_PARAMS((void));
150 SCMLTXT
int lt_dlexit
LT_PARAMS((void)) SCM_UNUSED
;
152 /* Module search path manipulation. */
153 SCMLTXT
int lt_dladdsearchdir
LT_PARAMS((const char *search_dir
)) SCM_UNUSED
;
154 SCMLTXT
int lt_dlinsertsearchdir
LT_PARAMS((const char *before
,
155 const char *search_dir
)) SCM_UNUSED
;
156 SCMLTXT
int lt_dlsetsearchpath
LT_PARAMS((const char *search_path
)) SCM_UNUSED
;
157 SCMLTXT
const char *lt_dlgetsearchpath
LT_PARAMS((void)) SCM_UNUSED
;
158 SCMLTXT
int lt_dlforeachfile
LT_PARAMS((
159 const char *search_path
,
160 int (*func
) (const char *filename
, lt_ptr data
),
161 lt_ptr data
)) SCM_UNUSED
;
163 /* Portable libltdl versions of the system dlopen() API. */
164 SCMLTXT lt_dlhandle lt_dlopen
LT_PARAMS((const char *filename
));
165 SCMLTXT lt_dlhandle lt_dlopenext
LT_PARAMS((const char *filename
));
166 SCMLTXT lt_ptr lt_dlsym
LT_PARAMS((lt_dlhandle handle
,
168 SCMLTXT
const char *lt_dlerror
LT_PARAMS((void));
169 SCMLTXT
int lt_dlclose
LT_PARAMS((lt_dlhandle handle
));
171 /* Module residency management. */
172 SCMLTXT
int lt_dlmakeresident
LT_PARAMS((lt_dlhandle handle
)) SCM_UNUSED
;
173 SCMLTXT
int lt_dlisresident
LT_PARAMS((lt_dlhandle handle
)) SCM_UNUSED
;
178 /* --- MUTEX LOCKING --- */
181 typedef void lt_dlmutex_lock
LT_PARAMS((void));
182 typedef void lt_dlmutex_unlock
LT_PARAMS((void));
183 typedef void lt_dlmutex_seterror
LT_PARAMS((const char *errmsg
));
184 typedef const char *lt_dlmutex_geterror
LT_PARAMS((void));
186 SCMLTXT
int lt_dlmutex_register
LT_PARAMS((lt_dlmutex_lock
*lock
,
187 lt_dlmutex_unlock
*unlock
,
188 lt_dlmutex_seterror
*seterror
,
189 lt_dlmutex_geterror
*geterror
)) SCM_UNUSED
;
194 /* --- MEMORY HANDLING --- */
197 /* By default, the realloc function pointer is set to our internal
198 realloc implementation which iself uses lt_dlmalloc and lt_dlfree.
199 libltdl relies on a featureful realloc, but if you are sure yours
200 has the right semantics then you can assign it directly. Generally,
201 it is safe to assign just a malloc() and a free() function. */
202 LT_SCOPE
lt_ptr (*lt_dlmalloc
) LT_PARAMS((size_t size
));
203 LT_SCOPE
lt_ptr (*lt_dlrealloc
) LT_PARAMS((lt_ptr ptr
, size_t size
)) SCM_UNUSED
;
204 LT_SCOPE
void (*lt_dlfree
) LT_PARAMS((lt_ptr ptr
));
209 /* --- PRELOADED MODULE SUPPORT --- */
212 /* A preopened symbol. Arrays of this type comprise the exported
213 symbols for a dlpreopened module. */
214 typedef struct SCM_INSERTED_DLSYMLIST_STRUCT_DECL
{
219 SCMLTXT
int lt_dlpreload
LT_PARAMS((const lt_dlsymlist
*preloaded
));
220 SCMLTXT
int lt_dlpreload_default
221 LT_PARAMS((const lt_dlsymlist
*preloaded
));
223 #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \
224 extern const lt_dlsymlist lt_preloaded_symbols[]; \
225 lt_dlpreload_default(lt_preloaded_symbols); \
231 /* --- MODULE INFORMATION --- */
234 /* Read only information pertaining to a loaded module. */
236 char *filename
; /* file name */
237 char *name
; /* module name */
238 int ref_count
; /* number of times lt_dlopened minus
239 number of times lt_dlclosed. */
242 SCMLTXT
const lt_dlinfo
*lt_dlgetinfo
LT_PARAMS((lt_dlhandle handle
)) SCM_UNUSED
;
243 SCMLTXT lt_dlhandle lt_dlhandle_next
LT_PARAMS((lt_dlhandle place
)) SCM_UNUSED
;
244 SCMLTXT
int lt_dlforeach
LT_PARAMS((
245 int (*func
) (lt_dlhandle handle
, lt_ptr data
),
246 lt_ptr data
)) SCM_UNUSED
;
248 /* Associating user data with loaded modules. */
249 typedef unsigned lt_dlcaller_id
;
251 SCMLTXT lt_dlcaller_id lt_dlcaller_register
LT_PARAMS((void)) SCM_UNUSED
;
252 SCMLTXT lt_ptr lt_dlcaller_set_data
LT_PARAMS((lt_dlcaller_id key
,
254 lt_ptr data
)) SCM_UNUSED
;
255 SCMLTXT lt_ptr lt_dlcaller_get_data
LT_PARAMS((lt_dlcaller_id key
,
256 lt_dlhandle handle
)) SCM_UNUSED
;
260 /* --- USER MODULE LOADER API --- */
263 typedef struct lt_dlloader lt_dlloader
;
264 typedef lt_ptr lt_user_data
;
265 typedef lt_ptr lt_module
;
267 /* Function pointer types for creating user defined module loaders. */
268 typedef lt_module lt_module_open
LT_PARAMS((lt_user_data loader_data
,
269 const char *filename
));
270 typedef int lt_module_close
LT_PARAMS((lt_user_data loader_data
,
272 typedef lt_ptr lt_find_sym
LT_PARAMS((lt_user_data loader_data
,
274 const char *symbol
));
275 typedef int lt_dlloader_exit
LT_PARAMS((lt_user_data loader_data
));
277 struct lt_user_dlloader
{
278 const char *sym_prefix
;
279 lt_module_open
*module_open
;
280 lt_module_close
*module_close
;
281 lt_find_sym
*find_sym
;
282 lt_dlloader_exit
*dlloader_exit
;
283 lt_user_data dlloader_data
;
286 SCMLTXT lt_dlloader
*lt_dlloader_next
LT_PARAMS((lt_dlloader
*place
));
287 SCMLTXT lt_dlloader
*lt_dlloader_find
LT_PARAMS((
288 const char *loader_name
));
289 SCMLTXT
const char *lt_dlloader_name
LT_PARAMS((lt_dlloader
*place
)) SCM_UNUSED
;
290 SCMLTXT lt_user_data
*lt_dlloader_data
LT_PARAMS((lt_dlloader
*place
)) SCM_UNUSED
;
291 SCMLTXT
int lt_dlloader_add
LT_PARAMS((lt_dlloader
*place
,
292 const struct lt_user_dlloader
*dlloader
,
293 const char *loader_name
));
294 SCMLTXT
int lt_dlloader_remove
LT_PARAMS((
295 const char *loader_name
)) SCM_UNUSED
;
299 /* --- ERROR MESSAGE HANDLING --- */
302 /* Defining error strings alongside their symbolic names in a macro in
303 this way allows us to expand the macro in different contexts with
304 confidence that the enumeration of symbolic names will map correctly
305 onto the table of error strings. */
306 #define lt_dlerror_table \
307 LT_ERROR(UNKNOWN, "unknown error") \
308 LT_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available") \
309 LT_ERROR(INVALID_LOADER, "invalid loader") \
310 LT_ERROR(INIT_LOADER, "loader initialization failed") \
311 LT_ERROR(REMOVE_LOADER, "loader removal failed") \
312 LT_ERROR(FILE_NOT_FOUND, "file not found") \
313 LT_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \
314 LT_ERROR(NO_SYMBOLS, "no symbols defined") \
315 LT_ERROR(CANNOT_OPEN, "can't open the module") \
316 LT_ERROR(CANNOT_CLOSE, "can't close the module") \
317 LT_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \
318 LT_ERROR(NO_MEMORY, "not enough memory") \
319 LT_ERROR(INVALID_HANDLE, "invalid module handle") \
320 LT_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \
321 LT_ERROR(INVALID_ERRORCODE, "invalid errorcode") \
322 LT_ERROR(SHUTDOWN, "library already shutdown") \
323 LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module") \
324 LT_ERROR(INVALID_MUTEX_ARGS, "invalid mutex handler registration") \
325 LT_ERROR(INVALID_POSITION, "invalid search path insert position")
327 /* Enumerate the symbolic error names. */
329 #define LT_ERROR(name, diagnostic) LT_CONC(LT_ERROR_, name),
336 /* These functions are only useful from inside custom module loaders. */
337 SCMLTXT
int lt_dladderror
LT_PARAMS((const char *diagnostic
)) SCM_UNUSED
;
338 SCMLTXT
int lt_dlseterror
LT_PARAMS((int errorcode
)) SCM_UNUSED
;