time.h: Add CLOCK_TAI
[uclibc-ng.git] / ldso / include / tlsdeschtab.h
blob056f859b75b8cc08fa1e6f5e6cb24b3ff3e1e82f
1 /* Hash table for TLS descriptors.
2 Copyright (C) 2005-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Alexandre Oliva <aoliva@redhat.com>
6 uClibc port by Baruch Siach <baruch@tkos.co.il>
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef TLSDESCHTAB_H
23 # define TLSDESCHTAB_H 1
25 # ifdef SHARED
27 # include <inline-hashtab.h>
29 inline static int
30 hash_tlsdesc (void *p)
32 struct tlsdesc_dynamic_arg *td = p;
34 /* We know all entries are for the same module, so ti_offset is the
35 only distinguishing entry. */
36 return td->tlsinfo.ti_offset;
39 inline static int
40 eq_tlsdesc (void *p, void *q)
42 struct tlsdesc_dynamic_arg *tdp = p, *tdq = q;
44 return tdp->tlsinfo.ti_offset == tdq->tlsinfo.ti_offset;
47 inline static int
48 map_generation (struct link_map *map)
50 size_t idx = map->l_tls_modid;
51 struct dtv_slotinfo_list *listp = GL(dl_tls_dtv_slotinfo_list);
53 /* Find the place in the dtv slotinfo list. */
56 /* Does it fit in the array of this list element? */
57 if (idx < listp->len)
59 /* We should never get here for a module in static TLS, so
60 we can assume that, if the generation count is zero, we
61 still haven't determined the generation count for this
62 module. */
63 if (listp->slotinfo[idx].gen)
64 return listp->slotinfo[idx].gen;
65 else
66 break;
68 idx -= listp->len;
69 listp = listp->next;
71 while (listp != NULL);
73 /* If we get to this point, the module still hasn't been assigned an
74 entry in the dtv slotinfo data structures, and it will when we're
75 done with relocations. At that point, the module will get a
76 generation number that is one past the current generation, so
77 return exactly that. */
78 return GL(dl_tls_generation) + 1;
81 void *
82 internal_function
83 _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
85 struct funcdesc_ht *ht;
86 void **entry;
87 struct tlsdesc_dynamic_arg *td, test;
89 ht = map->l_tlsdesc_table;
90 if (! ht)
92 ht = htab_create ();
93 if (! ht)
94 return 0;
95 map->l_tlsdesc_table = ht;
98 test.tlsinfo.ti_module = map->l_tls_modid;
99 test.tlsinfo.ti_offset = ti_offset;
100 entry = htab_find_slot (ht, &test, 1, hash_tlsdesc, eq_tlsdesc);
101 if (entry == NULL)
102 _dl_exit(1);
103 if (*entry)
105 td = *entry;
106 return td;
109 *entry = td = _dl_malloc (sizeof (struct tlsdesc_dynamic_arg));
110 /* This may be higher than the map's generation, but it doesn't
111 matter much. Worst case, we'll have one extra DTV update per
112 thread. */
113 td->gen_count = map_generation (map);
114 td->tlsinfo = test.tlsinfo;
116 return td;
119 # endif /* SHARED */
121 #endif