tls.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Definitions for thread-local data handling. linuxthreads/Alpha 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. dtv_t *dtv;
  34. /* Reserved for the thread implementation. Unused in LinuxThreads. */
  35. void *private;
  36. } tcbhead_t;
  37. #endif
  38. #ifdef HAVE_TLS_SUPPORT
  39. /* Signal that TLS support is available. */
  40. # define USE_TLS 1
  41. # ifndef __ASSEMBLER__
  42. /* Get system call information. */
  43. # include <sysdep.h>
  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. /* Alignment requirements for the TCB. */
  51. # define TLS_TCB_ALIGN __alignof__ (tcbhead_t)
  52. /* This is the size we need before TCB. */
  53. # define TLS_PRE_TCB_SIZE sizeof (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 *)__builtin_thread_pointer ())->dtv = (DTV))
  63. /* Return dtv of given thread descriptor. */
  64. # define GET_DTV(TCBP) \
  65. (((tcbhead_t *) (TCBP))->dtv)
  66. /* Code to initially initialize the thread pointer. This might need
  67. special attention since 'errno' is not yet available and if the
  68. operation can cause a failure 'errno' must not be touched. */
  69. # define TLS_INIT_TP(TCBP, SECONDCALL) \
  70. (__builtin_set_thread_pointer (TCBP), 0)
  71. /* Return the address of the dtv for the current thread. */
  72. # define THREAD_DTV() \
  73. (((tcbhead_t *)__builtin_thread_pointer ())->dtv)
  74. /* Return the thread descriptor for the current thread. */
  75. # undef THREAD_SELF
  76. # define THREAD_SELF \
  77. ((pthread_descr)__builtin_thread_pointer () - 1)
  78. # undef INIT_THREAD_SELF
  79. # define INIT_THREAD_SELF(DESCR, NR) \
  80. __builtin_set_thread_pointer ((struct _pthread_descr_struct *)(DESCR) + 1)
  81. /* Get the thread descriptor definition. */
  82. # include <linuxthreads/descr.h>
  83. /* ??? Generic bits of LinuxThreads may call these macros with
  84. DESCR set to NULL. We are expected to be able to reference
  85. the "current" value.
  86. In our case, we'd really prefer to use DESCR, since lots of
  87. PAL_code calls would be expensive. We can only trust that
  88. the compiler does its job and unifies the multiple
  89. __builtin_thread_pointer instances. */
  90. #define THREAD_GETMEM(descr, member) \
  91. ((void) sizeof (descr), THREAD_SELF->member)
  92. #define THREAD_GETMEM_NC(descr, member) \
  93. ((void) sizeof (descr), THREAD_SELF->member)
  94. #define THREAD_SETMEM(descr, member, value) \
  95. ((void) sizeof (descr), THREAD_SELF->member = (value))
  96. #define THREAD_SETMEM_NC(descr, member, value) \
  97. ((void) sizeof (descr), THREAD_SELF->member = (value))
  98. # endif /* HAVE_TLS_SUPPORT */
  99. #endif /* __ASSEMBLER__ */
  100. #endif /* tls.h */