1 | #ifndef _DLFCN_H |
2 | #include <dlfcn/dlfcn.h> |
3 | #ifndef _ISOMAC |
4 | #include <link.h> /* For ElfW. */ |
5 | #include <stdbool.h> |
6 | |
7 | /* Internally used flag. */ |
8 | #define __RTLD_DLOPEN 0x80000000 |
9 | #define __RTLD_SPROF 0x40000000 |
10 | #define __RTLD_OPENEXEC 0x20000000 |
11 | #define __RTLD_CALLMAP 0x10000000 |
12 | #define __RTLD_AUDIT 0x08000000 |
13 | #define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */ |
14 | #define __RTLD_NOIFUNC 0x02000000 /* Suppress calling ifunc functions. */ |
15 | |
16 | #define __LM_ID_CALLER -2 |
17 | |
18 | #ifdef SHARED |
19 | /* Locally stored program arguments. */ |
20 | extern int __dlfcn_argc attribute_hidden; |
21 | extern char **__dlfcn_argv attribute_hidden; |
22 | #else |
23 | /* These variables are defined and initialized in the startup code. */ |
24 | extern int __libc_argc attribute_hidden; |
25 | extern char **__libc_argv attribute_hidden; |
26 | |
27 | # define __dlfcn_argc __libc_argc |
28 | # define __dlfcn_argv __libc_argv |
29 | #endif |
30 | |
31 | |
32 | /* Now define the internal interfaces. */ |
33 | |
34 | /* Use RTLD_NOW here because: |
35 | 1. In pthread_cancel_init we want to use RTLD_NOW to reduce the stack usage |
36 | of future cancellation operations, particularly when the target thread |
37 | is running with a small stack. Likewise for consistency we do the same |
38 | thing in __libgcc_s_init. RTLD_NOW will rarely make a difference for |
39 | __libgcc_s_init because unwinding is already in progress, so libgcc_s.so |
40 | has already been loaded if its unwinder is used (Bug 22636). |
41 | 2. It allows us to provide robust fallback code at dlopen time for |
42 | incorrectly configured systems that mix old libnss_* modules |
43 | with newly installed libraries e.g. old libnss_dns.so.2 with new |
44 | libresolv.so.2. Using RTLD_LAZY here causes a failure at the |
45 | time the symbol is called and at that point it is much harder to |
46 | safely return an error (Bug 22766). |
47 | |
48 | The use of RTLD_NOW also impacts gconv module loading, backtracing |
49 | (where the unwinder form libgcc_s.so is used), and IDNA functions |
50 | (which load libidn2), all of which load their respective DSOs on |
51 | demand, and so should not impact program startup. That is to say |
52 | that the DSOs are loaded as part of an API call and therefore we |
53 | will be calling that family of API functions shortly so RTLD_NOW or |
54 | RTLD_LAZY is not a big difference in performance, but RTLD_NOW has |
55 | better error handling semantics for the library. */ |
56 | #define __libc_dlopen(name) \ |
57 | __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN) |
58 | extern void *__libc_dlopen_mode (const char *__name, int __mode); |
59 | extern void *__libc_dlsym (void *__map, const char *__name); |
60 | extern void *__libc_dlvsym (void *map, const char *name, const char *version); |
61 | extern int __libc_dlclose (void *__map); |
62 | libc_hidden_proto (__libc_dlopen_mode) |
63 | libc_hidden_proto (__libc_dlsym) |
64 | libc_hidden_proto (__libc_dlvsym) |
65 | libc_hidden_proto (__libc_dlclose) |
66 | |
67 | /* Locate shared object containing the given address. */ |
68 | #ifdef ElfW |
69 | extern int _dl_addr (const void *address, Dl_info *info, |
70 | struct link_map **mapp, const ElfW(Sym) **symbolp); |
71 | libc_hidden_proto (_dl_addr) |
72 | #endif |
73 | |
74 | struct link_map; |
75 | |
76 | /* Close an object previously opened by _dl_open. */ |
77 | extern void _dl_close (void *map) attribute_hidden; |
78 | /* Same as above, but without locking and safety checks for user |
79 | provided map arguments. */ |
80 | extern void _dl_close_worker (struct link_map *map, bool force) |
81 | attribute_hidden; |
82 | |
83 | /* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or |
84 | RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns |
85 | the symbol value, which may be NULL. */ |
86 | extern void *_dl_sym (void *handle, const char *name, void *who); |
87 | |
88 | /* Look up version VERSION of symbol NAME in shared object HANDLE |
89 | (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling |
90 | function, for RTLD_NEXT. Returns the symbol value, which may be |
91 | NULL. */ |
92 | extern void *_dl_vsym (void *handle, const char *name, const char *version, |
93 | void *who); |
94 | |
95 | /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via |
96 | _dl_catch_error. Returns zero for success, nonzero for failure; and |
97 | arranges for `dlerror' to return the error details. |
98 | ARGS is passed as argument to OPERATE. */ |
99 | extern int _dlerror_run (void (*operate) (void *), void *args) |
100 | attribute_hidden; |
101 | |
102 | #ifdef SHARED |
103 | # define DL_CALLER_DECL /* Nothing */ |
104 | # define DL_CALLER RETURN_ADDRESS (0) |
105 | #else |
106 | # define DL_CALLER_DECL , void *dl_caller |
107 | # define DL_CALLER dl_caller |
108 | #endif |
109 | |
110 | struct dlfcn_hook |
111 | { |
112 | void *(*dlopen) (const char *file, int mode, void *dl_caller); |
113 | int (*dlclose) (void *handle); |
114 | void *(*dlsym) (void *handle, const char *name, void *dl_caller); |
115 | void *(*dlvsym) (void *handle, const char *name, const char *version, |
116 | void *dl_caller); |
117 | char *(*dlerror) (void); |
118 | int (*dladdr) (const void *address, Dl_info *info); |
119 | int (*dladdr1) (const void *address, Dl_info *info, |
120 | void **, int flags); |
121 | int (*dlinfo) (void *handle, int request, void *arg); |
122 | void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller); |
123 | void *pad[4]; |
124 | }; |
125 | |
126 | extern struct dlfcn_hook *_dlfcn_hook; |
127 | libdl_hidden_proto (_dlfcn_hook) |
128 | |
129 | extern void *__dlopen (const char *file, int mode DL_CALLER_DECL) |
130 | attribute_hidden; |
131 | extern void *__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL) |
132 | attribute_hidden; |
133 | extern int __dlclose (void *handle) |
134 | attribute_hidden; |
135 | extern void *__dlsym (void *handle, const char *name DL_CALLER_DECL) |
136 | attribute_hidden; |
137 | extern void *__dlvsym (void *handle, const char *name, const char *version |
138 | DL_CALLER_DECL) |
139 | attribute_hidden; |
140 | extern char *__dlerror (void) |
141 | attribute_hidden; |
142 | extern int __dladdr (const void *address, Dl_info *info) |
143 | attribute_hidden; |
144 | extern int __dladdr1 (const void *address, Dl_info *info, |
145 | void **, int flags) |
146 | attribute_hidden; |
147 | extern int __dlinfo (void *handle, int request, void *arg) attribute_hidden; |
148 | |
149 | #ifndef SHARED |
150 | struct link_map; |
151 | extern void * __libc_dlsym_private (struct link_map *map, const char *name) |
152 | attribute_hidden; |
153 | extern void __libc_register_dl_open_hook (struct link_map *map) |
154 | attribute_hidden; |
155 | extern void __libc_register_dlfcn_hook (struct link_map *map) |
156 | attribute_hidden; |
157 | #endif |
158 | |
159 | extern void __dlerror_main_freeres (void) attribute_hidden; |
160 | |
161 | #endif |
162 | #endif |
163 | |