ltdl.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef LTDL_H
00029 #define LTDL_H 1
00030
00031 #include <sys/types.h>
00032
00033
00034
00035
00036
00037
00038 #define LT_EOS_CHAR '\0'
00039
00040
00041
00042
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
00048 # define LT_END_C_DECLS
00049 #endif
00050
00051 LT_BEGIN_C_DECLS
00052
00053
00054
00055
00056
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
00066
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
00081
00082 #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER) || defined(_AIX)
00083 # define LT_CONC(s,t) s##t
00084 #else
00085 # define LT_CONC(s,t) st
00086 #endif
00087
00088
00089 #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0)
00090
00091
00092
00093
00094
00095
00096
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
00115 #ifdef __WINDOWS__
00116 # ifndef __CYGWIN__
00117
00118
00119 # define LT_DIRSEP_CHAR '\\'
00120 # define LT_PATHSEP_CHAR ';'
00121 # endif
00122 #endif
00123 #ifndef LT_PATHSEP_CHAR
00124 # define LT_PATHSEP_CHAR ':'
00125 #endif
00126
00127
00128
00129 #ifndef LT_SCOPE
00130 # if defined(__WINDOWS__) || defined(__CYGWIN__)
00131 # ifdef DLL_EXPORT
00132 # define LT_SCOPE __declspec(dllexport)
00133 # endif
00134 # ifdef LIBLTDL_DLL_IMPORT
00135
00136 # define LT_SCOPE extern __declspec(dllimport)
00137 # endif
00138 # endif
00139 # ifndef LT_SCOPE
00140 # define LT_SCOPE extern
00141 # endif
00142 #endif
00143
00144
00145 #if defined(_MSC_VER)
00146 # define R_OK 4
00147 #endif
00148
00149
00150
00151
00152
00153
00154 typedef struct lt_dlhandle_struct *lt_dlhandle;
00155
00156
00157 LT_SCOPE int lt_dlinit LT_PARAMS((void));
00158 LT_SCOPE int lt_dlexit LT_PARAMS((void));
00159
00160
00161 LT_SCOPE int lt_dladdsearchdir LT_PARAMS((const char *search_dir));
00162 LT_SCOPE int lt_dlinsertsearchdir LT_PARAMS((const char *before,
00163 const char *search_dir));
00164 LT_SCOPE int lt_dlsetsearchpath LT_PARAMS((const char *search_path));
00165 LT_SCOPE const char *lt_dlgetsearchpath LT_PARAMS((void));
00166 LT_SCOPE int lt_dlforeachfile LT_PARAMS((
00167 const char *search_path,
00168 int (*func) (const char *filename, lt_ptr data),
00169 lt_ptr data));
00170
00171
00172 LT_SCOPE lt_dlhandle lt_dlopen LT_PARAMS((const char *filename));
00173 LT_SCOPE lt_dlhandle lt_dlopenext LT_PARAMS((const char *filename));
00174 LT_SCOPE lt_ptr lt_dlsym LT_PARAMS((lt_dlhandle handle,
00175 const char *name));
00176 LT_SCOPE const char *lt_dlerror LT_PARAMS((void));
00177 LT_SCOPE int lt_dlclose LT_PARAMS((lt_dlhandle handle));
00178
00179
00180 LT_SCOPE int lt_dlmakeresident LT_PARAMS((lt_dlhandle handle));
00181 LT_SCOPE int lt_dlisresident LT_PARAMS((lt_dlhandle handle));
00182
00183
00184
00185
00186
00187
00188
00189 typedef void lt_dlmutex_lock LT_PARAMS((void));
00190 typedef void lt_dlmutex_unlock LT_PARAMS((void));
00191 typedef void lt_dlmutex_seterror LT_PARAMS((const char *errmsg));
00192 typedef const char *lt_dlmutex_geterror LT_PARAMS((void));
00193
00194 LT_SCOPE int lt_dlmutex_register LT_PARAMS((lt_dlmutex_lock *lock,
00195 lt_dlmutex_unlock *unlock,
00196 lt_dlmutex_seterror *seterror,
00197 lt_dlmutex_geterror *geterror));
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 LT_SCOPE lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size));
00211 LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size));
00212 LT_SCOPE void (*lt_dlfree) LT_PARAMS((lt_ptr ptr));
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 typedef struct {
00223 const char *name;
00224 lt_ptr address;
00225 } lt_dlsymlist;
00226
00227 LT_SCOPE int lt_dlpreload LT_PARAMS((const lt_dlsymlist *preloaded));
00228 LT_SCOPE int lt_dlpreload_default
00229 LT_PARAMS((const lt_dlsymlist *preloaded));
00230
00231 #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \
00232 extern const lt_dlsymlist lt_preloaded_symbols[]; \
00233 lt_dlpreload_default(lt_preloaded_symbols); \
00234 }LT_STMT_END
00235
00236
00237
00238
00239
00240
00241
00242
00243 typedef struct {
00244 char *filename;
00245 char *name;
00246 int ref_count;
00247
00248 } lt_dlinfo;
00249
00250 LT_SCOPE const lt_dlinfo *lt_dlgetinfo LT_PARAMS((lt_dlhandle handle));
00251 LT_SCOPE lt_dlhandle lt_dlhandle_next LT_PARAMS((lt_dlhandle place));
00252 LT_SCOPE int lt_dlforeach LT_PARAMS((
00253 int (*func) (lt_dlhandle handle, lt_ptr data),
00254 lt_ptr data));
00255
00256
00257 typedef unsigned lt_dlcaller_id;
00258
00259 LT_SCOPE lt_dlcaller_id lt_dlcaller_register LT_PARAMS((void));
00260 LT_SCOPE lt_ptr lt_dlcaller_set_data LT_PARAMS((lt_dlcaller_id key,
00261 lt_dlhandle handle,
00262 lt_ptr data));
00263 LT_SCOPE lt_ptr lt_dlcaller_get_data LT_PARAMS((lt_dlcaller_id key,
00264 lt_dlhandle handle));
00265
00266
00267
00268
00269
00270
00271 typedef struct lt_dlloader lt_dlloader;
00272 typedef lt_ptr lt_user_data;
00273 typedef lt_ptr lt_module;
00274
00275
00276 typedef lt_module lt_module_open LT_PARAMS((lt_user_data loader_data,
00277 const char *filename));
00278 typedef int lt_module_close LT_PARAMS((lt_user_data loader_data,
00279 lt_module handle));
00280 typedef lt_ptr lt_find_sym LT_PARAMS((lt_user_data loader_data,
00281 lt_module handle,
00282 const char *symbol));
00283 typedef int lt_dlloader_exit LT_PARAMS((lt_user_data loader_data));
00284
00285 struct lt_user_dlloader {
00286 const char *sym_prefix;
00287 lt_module_open *module_open;
00288 lt_module_close *module_close;
00289 lt_find_sym *find_sym;
00290 lt_dlloader_exit *dlloader_exit;
00291 lt_user_data dlloader_data;
00292 };
00293
00294 LT_SCOPE lt_dlloader *lt_dlloader_next LT_PARAMS((lt_dlloader *place));
00295 LT_SCOPE lt_dlloader *lt_dlloader_find LT_PARAMS((
00296 const char *loader_name));
00297 LT_SCOPE const char *lt_dlloader_name LT_PARAMS((lt_dlloader *place));
00298 LT_SCOPE lt_user_data *lt_dlloader_data LT_PARAMS((lt_dlloader *place));
00299 LT_SCOPE int lt_dlloader_add LT_PARAMS((lt_dlloader *place,
00300 const struct lt_user_dlloader *dlloader,
00301 const char *loader_name));
00302 LT_SCOPE int lt_dlloader_remove LT_PARAMS((
00303 const char *loader_name));
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 #define lt_dlerror_table \
00315 LT_ERROR(UNKNOWN, "unknown error") \
00316 LT_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available") \
00317 LT_ERROR(INVALID_LOADER, "invalid loader") \
00318 LT_ERROR(INIT_LOADER, "loader initialization failed") \
00319 LT_ERROR(REMOVE_LOADER, "loader removal failed") \
00320 LT_ERROR(FILE_NOT_FOUND, "file not found") \
00321 LT_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \
00322 LT_ERROR(NO_SYMBOLS, "no symbols defined") \
00323 LT_ERROR(CANNOT_OPEN, "can't open the module") \
00324 LT_ERROR(CANNOT_CLOSE, "can't close the module") \
00325 LT_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \
00326 LT_ERROR(NO_MEMORY, "not enough memory") \
00327 LT_ERROR(INVALID_HANDLE, "invalid module handle") \
00328 LT_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \
00329 LT_ERROR(INVALID_ERRORCODE, "invalid errorcode") \
00330 LT_ERROR(SHUTDOWN, "library already shutdown") \
00331 LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module") \
00332 LT_ERROR(INVALID_MUTEX_ARGS, "invalid mutex handler registration") \
00333 LT_ERROR(INVALID_POSITION, "invalid search path insert position")
00334
00335
00336 enum {
00337 #define LT_ERROR(name, diagnostic) LT_CONC(LT_ERROR_, name),
00338 lt_dlerror_table
00339 #undef LT_ERROR
00340
00341 LT_ERROR_MAX
00342 };
00343
00344
00345 LT_SCOPE int lt_dladderror LT_PARAMS((const char *diagnostic));
00346 LT_SCOPE int lt_dlseterror LT_PARAMS((int errorcode));
00347
00348
00349
00350
00351
00352
00353
00354 #ifdef LT_NON_POSIX_NAMESPACE
00355 # define lt_ptr_t lt_ptr
00356 # define lt_module_t lt_module
00357 # define lt_module_open_t lt_module_open
00358 # define lt_module_close_t lt_module_close
00359 # define lt_find_sym_t lt_find_sym
00360 # define lt_dlloader_exit_t lt_dlloader_exit
00361 # define lt_dlloader_t lt_dlloader
00362 # define lt_dlloader_data_t lt_user_data
00363 #endif
00364
00365 LT_END_C_DECLS
00366
00367 #endif