tls.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Definitions for thread-local data handling. linuxthreads/sparc 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, 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. typedef struct
  32. {
  33. void *tcb; /* Pointer to the TCB. Not necessary the
  34. thread descriptor used by libpthread. */
  35. dtv_t *dtv;
  36. void *self; /* Pointer to the thread descriptor. */
  37. int multiple_threads;
  38. } tcbhead_t;
  39. #else /* __ASSEMBLER__ */
  40. # include <tcb-offsets.h>
  41. #endif /* __ASSEMBLER__ */
  42. #ifdef HAVE_TLS_SUPPORT
  43. /* Signal that TLS support is available. */
  44. # define USE_TLS 1
  45. # ifndef __ASSEMBLER__
  46. /* Get system call information. */
  47. # include <sysdep.h>
  48. /* Get the thread descriptor definition. */
  49. # include <linuxthreads/descr.h>
  50. /* This is the size of the initial TCB. */
  51. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  52. /* Alignment requirements for the initial TCB. */
  53. # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
  54. /* This is the size of the TCB. */
  55. # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
  56. /* Alignment requirements for the TCB. */
  57. # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
  58. /* The TCB can have any size and the memory following the address the
  59. thread pointer points to is unspecified. Allocate the TCB there. */
  60. # define TLS_TCB_AT_TP 1
  61. /* Install the dtv pointer. The pointer passed is to the element with
  62. index -1 which contain the length. */
  63. # define INSTALL_DTV(descr, dtvp) \
  64. ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
  65. /* Install new dtv for current thread. */
  66. # define INSTALL_NEW_DTV(DTV) \
  67. (((tcbhead_t *) __thread_self)->dtv = (DTV))
  68. /* Return dtv of given thread descriptor. */
  69. # define GET_DTV(descr) \
  70. (((tcbhead_t *) (descr))->dtv)
  71. /* Code to initially initialize the thread pointer. */
  72. # define TLS_INIT_TP(descr, secondcall) \
  73. (__thread_self = (__typeof (__thread_self)) (descr), NULL)
  74. /* Return the address of the dtv for the current thread. */
  75. # define THREAD_DTV() \
  76. (((tcbhead_t *) __thread_self)->dtv)
  77. # endif
  78. #else
  79. # define NONTLS_INIT_TP \
  80. do { \
  81. static const tcbhead_t nontls_init_tp \
  82. = { .multiple_threads = 0 }; \
  83. __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
  84. } while (0)
  85. #endif /* USE_TLS */
  86. #endif /* tls.h */