tls.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Copyright (C) 2005-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _TLS_H
  15. # define _TLS_H 1
  16. #ifndef __ASSEMBLER__
  17. # include <stdbool.h>
  18. # include <stddef.h>
  19. # include <stdint.h>
  20. /* Type for the dtv. */
  21. typedef union dtv
  22. {
  23. size_t counter;
  24. struct
  25. {
  26. void *val;
  27. bool is_static;
  28. } pointer;
  29. } dtv_t;
  30. #else /* __ASSEMBLER__ */
  31. # include <tcb-offsets.h>
  32. #endif /* __ASSEMBLER__ */
  33. /* We require TLS support in the tools. */
  34. #define HAVE_TLS_SUPPORT 1
  35. #define HAVE___THREAD 1
  36. #define HAVE_TLS_MODEL_ATTRIBUTE 1
  37. /* Signal that TLS support is available. */
  38. #define USE_TLS 1
  39. #ifndef __ASSEMBLER__
  40. /* Get system call information. */
  41. # include <sysdep.h>
  42. /* The TP points to the start of the thread blocks. */
  43. # define TLS_DTV_AT_TP 1
  44. /* Get the thread descriptor definition. */
  45. # include <../../descr.h>
  46. typedef struct
  47. {
  48. dtv_t *dtv;
  49. void *private;
  50. } tcbhead_t;
  51. #define READ_THREAD_POINTER() \
  52. ({ register void *__microblaze_thread_area __asm__ ("r21"); \
  53. __microblaze_thread_area; })
  54. /* This is the size of the initial TCB. */
  55. # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  56. /* Alignment requirements for the initial TCB. */
  57. # define TLS_INIT_TCB_ALIGN 16
  58. /* This is the size of the TCB. */
  59. # define TLS_TCB_SIZE sizeof (tcbhead_t)
  60. /* This is the size we need before TCB. */
  61. # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
  62. /* Alignment requirements for the TCB. */
  63. # define TLS_TCB_ALIGN 16
  64. /* Install the dtv pointer. The pointer passed is to the element with
  65. index -1 which contain the length. */
  66. # define INSTALL_DTV(tcbp, dtvp) \
  67. (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1)
  68. /* Install new dtv for current thread. */
  69. # define INSTALL_NEW_DTV(dtv) \
  70. (THREAD_DTV() = (dtv))
  71. /* Return dtv of given thread descriptor. */
  72. # define GET_DTV(tcbp) \
  73. (((tcbhead_t *) (tcbp))->dtv)
  74. /* Code to initially initialize the thread pointer.
  75. r21 is reserved for thread pointer. */
  76. # define TLS_INIT_TP(tcbp, secondcall) \
  77. ({ __asm__ __volatile__ ("or r21,r0,%0" : : "r" ((void *)tcbp)); NULL; })
  78. # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
  79. /* Return the address of the dtv for the current thread. */
  80. # define THREAD_DTV() \
  81. (((tcbhead_t *) READ_THREAD_POINTER())->dtv)
  82. /* Return the thread descriptor for the current thread. */
  83. # define THREAD_SELF \
  84. (((struct pthread *) READ_THREAD_POINTER()) - 1)
  85. /* Magic for libthread_db to know how to do THREAD_SELF. */
  86. # define DB_THREAD_SELF \
  87. CONST_THREAD_AREA (32, sizeof (struct pthread))
  88. /* Read member of the thread descriptor directly. */
  89. # define THREAD_GETMEM(descr, member) (descr->member)
  90. /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
  91. # define THREAD_GETMEM_NC(descr, member, idx) \
  92. (descr->member[idx])
  93. /* Set member of the thread descriptor directly. */
  94. # define THREAD_SETMEM(descr, member, value) \
  95. (descr->member = (value))
  96. /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
  97. # define THREAD_SETMEM_NC(descr, member, idx, value) \
  98. (descr->member[idx] = (value))
  99. /* Get and set the global scope generation counter in struct pthread. */
  100. # define THREAD_GSCOPE_FLAG_UNUSED 0
  101. # define THREAD_GSCOPE_FLAG_USED 1
  102. # define THREAD_GSCOPE_FLAG_WAIT 2
  103. # define THREAD_GSCOPE_RESET_FLAG() \
  104. do \
  105. { int __res \
  106. = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
  107. THREAD_GSCOPE_FLAG_UNUSED); \
  108. if (__res == THREAD_GSCOPE_FLAG_WAIT) \
  109. lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
  110. } \
  111. while (0)
  112. # define THREAD_GSCOPE_SET_FLAG() \
  113. do \
  114. { \
  115. THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
  116. atomic_write_barrier (); \
  117. } \
  118. while (0)
  119. # define THREAD_GSCOPE_WAIT() \
  120. GL (dl_wait_lookup_done) ()
  121. #endif /* __ASSEMBLER__ */
  122. #endif /* tls.h. */