tls.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Definitions for thread-local data handling. linuxthreads/s390 version.
  2. Copyright (C) 2002, 2003, 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. typedef struct
  33. {
  34. void *tcb; /* Pointer to the TCB. Not necessary the
  35. thread descriptor used by libpthread. */
  36. dtv_t *dtv;
  37. void *self; /* Pointer to the thread descriptor. */
  38. int multiple_threads;
  39. } tcbhead_t;
  40. #else /* __ASSEMBLER__ */
  41. # include <tcb-offsets.h>
  42. #endif /* __ASSEMBLER__ */
  43. /* TLS is always supported if the tools support it. There are no
  44. kernel dependencies. To avoid bothering with the TLS support code
  45. at all, use configure --without-tls.
  46. We need USE_TLS to be consistently defined, for ldsodefs.h
  47. conditionals. */
  48. #ifdef HAVE_TLS_SUPPORT
  49. /* Signal that TLS support is available. */
  50. # define USE_TLS 1
  51. # ifndef __ASSEMBLER__
  52. /* Get system call information. */
  53. # include <sysdep.h>
  54. /* Get the thread descriptor definition. */
  55. # include <linuxthreads/descr.h>
  56. /* This is the size of the initial TCB. */
  57. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  58. /* Alignment requirements for the initial TCB. */
  59. # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
  60. /* This is the size of the TCB. */
  61. # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
  62. /* Alignment requirements for the TCB. */
  63. # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
  64. /* The TCB can have any size and the memory following the address the
  65. thread pointer points to is unspecified. Allocate the TCB there. */
  66. # define TLS_TCB_AT_TP 1
  67. /* Install the dtv pointer. The pointer passed is to the element with
  68. index -1 which contain the length. */
  69. # define INSTALL_DTV(descr, dtvp) \
  70. ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
  71. /* Install new dtv for current thread. */
  72. # define INSTALL_NEW_DTV(dtv) \
  73. (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
  74. /* Return dtv of given thread descriptor. */
  75. # define GET_DTV(descr) \
  76. (((tcbhead_t *) (descr))->dtv)
  77. /* Code to initially initialize the thread pointer. This might need
  78. special attention since 'errno' is not yet available and if the
  79. operation can cause a failure 'errno' must not be touched.
  80. The value of this macro is null if successful, or an error string. */
  81. # define TLS_INIT_TP(descr, secondcall) \
  82. ({ \
  83. void *_descr = (descr); \
  84. tcbhead_t *head = _descr; \
  85. \
  86. head->tcb = _descr; \
  87. /* For now the thread descriptor is at the same address. */ \
  88. head->self = _descr; \
  89. \
  90. __builtin_set_thread_pointer (_descr); \
  91. NULL; \
  92. })
  93. /* Return the address of the dtv for the current thread. */
  94. # define THREAD_DTV() \
  95. (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
  96. # endif /* __ASSEMBLER__ */
  97. #else /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
  98. # ifndef __ASSEMBLER__
  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 \
  104. = { .multiple_threads = 0 }; \
  105. INIT_THREAD_SELF (&nontls_init_tp, 0); \
  106. } while (0)
  107. # endif /* __ASSEMBLER__ */
  108. #endif /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
  109. #endif /* tls.h */