descr.h 7.5 KB

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