]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/dlfcn.h
stdio: Remove __libc_message alloca usage
[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
5d28a896
FW
7rtld_hidden_proto (_dl_find_object)
8
2f54c82d
UD
9/* Internally used flag. */
10#define __RTLD_DLOPEN 0x80000000
9d0881aa 11#define __RTLD_SPROF 0x40000000
5a4b5076 12#define __RTLD_OPENEXEC 0x20000000
c14e9135 13#define __RTLD_CALLMAP 0x10000000
9dcafc55 14#define __RTLD_AUDIT 0x08000000
8e9f92e9 15#define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */
3a62d00d 16#define __RTLD_NOIFUNC 0x02000000 /* Suppress calling ifunc functions. */
f0e23d34
AZ
17#define __RTLD_VDSO 0x01000000 /* Tell _dl_new_object the object is
18 system-loaded. */
2f54c82d 19
c0f62c56
UD
20#define __LM_ID_CALLER -2
21
6a1ed327
FW
22/* These variables are defined and initialized in the startup code. */
23extern int __libc_argc attribute_hidden;
24extern char **__libc_argv attribute_hidden;
25
bdbf022d 26/* Now define the internal interfaces. */
b3fc5f84 27
81b49e96
TMQMF
28/* Use RTLD_NOW here because:
29 1. In pthread_cancel_init we want to use RTLD_NOW to reduce the stack usage
30 of future cancellation operations, particularly when the target thread
31 is running with a small stack. Likewise for consistency we do the same
32 thing in __libgcc_s_init. RTLD_NOW will rarely make a difference for
33 __libgcc_s_init because unwinding is already in progress, so libgcc_s.so
34 has already been loaded if its unwinder is used (Bug 22636).
35 2. It allows us to provide robust fallback code at dlopen time for
ae7a94e5
PV
36 incorrectly configured systems that mix old libnss_* modules
37 with newly installed libraries e.g. old libnss_dns.so.2 with new
38 libresolv.so.2. Using RTLD_LAZY here causes a failure at the
39 time the symbol is called and at that point it is much harder to
40 safely return an error (Bug 22766).
81b49e96
TMQMF
41
42 The use of RTLD_NOW also impacts gconv module loading, backtracing
43 (where the unwinder form libgcc_s.so is used), and IDNA functions
7f9f1ecb 44 (which load libidn2), all of which load their respective DSOs on
81b49e96
TMQMF
45 demand, and so should not impact program startup. That is to say
46 that the DSOs are loaded as part of an API call and therefore we
47 will be calling that family of API functions shortly so RTLD_NOW or
48 RTLD_LAZY is not a big difference in performance, but RTLD_NOW has
49 better error handling semantics for the library. */
102070bc 50#define __libc_dlopen(name) \
81b49e96 51 __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
7a5db2e8
FW
52extern void *__libc_dlopen_mode (const char *__name, int __mode)
53 attribute_hidden;
54extern void *__libc_dlsym (void *__map, const char *__name)
55 attribute_hidden;
56extern void *__libc_dlvsym (void *map, const char *name, const char *version)
57 attribute_hidden;
58extern int __libc_dlclose (void *__map)
59 attribute_hidden;
94e365c6
UD
60
61/* Locate shared object containing the given address. */
8dd56993
RM
62#ifdef ElfW
63extern int _dl_addr (const void *address, Dl_info *info,
7a5db2e8
FW
64 struct link_map **mapp, const ElfW(Sym) **symbolp)
65 attribute_hidden;
8dd56993 66#endif
94e365c6 67
965cba04
UD
68struct link_map;
69
94e365c6 70/* Close an object previously opened by _dl_open. */
9dcafc55 71extern void _dl_close (void *map) attribute_hidden;
11bf311e
UD
72/* Same as above, but without locking and safety checks for user
73 provided map arguments. */
02d5e5d9
PK
74extern void _dl_close_worker (struct link_map *map, bool force)
75 attribute_hidden;
94e365c6
UD
76
77/* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
78 RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns
79 the symbol value, which may be NULL. */
7a5db2e8
FW
80extern void *_dl_sym (void *handle, const char *name, void *who)
81 attribute_hidden;
b3fc5f84 82
94e365c6
UD
83/* Look up version VERSION of symbol NAME in shared object HANDLE
84 (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
85 function, for RTLD_NEXT. Returns the symbol value, which may be
86 NULL. */
87extern void *_dl_vsym (void *handle, const char *name, const char *version,
7a5db2e8 88 void *who) attribute_hidden;
8e17ea58 89
94e365c6
UD
90/* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
91 _dl_catch_error. Returns zero for success, nonzero for failure; and
92 arranges for `dlerror' to return the error details.
93 ARGS is passed as argument to OPERATE. */
7a5db2e8 94extern int _dlerror_run (void (*operate) (void *), void *args) attribute_hidden;
94e365c6 95
466c1ea1
FW
96/* This structure is used to make the outer (statically linked)
97 implementation of dlopen and related functions to the inner libc
98 after static dlopen, via the GLRO (dl_dlfcn_hook) pointer. */
5f21997b
UD
99struct dlfcn_hook
100{
466c1ea1 101 /* Public interfaces. */
5f21997b
UD
102 void *(*dlopen) (const char *file, int mode, void *dl_caller);
103 int (*dlclose) (void *handle);
104 void *(*dlsym) (void *handle, const char *name, void *dl_caller);
105 void *(*dlvsym) (void *handle, const char *name, const char *version,
106 void *dl_caller);
107 char *(*dlerror) (void);
108 int (*dladdr) (const void *address, Dl_info *info);
109 int (*dladdr1) (const void *address, Dl_info *info,
110 void **extra_info, int flags);
eb77a1fc 111 int (*dlinfo) (void *handle, int request, void *arg);
5f21997b 112 void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
5f21997b 113
466c1ea1
FW
114 /* Internal interfaces. */
115 void* (*libc_dlopen_mode) (const char *__name, int __mode);
116 void* (*libc_dlsym) (void *map, const char *name);
117 void* (*libc_dlvsym) (void *map, const char *name, const char *version);
118 int (*libc_dlclose) (void *map);
119};
5f21997b 120
466c1ea1
FW
121/* Note: These prototypes are for initializing _dlfcn_hook in static
122 builds; see __rtld_static_init. Internal calls in glibc should use
123 the __libc_dl* functions defined in elf/dl-libc.c instead. */
d8cce17d 124
0c1c3a77 125extern void *__dlopen (const char *file, int mode, void *caller);
6a1ed327
FW
126extern void *__dlmopen (Lmid_t nsid, const char *file, int mode,
127 void *dl_caller);
d8cce17d 128extern int __dlclose (void *handle);
77f876c0 129extern void *__dlsym (void *handle, const char *name, void *dl_caller);
add8d7ea
FW
130extern void *__dlvsym (void *handle, const char *name, const char *version,
131 void *dl_caller);
602252b5 132extern int __dladdr (const void *address, Dl_info *info);
5f21997b 133extern int __dladdr1 (const void *address, Dl_info *info,
492560a3 134 void **extra_info, int flags);
6dfc0207 135extern int __dlinfo (void *handle, int request, void *arg);
466c1ea1 136extern char *__dlerror (void);
5f21997b 137
2827ab99 138#endif
6796bc80 139#endif