tls.h 3.5 KB

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