|
|
| version 1.2, 2003/01/13 15:44:13 | version 1.3, 2012/06/09 07:44:29 |
|---|---|
| Line 1 | Line 1 |
| /* ltdl.h -- generic dlopen functions | /* ltdl.h -- generic dlopen functions |
| Copyright (C) 1998-2000 Free Software Foundation, Inc. | |
| Originally by Thomas Tanner <tanner@ffii.org> | |
| This file is part of GNU Libtool. | |
| This library is free software; you can redistribute it and/or | Copyright (C) 1998-2000, 2004, 2005, |
| 2007, 2008 Free Software Foundation, Inc. | |
| Written by Thomas Tanner, 1998 | |
| NOTE: The canonical source of this file is maintained with the | |
| GNU Libtool package. Report bugs to bug-libtool@gnu.org. | |
| GNU Libltdl is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Lesser General Public | modify it under the terms of the GNU Lesser General Public |
| License as published by the Free Software Foundation; either | License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. | version 2 of the License, or (at your option) any later version. |
| As a special exception to the GNU Lesser General Public License, | As a special exception to the GNU Lesser General Public License, |
| if you distribute this file as part of a program or library that | if you distribute this file as part of a program or library that |
| is built using GNU libtool, you may include it under the same | is built using GNU Libtool, you may include this file under the |
| distribution terms that you use for the rest of that program. | same distribution terms that you use for the rest of that program. |
| This library is distributed in the hope that it will be useful, | GNU Libltdl is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| Lesser General Public License for more details. | GNU Lesser General Public License for more details. |
| You should have received a copy of the GNU Lesser General Public | You should have received a copy of the GNU Lesser General Public |
| License along with this library; if not, write to the Free | License along with GNU Libltdl; see the file COPYING.LIB. If not, a |
| Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | copy can be downloaded from http://www.gnu.org/licenses/lgpl.html, |
| 02111-1307 USA | or obtained by writing to the Free Software Foundation, Inc., |
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| */ | */ |
| /* Only include this header file once. */ | /* Only include this header file once. */ |
| #ifndef LTDL_H | #if !defined(LTDL_H) |
| #define LTDL_H 1 | #define LTDL_H 1 |
| #include <sys/types.h> /* for size_t declaration */ | #include <libltdl/lt_system.h> |
| #include <libltdl/lt_error.h> | |
| #include <libltdl/lt_dlloader.h> | |
| /* --- MACROS FOR PORTABILITY --- */ | |
| /* Saves on those hard to debug '\0' typos.... */ | |
| #define LT_EOS_CHAR '\0' | |
| /* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations, | |
| so that C++ compilers don't mangle their names. Use LTDL_END_C_DECLS at | |
| the end of C declarations. */ | |
| #ifdef __cplusplus | |
| # define LT_BEGIN_C_DECLS extern "C" { | |
| # define LT_END_C_DECLS } | |
| #else | |
| # define LT_BEGIN_C_DECLS /* empty */ | |
| # define LT_END_C_DECLS /* empty */ | |
| #endif | |
| LT_BEGIN_C_DECLS | LT_BEGIN_C_DECLS |
| /* LT_PARAMS is a macro used to wrap function prototypes, so that compilers | |
| that don't understand ANSI C prototypes still work, and ANSI C | |
| compilers can issue warnings about type mismatches. */ | |
| #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus) | |
| # define LT_PARAMS(protos) protos | |
| # define lt_ptr void* | |
| #else | |
| # define LT_PARAMS(protos) () | |
| # define lt_ptr char* | |
| #endif | |
| /* LT_STMT_START/END are used to create macros which expand to a | |
| a single compound statement in a portable way. */ | |
| #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) | |
| # define LT_STMT_START (void)( | |
| # define LT_STMT_END ) | |
| #else | |
| # if (defined (sun) || defined (__sun__)) | |
| # define LT_STMT_START if (1) | |
| # define LT_STMT_END else (void)0 | |
| # else | |
| # define LT_STMT_START do | |
| # define LT_STMT_END while (0) | |
| # endif | |
| #endif | |
| /* LT_CONC creates a new concatenated symbol for the compiler | |
| in a portable way. */ | |
| #if defined(__STDC__) || defined(__cplusplus) | |
| # define LT_CONC(s,t) s##t | |
| #else | |
| # define LT_CONC(s,t) s/**/t | |
| #endif | |
| /* LT_STRLEN can be used safely on NULL pointers. */ | /* LT_STRLEN can be used safely on NULL pointers. */ |
| #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0) | #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0) |
| /* --- WINDOWS SUPPORT --- */ | |
| /* Canonicalise Windows and Cygwin recognition macros. */ | |
| #ifdef __CYGWIN32__ | |
| # ifndef __CYGWIN__ | |
| # define __CYGWIN__ __CYGWIN32__ | |
| # endif | |
| #endif | |
| #if defined(_WIN32) || defined(WIN32) | |
| # ifndef __WINDOWS__ | |
| # ifdef _WIN32 | |
| # define __WINDOWS__ _WIN32 | |
| # else | |
| # ifdef WIN32 | |
| # define __WINDOWS__ WIN32 | |
| # endif | |
| # endif | |
| # endif | |
| #endif | |
| #ifdef __WINDOWS__ | |
| # ifndef __CYGWIN__ | |
| /* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory | |
| separator when it is set. */ | |
| # define LT_DIRSEP_CHAR '\\' | |
| # define LT_PATHSEP_CHAR ';' | |
| # endif | |
| #endif | |
| #ifndef LT_PATHSEP_CHAR | |
| # define LT_PATHSEP_CHAR ':' | |
| #endif | |
| /* DLL building support on win32 hosts; mostly to workaround their | |
| ridiculous implementation of data symbol exporting. */ | |
| #ifndef LT_SCOPE | |
| # ifdef __WINDOWS__ | |
| # ifdef DLL_EXPORT /* defined by libtool (if required) */ | |
| # define LT_SCOPE __declspec(dllexport) | |
| # endif | |
| # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */ | |
| # define LT_SCOPE extern __declspec(dllimport) | |
| # endif | |
| # endif | |
| # ifndef LT_SCOPE /* static linking or !__WINDOWS__ */ | |
| # define LT_SCOPE extern | |
| # endif | |
| #endif | |
| /* --- DYNAMIC MODULE LOADING API --- */ | /* --- DYNAMIC MODULE LOADING API --- */ |
| typedef struct lt_dlhandle_struct *lt_dlhandle; /* A loaded module. */ | typedef struct lt__handle *lt_dlhandle; /* A loaded module. */ |
| /* Initialisation and finalisation functions for libltdl. */ | /* Initialisation and finalisation functions for libltdl. */ |
| extern int lt_dlinit LT_PARAMS((void)); | LT_SCOPE int lt_dlinit (void); |
| extern int lt_dlexit LT_PARAMS((void)); | LT_SCOPE int lt_dlexit (void); |
| /* Module search path manipulation. */ | /* Module search path manipulation. */ |
| extern int lt_dladdsearchdir LT_PARAMS((const char *search_dir)); | LT_SCOPE int lt_dladdsearchdir (const char *search_dir); |
| extern int lt_dlinsertsearchdir LT_PARAMS((const char *before, | LT_SCOPE int lt_dlinsertsearchdir (const char *before, |
| const char *search_dir)); | const char *search_dir); |
| extern int lt_dlsetsearchpath LT_PARAMS((const char *search_path)); | LT_SCOPE int lt_dlsetsearchpath (const char *search_path); |
| extern const char *lt_dlgetsearchpath LT_PARAMS((void)); | LT_SCOPE const char *lt_dlgetsearchpath (void); |
| extern int lt_dlforeachfile LT_PARAMS(( | LT_SCOPE int lt_dlforeachfile ( |
| const char *search_path, | const char *search_path, |
| int (*func) (const char *filename, lt_ptr data), | int (*func) (const char *filename, void *data), |
| lt_ptr data)); | void *data); |
| /* Portable libltdl versions of the system dlopen() API. */ | |
| extern lt_dlhandle lt_dlopen LT_PARAMS((const char *filename)); | |
| extern lt_dlhandle lt_dlopenext LT_PARAMS((const char *filename)); | |
| extern lt_ptr lt_dlsym LT_PARAMS((lt_dlhandle handle, | |
| const char *name)); | |
| extern const char *lt_dlerror LT_PARAMS((void)); | |
| extern int lt_dlclose LT_PARAMS((lt_dlhandle handle)); | |
| /* Module residency management. */ | |
| extern int lt_dlmakeresident LT_PARAMS((lt_dlhandle handle)); | |
| extern int lt_dlisresident LT_PARAMS((lt_dlhandle handle)); | |
| /* User module loading advisors. */ | |
| /* --- MUTEX LOCKING --- */ | LT_SCOPE int lt_dladvise_init (lt_dladvise *advise); |
| LT_SCOPE int lt_dladvise_destroy (lt_dladvise *advise); | |
| LT_SCOPE int lt_dladvise_ext (lt_dladvise *advise); | |
| typedef void lt_dlmutex_lock LT_PARAMS((void)); | LT_SCOPE int lt_dladvise_resident (lt_dladvise *advise); |
| typedef void lt_dlmutex_unlock LT_PARAMS((void)); | LT_SCOPE int lt_dladvise_local (lt_dladvise *advise); |
| typedef void lt_dlmutex_seterror LT_PARAMS((const char *errmsg)); | LT_SCOPE int lt_dladvise_global (lt_dladvise *advise); |
| typedef const char *lt_dlmutex_geterror LT_PARAMS((void)); | LT_SCOPE int lt_dladvise_preload (lt_dladvise *advise); |
| extern int lt_dlmutex_register LT_PARAMS((lt_dlmutex_lock *lock, | |
| lt_dlmutex_unlock *unlock, | |
| lt_dlmutex_seterror *seterror, | |
| lt_dlmutex_geterror *geterror)); | |
| /* Portable libltdl versions of the system dlopen() API. */ | |
| LT_SCOPE lt_dlhandle lt_dlopen (const char *filename); | |
| LT_SCOPE lt_dlhandle lt_dlopenext (const char *filename); | |
| /* --- MEMORY HANDLING --- */ | LT_SCOPE lt_dlhandle lt_dlopenadvise (const char *filename, |
| lt_dladvise advise); | |
| LT_SCOPE void * lt_dlsym (lt_dlhandle handle, const char *name); | |
| /* By default, the realloc function pointer is set to our internal | LT_SCOPE const char *lt_dlerror (void); |
| realloc implementation which iself uses lt_dlmalloc and lt_dlfree. | LT_SCOPE int lt_dlclose (lt_dlhandle handle); |
| libltdl relies on a featureful realloc, but if you are sure yours | |
| has the right semantics then you can assign it directly. Generally, | |
| it is safe to assign just a malloc() and a free() function. */ | |
| LT_SCOPE lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)); | |
| LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)); | |
| LT_SCOPE void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)); | |
| /* --- PRELOADED MODULE SUPPORT --- */ | /* --- PRELOADED MODULE SUPPORT --- */ |
| Line 215 LT_SCOPE void (*lt_dlfree) LT_PARAM | Line 91 LT_SCOPE void (*lt_dlfree) LT_PARAM |
| symbols for a dlpreopened module. */ | symbols for a dlpreopened module. */ |
| typedef struct { | typedef struct { |
| const char *name; | const char *name; |
| lt_ptr address; | void *address; |
| } lt_dlsymlist; | } lt_dlsymlist; |
| extern int lt_dlpreload LT_PARAMS((const lt_dlsymlist *preloaded)); | typedef int lt_dlpreload_callback_func (lt_dlhandle handle); |
| extern int lt_dlpreload_default | |
| LT_PARAMS((const lt_dlsymlist *preloaded)); | |
| #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \ | |
| extern const lt_dlsymlist lt_preloaded_symbols[]; \ | |
| lt_dlpreload_default(lt_preloaded_symbols); \ | |
| }LT_STMT_END | |
| /* --- MODULE INFORMATION --- */ | |
| /* Read only information pertaining to a loaded module. */ | |
| typedef struct { | |
| char *filename; /* file name */ | |
| char *name; /* module name */ | |
| int ref_count; /* number of times lt_dlopened minus | |
| number of times lt_dlclosed. */ | |
| } lt_dlinfo; | |
| extern const lt_dlinfo *lt_dlgetinfo LT_PARAMS((lt_dlhandle handle)); | LT_SCOPE int lt_dlpreload (const lt_dlsymlist *preloaded); |
| extern lt_dlhandle lt_dlhandle_next LT_PARAMS((lt_dlhandle place)); | LT_SCOPE int lt_dlpreload_default (const lt_dlsymlist *preloaded); |
| extern int lt_dlforeach LT_PARAMS(( | LT_SCOPE int lt_dlpreload_open (const char *originator, |
| int (*func) (lt_dlhandle handle, lt_ptr data), | lt_dlpreload_callback_func *func); |
| lt_ptr data)); | |
| #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols | |
| /* Ensure C linkage. */ | |
| extern LT_DLSYM_CONST lt_dlsymlist lt__PROGRAM__LTX_preloaded_symbols[]; | |
| /* Associating user data with loaded modules. */ | #define LTDL_SET_PRELOADED_SYMBOLS() \ |
| typedef unsigned lt_dlcaller_id; | lt_dlpreload_default(lt_preloaded_symbols) |
| extern lt_dlcaller_id lt_dlcaller_register LT_PARAMS((void)); | |
| extern lt_ptr lt_dlcaller_set_data LT_PARAMS((lt_dlcaller_id key, | |
| lt_dlhandle handle, | |
| lt_ptr data)); | |
| extern lt_ptr lt_dlcaller_get_data LT_PARAMS((lt_dlcaller_id key, | |
| lt_dlhandle handle)); | |
| /* --- USER MODULE LOADER API --- */ | /* --- MODULE INFORMATION --- */ |
| typedef struct lt_dlloader lt_dlloader; | /* Associating user data with loaded modules. */ |
| typedef lt_ptr lt_user_data; | typedef void * lt_dlinterface_id; |
| typedef lt_ptr lt_module; | typedef int lt_dlhandle_interface (lt_dlhandle handle, const char *id_string); |
| /* Function pointer types for creating user defined module loaders. */ | |
| typedef lt_module lt_module_open LT_PARAMS((lt_user_data loader_data, | |
| const char *filename)); | |
| typedef int lt_module_close LT_PARAMS((lt_user_data loader_data, | |
| lt_module handle)); | |
| typedef lt_ptr lt_find_sym LT_PARAMS((lt_user_data loader_data, | |
| lt_module handle, | |
| const char *symbol)); | |
| typedef int lt_dlloader_exit LT_PARAMS((lt_user_data loader_data)); | |
| struct lt_user_dlloader { | |
| const char *sym_prefix; | |
| lt_module_open *module_open; | |
| lt_module_close *module_close; | |
| lt_find_sym *find_sym; | |
| lt_dlloader_exit *dlloader_exit; | |
| lt_user_data dlloader_data; | |
| }; | |
| extern lt_dlloader *lt_dlloader_next LT_PARAMS((lt_dlloader *place)); | |
| extern lt_dlloader *lt_dlloader_find LT_PARAMS(( | |
| const char *loader_name)); | |
| extern const char *lt_dlloader_name LT_PARAMS((lt_dlloader *place)); | |
| extern lt_user_data *lt_dlloader_data LT_PARAMS((lt_dlloader *place)); | |
| extern int lt_dlloader_add LT_PARAMS((lt_dlloader *place, | |
| const struct lt_user_dlloader *dlloader, | |
| const char *loader_name)); | |
| extern int lt_dlloader_remove LT_PARAMS(( | |
| const char *loader_name)); | |
| LT_SCOPE lt_dlinterface_id lt_dlinterface_register (const char *id_string, | |
| lt_dlhandle_interface *iface); | |
| LT_SCOPE void lt_dlinterface_free (lt_dlinterface_id key); | |
| LT_SCOPE void * lt_dlcaller_set_data (lt_dlinterface_id key, | |
| lt_dlhandle handle, void *data); | |
| LT_SCOPE void * lt_dlcaller_get_data (lt_dlinterface_id key, | |
| lt_dlhandle handle); | |
| /* --- ERROR MESSAGE HANDLING --- */ | |
| /* Read only information pertaining to a loaded module. */ | |
| typedef struct { | |
| char * filename; /* file name */ | |
| char * name; /* module name */ | |
| int ref_count; /* number of times lt_dlopened minus | |
| number of times lt_dlclosed. */ | |
| unsigned int is_resident:1; /* module can't be unloaded. */ | |
| unsigned int is_symglobal:1; /* module symbols can satisfy | |
| subsequently loaded modules. */ | |
| unsigned int is_symlocal:1; /* module symbols are only available | |
| locally. */ | |
| } lt_dlinfo; | |
| /* Defining error strings alongside their symbolic names in a macro in | LT_SCOPE const lt_dlinfo *lt_dlgetinfo (lt_dlhandle handle); |
| this way allows us to expand the macro in different contexts with | |
| confidence that the enumeration of symbolic names will map correctly | |
| onto the table of error strings. */ | |
| #define lt_dlerror_table \ | |
| LT_ERROR(UNKNOWN, "unknown error") \ | |
| LT_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available") \ | |
| LT_ERROR(INVALID_LOADER, "invalid loader") \ | |
| LT_ERROR(INIT_LOADER, "loader initialization failed") \ | |
| LT_ERROR(REMOVE_LOADER, "loader removal failed") \ | |
| LT_ERROR(FILE_NOT_FOUND, "file not found") \ | |
| LT_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \ | |
| LT_ERROR(NO_SYMBOLS, "no symbols defined") \ | |
| LT_ERROR(CANNOT_OPEN, "can't open the module") \ | |
| LT_ERROR(CANNOT_CLOSE, "can't close the module") \ | |
| LT_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \ | |
| LT_ERROR(NO_MEMORY, "not enough memory") \ | |
| LT_ERROR(INVALID_HANDLE, "invalid module handle") \ | |
| LT_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \ | |
| LT_ERROR(INVALID_ERRORCODE, "invalid errorcode") \ | |
| LT_ERROR(SHUTDOWN, "library already shutdown") \ | |
| LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module") \ | |
| LT_ERROR(INVALID_MUTEX_ARGS, "invalid mutex handler registration") \ | |
| LT_ERROR(INVALID_POSITION, "invalid search path insert position") | |
| /* Enumerate the symbolic error names. */ | |
| enum { | |
| #define LT_ERROR(name, diagnostic) LT_CONC(LT_ERROR_, name), | |
| lt_dlerror_table | |
| #undef LT_ERROR | |
| LT_ERROR_MAX | |
| }; | |
| /* These functions are only useful from inside custom module loaders. */ | |
| extern int lt_dladderror LT_PARAMS((const char *diagnostic)); | |
| extern int lt_dlseterror LT_PARAMS((int errorcode)); | |
| LT_SCOPE lt_dlhandle lt_dlhandle_iterate (lt_dlinterface_id iface, | |
| lt_dlhandle place); | |
| LT_SCOPE lt_dlhandle lt_dlhandle_fetch (lt_dlinterface_id iface, | |
| const char *module_name); | |
| LT_SCOPE int lt_dlhandle_map (lt_dlinterface_id iface, | |
| int (*func) (lt_dlhandle handle, void *data), | |
| void *data); | |
| /* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */ | |
| /* Deprecated module residency management API. */ | |
| LT_SCOPE int lt_dlmakeresident (lt_dlhandle handle); | |
| LT_SCOPE int lt_dlisresident (lt_dlhandle handle); | |
| #ifdef LT_NON_POSIX_NAMESPACE | #define lt_ptr void * |
| # define lt_ptr_t lt_ptr | |
| # define lt_module_t lt_module | |
| # define lt_module_open_t lt_module_open | |
| # define lt_module_close_t lt_module_close | |
| # define lt_find_sym_t lt_find_sym | |
| # define lt_dlloader_exit_t lt_dlloader_exit | |
| # define lt_dlloader_t lt_dlloader | |
| # define lt_dlloader_data_t lt_user_data | |
| #endif | |
| LT_END_C_DECLS | LT_END_C_DECLS |
| #endif /* !LTDL_H */ | #endif /*!defined(LTDL_H)*/ |