2005-01-21 Roland McGrath <roland@redhat.com>
[glibc.git] / include / dlfcn.h
blob460c037ed1aac4e22df13fd87edda1f52c2fafdb
1 #ifndef _DLFCN_H
2 #include <dlfcn/dlfcn.h>
3 #include <link.h> /* For ElfW. */
5 /* Internally used flag. */
6 #define __RTLD_DLOPEN 0x80000000
7 #define __RTLD_SPROF 0x40000000
8 #define __RTLD_OPENEXEC 0x20000000
9 #define __RTLD_CALLMAP 0x10000000
10 #define __RTLD_AUDIT 0x08000000
12 #define __LM_ID_CALLER -2
14 #ifdef SHARED
15 /* Locally stored program arguments. */
16 extern int __dlfcn_argc attribute_hidden;
17 extern char **__dlfcn_argv attribute_hidden;
18 #else
19 /* These variables are defined and initialized in the startup code. */
20 extern int __libc_argc attribute_hidden;
21 extern char **__libc_argv attribute_hidden;
23 # define __dlfcn_argc __libc_argc
24 # define __dlfcn_argv __libc_argv
25 #endif
28 /* Now define the internal interfaces. */
30 #define __libc_dlopen(name) \
31 __libc_dlopen_mode (name, RTLD_LAZY | __RTLD_DLOPEN)
32 extern void *__libc_dlopen_mode (__const char *__name, int __mode);
33 extern void *__libc_dlsym (void *__map, __const char *__name);
34 extern int __libc_dlclose (void *__map);
35 libc_hidden_proto (__libc_dlopen_mode)
36 libc_hidden_proto (__libc_dlsym)
37 libc_hidden_proto (__libc_dlclose)
39 /* Locate shared object containing the given address. */
40 #ifdef ElfW
41 extern int _dl_addr (const void *address, Dl_info *info,
42 struct link_map **mapp, const ElfW(Sym) **symbolp)
43 internal_function;
44 libc_hidden_proto (_dl_addr)
45 #endif
47 /* Close an object previously opened by _dl_open. */
48 extern void _dl_close (void *map) attribute_hidden;
50 /* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
51 RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns
52 the symbol value, which may be NULL. */
53 extern void *_dl_sym (void *handle, const char *name, void *who)
54 internal_function;
56 /* Look up version VERSION of symbol NAME in shared object HANDLE
57 (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
58 function, for RTLD_NEXT. Returns the symbol value, which may be
59 NULL. */
60 extern void *_dl_vsym (void *handle, const char *name, const char *version,
61 void *who)
62 internal_function;
64 /* Call OPERATE, catching errors from `dl_signal_error'. If there is no
65 error, *ERRSTRING is set to null. If there is an error, *ERRSTRING is
66 set to a string constructed from the strings passed to _dl_signal_error,
67 and the error code passed is the return value and *OBJNAME is set to
68 the object name which experienced the problems. ERRSTRING if nonzero
69 points to a malloc'ed string which the caller has to free after use.
70 ARGS is passed as argument to OPERATE. */
71 extern int _dl_catch_error (const char **objname, const char **errstring,
72 void (*operate) (void *),
73 void *args)
74 internal_function;
76 /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
77 _dl_catch_error. Returns zero for success, nonzero for failure; and
78 arranges for `dlerror' to return the error details.
79 ARGS is passed as argument to OPERATE. */
80 extern int _dlerror_run (void (*operate) (void *), void *args)
81 internal_function;
83 #ifdef SHARED
84 # define DL_CALLER_DECL /* Nothing */
85 # define DL_CALLER RETURN_ADDRESS (0)
86 #else
87 # define DL_CALLER_DECL , void *dl_caller
88 # define DL_CALLER dl_caller
89 #endif
91 struct dlfcn_hook
93 void *(*dlopen) (const char *file, int mode, void *dl_caller);
94 int (*dlclose) (void *handle);
95 void *(*dlsym) (void *handle, const char *name, void *dl_caller);
96 void *(*dlvsym) (void *handle, const char *name, const char *version,
97 void *dl_caller);
98 char *(*dlerror) (void);
99 int (*dladdr) (const void *address, Dl_info *info);
100 int (*dladdr1) (const void *address, Dl_info *info,
101 void **extra_info, int flags);
102 int (*dlinfo) (void *handle, int request, void *arg, void *dl_caller);
103 void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
104 void *pad[4];
107 extern struct dlfcn_hook *_dlfcn_hook;
108 libdl_hidden_proto (_dlfcn_hook)
110 extern void *__dlopen (const char *file, int mode DL_CALLER_DECL)
111 attribute_hidden;
112 extern void *__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL)
113 attribute_hidden;
114 extern int __dlclose (void *handle)
115 attribute_hidden;
116 extern void *__dlsym (void *handle, const char *name DL_CALLER_DECL)
117 attribute_hidden;
118 extern void *__dlvsym (void *handle, const char *name, const char *version
119 DL_CALLER_DECL)
120 attribute_hidden;
121 extern char *__dlerror (void)
122 attribute_hidden;
123 extern int __dladdr (const void *address, Dl_info *info)
124 attribute_hidden;
125 extern int __dladdr1 (const void *address, Dl_info *info,
126 void **extra_info, int flags)
127 attribute_hidden;
128 extern int __dlinfo (void *handle, int request, void *arg DL_CALLER_DECL)
129 attribute_hidden;
131 #ifndef SHARED
132 struct link_map;
133 extern void * __libc_dlsym_private (struct link_map *map, const char *name)
134 attribute_hidden;
135 extern void __libc_register_dl_open_hook (struct link_map *map)
136 attribute_hidden;
137 extern void __libc_register_dlfcn_hook (struct link_map *map)
138 attribute_hidden;
139 #endif
141 #endif