tls.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Definition for thread-local data handling. NPTL/ARM version.
  2. Copyright (C) 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 1
  18. #ifndef __ASSEMBLER__
  19. #include <dl-sysdep.h>
  20. # include <stdbool.h>
  21. # include <stddef.h>
  22. # include <stdint.h>
  23. /* Type for the dtv. */
  24. typedef union dtv
  25. {
  26. size_t counter;
  27. struct
  28. {
  29. void *val;
  30. bool is_static;
  31. } pointer;
  32. } dtv_t;
  33. #else /* __ASSEMBLER__ */
  34. # include <tcb-offsets.h>
  35. #endif /* __ASSEMBLER__ */
  36. /* We require TLS support in the tools. */
  37. #define HAVE_TLS_SUPPORT 1
  38. #define HAVE_TLS_MODEL_ATTRIBUTE 1
  39. #define HAVE___THREAD 1
  40. /* Signal that TLS support is available. */
  41. #define USE_TLS 1
  42. /* Like all other modern NPTL ports, ARM uses forced unwinding. */
  43. #define HAVE_FORCED_UNWIND
  44. #ifndef __ASSEMBLER__
  45. /* Get system call information. */
  46. # include <sysdep.h>
  47. /* The TP points to the start of the thread blocks. */
  48. # define TLS_DTV_AT_TP 1
  49. /* Get the thread descriptor definition. */
  50. # include <../../descr.h>
  51. typedef struct
  52. {
  53. dtv_t *dtv;
  54. void *private;
  55. } tcbhead_t;
  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 16
  60. /* This is the size of the TCB. */
  61. # define TLS_TCB_SIZE sizeof (tcbhead_t)
  62. /* This is the size we need before TCB. */
  63. # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
  64. /* Alignment requirements for the TCB. */
  65. # define TLS_TCB_ALIGN 16
  66. /* Install the dtv pointer. The pointer passed is to the element with
  67. index -1 which contain the length. */
  68. # define INSTALL_DTV(tcbp, dtvp) \
  69. (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1)
  70. /* Install new dtv for current thread. */
  71. # define INSTALL_NEW_DTV(dtv) \
  72. (THREAD_DTV() = (dtv))
  73. /* Return dtv of given thread descriptor. */
  74. # define GET_DTV(tcbp) \
  75. (((tcbhead_t *) (tcbp))->dtv)
  76. /* Code to initially initialize the thread pointer. This might need
  77. special attention since 'errno' is not yet available and if the
  78. operation can cause a failure 'errno' must not be touched. */
  79. # define TLS_INIT_TP(tcbp, secondcall) \
  80. ({ INTERNAL_SYSCALL_DECL (err); \
  81. long result_var; \
  82. result_var = INTERNAL_SYSCALL_ARM (set_tls, err, 1, (tcbp)); \
  83. INTERNAL_SYSCALL_ERROR_P (result_var, err) \
  84. ? "unknown error" : NULL; })
  85. /* Return the address of the dtv for the current thread. */
  86. # define THREAD_DTV() \
  87. (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
  88. /* Return the thread descriptor for the current thread. */
  89. # define THREAD_SELF \
  90. ((struct pthread *)__builtin_thread_pointer () - 1)
  91. /* Magic for libthread_db to know how to do THREAD_SELF. */
  92. # define DB_THREAD_SELF \
  93. CONST_THREAD_AREA (32, sizeof (struct pthread))
  94. /* Access to data in the thread descriptor is easy. */
  95. #define THREAD_GETMEM(descr, member) \
  96. descr->member
  97. #define THREAD_GETMEM_NC(descr, member, idx) \
  98. descr->member[idx]
  99. #define THREAD_SETMEM(descr, member, value) \
  100. descr->member = (value)
  101. #define THREAD_SETMEM_NC(descr, member, idx, value) \
  102. descr->member[idx] = (value)
  103. /* Initializing the thread pointer will generate a SIGILL if the syscall
  104. is not available. */
  105. #define TLS_INIT_TP_EXPENSIVE 1
  106. #endif /* __ASSEMBLER__ */
  107. #endif /* tls.h */