tls.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Definition for thread-local data handling. linuxthreads/SH 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. # include <pt-machine.h>
  18. #ifndef __ASSEMBLER__
  19. # include <stdbool.h>
  20. # include <stddef.h>
  21. # include <stdint.h>
  22. /* Type for the dtv. */
  23. typedef union dtv
  24. {
  25. size_t counter;
  26. void *pointer;
  27. } dtv_t;
  28. typedef struct
  29. {
  30. void *tcb; /* Pointer to the TCB. Not necessary the
  31. thread descriptor used by libpthread. */
  32. dtv_t *dtv;
  33. void *self; /* Pointer to the thread descriptor. */
  34. } tcbhead_t;
  35. /* We can support TLS only if the floating-stack support is available. */
  36. #if defined FLOATING_STACKS && defined HAVE_TLS_SUPPORT
  37. /* Get system call information. */
  38. # include <sysdep.h>
  39. /* Signal that TLS support is available. */
  40. //# define USE_TLS 1
  41. /* Get the thread descriptor definition. */
  42. # include <linuxthreads/descr.h>
  43. /* This is the size of the initial TCB. */
  44. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  45. /* Alignment requirements for the initial TCB. */
  46. # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
  47. /* This is the size of the TCB. */
  48. # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
  49. /* Alignment requirements for the TCB. */
  50. # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
  51. /* The TLS blocks start right after the TCB. */
  52. # define TLS_DTV_AT_TP 1
  53. /* Install the dtv pointer. The pointer passed is to the element with
  54. index -1 which contain the length. */
  55. # define INSTALL_DTV(descr, dtvp) \
  56. ((tcbhead_t *) (descr))->dtv = dtvp + 1
  57. /* Install new dtv for current thread. */
  58. # define INSTALL_NEW_DTV(dtv) \
  59. ({ struct _pthread_descr_struct *__descr; \
  60. THREAD_SETMEM (__descr, p_header.data.dtvp, (dtv)); })
  61. /* Return dtv of given thread descriptor. */
  62. # define GET_DTV(descr) \
  63. (((tcbhead_t *) (descr))->dtv)
  64. /* Code to initially initialize the thread pointer. This might need
  65. special attention since 'errno' is not yet available and if the
  66. operation can cause a failure 'errno' must not be touched. */
  67. # define TLS_INIT_TP(descr, secondcall) \
  68. ({ \
  69. void *_descr = (descr); \
  70. int result; \
  71. tcbhead_t *head = _descr; \
  72. \
  73. head->tcb = _descr; \
  74. /* For now the thread descriptor is at the same address. */ \
  75. head->self = _descr; \
  76. \
  77. __asm__ ("ldc %0,gbr" : : "r" (_descr)); \
  78. \
  79. 0; \
  80. })
  81. /* Return the address of the dtv for the current thread. */
  82. # define THREAD_DTV() \
  83. ({ struct _pthread_descr_struct *__descr; \
  84. THREAD_GETMEM (__descr, p_header.data.dtvp); })
  85. #endif /* FLOATING_STACKS && HAVE_TLS_SUPPORT */
  86. #endif /* __ASSEMBLER__ */
  87. #endif /* tls.h */