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