diff options
Diffstat (limited to 'libjava/libltdl/ltdl.h')
-rw-r--r-- | libjava/libltdl/ltdl.h | 425 |
1 files changed, 268 insertions, 157 deletions
diff --git a/libjava/libltdl/ltdl.h b/libjava/libltdl/ltdl.h index 666c785c8c1..2bbfa302cc4 100644 --- a/libjava/libltdl/ltdl.h +++ b/libjava/libltdl/ltdl.h @@ -25,226 +25,337 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */ /* Only include this header file once. */ -#ifndef _LTDL_H_ -#define _LTDL_H_ 1 +#ifndef LTDL_H +#define LTDL_H 1 -/* Canonicalise Windows and Cygwin recognition macros. */ -#ifdef __CYGWIN32__ -# ifndef __CYGWIN__ -# define __CYGWIN__ __CYGWIN32__ -# endif -#endif -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 _WIN32 -# endif -#endif +#include <sys/types.h> /* for size_t declaration */ + + +/* --- MACROS FOR PORTABILITY --- */ -/* __BEGIN_DECLS should be used at the beginning of your declarations, - so that C++ compilers don't mangle their names. Use __END_DECLS at + +/* 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. */ -#undef __BEGIN_DECLS -#undef __END_DECLS #ifdef __cplusplus -# define __BEGIN_DECLS extern "C" { -# define __END_DECLS } +# define LT_BEGIN_C_DECLS extern "C" { +# define LT_END_C_DECLS } #else -# define __BEGIN_DECLS /* empty */ -# define __END_DECLS /* empty */ +# define LT_BEGIN_C_DECLS /* empty */ +# define LT_END_C_DECLS /* empty */ #endif -/* LTDL_PARAMS is a macro used to wrap function prototypes, so that compilers +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. */ -#undef LTDL_PARAMS -#undef lt_ptr_t + compilers can issue warnings about type mismatches. */ #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus) -# define LTDL_PARAMS(protos) protos -# define lt_ptr_t void* +# define LT_PARAMS(protos) protos +# define lt_ptr void* #else -# define LTDL_PARAMS(protos) () -# define lt_ptr_t char* +# define LT_PARAMS(protos) () +# define lt_ptr char* #endif -/* LTDL_STMT_START/END are used to create macros which expand to a - a single compound statement in a portable way. */ -#undef LTDL_STMT_START -#undef LTDL_STMT_END +/* 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 LTDL_STMT_START (void)( -# define LTDL_STMT_END ) +# define LT_STMT_START (void)( +# define LT_STMT_END ) #else # if (defined (sun) || defined (__sun__)) -# define LTDL_STMT_START if (1) -# define LTDL_STMT_END else (void)0 +# define LT_STMT_START if (1) +# define LT_STMT_END else (void)0 # else -# define LTDL_STMT_START do -# define LTDL_STMT_END while (0) +# 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. */ +#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 WIN32 +#ifdef __WINDOWS__ # ifndef __CYGWIN__ -/* LTDL_DIRSEP_CHAR is accepted *in addition* to '/' as a directory +/* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory separator when it is set. */ -# define LTDL_DIRSEP_CHAR '\\' -# define LTDL_PATHSEP_CHAR ';' +# define LT_DIRSEP_CHAR '\\' +# define LT_PATHSEP_CHAR ';' # endif #endif -#ifndef LTDL_PATHSEP_CHAR -# define LTDL_PATHSEP_CHAR ':' +#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 LTDL_SCOPE -# ifdef _WIN32 +#ifndef LT_SCOPE +# ifdef __WINDOWS__ # ifdef DLL_EXPORT /* defined by libtool (if required) */ -# define LTDL_SCOPE __declspec(dllexport) +# define LT_SCOPE __declspec(dllexport) # endif # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */ -# define LTDL_SCOPE extern __declspec(dllimport) +# define LT_SCOPE extern __declspec(dllimport) # endif # endif -# ifndef LTDL_SCOPE /* static linking or !_WIN32 */ -# define LTDL_SCOPE extern +# ifndef LT_SCOPE /* static linking or !__WINDOWS__ */ +# define LT_SCOPE extern # endif #endif -#include <stdlib.h> -/* Defining error strings alongside their symbolic names in a macro in - 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 ltdl_error_table \ - LTDL_ERROR(UNKNOWN, "unknown error") \ - LTDL_ERROR(DLOPEN_NOT_SUPPORTED, "dlopen support not available")\ - LTDL_ERROR(INVALID_LOADER, "invalid loader") \ - LTDL_ERROR(INIT_LOADER, "loader initialization failed") \ - LTDL_ERROR(REMOVE_LOADER, "loader removal failed") \ - LTDL_ERROR(FILE_NOT_FOUND, "file not found") \ - LTDL_ERROR(DEPLIB_NOT_FOUND, "dependency library not found") \ - LTDL_ERROR(NO_SYMBOLS, "no symbols defined") \ - LTDL_ERROR(CANNOT_OPEN, "can't open the module") \ - LTDL_ERROR(CANNOT_CLOSE, "can't close the module") \ - LTDL_ERROR(SYMBOL_NOT_FOUND, "symbol not found") \ - LTDL_ERROR(NO_MEMORY, "not enough memory") \ - LTDL_ERROR(INVALID_HANDLE, "invalid module handle") \ - LTDL_ERROR(BUFFER_OVERFLOW, "internal buffer overflow") \ - LTDL_ERROR(INVALID_ERRORCODE, "invalid errorcode") \ - LTDL_ERROR(SHUTDOWN, "library already shutdown") -/* Enumerate the symbolic error names. */ -#if defined(__STDC__) || defined(__cplusplus) -# define LTDL_ERROR(name, diagnostic) LTDL_ERROR_##name, -#else -# define LTDL_ERROR(name, diagnostic) LTDL_ERROR_/**/name, -#endif -enum { - ltdl_error_table - LTDL_ERROR_MAX -}; -#undef LTDL_ERROR + +/* --- DYNAMIC MODULE LOADING API --- */ + + +typedef struct lt_dlhandle_struct *lt_dlhandle; /* A loaded module. */ + +/* Initialisation and finalisation functions for libltdl. */ +extern int lt_dlinit LT_PARAMS((void)); +extern int lt_dlexit LT_PARAMS((void)); + +/* Module search path manipulation. */ +extern int lt_dladdsearchdir LT_PARAMS((const char *search_dir)); +extern int lt_dlinsertsearchdir LT_PARAMS((const char *before, + const char *search_dir)); +extern int lt_dlsetsearchpath LT_PARAMS((const char *search_path)); +extern const char *lt_dlgetsearchpath LT_PARAMS((void)); +extern int lt_dlforeachfile LT_PARAMS(( + const char *search_path, + int (*func) (const char *filename, lt_ptr data), + lt_ptr 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)); + + + + +/* --- MUTEX LOCKING --- */ + + +typedef void lt_dlmutex_lock LT_PARAMS((void)); +typedef void lt_dlmutex_unlock LT_PARAMS((void)); +typedef void lt_dlmutex_seterror LT_PARAMS((const char *errmsg)); +typedef const char *lt_dlmutex_geterror LT_PARAMS((void)); + +extern int lt_dlmutex_register LT_PARAMS((lt_dlmutex_lock *lock, + lt_dlmutex_unlock *unlock, + lt_dlmutex_seterror *seterror, + lt_dlmutex_geterror *geterror)); + + + + +/* --- MEMORY HANDLING --- */ + + +/* By default, the realloc function pointer is set to our internal + realloc implementation which iself uses lt_dlmalloc and lt_dlfree. + 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 --- */ -/* An opaque handle for a successfully lt_dlopened module instance. */ -#ifdef _LTDL_COMPILE_ -typedef struct lt_dlhandle_t *lt_dlhandle; -#else -typedef lt_ptr_t lt_dlhandle; -#endif /* A preopened symbol. Arrays of this type comprise the exported symbols for a dlpreopened module. */ typedef struct { - const char *name; - lt_ptr_t address; + const char *name; + lt_ptr address; } lt_dlsymlist; +extern int lt_dlpreload LT_PARAMS((const lt_dlsymlist *preloaded)); +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 + char *filename; /* file name */ + char *name; /* module name */ + int ref_count; /* number of times lt_dlopened minus number of times lt_dlclosed. */ } lt_dlinfo; -/* An opaque handle for a module loaded by a system call. This is only - used internally by ltdl loaders, and by user module loaders. */ -typedef lt_ptr_t lt_module_t; +extern const lt_dlinfo *lt_dlgetinfo LT_PARAMS((lt_dlhandle handle)); +extern lt_dlhandle lt_dlhandle_next LT_PARAMS((lt_dlhandle place)); +extern int lt_dlforeach LT_PARAMS(( + int (*func) (lt_dlhandle handle, lt_ptr data), + lt_ptr data)); + +/* Associating user data with loaded modules. */ +typedef unsigned lt_dlcaller_id; + +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 --- */ -/* An opaque handle for a module loader. */ -#ifdef _LTDL_COMPILE_ -typedef struct lt_dlloader_t lt_dlloader_t; -#else -typedef lt_ptr_t lt_dlloader_t; -#endif -typedef lt_ptr_t lt_dlloader_data_t; +typedef struct lt_dlloader lt_dlloader; +typedef lt_ptr lt_user_data; +typedef lt_ptr lt_module; /* Function pointer types for creating user defined module loaders. */ -typedef lt_module_t lt_module_open_t LTDL_PARAMS((lt_dlloader_data_t loader_data, const char *filename)); -typedef int lt_module_close_t LTDL_PARAMS((lt_dlloader_data_t loader_data, lt_module_t handle)); -typedef lt_ptr_t lt_find_sym_t LTDL_PARAMS((lt_dlloader_data_t loader_data, lt_module_t handle, const char *symbol)); -typedef int lt_dlloader_exit_t LTDL_PARAMS((lt_dlloader_data_t loader_data)); +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)); -__BEGIN_DECLS -/* Initialisation and finalisation functions for libltdl. */ -extern int lt_dlinit LTDL_PARAMS((void)); -extern int lt_dlexit LTDL_PARAMS((void)); +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; +}; -/* Module search path manipultation. */ -extern int lt_dladdsearchdir LTDL_PARAMS((const char *search_dir)); -extern int lt_dlsetsearchpath LTDL_PARAMS((const char *search_path)); -extern const char *lt_dlgetsearchpath LTDL_PARAMS((void)); +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)); -/* Portable libltdl versions of the system dlopen() API. */ -extern lt_dlhandle lt_dlopen LTDL_PARAMS((const char *filename)); -extern lt_dlhandle lt_dlopenext LTDL_PARAMS((const char *filename)); -extern lt_ptr_t lt_dlsym LTDL_PARAMS((lt_dlhandle handle, const char *name)); -extern const char *lt_dlerror LTDL_PARAMS((void)); -extern int lt_dlclose LTDL_PARAMS((lt_dlhandle handle)); -/* Support for preloaded modules through lt_dlopen() API. */ -extern int lt_dlpreload LTDL_PARAMS((const lt_dlsymlist *preloaded)); -extern int lt_dlpreload_default LTDL_PARAMS((const lt_dlsymlist *preloaded)); + +/* --- ERROR MESSAGE HANDLING --- */ -#define LTDL_SET_PRELOADED_SYMBOLS() LTDL_STMT_START{ \ - extern const lt_dlsymlist lt_preloaded_symbols[]; \ - lt_dlpreload_default(lt_preloaded_symbols); \ - }LTDL_STMT_END -/* Managing user data associated with a loaded modules. */ -extern const lt_dlinfo *lt_dlgetinfo LTDL_PARAMS((lt_dlhandle handle)); -extern int lt_dlforeach LTDL_PARAMS(( - int (*func)(lt_dlhandle handle, lt_ptr_t data), lt_ptr_t data)); +/* Defining error strings alongside their symbolic names in a macro in + 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") -/* User module loader API. */ -struct lt_user_dlloader { - const char *sym_prefix; - lt_module_open_t *module_open; - lt_module_close_t *module_close; - lt_find_sym_t *find_sym; - lt_dlloader_exit_t *dlloader_exit; - lt_dlloader_data_t dlloader_data; +/* 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 }; -extern lt_dlloader_t *lt_dlloader_next LTDL_PARAMS((lt_dlloader_t *place)); -extern lt_dlloader_t *lt_dlloader_find LTDL_PARAMS((const char *loader_name)); -extern const char *lt_dlloader_name LTDL_PARAMS((lt_dlloader_t *place)); -extern lt_dlloader_data_t *lt_dlloader_data LTDL_PARAMS((lt_dlloader_t *place)); -extern lt_dlloader_t *lt_find_dlloader LTDL_PARAMS((const char *loader_name)); -extern int lt_dlloader_add LTDL_PARAMS((lt_dlloader_t *place, const struct lt_user_dlloader *dlloader, const char *loader_name)); -extern int lt_dlloader_remove LTDL_PARAMS((const char *loader_name)); +/* 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)); + -/* Integrated lt_dlerror() messages for user loaders. */ -extern int lt_dladderror LTDL_PARAMS((const char *diagnostic)); -extern int lt_dlseterror LTDL_PARAMS((int errorcode)); -/* Pointers to memory management functions to be used by libltdl. */ -LTDL_SCOPE lt_ptr_t (*lt_dlmalloc)LTDL_PARAMS((size_t size)); -LTDL_SCOPE void (*lt_dlfree)LTDL_PARAMS((lt_ptr_t ptr)); + +/* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */ + + +#ifdef LT_NON_POSIX_NAMESPACE +# 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 -__END_DECLS +LT_END_C_DECLS -#endif /* !_LTDL_H_ */ +#endif /* !LTDL_H */ |