tlsdeschtab.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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>
  5. uClibc port by Baruch Siach <baruch@tkos.co.il>
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. #ifndef TLSDESCHTAB_H
  18. # define TLSDESCHTAB_H 1
  19. # ifdef SHARED
  20. # include <inline-hashtab.h>
  21. inline static int
  22. hash_tlsdesc (void *p)
  23. {
  24. struct tlsdesc_dynamic_arg *td = p;
  25. /* We know all entries are for the same module, so ti_offset is the
  26. only distinguishing entry. */
  27. return td->tlsinfo.ti_offset;
  28. }
  29. inline static int
  30. eq_tlsdesc (void *p, void *q)
  31. {
  32. struct tlsdesc_dynamic_arg *tdp = p, *tdq = q;
  33. return tdp->tlsinfo.ti_offset == tdq->tlsinfo.ti_offset;
  34. }
  35. inline static int
  36. map_generation (struct link_map *map)
  37. {
  38. size_t idx = map->l_tls_modid;
  39. struct dtv_slotinfo_list *listp = GL(dl_tls_dtv_slotinfo_list);
  40. /* Find the place in the dtv slotinfo list. */
  41. do
  42. {
  43. /* Does it fit in the array of this list element? */
  44. if (idx < listp->len)
  45. {
  46. /* We should never get here for a module in static TLS, so
  47. we can assume that, if the generation count is zero, we
  48. still haven't determined the generation count for this
  49. module. */
  50. if (listp->slotinfo[idx].gen)
  51. return listp->slotinfo[idx].gen;
  52. else
  53. break;
  54. }
  55. idx -= listp->len;
  56. listp = listp->next;
  57. }
  58. while (listp != NULL);
  59. /* If we get to this point, the module still hasn't been assigned an
  60. entry in the dtv slotinfo data structures, and it will when we're
  61. done with relocations. At that point, the module will get a
  62. generation number that is one past the current generation, so
  63. return exactly that. */
  64. return GL(dl_tls_generation) + 1;
  65. }
  66. void *
  67. internal_function
  68. _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
  69. {
  70. struct funcdesc_ht *ht;
  71. void **entry;
  72. struct tlsdesc_dynamic_arg *td, test;
  73. ht = map->l_tlsdesc_table;
  74. if (! ht)
  75. {
  76. ht = htab_create ();
  77. if (! ht)
  78. return 0;
  79. map->l_tlsdesc_table = ht;
  80. }
  81. test.tlsinfo.ti_module = map->l_tls_modid;
  82. test.tlsinfo.ti_offset = ti_offset;
  83. entry = htab_find_slot (ht, &test, 1, hash_tlsdesc, eq_tlsdesc);
  84. if (*entry)
  85. {
  86. td = *entry;
  87. return td;
  88. }
  89. *entry = td = _dl_malloc (sizeof (struct tlsdesc_dynamic_arg));
  90. /* This may be higher than the map's generation, but it doesn't
  91. matter much. Worst case, we'll have one extra DTV update per
  92. thread. */
  93. td->gen_count = map_generation (map);
  94. td->tlsinfo = test.tlsinfo;
  95. return td;
  96. }
  97. # endif /* SHARED */
  98. #endif