tls.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Definitions for thread-local data handling. NPTL/sparc version.
  2. Copyright (C) 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. #include <dl-sysdep.h>
  19. #ifndef __ASSEMBLER__
  20. # include <stdbool.h>
  21. # include <stddef.h>
  22. # include <stdint.h>
  23. # include <stdlib.h>
  24. # include <list.h>
  25. /* Type for the dtv. */
  26. typedef union dtv
  27. {
  28. size_t counter;
  29. struct
  30. {
  31. void *val;
  32. bool is_static;
  33. } pointer;
  34. } dtv_t;
  35. typedef struct
  36. {
  37. void *tcb; /* Pointer to the TCB. Not necessary the
  38. thread descriptor used by libpthread. */
  39. dtv_t *dtv;
  40. void *self;
  41. int multiple_threads;
  42. } tcbhead_t;
  43. #else /* __ASSEMBLER__ */
  44. # include <tcb-offsets.h>
  45. #endif /* __ASSEMBLER__ */
  46. /* We require TLS support in the tools. */
  47. #ifndef HAVE_TLS_SUPPORT
  48. # error "TLS support is required."
  49. #endif
  50. /* Signal that TLS support is available. */
  51. #define USE_TLS 1
  52. #ifndef __ASSEMBLER__
  53. /* Get system call information. */
  54. # include <sysdep.h>
  55. /* Get the thread descriptor definition. */
  56. # include <nptl/descr.h>
  57. register struct pthread *__thread_self __asm__("%g7");
  58. /* This is the size of the initial TCB. */
  59. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  60. /* Alignment requirements for the initial TCB. */
  61. # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
  62. /* This is the size of the TCB. */
  63. # define TLS_TCB_SIZE sizeof (struct pthread)
  64. /* Alignment requirements for the TCB. */
  65. # define TLS_TCB_ALIGN __alignof__ (struct pthread)
  66. /* The TCB can have any size and the memory following the address the
  67. thread pointer points to is unspecified. Allocate the TCB there. */
  68. # define TLS_TCB_AT_TP 1
  69. /* Install the dtv pointer. The pointer passed is to the element with
  70. index -1 which contain the length. */
  71. # define INSTALL_DTV(descr, dtvp) \
  72. ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
  73. /* Install new dtv for current thread. */
  74. # define INSTALL_NEW_DTV(DTV) \
  75. (((tcbhead_t *) __thread_self)->dtv = (DTV))
  76. /* Return dtv of given thread descriptor. */
  77. # define GET_DTV(descr) \
  78. (((tcbhead_t *) (descr))->dtv)
  79. /* Code to initially initialize the thread pointer. */
  80. # define TLS_INIT_TP(descr, secondcall) \
  81. (__thread_self = (__typeof (__thread_self)) (descr), NULL)
  82. /* Return the address of the dtv for the current thread. */
  83. # define THREAD_DTV() \
  84. (((tcbhead_t *) __thread_self)->dtv)
  85. /* Return the thread descriptor for the current thread. */
  86. #define THREAD_SELF __thread_self
  87. /* Magic for libthread_db to know how to do THREAD_SELF. */
  88. # define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
  89. # define DB_THREAD_SELF \
  90. REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
  91. /* Access to data in the thread descriptor is easy. */
  92. #define THREAD_GETMEM(descr, member) \
  93. descr->member
  94. #define THREAD_GETMEM_NC(descr, member, idx) \
  95. descr->member[idx]
  96. #define THREAD_SETMEM(descr, member, value) \
  97. descr->member = (value)
  98. #define THREAD_SETMEM_NC(descr, member, idx, value) \
  99. descr->member[idx] = (value)
  100. #endif /* !ASSEMBLER */
  101. #endif /* tls.h */