tls.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Definitions for thread-local data handling. linuxthreads/IA-64 version.
  2. Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _TLS_H
  16. #define _TLS_H
  17. #ifndef __ASSEMBLER__
  18. # include <pt-machine.h>
  19. # include <stdbool.h>
  20. # include <stddef.h>
  21. /* Type for the dtv. */
  22. typedef union dtv
  23. {
  24. size_t counter;
  25. struct
  26. {
  27. void *val;
  28. bool is_static;
  29. } pointer;
  30. } dtv_t;
  31. #else /* __ASSEMBLER__ */
  32. # include <tcb-offsets.h>
  33. #endif /* __ASSEMBLER__ */
  34. #ifdef HAVE_TLS_SUPPORT
  35. /* Signal that TLS support is available. */
  36. # define USE_TLS 1
  37. # ifndef __ASSEMBLER__
  38. typedef struct
  39. {
  40. dtv_t *dtv;
  41. void *private;
  42. } tcbhead_t;
  43. /* This is the size of the initial TCB. */
  44. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  45. /* Alignment requirements for the initial TCB. */
  46. # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
  47. /* This is the size of the TCB. */
  48. # define TLS_TCB_SIZE sizeof (tcbhead_t)
  49. /* This is the size we need before TCB. */
  50. # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
  51. /* Alignment requirements for the TCB. */
  52. # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
  53. /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
  54. # define TLS_DTV_AT_TP 1
  55. /* Install the dtv pointer. The pointer passed is to the element with
  56. index -1 which contain the length. */
  57. # define INSTALL_DTV(tcbp, dtvp) \
  58. ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
  59. /* Install new dtv for current thread. */
  60. # define INSTALL_NEW_DTV(DTV) \
  61. (((tcbhead_t *)__thread_self)->dtv = (DTV))
  62. /* Return dtv of given thread descriptor. */
  63. # define GET_DTV(tcbp) \
  64. (((tcbhead_t *) (tcbp))->dtv)
  65. #if defined NEED_DL_SYSINFO
  66. # define INIT_SYSINFO \
  67. (((tcbhead_t *) __thread_self)->private = (void *) GLRO(dl_sysinfo))
  68. #else
  69. # define INIT_SYSINFO 0
  70. #endif
  71. /* Code to initially initialize the thread pointer. This might need
  72. special attention since 'errno' is not yet available and if the
  73. operation can cause a failure 'errno' must not be touched. */
  74. # define TLS_INIT_TP(tcbp, secondcall) \
  75. (__thread_self = (__typeof (__thread_self)) (tcbp), INIT_SYSINFO, NULL)
  76. /* Return the address of the dtv for the current thread. */
  77. # define THREAD_DTV() \
  78. (((tcbhead_t *)__thread_self)->dtv)
  79. /* Return the thread descriptor for the current thread. */
  80. # undef THREAD_SELF
  81. # define THREAD_SELF (__thread_self - 1)
  82. # undef INIT_THREAD_SELF
  83. # define INIT_THREAD_SELF(descr, nr) \
  84. (__thread_self = (struct _pthread_descr_struct *)(descr) + 1)
  85. # define TLS_MULTIPLE_THREADS_IN_TCB 1
  86. # endif
  87. #else
  88. # ifndef __ASSEMBLER__
  89. typedef struct
  90. {
  91. void *tcb;
  92. dtv_t *dtv;
  93. void *self;
  94. int multiple_threads;
  95. } tcbhead_t;
  96. # define NONTLS_INIT_TP \
  97. do { \
  98. static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
  99. __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
  100. } while (0)
  101. #endif
  102. #endif /* USE_TLS */
  103. #endif /* tls.h */