Add multiple inclusion protection to some Mach/i386 internal headers.
[glibc.git] / include / dlfcn.h
blobaf92483f5920df64efb21ce718c113f27c50d0e4
1 #ifndef _DLFCN_H
2 #include <dlfcn/dlfcn.h>
3 #include <link.h> /* For ElfW. */
4 #include <stdbool.h>
6 /* Internally used flag. */
7 #define __RTLD_DLOPEN 0x80000000
8 #define __RTLD_SPROF 0x40000000
9 #define __RTLD_OPENEXEC 0x20000000
10 #define __RTLD_CALLMAP 0x10000000
11 #define __RTLD_AUDIT 0x08000000
12 #define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */
14 #define __LM_ID_CALLER -2
16 #ifdef SHARED
17 /* Locally stored program arguments. */
18 extern int __dlfcn_argc attribute_hidden;
19 extern char **__dlfcn_argv attribute_hidden;
20 #else
21 /* These variables are defined and initialized in the startup code. */
22 extern int __libc_argc attribute_hidden;
23 extern char **__libc_argv attribute_hidden;
25 # define __dlfcn_argc __libc_argc
26 # define __dlfcn_argv __libc_argv
27 #endif
30 /* Now define the internal interfaces. */
32 #define __libc_dlopen(name) \
33 __libc_dlopen_mode (name, RTLD_LAZY | __RTLD_DLOPEN)
34 extern void *__libc_dlopen_mode (__const char *__name, int __mode);
35 extern void *__libc_dlsym (void *__map, __const char *__name);
36 extern int __libc_dlclose (void *__map);
37 libc_hidden_proto (__libc_dlopen_mode)
38 libc_hidden_proto (__libc_dlsym)
39 libc_hidden_proto (__libc_dlclose)
41 /* Locate shared object containing the given address. */
42 #ifdef ElfW
43 extern int _dl_addr (const void *address, Dl_info *info,
44 struct link_map **mapp, const ElfW(Sym) **symbolp)
45 internal_function;
46 libc_hidden_proto (_dl_addr)
47 #endif
49 struct link_map;
51 /* Close an object previously opened by _dl_open. */
52 extern void _dl_close (void *map) attribute_hidden;
53 /* Same as above, but without locking and safety checks for user
54 provided map arguments. */
55 extern void _dl_close_worker (struct link_map *map) attribute_hidden;
57 /* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
58 RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns
59 the symbol value, which may be NULL. */
60 extern void *_dl_sym (void *handle, const char *name, void *who)
61 internal_function;
63 /* Look up version VERSION of symbol NAME in shared object HANDLE
64 (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
65 function, for RTLD_NEXT. Returns the symbol value, which may be
66 NULL. */
67 extern void *_dl_vsym (void *handle, const char *name, const char *version,
68 void *who)
69 internal_function;
71 /* Call OPERATE, catching errors from `dl_signal_error'. If there is no
72 error, *ERRSTRING is set to null. If there is an error, *ERRSTRING is
73 set to a string constructed from the strings passed to _dl_signal_error,
74 and the error code passed is the return value and *OBJNAME is set to
75 the object name which experienced the problems. ERRSTRING if nonzero
76 points to a malloc'ed string which the caller has to free after use.
77 ARGS is passed as argument to OPERATE. MALLOCEDP is set to true only
78 if the returned string is allocated using the libc's malloc. */
79 extern int _dl_catch_error (const char **objname, const char **errstring,
80 bool *mallocedp, void (*operate) (void *),
81 void *args)
82 internal_function;
84 /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
85 _dl_catch_error. Returns zero for success, nonzero for failure; and
86 arranges for `dlerror' to return the error details.
87 ARGS is passed as argument to OPERATE. */
88 extern int _dlerror_run (void (*operate) (void *), void *args)
89 internal_function;
91 #ifdef SHARED
92 # define DL_CALLER_DECL /* Nothing */
93 # define DL_CALLER RETURN_ADDRESS (0)
94 #else
95 # define DL_CALLER_DECL , void *dl_caller
96 # define DL_CALLER dl_caller
97 #endif
99 struct dlfcn_hook
101 void *(*dlopen) (const char *file, int mode, void *dl_caller);
102 int (*dlclose) (void *handle);
103 void *(*dlsym) (void *handle, const char *name, void *dl_caller);
104 void *(*dlvsym) (void *handle, const char *name, const char *version,
105 void *dl_caller);
106 char *(*dlerror) (void);
107 int (*dladdr) (const void *address, Dl_info *info);
108 int (*dladdr1) (const void *address, Dl_info *info,
109 void **extra_info, int flags);
110 int (*dlinfo) (void *handle, int request, void *arg, void *dl_caller);
111 void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
112 void *pad[4];
115 extern struct dlfcn_hook *_dlfcn_hook;
116 libdl_hidden_proto (_dlfcn_hook)
118 extern void *__dlopen (const char *file, int mode DL_CALLER_DECL)
119 attribute_hidden;
120 extern void *__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL)
121 attribute_hidden;
122 extern int __dlclose (void *handle)
123 attribute_hidden;
124 extern void *__dlsym (void *handle, const char *name DL_CALLER_DECL)
125 attribute_hidden;
126 extern void *__dlvsym (void *handle, const char *name, const char *version
127 DL_CALLER_DECL)
128 attribute_hidden;
129 extern char *__dlerror (void)
130 attribute_hidden;
131 extern int __dladdr (const void *address, Dl_info *info)
132 attribute_hidden;
133 extern int __dladdr1 (const void *address, Dl_info *info,
134 void **extra_info, int flags)
135 attribute_hidden;
136 extern int __dlinfo (void *handle, int request, void *arg DL_CALLER_DECL)
137 attribute_hidden;
139 #ifndef SHARED
140 struct link_map;
141 extern void * __libc_dlsym_private (struct link_map *map, const char *name)
142 attribute_hidden;
143 extern void __libc_register_dl_open_hook (struct link_map *map)
144 attribute_hidden;
145 extern void __libc_register_dlfcn_hook (struct link_map *map)
146 attribute_hidden;
147 #endif
149 #endif