tls.h 4.1 KB

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