descr.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 _DESCR_H
  17. #define _DESCR_H 1
  18. #include <limits.h>
  19. #include <sched.h>
  20. #include <setjmp.h>
  21. #include <stdbool.h>
  22. #include <sys/types.h>
  23. #include <hp-timing.h>
  24. #include <list.h>
  25. #include <lowlevellock.h>
  26. #include <pthreaddef.h>
  27. #include "../nptl_db/thread_db.h"
  28. #include <tls.h>
  29. #ifdef HAVE_FORCED_UNWIND
  30. # include <unwind.h>
  31. #endif
  32. #define __need_res_state
  33. #include <resolv.h>
  34. #ifndef TCB_ALIGNMENT
  35. # define TCB_ALIGNMENT sizeof (double)
  36. #endif
  37. /* We keep thread specific data in a special data structure, a two-level
  38. array. The top-level array contains pointers to dynamically allocated
  39. arrays of a certain number of data pointers. So we can implement a
  40. sparse array. Each dynamic second-level array has
  41. PTHREAD_KEY_2NDLEVEL_SIZE
  42. entries. This value shouldn't be too large. */
  43. #define PTHREAD_KEY_2NDLEVEL_SIZE 32
  44. /* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
  45. keys in each subarray. */
  46. #define PTHREAD_KEY_1STLEVEL_SIZE \
  47. ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
  48. / PTHREAD_KEY_2NDLEVEL_SIZE)
  49. /* Internal version of the buffer to store cancellation handler
  50. information. */
  51. struct pthread_unwind_buf
  52. {
  53. struct
  54. {
  55. __jmp_buf jmp_buf;
  56. int mask_was_saved;
  57. } cancel_jmp_buf[1];
  58. union
  59. {
  60. /* This is the placeholder of the public version. */
  61. void *pad[4];
  62. struct
  63. {
  64. /* Pointer to the previous cleanup buffer. */
  65. struct pthread_unwind_buf *prev;
  66. /* Backward compatibility: state of the old-style cleanup
  67. handler at the time of the previous new-style cleanup handler
  68. installment. */
  69. struct _pthread_cleanup_buffer *cleanup;
  70. /* Cancellation type before the push call. */
  71. int canceltype;
  72. } data;
  73. } priv;
  74. };
  75. /* Opcodes and data types for communication with the signal handler to
  76. change user/group IDs. */
  77. struct xid_command
  78. {
  79. int syscall_no;
  80. long int id[3];
  81. volatile int cntr;
  82. };
  83. /* Thread descriptor data structure. */
  84. struct pthread
  85. {
  86. union
  87. {
  88. #if !defined(TLS_DTV_AT_TP)
  89. /* This overlaps the TCB as used for TLS without threads (see tls.h). */
  90. tcbhead_t header;
  91. #else
  92. struct
  93. {
  94. int multiple_threads;
  95. } header;
  96. #endif
  97. /* This extra padding has no special purpose, and this structure layout
  98. is private and subject to change without affecting the official ABI.
  99. We just have it here in case it might be convenient for some
  100. implementation-specific instrumentation hack or suchlike. */
  101. void *__padding[16];
  102. };
  103. /* This descriptor's link on the `stack_used' or `__stack_user' list. */
  104. list_t list;
  105. /* Thread ID - which is also a 'is this thread descriptor (and
  106. therefore stack) used' flag. */
  107. pid_t tid;
  108. /* Process ID - thread group ID in kernel speak. */
  109. pid_t pid;
  110. /* List of cleanup buffers. */
  111. struct _pthread_cleanup_buffer *cleanup;
  112. /* Unwind information. */
  113. struct pthread_unwind_buf *cleanup_jmp_buf;
  114. #define HAVE_CLEANUP_JMP_BUF
  115. /* Flags determining processing of cancellation. */
  116. int cancelhandling;
  117. /* Bit set if cancellation is disabled. */
  118. #define CANCELSTATE_BIT 0
  119. #define CANCELSTATE_BITMASK 0x01
  120. /* Bit set if asynchronous cancellation mode is selected. */
  121. #define CANCELTYPE_BIT 1
  122. #define CANCELTYPE_BITMASK 0x02
  123. /* Bit set if canceling has been initiated. */
  124. #define CANCELING_BIT 2
  125. #define CANCELING_BITMASK 0x04
  126. /* Bit set if canceled. */
  127. #define CANCELED_BIT 3
  128. #define CANCELED_BITMASK 0x08
  129. /* Bit set if thread is exiting. */
  130. #define EXITING_BIT 4
  131. #define EXITING_BITMASK 0x10
  132. /* Bit set if thread terminated and TCB is freed. */
  133. #define TERMINATED_BIT 5
  134. #define TERMINATED_BITMASK 0x20
  135. /* Bit set if thread is supposed to change XID. */
  136. #define SETXID_BIT 6
  137. #define SETXID_BITMASK 0x40
  138. /* Mask for the rest. Helps the compiler to optimize. */
  139. #define CANCEL_RESTMASK 0xffffff80
  140. #define CANCEL_ENABLED_AND_CANCELED(value) \
  141. (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
  142. | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
  143. #define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
  144. (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
  145. | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
  146. == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
  147. /* We allocate one block of references here. This should be enough
  148. to avoid allocating any memory dynamically for most applications. */
  149. struct pthread_key_data
  150. {
  151. /* Sequence number. We use uintptr_t to not require padding on
  152. 32- and 64-bit machines. On 64-bit machines it helps to avoid
  153. wrapping, too. */
  154. uintptr_t seq;
  155. /* Data pointer. */
  156. void *data;
  157. } specific_1stblock[PTHREAD_KEY_2NDLEVEL_SIZE];
  158. /* Flag which is set when specific data is set. */
  159. bool specific_used;
  160. /* Two-level array for the thread-specific data. */
  161. struct pthread_key_data *specific[PTHREAD_KEY_1STLEVEL_SIZE];
  162. /* True if events must be reported. */
  163. bool report_events;
  164. /* True if the user provided the stack. */
  165. bool user_stack;
  166. /* True if thread must stop at startup time. */
  167. bool stopped_start;
  168. /* Lock to synchronize access to the descriptor. */
  169. lll_lock_t lock;
  170. /* Lock for synchronizing setxid calls. */
  171. lll_lock_t setxid_futex;
  172. #if HP_TIMING_AVAIL
  173. /* Offset of the CPU clock at start thread start time. */
  174. hp_timing_t cpuclock_offset;
  175. #endif
  176. /* If the thread waits to join another one the ID of the latter is
  177. stored here.
  178. In case a thread is detached this field contains a pointer of the
  179. TCB if the thread itself. This is something which cannot happen
  180. in normal operation. */
  181. struct pthread *joinid;
  182. /* Check whether a thread is detached. */
  183. #define IS_DETACHED(pd) ((pd)->joinid == (pd))
  184. /* Flags. Including those copied from the thread attribute. */
  185. int flags;
  186. /* The result of the thread function. */
  187. void *result;
  188. /* Scheduling parameters for the new thread. */
  189. struct sched_param schedparam;
  190. int schedpolicy;
  191. /* Start position of the code to be executed and the argument passed
  192. to the function. */
  193. void *(*start_routine) (void *);
  194. void *arg;
  195. /* Debug state. */
  196. td_eventbuf_t eventbuf;
  197. /* Next descriptor with a pending event. */
  198. struct pthread *nextevent;
  199. #ifdef HAVE_FORCED_UNWIND
  200. /* Machine-specific unwind info. */
  201. struct _Unwind_Exception exc;
  202. #endif
  203. /* If nonzero pointer to area allocated for the stack and its
  204. size. */
  205. void *stackblock;
  206. size_t stackblock_size;
  207. /* Size of the included guard area. */
  208. size_t guardsize;
  209. /* This is what the user specified and what we will report. */
  210. size_t reported_guardsize;
  211. /* Resolver state. */
  212. struct __res_state res;
  213. /* This member must be last. */
  214. char end_padding[];
  215. #define PTHREAD_STRUCT_END_PADDING \
  216. (sizeof (struct pthread) - offsetof (struct pthread, end_padding))
  217. } __attribute ((aligned (TCB_ALIGNMENT)));
  218. #endif /* descr.h */