1 #ifndef _DLFCN_H 2 #include <dlfcn/dlfcn.h> 3 #ifndef _ISOMAC 4 #include <link.h> /* For ElfW. */ 5 #include <stdbool.h> 6 7 rtld_hidden_proto (_dl_find_object) 8 9 /* Internally used flag. */ 10 #define __RTLD_DLOPEN 0x80000000 11 #define __RTLD_SPROF 0x40000000 12 #define __RTLD_OPENEXEC 0x20000000 13 #define __RTLD_CALLMAP 0x10000000 14 #define __RTLD_AUDIT 0x08000000 15 #define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */ 16 #define __RTLD_NOIFUNC 0x02000000 /* Suppress calling ifunc functions. */ 17 #define __RTLD_VDSO 0x01000000 /* Tell _dl_new_object the object is 18 system-loaded. */ 19 20 #define __LM_ID_CALLER -2 21 22 /* These variables are defined and initialized in the startup code. */ 23 extern int __libc_argc attribute_hidden; 24 extern char **__libc_argv attribute_hidden; 25 26 /* Now define the internal interfaces. */ 27 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 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). 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 44 (which load libidn2), all of which load their respective DSOs on 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. */ 50 #define __libc_dlopen(name) \ 51 __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN) 52 extern void *__libc_dlopen_mode (const char *__name, int __mode) 53 attribute_hidden; 54 extern void *__libc_dlsym (void *__map, const char *__name) 55 attribute_hidden; 56 extern void *__libc_dlvsym (void *map, const char *name, const char *version) 57 attribute_hidden; 58 extern int __libc_dlclose (void *__map) 59 attribute_hidden; 60 61 /* Locate shared object containing the given address. */ 62 #ifdef ElfW 63 extern int _dl_addr (const void *address, Dl_info *info, 64 struct link_map **mapp, const ElfW(Sym) **symbolp) 65 attribute_hidden; 66 #endif 67 68 struct link_map; 69 70 /* Close an object previously opened by _dl_open. */ 71 extern void _dl_close (void *map) attribute_hidden; 72 /* Same as above, but without locking and safety checks for user 73 provided map arguments. */ 74 extern void _dl_close_worker (struct link_map *map, bool force) 75 attribute_hidden; 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. */ 80 extern void *_dl_sym (void *handle, const char *name, void *who) 81 attribute_hidden; 82 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. */ 87 extern void *_dl_vsym (void *handle, const char *name, const char *version, 88 void *who) attribute_hidden; 89 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. */ 94 extern int _dlerror_run (void (*operate) (void *), void *args) attribute_hidden; 95 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. */ 99 struct dlfcn_hook 100 { 101 /* Public interfaces. */ 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); 111 int (*dlinfo) (void *handle, int request, void *arg); 112 void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller); 113 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 }; 120 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. */ 124 125 extern void *__dlopen (const char *file, int mode, void *caller); 126 extern void *__dlmopen (Lmid_t nsid, const char *file, int mode, 127 void *dl_caller); 128 extern int __dlclose (void *handle); 129 extern void *__dlsym (void *handle, const char *name, void *dl_caller); 130 extern void *__dlvsym (void *handle, const char *name, const char *version, 131 void *dl_caller); 132 extern int __dladdr (const void *address, Dl_info *info); 133 extern int __dladdr1 (const void *address, Dl_info *info, 134 void **extra_info, int flags); 135 extern int __dlinfo (void *handle, int request, void *arg); 136 extern char *__dlerror (void); 137 138 #endif 139 #endif 140