tls.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _TLS_H
  17. #define _TLS_H
  18. #ifndef __ASSEMBLER__
  19. # include <pt-machine.h>
  20. # include <stdbool.h>
  21. # include <stddef.h>
  22. /* Type for the dtv. */
  23. typedef union dtv
  24. {
  25. size_t counter;
  26. struct
  27. {
  28. void *val;
  29. bool is_static;
  30. } pointer;
  31. } dtv_t;
  32. #else /* __ASSEMBLER__ */
  33. # include <tcb-offsets.h>
  34. #endif /* __ASSEMBLER__ */
  35. #ifdef HAVE_TLS_SUPPORT
  36. /* Signal that TLS support is available. */
  37. # define USE_TLS 1
  38. # ifndef __ASSEMBLER__
  39. typedef struct
  40. {
  41. dtv_t *dtv;
  42. void *private;
  43. } tcbhead_t;
  44. /* This is the size of the initial TCB. */
  45. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  46. /* Alignment requirements for the initial TCB. */
  47. # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
  48. /* This is the size of the TCB. */
  49. # define TLS_TCB_SIZE sizeof (tcbhead_t)
  50. /* This is the size we need before TCB. */
  51. # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
  52. /* Alignment requirements for the TCB. */
  53. # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
  54. /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
  55. # define TLS_DTV_AT_TP 1
  56. /* Install the dtv pointer. The pointer passed is to the element with
  57. index -1 which contain the length. */
  58. # define INSTALL_DTV(tcbp, dtvp) \
  59. ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
  60. /* Install new dtv for current thread. */
  61. # define INSTALL_NEW_DTV(DTV) \
  62. (((tcbhead_t *)__thread_self)->dtv = (DTV))
  63. /* Return dtv of given thread descriptor. */
  64. # define GET_DTV(tcbp) \
  65. (((tcbhead_t *) (tcbp))->dtv)
  66. #if defined NEED_DL_SYSINFO
  67. # define INIT_SYSINFO \
  68. (((tcbhead_t *) __thread_self)->private = (void *) GLRO(dl_sysinfo))
  69. #else
  70. # define INIT_SYSINFO 0
  71. #endif
  72. /* Code to initially initialize the thread pointer. This might need
  73. special attention since 'errno' is not yet available and if the
  74. operation can cause a failure 'errno' must not be touched. */
  75. # define TLS_INIT_TP(tcbp, secondcall) \
  76. (__thread_self = (__typeof (__thread_self)) (tcbp), INIT_SYSINFO, NULL)
  77. /* Return the address of the dtv for the current thread. */
  78. # define THREAD_DTV() \
  79. (((tcbhead_t *)__thread_self)->dtv)
  80. /* Return the thread descriptor for the current thread. */
  81. # undef THREAD_SELF
  82. # define THREAD_SELF (__thread_self - 1)
  83. # undef INIT_THREAD_SELF
  84. # define INIT_THREAD_SELF(descr, nr) \
  85. (__thread_self = (struct _pthread_descr_struct *)(descr) + 1)
  86. # define TLS_MULTIPLE_THREADS_IN_TCB 1
  87. /* Get the thread descriptor definition. */
  88. # include <linuxthreads/descr.h>
  89. # endif
  90. #else
  91. # ifndef __ASSEMBLER__
  92. typedef struct
  93. {
  94. void *tcb;
  95. dtv_t *dtv;
  96. void *self;
  97. int multiple_threads;
  98. } tcbhead_t;
  99. /* Get the thread descriptor definition. */
  100. # include <linuxthreads/descr.h>
  101. # define NONTLS_INIT_TP \
  102. do { \
  103. static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
  104. __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
  105. } while (0)
  106. #endif
  107. #endif /* USE_TLS */
  108. #endif /* tls.h */