1 /* This file is included by pthread_create.c to define in libpthread
2    all the magic symbols required by libthread_db.
3 
4    Copyright (C) 2003-2022 Free Software Foundation, Inc.
5    This file is part of the GNU C Library.
6 
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
11 
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16 
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, see
19    <https://www.gnu.org/licenses/>.  */
20 
21 #include <stdint.h>
22 #include "thread_dbP.h"
23 #include <tls.h>
24 #include <ldsodefs.h>
25 
26 typedef struct pthread pthread;
27 typedef struct pthread_key_struct pthread_key_struct;
28 typedef struct pthread_key_data pthread_key_data;
29 typedef struct
30 {
31   struct pthread_key_data data[PTHREAD_KEY_2NDLEVEL_SIZE];
32 }
33 pthread_key_data_level2;
34 
35 typedef struct
36 {
37   union dtv dtv[UINT32_MAX / 2 / sizeof (union dtv)]; /* No constant bound.  */
38 } dtv;
39 
40 typedef struct link_map link_map;
41 typedef struct rtld_global rtld_global;
42 typedef struct dtv_slotinfo_list dtv_slotinfo_list;
43 typedef struct dtv_slotinfo dtv_slotinfo;
44 
45 #define schedparam_sched_priority schedparam.sched_priority
46 
47 #define eventbuf_eventmask eventbuf.eventmask
48 #define eventbuf_eventmask_event_bits eventbuf.eventmask.event_bits
49 
50 #define DESC(name, offset, obj) \
51   DB_DEFINE_DESC (name, 8 * sizeof (obj), 1, offset);
52 #define ARRAY_DESC(name, offset, obj) \
53   DB_DEFINE_DESC (name, \
54 		  8 * sizeof (obj)[0], sizeof (obj) / sizeof (obj)[0], \
55 		  offset);
56 /* Flexible arrays do not have a length that can be determined.  */
57 #define FLEXIBLE_ARRAY_DESC(name, offset, obj) \
58   DB_DEFINE_DESC (name, 8 * sizeof (obj)[0], 0, offset);
59 
60 #if TLS_TCB_AT_TP
61 # define dtvp header.dtv
62 #elif TLS_DTV_AT_TP
63 /* Special case hack.  If TLS_TCB_SIZE == 0 (on PowerPC), there is no TCB
64    containing the DTV at the TP, but actually the TCB lies behind the TP,
65    i.e. at the very end of the area covered by TLS_PRE_TCB_SIZE.  */
66 DESC (_thread_db_pthread_dtvp,
67       TLS_PRE_TCB_SIZE + offsetof (tcbhead_t, dtv)
68       - (TLS_TCB_SIZE == 0 ? sizeof (tcbhead_t) : 0), union dtv *)
69 #endif
70 
71 
72 #define DB_STRUCT(type) \
73   const uint32_t _thread_db_sizeof_##type = sizeof (type);
74 #define DB_STRUCT_FIELD(type, field) \
75   DESC (_thread_db_##type##_##field, \
76 	offsetof (type, field), ((type *) 0)->field)
77 #define DB_STRUCT_ARRAY_FIELD(type, field) \
78   ARRAY_DESC (_thread_db_##type##_##field, \
79 	      offsetof (type, field), ((type *) 0)->field)
80 #define DB_STRUCT_FLEXIBLE_ARRAY(type, field) \
81   FLEXIBLE_ARRAY_DESC (_thread_db_##type##_##field, \
82 		       offsetof (type, field), ((type *) 0)->field)
83 #define DB_VARIABLE(name) DESC (_thread_db_##name, 0, name)
84 #define DB_ARRAY_VARIABLE(name) ARRAY_DESC (_thread_db_##name, 0, name)
85 #define DB_SYMBOL(name)	/* Nothing.  */
86 #define DB_FUNCTION(name) /* Nothing.  */
87 #include "structs.def"
88 #undef DB_STRUCT
89 #undef DB_STRUCT_FIELD
90 #undef DB_SYMBOL
91 #undef DB_FUNCTION
92 #undef DB_VARIABLE
93 #undef DESC
94 
95 
96 
97 #ifdef DB_THREAD_SELF
98 # ifdef DB_THREAD_SELF_INCLUDE
99 #  include DB_THREAD_SELF_INCLUDE
100 # endif
101 
102 /* This macro is defined in the machine's tls.h using the three below.  */
103 # define CONST_THREAD_AREA(bits, value) \
104   const uint32_t _thread_db_const_thread_area = (value);
105 # define REGISTER_THREAD_AREA(bits, regofs, scale) \
106   DB_DEFINE_DESC (_thread_db_register##bits##_thread_area, \
107 		  bits, (scale), (regofs));
108 # define REGISTER(bits, size, regofs, bias) \
109   DB_DEFINE_DESC (_thread_db_register##bits, size, (uint32_t)(bias), (regofs));
110 
111 DB_THREAD_SELF
112 #endif
113