]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/dlfcn.h
dlfcn: Move dlinfo into libc
[thirdparty/glibc.git] / include / dlfcn.h
CommitLineData
6796bc80 1#ifndef _DLFCN_H
94e365c6 2#include <dlfcn/dlfcn.h>
31341567 3#ifndef _ISOMAC
8dd56993 4#include <link.h> /* For ElfW. */
74780cf6 5#include <stdbool.h>
bdbf022d 6
2f54c82d
UD
7/* Internally used flag. */
8#define __RTLD_DLOPEN 0x80000000
9d0881aa 9#define __RTLD_SPROF 0x40000000
5a4b5076 10#define __RTLD_OPENEXEC 0x20000000
c14e9135 11#define __RTLD_CALLMAP 0x10000000
9dcafc55 12#define __RTLD_AUDIT 0x08000000
8e9f92e9 13#define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */
3a62d00d 14#define __RTLD_NOIFUNC 0x02000000 /* Suppress calling ifunc functions. */
2f54c82d 15
c0f62c56
UD
16#define __LM_ID_CALLER -2
17
6a1ed327
FW
18/* These variables are defined and initialized in the startup code. */
19extern int __libc_argc attribute_hidden;
20extern char **__libc_argv attribute_hidden;
21
9dcafc55
UD
22#ifdef SHARED
23/* Locally stored program arguments. */
24extern int __dlfcn_argc attribute_hidden;
25extern char **__dlfcn_argv attribute_hidden;
26#else
9dcafc55
UD
27# define __dlfcn_argc __libc_argc
28# define __dlfcn_argv __libc_argv
29#endif
30
31
bdbf022d 32/* Now define the internal interfaces. */
b3fc5f84 33
81b49e96
TMQMF
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
ae7a94e5
PV
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).
81b49e96
TMQMF
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
7f9f1ecb 50 (which load libidn2), all of which load their respective DSOs on
81b49e96
TMQMF
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. */
102070bc 56#define __libc_dlopen(name) \
81b49e96 57 __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
a784e502
UD
58extern void *__libc_dlopen_mode (const char *__name, int __mode);
59extern void *__libc_dlsym (void *__map, const char *__name);
82eef55f 60extern void *__libc_dlvsym (void *map, const char *name, const char *version);
aaa8d85c 61extern int __libc_dlclose (void *__map);
9d79e037
UD
62libc_hidden_proto (__libc_dlopen_mode)
63libc_hidden_proto (__libc_dlsym)
82eef55f 64libc_hidden_proto (__libc_dlvsym)
9d79e037 65libc_hidden_proto (__libc_dlclose)
94e365c6
UD
66
67/* Locate shared object containing the given address. */
8dd56993
RM
68#ifdef ElfW
69extern int _dl_addr (const void *address, Dl_info *info,
3012cfb0 70 struct link_map **mapp, const ElfW(Sym) **symbolp);
a20d8dbe 71libc_hidden_proto (_dl_addr)
8dd56993 72#endif
94e365c6 73
965cba04
UD
74struct link_map;
75
94e365c6 76/* Close an object previously opened by _dl_open. */
9dcafc55 77extern void _dl_close (void *map) attribute_hidden;
11bf311e
UD
78/* Same as above, but without locking and safety checks for user
79 provided map arguments. */
02d5e5d9
PK
80extern void _dl_close_worker (struct link_map *map, bool force)
81 attribute_hidden;
94e365c6
UD
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. */
86e4919f 86extern void *_dl_sym (void *handle, const char *name, void *who);
77f876c0 87libc_hidden_proto (_dl_sym)
b3fc5f84 88
94e365c6
UD
89/* Look up version VERSION of symbol NAME in shared object HANDLE
90 (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
91 function, for RTLD_NEXT. Returns the symbol value, which may be
92 NULL. */
93extern void *_dl_vsym (void *handle, const char *name, const char *version,
86e4919f 94 void *who);
8e17ea58 95
94e365c6
UD
96/* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
97 _dl_catch_error. Returns zero for success, nonzero for failure; and
98 arranges for `dlerror' to return the error details.
99 ARGS is passed as argument to OPERATE. */
a23c28ec
FW
100extern int _dlerror_run (void (*operate) (void *), void *args);
101libc_hidden_proto (_dlerror_run)
94e365c6 102
5f21997b
UD
103#ifdef SHARED
104# define DL_CALLER_DECL /* Nothing */
105# define DL_CALLER RETURN_ADDRESS (0)
106#else
107# define DL_CALLER_DECL , void *dl_caller
108# define DL_CALLER dl_caller
109#endif
110
111struct dlfcn_hook
112{
113 void *(*dlopen) (const char *file, int mode, void *dl_caller);
114 int (*dlclose) (void *handle);
115 void *(*dlsym) (void *handle, const char *name, void *dl_caller);
116 void *(*dlvsym) (void *handle, const char *name, const char *version,
117 void *dl_caller);
118 char *(*dlerror) (void);
119 int (*dladdr) (const void *address, Dl_info *info);
120 int (*dladdr1) (const void *address, Dl_info *info,
121 void **extra_info, int flags);
eb77a1fc 122 int (*dlinfo) (void *handle, int request, void *arg);
5f21997b
UD
123 void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
124 void *pad[4];
125};
126
127extern struct dlfcn_hook *_dlfcn_hook;
a23c28ec 128libc_hidden_proto (_dlfcn_hook)
5f21997b 129
d8cce17d
FW
130/* Note: These prototypes are for initializing _dflcn_hook in static
131 libraries. Internal calls in glibc should use the __libc_dl*
132 functions defined in elf/dl-libc.c instead. */
133
5f21997b
UD
134extern void *__dlopen (const char *file, int mode DL_CALLER_DECL)
135 attribute_hidden;
6a1ed327
FW
136extern void *__dlmopen (Lmid_t nsid, const char *file, int mode,
137 void *dl_caller);
d8cce17d 138extern int __dlclose (void *handle);
77f876c0 139extern void *__dlsym (void *handle, const char *name, void *dl_caller);
5f21997b
UD
140extern void *__dlvsym (void *handle, const char *name, const char *version
141 DL_CALLER_DECL)
142 attribute_hidden;
602252b5 143extern int __dladdr (const void *address, Dl_info *info);
5f21997b 144extern int __dladdr1 (const void *address, Dl_info *info,
492560a3 145 void **extra_info, int flags);
6dfc0207 146extern int __dlinfo (void *handle, int request, void *arg);
5f21997b
UD
147
148#ifndef SHARED
149struct link_map;
150extern void * __libc_dlsym_private (struct link_map *map, const char *name)
151 attribute_hidden;
152extern void __libc_register_dl_open_hook (struct link_map *map)
153 attribute_hidden;
154extern void __libc_register_dlfcn_hook (struct link_map *map)
155 attribute_hidden;
156#endif
157
2827ab99 158#endif
6796bc80 159#endif