Back to index

glibc  2.9
dlfcn.h
Go to the documentation of this file.
00001 #ifndef _DLFCN_H
00002 #include <dlfcn/dlfcn.h>
00003 #include <link.h>           /* For ElfW.  */
00004 #include <stdbool.h>
00005 
00006 /* Internally used flag.  */
00007 #define __RTLD_DLOPEN       0x80000000
00008 #define __RTLD_SPROF 0x40000000
00009 #define __RTLD_OPENEXEC     0x20000000
00010 #define __RTLD_CALLMAP      0x10000000
00011 #define __RTLD_AUDIT 0x08000000
00012 
00013 #define __LM_ID_CALLER      -2
00014 
00015 #ifdef SHARED
00016 /* Locally stored program arguments.  */
00017 extern int __dlfcn_argc attribute_hidden;
00018 extern char **__dlfcn_argv attribute_hidden;
00019 #else
00020 /* These variables are defined and initialized in the startup code.  */
00021 extern int __libc_argc attribute_hidden;
00022 extern char **__libc_argv attribute_hidden;
00023 
00024 # define __dlfcn_argc __libc_argc
00025 # define __dlfcn_argv __libc_argv
00026 #endif
00027 
00028 
00029 /* Now define the internal interfaces.  */
00030 
00031 #define __libc_dlopen(name) \
00032   __libc_dlopen_mode (name, RTLD_LAZY | __RTLD_DLOPEN)
00033 extern void *__libc_dlopen_mode  (__const char *__name, int __mode);
00034 extern void *__libc_dlsym   (void *__map, __const char *__name);
00035 extern int   __libc_dlclose (void *__map);
00036 libc_hidden_proto (__libc_dlopen_mode)
00037 libc_hidden_proto (__libc_dlsym)
00038 libc_hidden_proto (__libc_dlclose)
00039 
00040 /* Locate shared object containing the given address.  */
00041 #ifdef ElfW
00042 extern int _dl_addr (const void *address, Dl_info *info,
00043                    struct link_map **mapp, const ElfW(Sym) **symbolp)
00044      internal_function;
00045 libc_hidden_proto (_dl_addr)
00046 #endif
00047 
00048 struct link_map;
00049 
00050 /* Close an object previously opened by _dl_open.  */
00051 extern void _dl_close (void *map) attribute_hidden;
00052 /* Same as above, but without locking and safety checks for user
00053    provided map arguments.  */
00054 extern void _dl_close_worker (struct link_map *map) attribute_hidden;
00055 
00056 /* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
00057    RTLD_NEXT).  WHO is the calling function, for RTLD_NEXT.  Returns
00058    the symbol value, which may be NULL.  */
00059 extern void *_dl_sym (void *handle, const char *name, void *who)
00060     internal_function;
00061 
00062 /* Look up version VERSION of symbol NAME in shared object HANDLE
00063    (which may be RTLD_DEFAULT or RTLD_NEXT).  WHO is the calling
00064    function, for RTLD_NEXT.  Returns the symbol value, which may be
00065    NULL.  */
00066 extern void *_dl_vsym (void *handle, const char *name, const char *version,
00067                      void *who)
00068     internal_function;
00069 
00070 /* Call OPERATE, catching errors from `dl_signal_error'.  If there is no
00071    error, *ERRSTRING is set to null.  If there is an error, *ERRSTRING is
00072    set to a string constructed from the strings passed to _dl_signal_error,
00073    and the error code passed is the return value and *OBJNAME is set to
00074    the object name which experienced the problems.  ERRSTRING if nonzero
00075    points to a malloc'ed string which the caller has to free after use.
00076    ARGS is passed as argument to OPERATE.  MALLOCEDP is set to true only
00077    if the returned string is allocated using the libc's malloc.  */
00078 extern int _dl_catch_error (const char **objname, const char **errstring,
00079                          bool *mallocedp, void (*operate) (void *),
00080                          void *args)
00081      internal_function;
00082 
00083 /* Helper function for <dlfcn.h> functions.  Runs the OPERATE function via
00084    _dl_catch_error.  Returns zero for success, nonzero for failure; and
00085    arranges for `dlerror' to return the error details.
00086    ARGS is passed as argument to OPERATE.  */
00087 extern int _dlerror_run (void (*operate) (void *), void *args)
00088      internal_function;
00089 
00090 #ifdef SHARED
00091 # define DL_CALLER_DECL /* Nothing */
00092 # define DL_CALLER RETURN_ADDRESS (0)
00093 #else
00094 # define DL_CALLER_DECL , void *dl_caller
00095 # define DL_CALLER dl_caller
00096 #endif
00097 
00098 struct dlfcn_hook
00099 {
00100   void *(*dlopen) (const char *file, int mode, void *dl_caller);
00101   int (*dlclose) (void *handle);
00102   void *(*dlsym) (void *handle, const char *name, void *dl_caller);
00103   void *(*dlvsym) (void *handle, const char *name, const char *version,
00104                  void *dl_caller);
00105   char *(*dlerror) (void);
00106   int (*dladdr) (const void *address, Dl_info *info);
00107   int (*dladdr1) (const void *address, Dl_info *info,
00108                 void **extra_info, int flags);
00109   int (*dlinfo) (void *handle, int request, void *arg, void *dl_caller);
00110   void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
00111   void *pad[4];
00112 };
00113 
00114 extern struct dlfcn_hook *_dlfcn_hook;
00115 libdl_hidden_proto (_dlfcn_hook)
00116 
00117 extern void *__dlopen (const char *file, int mode DL_CALLER_DECL)
00118      attribute_hidden;
00119 extern void *__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL)
00120      attribute_hidden;
00121 extern int __dlclose (void *handle)
00122      attribute_hidden;
00123 extern void *__dlsym (void *handle, const char *name DL_CALLER_DECL)
00124      attribute_hidden;
00125 extern void *__dlvsym (void *handle, const char *name, const char *version
00126                      DL_CALLER_DECL)
00127      attribute_hidden;
00128 extern char *__dlerror (void)
00129      attribute_hidden;
00130 extern int __dladdr (const void *address, Dl_info *info)
00131      attribute_hidden;
00132 extern int __dladdr1 (const void *address, Dl_info *info,
00133                     void **extra_info, int flags)
00134      attribute_hidden;
00135 extern int __dlinfo (void *handle, int request, void *arg DL_CALLER_DECL)
00136      attribute_hidden;
00137 
00138 #ifndef SHARED
00139 struct link_map;
00140 extern void * __libc_dlsym_private (struct link_map *map, const char *name)
00141      attribute_hidden;
00142 extern void __libc_register_dl_open_hook (struct link_map *map)
00143      attribute_hidden;
00144 extern void __libc_register_dlfcn_hook (struct link_map *map)
00145      attribute_hidden;
00146 #endif
00147 
00148 #endif