dlfcn.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef _DLFCN_H
  2. #include <dlfcn/dlfcn.h>
  3. #ifndef _ISOMAC
  4. #include <link.h> /* For ElfW. */
  5. #include <stdbool.h>
  6. rtld_hidden_proto (_dl_find_object)
  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. #define __RTLD_VDSO 0x01000000 /* Tell _dl_new_object the object is
  16. system-loaded. */
  17. #define __LM_ID_CALLER -2
  18. /* These variables are defined and initialized in the startup code. */
  19. extern int __libc_argc attribute_hidden;
  20. extern char **__libc_argv attribute_hidden;
  21. /* Now define the internal interfaces. */
  22. /* Use RTLD_NOW here because:
  23. 1. In pthread_cancel_init we want to use RTLD_NOW to reduce the stack usage
  24. of future cancellation operations, particularly when the target thread
  25. is running with a small stack. Likewise for consistency we do the same
  26. thing in __libgcc_s_init. RTLD_NOW will rarely make a difference for
  27. __libgcc_s_init because unwinding is already in progress, so libgcc_s.so
  28. has already been loaded if its unwinder is used (Bug 22636).
  29. 2. It allows us to provide robust fallback code at dlopen time for
  30. incorrectly configured systems that mix old libnss_* modules
  31. with newly installed libraries e.g. old libnss_dns.so.2 with new
  32. libresolv.so.2. Using RTLD_LAZY here causes a failure at the
  33. time the symbol is called and at that point it is much harder to
  34. safely return an error (Bug 22766).
  35. The use of RTLD_NOW also impacts gconv module loading, backtracing
  36. (where the unwinder form libgcc_s.so is used), and IDNA functions
  37. (which load libidn2), all of which load their respective DSOs on
  38. demand, and so should not impact program startup. That is to say
  39. that the DSOs are loaded as part of an API call and therefore we
  40. will be calling that family of API functions shortly so RTLD_NOW or
  41. RTLD_LAZY is not a big difference in performance, but RTLD_NOW has
  42. better error handling semantics for the library. */
  43. #define __libc_dlopen(name) \
  44. __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
  45. extern void *__libc_dlopen_mode (const char *__name, int __mode)
  46. attribute_hidden;
  47. extern void *__libc_dlsym (void *__map, const char *__name)
  48. attribute_hidden;
  49. extern void *__libc_dlvsym (void *map, const char *name, const char *version)
  50. attribute_hidden;
  51. extern int __libc_dlclose (void *__map)
  52. attribute_hidden;
  53. /* Locate shared object containing the given address. */
  54. #ifdef ElfW
  55. extern int _dl_addr (const void *address, Dl_info *info,
  56. struct link_map **mapp, const ElfW(Sym) **symbolp)
  57. attribute_hidden;
  58. #endif
  59. struct link_map;
  60. /* Close an object previously opened by _dl_open. */
  61. extern void _dl_close (void *map) attribute_hidden;
  62. /* Same as above, but without locking and safety checks for user
  63. provided map arguments. */
  64. extern void _dl_close_worker (struct link_map *map, bool force)
  65. attribute_hidden;
  66. /* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
  67. RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns
  68. the symbol value, which may be NULL. */
  69. extern void *_dl_sym (void *handle, const char *name, void *who)
  70. attribute_hidden;
  71. /* Look up version VERSION of symbol NAME in shared object HANDLE
  72. (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
  73. function, for RTLD_NEXT. Returns the symbol value, which may be
  74. NULL. */
  75. extern void *_dl_vsym (void *handle, const char *name, const char *version,
  76. void *who) attribute_hidden;
  77. /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
  78. _dl_catch_error. Returns zero for success, nonzero for failure; and
  79. arranges for `dlerror' to return the error details.
  80. ARGS is passed as argument to OPERATE. */
  81. extern int _dlerror_run (void (*operate) (void *), void *args) attribute_hidden;
  82. /* This structure is used to make the outer (statically linked)
  83. implementation of dlopen and related functions to the inner libc
  84. after static dlopen, via the GLRO (dl_dlfcn_hook) pointer. */
  85. struct dlfcn_hook
  86. {
  87. /* Public interfaces. */
  88. void *(*dlopen) (const char *file, int mode, void *dl_caller);
  89. int (*dlclose) (void *handle);
  90. void *(*dlsym) (void *handle, const char *name, void *dl_caller);
  91. void *(*dlvsym) (void *handle, const char *name, const char *version,
  92. void *dl_caller);
  93. char *(*dlerror) (void);
  94. int (*dladdr) (const void *address, Dl_info *info);
  95. int (*dladdr1) (const void *address, Dl_info *info,
  96. void **extra_info, int flags);
  97. int (*dlinfo) (void *handle, int request, void *arg);
  98. void *(*dlmopen) (Lmid_t nsid, const char *file, int mode, void *dl_caller);
  99. /* Internal interfaces. */
  100. void* (*libc_dlopen_mode) (const char *__name, int __mode);
  101. void* (*libc_dlsym) (void *map, const char *name);
  102. void* (*libc_dlvsym) (void *map, const char *name, const char *version);
  103. int (*libc_dlclose) (void *map);
  104. };
  105. /* Note: These prototypes are for initializing _dlfcn_hook in static
  106. builds; see __rtld_static_init. Internal calls in glibc should use
  107. the __libc_dl* functions defined in elf/dl-libc.c instead. */
  108. extern void *__dlopen (const char *file, int mode, void *caller);
  109. extern void *__dlmopen (Lmid_t nsid, const char *file, int mode,
  110. void *dl_caller);
  111. extern int __dlclose (void *handle);
  112. extern void *__dlsym (void *handle, const char *name, void *dl_caller);
  113. extern void *__dlvsym (void *handle, const char *name, const char *version,
  114. void *dl_caller);
  115. extern int __dladdr (const void *address, Dl_info *info);
  116. extern int __dladdr1 (const void *address, Dl_info *info,
  117. void **extra_info, int flags);
  118. extern int __dlinfo (void *handle, int request, void *arg);
  119. extern char *__dlerror (void);
  120. #ifndef SHARED
  121. # undef DL_CALL_FCT
  122. # define DL_CALL_FCT(fctp, args) ((fctp) args)
  123. #endif
  124. #endif
  125. #endif