blob: 0ce0af5276218c6dcbb093823d3965de753e9155 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#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. */
20extern int __dlfcn_argc attribute_hidden;
21extern char **__dlfcn_argv attribute_hidden;
22#else
23/* These variables are defined and initialized in the startup code. */
24extern int __libc_argc attribute_hidden;
25extern 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#define __libc_dlopen(name) \
35 __libc_dlopen_mode (name, RTLD_LAZY | __RTLD_DLOPEN)
36extern void *__libc_dlopen_mode (const char *__name, int __mode);
37extern void *__libc_dlsym (void *__map, const char *__name);
38extern int __libc_dlclose (void *__map);
39libc_hidden_proto (__libc_dlopen_mode)
40libc_hidden_proto (__libc_dlsym)
41libc_hidden_proto (__libc_dlclose)
42
43/* Locate shared object containing the given address. */
44#ifdef ElfW
45extern int _dl_addr (const void *address, Dl_info *info,
46 struct link_map **mapp, const ElfW(Sym) **symbolp)
47 internal_function;
48libc_hidden_proto (_dl_addr)
49#endif
50
51struct link_map;
52
53/* Close an object previously opened by _dl_open. */
54extern void _dl_close (void *map) attribute_hidden;
55/* Same as above, but without locking and safety checks for user
56 provided map arguments. */
57extern void _dl_close_worker (struct link_map *map, bool force)
58 attribute_hidden;
59
60/* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
61 RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns
62 the symbol value, which may be NULL. */
63extern void *_dl_sym (void *handle, const char *name, void *who)
64 internal_function;
65
66/* Look up version VERSION of symbol NAME in shared object HANDLE
67 (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
68 function, for RTLD_NEXT. Returns the symbol value, which may be
69 NULL. */
70extern void *_dl_vsym (void *handle, const char *name, const char *version,
71 void *who)
72 internal_function;
73
74/* Call OPERATE, catching errors from `dl_signal_error'. If there is no
75 error, *ERRSTRING is set to null. If there is an error, *ERRSTRING is
76 set to a string constructed from the strings passed to _dl_signal_error,
77 and the error code passed is the return value and *OBJNAME is set to
78 the object name which experienced the problems. ERRSTRING if nonzero
79 points to a malloc'ed string which the caller has to free after use.
80 ARGS is passed as argument to OPERATE. MALLOCEDP is set to true only
81 if the returned string is allocated using the libc's malloc. */
82extern int _dl_catch_error (const char **objname, const char **errstring,
83 bool *mallocedp, void (*operate) (void *),
84 void *args)
85 internal_function;
86
87/* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
88 _dl_catch_error. Returns zero for success, nonzero for failure; and
89 arranges for `dlerror' to return the error details.
90 ARGS is passed as argument to OPERATE. */
91extern int _dlerror_run (void (*operate) (void *), void *args)
92 internal_function;
93
94#ifdef SHARED
95# define DL_CALLER_DECL /* Nothing */
96# define DL_CALLER RETURN_ADDRESS (0)
97#else
98# define DL_CALLER_DECL , void *dl_caller
99# define DL_CALLER dl_caller
100#endif
101
102struct dlfcn_hook
103{
104 void *(*dlopen) (const char *file, int mode, void *dl_caller);
105 int (*dlclose) (void *handle);
106 void *(*dlsym) (void *handle, const char *name, void *dl_caller);
107 void *(*dlvsym) (void *handle, const char *name, const char *version,
108 void *dl_caller);
109 char *(*dlerror) (void);
110 int (*dladdr) (const void *address, Dl_info *info);
111 int (*dladdr1) (const void *address, Dl_info *info,
112 void **extra_info, int flags);
113 int (*dlinfo) (void *handle, int request, void *arg, void *dl_caller);
114 void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
115 void *pad[4];
116};
117
118extern struct dlfcn_hook *_dlfcn_hook;
119libdl_hidden_proto (_dlfcn_hook)
120
121extern void *__dlopen (const char *file, int mode DL_CALLER_DECL)
122 attribute_hidden;
123extern void *__dlmopen (Lmid_t nsid, const char *file, int mode DL_CALLER_DECL)
124 attribute_hidden;
125extern int __dlclose (void *handle)
126 attribute_hidden;
127extern void *__dlsym (void *handle, const char *name DL_CALLER_DECL)
128 attribute_hidden;
129extern void *__dlvsym (void *handle, const char *name, const char *version
130 DL_CALLER_DECL)
131 attribute_hidden;
132extern char *__dlerror (void)
133 attribute_hidden;
134extern int __dladdr (const void *address, Dl_info *info)
135 attribute_hidden;
136extern int __dladdr1 (const void *address, Dl_info *info,
137 void **extra_info, int flags)
138 attribute_hidden;
139extern int __dlinfo (void *handle, int request, void *arg DL_CALLER_DECL)
140 attribute_hidden;
141
142#ifndef SHARED
143struct link_map;
144extern void * __libc_dlsym_private (struct link_map *map, const char *name)
145 attribute_hidden;
146extern void __libc_register_dl_open_hook (struct link_map *map)
147 attribute_hidden;
148extern void __libc_register_dlfcn_hook (struct link_map *map)
149 attribute_hidden;
150#endif
151#endif
152
153#endif