ldso.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
  3. *
  4. * GNU Lesser General Public License version 2.1 or later.
  5. */
  6. #ifndef _LDSO_H
  7. #define _LDSO_H
  8. #include <features.h>
  9. #ifdef __ARCH_USE_MMU__
  10. # define _MAP_UNINITIALIZED 0
  11. #else
  12. # define _MAP_UNINITIALIZED MAP_UNINITIALIZED
  13. #endif
  14. /* Prepare for the case that `__builtin_expect' is not available. */
  15. #if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ < 96
  16. #define __builtin_expect(x, expected_value) (x)
  17. #endif
  18. #ifndef likely
  19. # define likely(x) __builtin_expect((!!(x)),1)
  20. #endif
  21. #ifndef unlikely
  22. # define unlikely(x) __builtin_expect((!!(x)),0)
  23. #endif
  24. #ifndef __LINUX_COMPILER_H
  25. #define __LINUX_COMPILER_H
  26. #endif
  27. /* Pull in compiler and arch stuff */
  28. #include <stdlib.h>
  29. #include <stdarg.h>
  30. #include <stddef.h> /* for ptrdiff_t */
  31. #include <stdbool.h>
  32. #define _FCNTL_H
  33. /* We need this if arch has only new syscalls defined */
  34. #ifndef AT_FDCWD
  35. #define AT_FDCWD -100
  36. #endif /* AT_FDCWD */
  37. #include <bits/fcntl.h>
  38. #include <bits/wordsize.h>
  39. /* Pull in the arch specific type information */
  40. #include <sys/types.h>
  41. /* Pull in the arch specific page size */
  42. #include <bits/uClibc_page.h>
  43. /* Pull in the MIN macro */
  44. #include <sys/param.h>
  45. /* Pull in the ldso syscalls and string functions */
  46. #if !defined(__ARCH_HAS_NO_SHARED__) || !defined(__ARCH_HAS_NO_LDSO__)
  47. #include <dl-syscall.h>
  48. #include <dl-string.h>
  49. /* Now the ldso specific headers */
  50. #include <dl-elf.h>
  51. #ifdef __UCLIBC_HAS_TLS__
  52. /* Defines USE_TLS */
  53. #include <tls.h>
  54. #endif
  55. #include <dl-hash.h>
  56. /* common align masks, if not specified by sysdep headers */
  57. #ifndef ADDR_ALIGN
  58. #define ADDR_ALIGN (_dl_pagesize - 1)
  59. #endif
  60. #ifndef PAGE_ALIGN
  61. #define PAGE_ALIGN (~ADDR_ALIGN)
  62. #endif
  63. #ifndef OFFS_ALIGN
  64. #define OFFS_ALIGN (PAGE_ALIGN & ~(1ul << (sizeof(_dl_pagesize) * 8 - 1)))
  65. #endif
  66. /* For INIT/FINI dependency sorting. */
  67. struct init_fini_list {
  68. struct init_fini_list *next;
  69. struct elf_resolve *tpnt;
  70. };
  71. /* Global variables used within the shared library loader */
  72. extern char *_dl_library_path; /* Where we look for libraries */
  73. extern char *_dl_preload; /* Things to be loaded before the libs */
  74. #ifdef __LDSO_SEARCH_INTERP_PATH__
  75. extern const char *_dl_ldsopath; /* Where the shared lib loader was found */
  76. #endif
  77. extern const char *_dl_progname; /* The name of the executable being run */
  78. extern size_t _dl_pagesize; /* Store the page size for use later */
  79. #ifdef __LDSO_PRELINK_SUPPORT__
  80. extern char *_dl_trace_prelink; /* Library for prelinking trace */
  81. extern struct elf_resolve *_dl_trace_prelink_map; /* Library map for prelinking trace */
  82. #else
  83. #define _dl_trace_prelink 0
  84. #endif
  85. #ifdef __DSBT__
  86. extern void **_dl_ldso_dsbt;
  87. #endif
  88. #if defined(USE_TLS) && USE_TLS
  89. extern void _dl_add_to_slotinfo (struct link_map *l);
  90. extern void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
  91. #endif
  92. #ifdef __SUPPORT_LD_DEBUG__
  93. extern char *_dl_debug;
  94. extern char *_dl_debug_symbols;
  95. extern char *_dl_debug_move;
  96. extern char *_dl_debug_reloc;
  97. extern char *_dl_debug_detail;
  98. extern char *_dl_debug_nofixups;
  99. extern char *_dl_debug_bindings;
  100. extern char *_dl_debug_vdso;
  101. extern int _dl_debug_file;
  102. # define __dl_debug_dprint(fmt, args...) \
  103. _dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __func__, __LINE__, ## args);
  104. # define _dl_if_debug_dprint(fmt, args...) \
  105. do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)
  106. #else
  107. # define __dl_debug_dprint(fmt, args...) do {} while (0)
  108. # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
  109. /* disabled on purpose, _dl_debug_file should be guarded by __SUPPORT_LD_DEBUG__
  110. # define _dl_debug_file 2*/
  111. #endif /* __SUPPORT_LD_DEBUG__ */
  112. #ifdef IS_IN_rtld
  113. # ifdef __SUPPORT_LD_DEBUG__
  114. # define _dl_assert(expr) \
  115. do { \
  116. if (!(expr)) { \
  117. __dl_debug_dprint("assert(%s)\n", #expr); \
  118. _dl_exit(45); \
  119. } \
  120. } while (0)
  121. # else
  122. # define _dl_assert(expr) ((void)0)
  123. # endif
  124. #else
  125. # include <assert.h>
  126. # define _dl_assert(expr) assert(expr)
  127. #endif
  128. #ifdef __SUPPORT_LD_DEBUG_EARLY__
  129. # define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
  130. #else
  131. # define _dl_debug_early(fmt, args...) do {} while (0)
  132. #endif /* __SUPPORT_LD_DEBUG_EARLY__ */
  133. #ifndef NULL
  134. #define NULL ((void *) 0)
  135. #endif
  136. extern void *_dl_malloc(size_t size);
  137. extern void *_dl_calloc(size_t __nmemb, size_t __size);
  138. extern void *_dl_realloc(void *__ptr, size_t __size);
  139. extern void _dl_free(void *);
  140. extern char *_dl_getenv(const char *symbol, char **envp);
  141. extern void _dl_unsetenv(const char *symbol, char **envp);
  142. #ifdef IS_IN_rtld
  143. extern char *_dl_strdup(const char *string);
  144. extern void _dl_dprintf(int, const char *, ...);
  145. #else
  146. # include <string.h>
  147. # define _dl_strdup strdup
  148. # include <stdio.h>
  149. # ifdef __USE_GNU
  150. # define _dl_dprintf dprintf
  151. # else
  152. # define _dl_dprintf(fd, fmt, args...) fprintf(stderr, fmt, ## args)
  153. # endif
  154. #endif
  155. #ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
  156. # define DL_GET_READY_TO_RUN_EXTRA_PARMS
  157. #endif
  158. #ifndef DL_GET_READY_TO_RUN_EXTRA_ARGS
  159. # define DL_GET_READY_TO_RUN_EXTRA_ARGS
  160. #endif
  161. extern void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
  162. char **envp, char **argv
  163. DL_GET_READY_TO_RUN_EXTRA_PARMS);
  164. #ifdef HAVE_DL_INLINES_H
  165. #include <dl-inlines.h>
  166. #endif
  167. #else /* __ARCH_HAS_NO_SHARED__ */
  168. #include <dl-defs.h>
  169. #include <dl-elf.h>
  170. #endif
  171. #define AUX_MAX_AT_ID 40
  172. extern ElfW(auxv_t) _dl_auxvt[AUX_MAX_AT_ID];
  173. void load_vdso(void *sys_info_ehdr, char **envp );
  174. #endif /* _LDSO_H */