1 /////////////////////////////////////////////////////////////////////////
2 // $Id: ltdl.h,v 1.2 2002/10/24 21:04:37 bdenney Exp $
4 // NOTE: The ltdl library comes from the Libtool package. Bochs uses
5 // ltdl and libtool to build and load plugins. The libtool
6 // documentation describes how to copy ltdl.c and ltdl.h into your
7 // distribution, so it is clearly legal to do so.
8 /////////////////////////////////////////////////////////////////////////
10 /* ltdl.h -- generic dlopen functions
11 Copyright (C) 1998-2000 Free Software Foundation, Inc.
12 Originally by Thomas Tanner <tanner@ffii.org>
13 This file is part of GNU Libtool.
15 This library is free software; you can redistribute it and/or
16 modify it under the terms of the GNU Lesser General Public
17 License as published by the Free Software Foundation; either
18 version 2 of the License, or (at your option) any later version.
20 As a special exception to the GNU Lesser General Public License,
21 if you distribute this file as part of a program or library that
22 is built using GNU libtool, you may include it under the same
23 distribution terms that you use for the rest of that program.
25 This library is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 Lesser General Public License for more details.
30 You should have received a copy of the GNU Lesser General Public
31 License along with this library; if not, write to the Free
32 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
36 /* Only include this header file once. */
43 #include <sys/types.h> /* for size_t declaration */
49 /* --- MACROS FOR PORTABILITY --- */
52 /* Saves on those hard to debug '\0' typos.... */
53 #define LT_EOS_CHAR '\0'
55 /* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations,
56 so that C++ compilers don't mangle their names. Use LTDL_END_C_DECLS at
57 the end of C declarations. */
59 # define LT_BEGIN_C_DECLS extern "C" {
60 # define LT_END_C_DECLS }
62 # define LT_BEGIN_C_DECLS /* empty */
63 # define LT_END_C_DECLS /* empty */
69 /* LT_PARAMS is a macro used to wrap function prototypes, so that compilers
70 that don't understand ANSI C prototypes still work, and ANSI C
71 compilers can issue warnings about type mismatches. */
72 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
73 # define LT_PARAMS(protos) protos
76 # define LT_PARAMS(protos) ()
80 /* LT_STMT_START/END are used to create macros which expand to a
81 a single compound statement in a portable way. */
82 #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
83 # define LT_STMT_START (void)(
84 # define LT_STMT_END )
86 # if (defined (sun) || defined (__sun__))
87 # define LT_STMT_START if (1)
88 # define LT_STMT_END else (void)0
90 # define LT_STMT_START do
91 # define LT_STMT_END while (0)
95 /* LT_CONC creates a new concatenated symbol for the compiler
97 #if defined(__STDC__) || defined(__cplusplus)
98 # define LT_CONC(s,t) s##t
100 # define LT_CONC(s,t) s/**/t
103 /* LT_STRLEN can be used safely on NULL pointers. */
104 #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0)
108 /* --- WINDOWS SUPPORT --- */
111 /* Canonicalise Windows and Cygwin recognition macros. */
114 # define __CYGWIN__ __CYGWIN32__
117 #if defined(_WIN32) || defined(WIN32)
120 # define __WINDOWS__ _WIN32
123 # define __WINDOWS__ WIN32
131 /* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory
132 separator when it is set. */
133 # define LT_DIRSEP_CHAR '\\'
134 # define LT_PATHSEP_CHAR ';'
137 #ifndef LT_PATHSEP_CHAR
138 # define LT_PATHSEP_CHAR ':'
141 /* DLL building support on win32 hosts; mostly to workaround their
142 ridiculous implementation of data symbol exporting. */
145 # ifdef DLL_EXPORT /* defined by libtool (if required) */
146 # define LT_SCOPE __declspec(dllexport)
148 # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */
149 # define LT_SCOPE extern __declspec(dllimport)
152 # ifndef LT_SCOPE /* static linking or !__WINDOWS__ */
153 # define LT_SCOPE extern
160 /* --- DYNAMIC MODULE LOADING API --- */
163 typedef struct lt_dlhandle_struct
*lt_dlhandle
; /* A loaded module. */
165 /* Initialisation and finalisation functions for libltdl. */
166 extern int lt_dlinit
LT_PARAMS((void));
167 extern int lt_dlexit
LT_PARAMS((void));
169 /* Module search path manipulation. */
170 extern int lt_dladdsearchdir
LT_PARAMS((const char *search_dir
));
171 extern int lt_dlinsertsearchdir
LT_PARAMS((const char *before
,
172 const char *search_dir
));
173 extern int lt_dlsetsearchpath
LT_PARAMS((const char *search_path
));
174 extern const char *lt_dlgetsearchpath
LT_PARAMS((void));
175 extern int lt_dlforeachfile
LT_PARAMS((
176 const char *search_path
,
177 int (*func
) (const char *filename
, lt_ptr data
),
180 /* Portable libltdl versions of the system dlopen() API. */
181 extern lt_dlhandle lt_dlopen
LT_PARAMS((const char *filename
));
182 extern lt_dlhandle lt_dlopenext
LT_PARAMS((const char *filename
));
183 extern lt_ptr lt_dlsym
LT_PARAMS((lt_dlhandle handle
,
185 extern const char *lt_dlerror
LT_PARAMS((void));
186 extern int lt_dlclose
LT_PARAMS((lt_dlhandle handle
));
188 /* Module residency management. */
189 extern int lt_dlmakeresident
LT_PARAMS((lt_dlhandle handle
));
190 extern int lt_dlisresident
LT_PARAMS((lt_dlhandle handle
));
195 /* --- MUTEX LOCKING --- */
198 typedef void lt_dlmutex_lock
LT_PARAMS((void));
199 typedef void lt_dlmutex_unlock
LT_PARAMS((void));
200 typedef void lt_dlmutex_seterror
LT_PARAMS((const char *errmsg
));
201 typedef const char *lt_dlmutex_geterror
LT_PARAMS((void));
203 extern int lt_dlmutex_register
LT_PARAMS((lt_dlmutex_lock
*lock
,
204 lt_dlmutex_unlock
*unlock
,
205 lt_dlmutex_seterror
*seterror
,
206 lt_dlmutex_geterror
*geterror
));
211 /* --- MEMORY HANDLING --- */
214 /* By default, the realloc function pointer is set to our internal
215 realloc implementation which iself uses lt_dlmalloc and lt_dlfree.
216 libltdl relies on a featureful realloc, but if you are sure yours
217 has the right semantics then you can assign it directly. Generally,
218 it is safe to assign just a malloc() and a free() function. */
219 LT_SCOPE
lt_ptr (*lt_dlmalloc
) LT_PARAMS((size_t size
));
220 LT_SCOPE
lt_ptr (*lt_dlrealloc
) LT_PARAMS((lt_ptr ptr
, size_t size
));
221 LT_SCOPE
void (*lt_dlfree
) LT_PARAMS((lt_ptr ptr
));
226 /* --- PRELOADED MODULE SUPPORT --- */
229 /* A preopened symbol. Arrays of this type comprise the exported
230 symbols for a dlpreopened module. */
236 extern int lt_dlpreload
LT_PARAMS((const lt_dlsymlist
*preloaded
));
237 extern int lt_dlpreload_default
238 LT_PARAMS((const lt_dlsymlist
*preloaded
));
240 #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \
241 extern const lt_dlsymlist lt_preloaded_symbols[]; \
242 lt_dlpreload_default(lt_preloaded_symbols); \
248 /* --- MODULE INFORMATION --- */
251 /* Read only information pertaining to a loaded module. */
253 char *filename
; /* file name */
254 char *name
; /* module name */
255 int ref_count
; /* number of times lt_dlopened minus
256 number of times lt_dlclosed. */
259 extern const lt_dlinfo
*lt_dlgetinfo
LT_PARAMS((lt_dlhandle handle
));
260 extern lt_dlhandle lt_dlhandle_next
LT_PARAMS((lt_dlhandle place
));
261 extern int lt_dlforeach
LT_PARAMS((
262 int (*func
) (lt_dlhandle handle
, lt_ptr data
),
265 /* Associating user data with loaded modules. */
266 typedef unsigned lt_dlcaller_id
;
268 extern lt_dlcaller_id lt_dlcaller_register
LT_PARAMS((void));
269 extern lt_ptr lt_dlcaller_set_data
LT_PARAMS((lt_dlcaller_id key
,
272 extern lt_ptr lt_dlcaller_get_data
LT_PARAMS((lt_dlcaller_id key
,
273 lt_dlhandle handle
));
277 /* --- USER MODULE LOADER API --- */
280 typedef struct lt_dlloader lt_dlloader
;
281 typedef lt_ptr lt_user_data
;
282 typedef lt_ptr lt_module
;
284 /* Function pointer types for creating user defined module loaders. */
285 typedef lt_module lt_module_open
LT_PARAMS((lt_user_data loader_data
,
286 const char *filename
));
287 typedef int lt_module_close
LT_PARAMS((lt_user_data loader_data
,
289 typedef lt_ptr lt_find_sym
LT_PARAMS((lt_user_data loader_data
,
291 const char *symbol
));
292 typedef int lt_dlloader_exit
LT_PARAMS((lt_user_data loader_data
));
294 struct lt_user_dlloader
{
295 const char *sym_prefix
;
296 lt_module_open
*module_open
;
297 lt_module_close
*module_close
;
298 lt_find_sym
*find_sym
;
299 lt_dlloader_exit
*dlloader_exit
;
300 lt_user_data dlloader_data
;
303 extern lt_dlloader
*lt_dlloader_next
LT_PARAMS((lt_dlloader
*place
));
304 extern lt_dlloader
*lt_dlloader_find
LT_PARAMS((
305 const char *loader_name
));
306 extern const char *lt_dlloader_name
LT_PARAMS((lt_dlloader
*place
));
307 extern lt_user_data
*lt_dlloader_data
LT_PARAMS((lt_dlloader
*place
));
308 extern int lt_dlloader_add
LT_PARAMS((lt_dlloader
*place
,
309 const struct lt_user_dlloader
*dlloader
,
310 const char *loader_name
));
311 extern int lt_dlloader_remove
LT_PARAMS((
312 const char *loader_name
));
316 /* --- ERROR MESSAGE HANDLING --- */
318 /* Bryce rewrote the error table in a way that would be likely to work
319 on all compilers. VC++ was not able to handle it the way it was
322 /* ORIG COMMENT: Defining error strings alongside their symbolic names in a
323 macro in this way allows us to expand the macro in different contexts with
324 confidence that the enumeration of symbolic names will map correctly
325 onto the table of error strings. */
327 #define lt_dlerror_symbols_list \
329 LT_ERROR_DLOPEN_NOT_SUPPORTED, \
330 LT_ERROR_INVALID_LOADER, \
331 LT_ERROR_INIT_LOADER, \
332 LT_ERROR_REMOVE_LOADER, \
333 LT_ERROR_FILE_NOT_FOUND, \
334 LT_ERROR_DEPLIB_NOT_FOUND, \
335 LT_ERROR_NO_SYMBOLS, \
336 LT_ERROR_CANNOT_OPEN, \
337 LT_ERROR_CANNOT_CLOSE, \
338 LT_ERROR_SYMBOL_NOT_FOUND, \
339 LT_ERROR_NO_MEMORY, \
340 LT_ERROR_INVALID_HANDLE, \
341 LT_ERROR_BUFFER_OVERFLOW, \
342 LT_ERROR_INVALID_ERRORCODE, \
344 LT_ERROR_CLOSE_RESIDENT_MODULE, \
345 LT_ERROR_INVALID_MUTEX_ARGS, \
346 LT_ERROR_INVALID_POSITION,
348 #define lt_dlerror_names_list \
350 "dlopen support not available", \
352 "loader initialization failed", \
353 "loader removal failed", \
355 "dependency library not found", \
356 "no symbols defined", \
357 "can't open the module", \
358 "can't close the module", \
359 "symbol not found", \
360 "not enough memory", \
361 "invalid module handle", \
362 "internal buffer overflow", \
363 "invalid errorcode", \
364 "library already shutdown", \
365 "can't close resident module", \
366 "invalid mutex handler registration", \
367 "invalid search path insert position",
369 /* Enumerate the symbolic error names. */
371 lt_dlerror_symbols_list
375 /* These functions are only useful from inside custom module loaders. */
376 extern int lt_dladderror
LT_PARAMS((const char *diagnostic
));
377 extern int lt_dlseterror
LT_PARAMS((int errorcode
));
382 /* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */
385 #ifdef LT_NON_POSIX_NAMESPACE
386 # define lt_ptr_t lt_ptr
387 # define lt_module_t lt_module
388 # define lt_module_open_t lt_module_open
389 # define lt_module_close_t lt_module_close
390 # define lt_find_sym_t lt_find_sym
391 # define lt_dlloader_exit_t lt_dlloader_exit
392 # define lt_dlloader_t lt_dlloader
393 # define lt_dlloader_data_t lt_user_data