Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

ltdl.h

00001 /* ltdl.h -- generic dlopen functions
00002    Copyright (C) 1998-2000 Free Software Foundation, Inc.
00003    Originally by Thomas Tanner <tanner@ffii.org>
00004    This file is part of GNU Libtool.
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2 of the License, or (at your option) any later version.
00010 
00011 As a special exception to the GNU Lesser General Public License,
00012 if you distribute this file as part of a program or library that
00013 is built using GNU libtool, you may include it under the same
00014 distribution terms that you use for the rest of that program.
00015 
00016 This library is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 Lesser General Public License for more details.
00020 
00021 You should have received a copy of the GNU Lesser General Public
00022 License along with this library; if not, write to the Free
00023 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00024 02111-1307  USA
00025 */
00026 
00027 /* Only include this header file once. */
00028 #ifndef LTDL_H
00029 #define LTDL_H 1
00030 
00031 #include <sys/types.h>          /* for size_t declaration */
00032 
00033 
00034 /* --- MACROS FOR PORTABILITY --- */
00035 
00036 
00037 /* Saves on those hard to debug '\0' typos....  */
00038 #define LT_EOS_CHAR     '\0'
00039 
00040 /* LTDL_BEGIN_C_DECLS should be used at the beginning of your declarations,
00041    so that C++ compilers don't mangle their names.  Use LTDL_END_C_DECLS at
00042    the end of C declarations. */
00043 #ifdef __cplusplus
00044 # define LT_BEGIN_C_DECLS       extern "C" {
00045 # define LT_END_C_DECLS         }
00046 #else
00047 # define LT_BEGIN_C_DECLS       /* empty */
00048 # define LT_END_C_DECLS         /* empty */
00049 #endif
00050 
00051 LT_BEGIN_C_DECLS
00052 
00053 
00054 /* LT_PARAMS is a macro used to wrap function prototypes, so that compilers
00055    that don't understand ANSI C prototypes still work, and ANSI C
00056    compilers can issue warnings about type mismatches.  */
00057 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
00058 # define LT_PARAMS(protos)      protos
00059 # define lt_ptr         void*
00060 #else
00061 # define LT_PARAMS(protos)      ()
00062 # define lt_ptr         char*
00063 #endif
00064 
00065 /* LT_STMT_START/END are used to create macros which expand to a
00066    a single compound statement in a portable way.  */
00067 #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
00068 #  define LT_STMT_START        (void)(
00069 #  define LT_STMT_END          )
00070 #else
00071 #  if (defined (sun) || defined (__sun__))
00072 #    define LT_STMT_START      if (1)
00073 #    define LT_STMT_END        else (void)0
00074 #  else
00075 #    define LT_STMT_START      do
00076 #    define LT_STMT_END        while (0)
00077 #  endif
00078 #endif
00079 
00080 /* LT_CONC creates a new concatenated symbol for the compiler
00081    in a portable way.  */
00082 #if defined(__STDC__) || defined(__cplusplus)
00083 #  define LT_CONC(s,t)  s##t
00084 #else
00085 #  define LT_CONC(s,t)  st
00086 #endif
00087 
00088 /* LT_STRLEN can be used safely on NULL pointers.  */
00089 #define LT_STRLEN(s)    (((s) && (s)[0]) ? strlen (s) : 0)
00090 
00091 
00092 
00093 /* --- WINDOWS SUPPORT --- */
00094 
00095 
00096 /* Canonicalise Windows and Cygwin recognition macros.  */
00097 #ifdef __CYGWIN32__
00098 #  ifndef __CYGWIN__
00099 #    define __CYGWIN__ __CYGWIN32__
00100 #  endif
00101 #endif
00102 #if defined(_WIN32) || defined(WIN32)
00103 #  ifndef __WINDOWS__
00104 #    ifdef _WIN32
00105 #      define __WINDOWS__ _WIN32
00106 #    else
00107 #      ifdef WIN32
00108 #        define __WINDOWS__ WIN32
00109 #      endif
00110 #    endif
00111 #  endif
00112 #endif
00113 
00114 #ifdef __WINDOWS__
00115 #  ifndef __CYGWIN__
00116 /* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory
00117    separator when it is set. */
00118 #    define LT_DIRSEP_CHAR      '\\'
00119 #    define LT_PATHSEP_CHAR     ';'
00120 #  endif
00121 #endif
00122 #ifndef LT_PATHSEP_CHAR
00123 #  define LT_PATHSEP_CHAR       ':'
00124 #endif
00125 
00126 /* DLL building support on win32 hosts;  mostly to workaround their
00127    ridiculous implementation of data symbol exporting. */
00128 #ifndef LT_SCOPE
00129 #  ifdef __WINDOWS__
00130 #    ifdef DLL_EXPORT           /* defined by libtool (if required) */
00131 #      define LT_SCOPE  __declspec(dllexport)
00132 #    endif
00133 #    ifdef LIBLTDL_DLL_IMPORT   /* define if linking with this dll */
00134 #      define LT_SCOPE  extern __declspec(dllimport)
00135 #    endif
00136 #  endif
00137 #  ifndef LT_SCOPE              /* static linking or !__WINDOWS__ */
00138 #    define LT_SCOPE    extern
00139 #  endif
00140 #endif
00141 
00142 
00143 
00144 
00145 /* --- DYNAMIC MODULE LOADING API --- */
00146 
00147 
00148 typedef struct lt_dlhandle_struct *lt_dlhandle; /* A loaded module.  */
00149 
00150 /* Initialisation and finalisation functions for libltdl. */
00151 extern  int         lt_dlinit           LT_PARAMS((void));
00152 extern  int         lt_dlexit           LT_PARAMS((void));
00153 
00154 /* Module search path manipulation.  */
00155 extern  int         lt_dladdsearchdir    LT_PARAMS((const char *search_dir));
00156 extern  int         lt_dlinsertsearchdir LT_PARAMS((const char *before,
00157                                                     const char *search_dir));
00158 extern  int         lt_dlsetsearchpath   LT_PARAMS((const char *search_path));
00159 extern  const char *lt_dlgetsearchpath   LT_PARAMS((void));
00160 extern  int         lt_dlforeachfile     LT_PARAMS((
00161                         const char *search_path,
00162                         int (*func) (const char *filename, lt_ptr data),
00163                         lt_ptr data));
00164 
00165 /* Portable libltdl versions of the system dlopen() API. */
00166 extern  lt_dlhandle lt_dlopen           LT_PARAMS((const char *filename));
00167 extern  lt_dlhandle lt_dlopenext        LT_PARAMS((const char *filename));
00168 extern  lt_ptr      lt_dlsym            LT_PARAMS((lt_dlhandle handle,
00169                                                      const char *name));
00170 extern  const char *lt_dlerror          LT_PARAMS((void));
00171 extern  int         lt_dlclose          LT_PARAMS((lt_dlhandle handle));
00172 
00173 /* Module residency management. */
00174 extern  int         lt_dlmakeresident   LT_PARAMS((lt_dlhandle handle));
00175 extern  int         lt_dlisresident     LT_PARAMS((lt_dlhandle handle));
00176 
00177 
00178 
00179 
00180 /* --- MUTEX LOCKING --- */
00181 
00182 
00183 typedef void    lt_dlmutex_lock         LT_PARAMS((void));
00184 typedef void    lt_dlmutex_unlock       LT_PARAMS((void));
00185 typedef void    lt_dlmutex_seterror     LT_PARAMS((const char *errmsg));
00186 typedef const char *lt_dlmutex_geterror LT_PARAMS((void));
00187 
00188 extern  int     lt_dlmutex_register     LT_PARAMS((lt_dlmutex_lock *lock,
00189                                             lt_dlmutex_unlock *unlock,
00190                                             lt_dlmutex_seterror *seterror,
00191                                             lt_dlmutex_geterror *geterror));
00192 
00193 
00194 
00195 
00196 /* --- MEMORY HANDLING --- */
00197 
00198 
00199 /* By default, the realloc function pointer is set to our internal
00200    realloc implementation which iself uses lt_dlmalloc and lt_dlfree.
00201    libltdl relies on a featureful realloc, but if you are sure yours
00202    has the right semantics then you can assign it directly.  Generally,
00203    it is safe to assign just a malloc() and a free() function.  */
00204 LT_SCOPE  lt_ptr   (*lt_dlmalloc)       LT_PARAMS((size_t size));
00205 LT_SCOPE  lt_ptr   (*lt_dlrealloc)      LT_PARAMS((lt_ptr ptr, size_t size));
00206 LT_SCOPE  void     (*lt_dlfree)         LT_PARAMS((lt_ptr ptr));
00207 
00208 
00209 
00210 
00211 /* --- PRELOADED MODULE SUPPORT --- */
00212 
00213 
00214 /* A preopened symbol. Arrays of this type comprise the exported
00215    symbols for a dlpreopened module. */
00216 typedef struct {
00217   const char *name;
00218   lt_ptr      address;
00219 } lt_dlsymlist;
00220 
00221 extern  int     lt_dlpreload    LT_PARAMS((const lt_dlsymlist *preloaded));
00222 extern  int     lt_dlpreload_default
00223                                 LT_PARAMS((const lt_dlsymlist *preloaded));
00224 
00225 #define LTDL_SET_PRELOADED_SYMBOLS()            LT_STMT_START{  \
00226         extern const lt_dlsymlist lt_preloaded_symbols[];               \
00227         lt_dlpreload_default(lt_preloaded_symbols);                     \
00228                                                 }LT_STMT_END
00229 
00230 
00231 
00232 
00233 /* --- MODULE INFORMATION --- */
00234 
00235 
00236 /* Read only information pertaining to a loaded module. */
00237 typedef struct {
00238   char  *filename;              /* file name */
00239   char  *name;                  /* module name */
00240   int   ref_count;              /* number of times lt_dlopened minus
00241                                    number of times lt_dlclosed. */
00242 } lt_dlinfo;
00243 
00244 extern  const lt_dlinfo *lt_dlgetinfo       LT_PARAMS((lt_dlhandle handle));
00245 extern  lt_dlhandle     lt_dlhandle_next    LT_PARAMS((lt_dlhandle place));
00246 extern  int             lt_dlforeach        LT_PARAMS((
00247                                 int (*func) (lt_dlhandle handle, lt_ptr data),
00248                                 lt_ptr data));
00249 
00250 /* Associating user data with loaded modules. */
00251 typedef unsigned lt_dlcaller_id;
00252 
00253 extern  lt_dlcaller_id  lt_dlcaller_register  LT_PARAMS((void));
00254 extern  lt_ptr          lt_dlcaller_set_data  LT_PARAMS((lt_dlcaller_id key,
00255                                                 lt_dlhandle handle,
00256                                                 lt_ptr data));
00257 extern  lt_ptr          lt_dlcaller_get_data  LT_PARAMS((lt_dlcaller_id key,
00258                                                 lt_dlhandle handle));
00259 
00260 
00261 
00262 /* --- USER MODULE LOADER API --- */
00263 
00264 
00265 typedef struct lt_dlloader      lt_dlloader;
00266 typedef lt_ptr                  lt_user_data;
00267 typedef lt_ptr                  lt_module;
00268 
00269 /* Function pointer types for creating user defined module loaders. */
00270 typedef lt_module   lt_module_open      LT_PARAMS((lt_user_data loader_data,
00271                                             const char *filename));
00272 typedef int         lt_module_close     LT_PARAMS((lt_user_data loader_data,
00273                                             lt_module handle));
00274 typedef lt_ptr      lt_find_sym         LT_PARAMS((lt_user_data loader_data,
00275                                             lt_module handle,
00276                                             const char *symbol));
00277 typedef int         lt_dlloader_exit    LT_PARAMS((lt_user_data loader_data));
00278 
00279 struct lt_user_dlloader {
00280   const char           *sym_prefix;
00281   lt_module_open       *module_open;
00282   lt_module_close      *module_close;
00283   lt_find_sym          *find_sym;
00284   lt_dlloader_exit     *dlloader_exit;
00285   lt_user_data          dlloader_data;
00286 };
00287 
00288 extern  lt_dlloader    *lt_dlloader_next    LT_PARAMS((lt_dlloader *place));
00289 extern  lt_dlloader    *lt_dlloader_find    LT_PARAMS((
00290                                                 const char *loader_name));
00291 extern  const char     *lt_dlloader_name    LT_PARAMS((lt_dlloader *place));
00292 extern  lt_user_data   *lt_dlloader_data    LT_PARAMS((lt_dlloader *place));
00293 extern  int             lt_dlloader_add     LT_PARAMS((lt_dlloader *place,
00294                                 const struct lt_user_dlloader *dlloader,
00295                                 const char *loader_name));
00296 extern  int             lt_dlloader_remove  LT_PARAMS((
00297                                                 const char *loader_name));
00298 
00299 
00300 
00301 /* --- ERROR MESSAGE HANDLING --- */
00302 
00303 
00304 /* Defining error strings alongside their symbolic names in a macro in
00305    this way allows us to expand the macro in different contexts with
00306    confidence that the enumeration of symbolic names will map correctly
00307    onto the table of error strings.  */
00308 #define lt_dlerror_table                                                \
00309     LT_ERROR(UNKNOWN,               "unknown error")                    \
00310     LT_ERROR(DLOPEN_NOT_SUPPORTED,  "dlopen support not available")     \
00311     LT_ERROR(INVALID_LOADER,        "invalid loader")                   \
00312     LT_ERROR(INIT_LOADER,           "loader initialization failed")     \
00313     LT_ERROR(REMOVE_LOADER,         "loader removal failed")            \
00314     LT_ERROR(FILE_NOT_FOUND,        "file not found")                   \
00315     LT_ERROR(DEPLIB_NOT_FOUND,      "dependency library not found")     \
00316     LT_ERROR(NO_SYMBOLS,            "no symbols defined")               \
00317     LT_ERROR(CANNOT_OPEN,           "can't open the module")            \
00318     LT_ERROR(CANNOT_CLOSE,          "can't close the module")           \
00319     LT_ERROR(SYMBOL_NOT_FOUND,      "symbol not found")                 \
00320     LT_ERROR(NO_MEMORY,             "not enough memory")                \
00321     LT_ERROR(INVALID_HANDLE,        "invalid module handle")            \
00322     LT_ERROR(BUFFER_OVERFLOW,       "internal buffer overflow")         \
00323     LT_ERROR(INVALID_ERRORCODE,     "invalid errorcode")                \
00324     LT_ERROR(SHUTDOWN,              "library already shutdown")         \
00325     LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module")      \
00326     LT_ERROR(INVALID_MUTEX_ARGS,    "invalid mutex handler registration") \
00327     LT_ERROR(INVALID_POSITION,      "invalid search path insert position")
00328 
00329 /* Enumerate the symbolic error names. */
00330 enum {
00331 #define LT_ERROR(name, diagnostic)      LT_CONC(LT_ERROR_, name),
00332         lt_dlerror_table
00333 #undef LT_ERROR
00334 
00335         LT_ERROR_MAX
00336 };
00337 
00338 /* These functions are only useful from inside custom module loaders. */
00339 extern  int     lt_dladderror   LT_PARAMS((const char *diagnostic));
00340 extern  int     lt_dlseterror   LT_PARAMS((int errorcode));
00341 
00342 
00343 
00344 
00345 /* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */
00346 
00347 
00348 #ifdef LT_NON_POSIX_NAMESPACE
00349 #  define lt_ptr_t              lt_ptr
00350 #  define lt_module_t           lt_module
00351 #  define lt_module_open_t      lt_module_open
00352 #  define lt_module_close_t     lt_module_close
00353 #  define lt_find_sym_t         lt_find_sym
00354 #  define lt_dlloader_exit_t    lt_dlloader_exit
00355 #  define lt_dlloader_t         lt_dlloader
00356 #  define lt_dlloader_data_t    lt_user_data
00357 #endif
00358 
00359 LT_END_C_DECLS
00360 
00361 #endif /* !LTDL_H */

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18