ldsodefs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef _LDSODEFS_H
  2. #define _LDSODEFS_H 1
  3. #include <bits/kernel-features.h>
  4. #include <features.h>
  5. #include <tls.h>
  6. #ifdef __mips__
  7. /* The MIPS ABI specifies that the dynamic section has to be read-only. */
  8. #define DL_RO_DYN_SECTION 1
  9. /* TODO: Import in 64-bit relocations from glibc. */
  10. #endif
  11. #ifndef SHARED
  12. # define EXTERN extern
  13. #else
  14. # ifdef IS_IN_rtld
  15. # define EXTERN
  16. # else
  17. # define EXTERN extern
  18. # endif
  19. #endif
  20. /* Non-shared code has no support for multiple namespaces. */
  21. #ifdef SHARED
  22. # define DL_NNS 16
  23. #else
  24. # define DL_NNS 1
  25. #endif
  26. #define GL(x) _##x
  27. #define GLRO(x) _##x
  28. /* Variable pointing to the end of the stack (or close to it). This value
  29. must be constant over the runtime of the application. Some programs
  30. might use the variable which results in copy relocations on some
  31. platforms. But this does not matter, ld.so can always use the local
  32. copy. */
  33. extern void *__libc_stack_end;
  34. /* Determine next available module ID. */
  35. extern size_t _dl_next_tls_modid (void) internal_function attribute_hidden;
  36. /* Calculate offset of the TLS blocks in the static TLS block. */
  37. extern void _dl_determine_tlsoffset (void) internal_function attribute_hidden;
  38. /* Set up the data structures for TLS, when they were not set up at startup.
  39. Returns nonzero on malloc failure.
  40. This is called from _dl_map_object_from_fd or by libpthread. */
  41. extern int _dl_tls_setup (void) internal_function;
  42. rtld_hidden_proto (_dl_tls_setup)
  43. /* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */
  44. extern void *_dl_allocate_tls (void *mem) internal_function;
  45. /* Get size and alignment requirements of the static TLS block. */
  46. extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp)
  47. internal_function;
  48. extern void _dl_allocate_static_tls (struct link_map *map)
  49. internal_function attribute_hidden;
  50. extern int _dl_try_allocate_static_tls (struct link_map* map)
  51. internal_function attribute_hidden;
  52. /* Taken from glibc/elf/dl-reloc.c */
  53. #define CHECK_STATIC_TLS(sym_map) \
  54. do { \
  55. if (__builtin_expect ((sym_map)->l_tls_offset == NO_TLS_OFFSET, 0)) \
  56. _dl_allocate_static_tls (sym_map); \
  57. } while (0)
  58. #define TRY_STATIC_TLS(sym_map) \
  59. (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1) \
  60. || _dl_try_allocate_static_tls (sym_map) == 0)
  61. /* These are internal entry points to the two halves of _dl_allocate_tls,
  62. only used within rtld.c itself at startup time. */
  63. extern void *_dl_allocate_tls_storage (void)
  64. internal_function attribute_hidden;
  65. extern void *_dl_allocate_tls_init (void *) internal_function;
  66. /* Deallocate memory allocated with _dl_allocate_tls. */
  67. extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb) internal_function;
  68. extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
  69. /* Highest dtv index currently needed. */
  70. EXTERN size_t _dl_tls_max_dtv_idx;
  71. /* Flag signalling whether there are gaps in the module ID allocation. */
  72. EXTERN bool _dl_tls_dtv_gaps;
  73. /* Information about the dtv slots. */
  74. EXTERN struct dtv_slotinfo_list
  75. {
  76. size_t len;
  77. struct dtv_slotinfo_list *next;
  78. struct dtv_slotinfo
  79. {
  80. size_t gen;
  81. bool is_static;
  82. struct link_map *map;
  83. } slotinfo[0];
  84. } *_dl_tls_dtv_slotinfo_list;
  85. /* Number of modules in the static TLS block. */
  86. EXTERN size_t _dl_tls_static_nelem;
  87. /* Size of the static TLS block. */
  88. EXTERN size_t _dl_tls_static_size;
  89. /* Size actually allocated in the static TLS block. */
  90. EXTERN size_t _dl_tls_static_used;
  91. /* Alignment requirement of the static TLS block. */
  92. EXTERN size_t _dl_tls_static_align;
  93. /* Function pointer for catching TLS errors. */
  94. #if 1 /* def _LIBC_REENTRANT */
  95. EXTERN void **(*_dl_error_catch_tsd) (void) __attribute__ ((const));
  96. #endif
  97. /* Number of additional entries in the slotinfo array of each slotinfo
  98. list element. A large number makes it almost certain take we never
  99. have to iterate beyond the first element in the slotinfo list. */
  100. # define TLS_SLOTINFO_SURPLUS (62)
  101. /* Number of additional slots in the dtv allocated. */
  102. # define DTV_SURPLUS (14)
  103. /* Initial dtv of the main thread, not allocated with normal malloc. */
  104. EXTERN void *_dl_initial_dtv;
  105. /* Generation counter for the dtv. */
  106. EXTERN size_t _dl_tls_generation;
  107. EXTERN void (*_dl_init_static_tls) (struct link_map *);
  108. /* We have the auxiliary vector. */
  109. #define HAVE_AUX_VECTOR
  110. /* We can assume that the kernel always provides the AT_UID, AT_EUID,
  111. AT_GID, and AT_EGID values in the auxiliary vector from 2.4.0 or so on. */
  112. #if __ASSUME_AT_XID
  113. # define HAVE_AUX_XID
  114. #endif
  115. /* We can assume that the kernel always provides the AT_SECURE value
  116. in the auxiliary vector from 2.5.74 or so on. */
  117. #if __ASSUME_AT_SECURE
  118. # define HAVE_AUX_SECURE
  119. #endif
  120. /* Starting with one of the 2.4.0 pre-releases the Linux kernel passes
  121. up the page size information. */
  122. #if __ASSUME_AT_PAGESIZE
  123. # define HAVE_AUX_PAGESIZE
  124. #endif
  125. #endif