ldso.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #ifndef __ARCH_HAS_NO_SHARED__
  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 int _dl_debug_file;
  101. # define __dl_debug_dprint(fmt, args...) \
  102. _dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __func__, __LINE__, ## args);
  103. # define _dl_if_debug_dprint(fmt, args...) \
  104. do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)
  105. #else
  106. # define __dl_debug_dprint(fmt, args...) do {} while (0)
  107. # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
  108. /* disabled on purpose, _dl_debug_file should be guarded by __SUPPORT_LD_DEBUG__
  109. # define _dl_debug_file 2*/
  110. #endif /* __SUPPORT_LD_DEBUG__ */
  111. #ifdef IS_IN_rtld
  112. # ifdef __SUPPORT_LD_DEBUG__
  113. # define _dl_assert(expr) \
  114. do { \
  115. if (!(expr)) { \
  116. __dl_debug_dprint("assert(%s)\n", #expr); \
  117. _dl_exit(45); \
  118. } \
  119. } while (0)
  120. # else
  121. # define _dl_assert(expr) ((void)0)
  122. # endif
  123. #else
  124. # include <assert.h>
  125. # define _dl_assert(expr) assert(expr)
  126. #endif
  127. #ifdef __SUPPORT_LD_DEBUG_EARLY__
  128. # define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
  129. #else
  130. # define _dl_debug_early(fmt, args...) do {} while (0)
  131. #endif /* __SUPPORT_LD_DEBUG_EARLY__ */
  132. #ifndef NULL
  133. #define NULL ((void *) 0)
  134. #endif
  135. extern void *_dl_malloc(size_t size);
  136. extern void *_dl_calloc(size_t __nmemb, size_t __size);
  137. extern void *_dl_realloc(void *__ptr, size_t __size);
  138. extern void _dl_free(void *);
  139. extern char *_dl_getenv(const char *symbol, char **envp);
  140. extern void _dl_unsetenv(const char *symbol, char **envp);
  141. #ifdef IS_IN_rtld
  142. extern char *_dl_strdup(const char *string);
  143. extern void _dl_dprintf(int, const char *, ...);
  144. #else
  145. # include <string.h>
  146. # define _dl_strdup strdup
  147. # include <stdio.h>
  148. # ifdef __USE_GNU
  149. # define _dl_dprintf dprintf
  150. # else
  151. # define _dl_dprintf(fd, fmt, args...) fprintf(stderr, fmt, ## args)
  152. # endif
  153. #endif
  154. #ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
  155. # define DL_GET_READY_TO_RUN_EXTRA_PARMS
  156. #endif
  157. #ifndef DL_GET_READY_TO_RUN_EXTRA_ARGS
  158. # define DL_GET_READY_TO_RUN_EXTRA_ARGS
  159. #endif
  160. extern void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
  161. char **envp, char **argv
  162. DL_GET_READY_TO_RUN_EXTRA_PARMS);
  163. #ifdef HAVE_DL_INLINES_H
  164. #include <dl-inlines.h>
  165. #endif
  166. #else /* __ARCH_HAS_NO_SHARED__ */
  167. #include <dl-defs.h>
  168. #include <dl-elf.h>
  169. #endif
  170. #define AUX_MAX_AT_ID 40
  171. extern ElfW(auxv_t) _dl_auxvt[AUX_MAX_AT_ID];
  172. #endif /* _LDSO_H */