tls.h 3.5 KB

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