blob: 04078b9e7a7fc22f6878cc496ecf3e586106b9fb [file] [log] [blame]
bart5f57be92008-07-01 08:48:56 +00001/*
bart86562bd2009-02-16 19:43:56 +00002 This file is part of drd, a thread error detector.
bart5f57be92008-07-01 08:48:56 +00003
Elliott Hughesed398002017-06-21 14:41:24 -07004 Copyright (C) 2006-2017 Bart Van Assche <bvanassche@acm.org>.
bart5f57be92008-07-01 08:48:56 +00005
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307, USA.
20
21 The GNU General Public License is contained in the file COPYING.
22*/
23
bart1335ecc2009-02-14 16:10:53 +000024
bart09dc13f2009-02-14 15:13:31 +000025/*
26 * This header file contains the tool-internal interface for the code that
27 * processes client requests.
28 */
29
bart5f57be92008-07-01 08:48:56 +000030
sewardjaf44c822007-11-25 14:01:38 +000031#ifndef __DRD_CLIENTREQ_H
32#define __DRD_CLIENTREQ_H
33
34
bart3c1e9d82008-06-30 17:10:29 +000035#include "drd.h"
bart09dc13f2009-02-14 15:13:31 +000036#include "drd_basics.h" /* DRD_() */
bartd00bd222008-03-30 08:40:49 +000037
38
bart09dc13f2009-02-14 15:13:31 +000039/*
40 * While the client requests defined in the header file "drd.h" define a
41 * public interface between client programs and the DRD tool, the client
42 * requests defined below are a tool-internal interface. These last client
43 * requests must only be used by the source code in the various *_intercepts.c
44 * source files.
45 */
sewardjaf44c822007-11-25 14:01:38 +000046enum {
bart850f1992010-05-29 18:43:21 +000047 /* Declare the address and size of a variable with value
48 * PTHREAD_COND_INITIALIZER.
49 */
50 VG_USERREQ__SET_PTHREAD_COND_INITIALIZER = VG_USERREQ_TOOL_BASE('D', 'r'),
51 /* args: address, size. */
52
bartbedfd232009-03-26 19:07:15 +000053 /* To ask the drd tool to start a new segment in the specified thread. */
bart850f1992010-05-29 18:43:21 +000054 VG_USERREQ__DRD_START_NEW_SEGMENT,
bartbedfd232009-03-26 19:07:15 +000055 /* args: POSIX thread ID. */
sewardjaf44c822007-11-25 14:01:38 +000056
bartbedfd232009-03-26 19:07:15 +000057 /* Tell drd the pthread_t of the running thread. */
58 VG_USERREQ__SET_PTHREADID,
59 /* args: pthread_t. */
60 /* Ask drd that a the thread's state transition from */
61 /* VgTs_Zombie to VgTs_Empty is delayed until */
62 /* VG_USERREQ__POST_THREAD_JOIN is performed. */
63 VG_USERREQ__SET_JOINABLE,
64 /* args: pthread_t, Bool */
sewardjaf44c822007-11-25 14:01:38 +000065
bartdd75cdf2009-07-24 08:20:10 +000066 /* Tell DRD that the calling thread is about to enter pthread_create(). */
67 VG_USERREQ__ENTERING_PTHREAD_CREATE,
68 /* args: (none) */
69 /* Tell DRD that the calling thread has left pthread_create(). */
70 VG_USERREQ__LEFT_PTHREAD_CREATE,
71 /* args: (none) */
72
bartbedfd232009-03-26 19:07:15 +000073 /* To notify drd that a thread finished because */
74 /* pthread_thread_join() was called on it. */
75 VG_USERREQ__POST_THREAD_JOIN,
76 /* args: pthread_t (joinee) */
sewardjaf44c822007-11-25 14:01:38 +000077
bartbedfd232009-03-26 19:07:15 +000078 /* To notify drd before a pthread_cancel call. */
79 VG_USERREQ__PRE_THREAD_CANCEL,
80 /* args: pthread_t */
81 /* To notify drd after a pthread_cancel call. */
82 VG_USERREQ__POST_THREAD_CANCEL,
83 /* args: pthread_t, Bool */
bart0f099cd2008-09-27 12:36:48 +000084
bartbedfd232009-03-26 19:07:15 +000085 /* to notify the drd tool of a pthread_mutex_init call. */
86 VG_USERREQ__PRE_MUTEX_INIT,
87 /* args: Addr, MutexT */
88 /* to notify the drd tool of a pthread_mutex_init call. */
89 VG_USERREQ__POST_MUTEX_INIT,
90 /* args: Addr */
91 /* to notify the drd tool of a pthread_mutex_destroy call. */
92 VG_USERREQ__PRE_MUTEX_DESTROY,
93 /* args: Addr */
94 /* to notify the drd tool of a pthread_mutex_destroy call. */
95 VG_USERREQ__POST_MUTEX_DESTROY,
96 /* args: Addr, MutexT */
97 /* to notify the drd tool of pthread_mutex_lock calls */
98 VG_USERREQ__PRE_MUTEX_LOCK,
99 /* args: Addr, MutexT, Bool */
100 /* to notify the drd tool of pthread_mutex_lock calls */
101 VG_USERREQ__POST_MUTEX_LOCK,
102 /* args: Addr, Bool */
103 /* to notify the drd tool of pthread_mutex_unlock calls */
104 VG_USERREQ__PRE_MUTEX_UNLOCK,
105 /* args: Addr */
106 /* to notify the drd tool of pthread_mutex_unlock calls */
107 VG_USERREQ__POST_MUTEX_UNLOCK,
108 /* args: Addr */
109 /* to notify the drd tool of a pthread_spin_init/pthread_spin_unlock call */
110 VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK,
111 /* args: Addr */
112 /* to notify the drd tool of a pthread_spin_init/pthread_spin_unlock call */
113 VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK,
114 /* args: Addr */
sewardjaf44c822007-11-25 14:01:38 +0000115
116
bartbedfd232009-03-26 19:07:15 +0000117 /* to notify the drd tool of a pthread_cond_init call. */
118 VG_USERREQ__PRE_COND_INIT,
119 /* args: Addr */
120 /* to notify the drd tool of a pthread_cond_init call. */
121 VG_USERREQ__POST_COND_INIT,
122 /* args: Addr */
123 /* to notify the drd tool of a pthread_cond_destroy call. */
124 VG_USERREQ__PRE_COND_DESTROY,
125 /* args: Addr */
126 /* to notify the drd tool of a pthread_cond_destroy call. */
127 VG_USERREQ__POST_COND_DESTROY,
bartd36fa802012-12-24 10:22:14 +0000128 /* args: Addr cond, Bool destroy_succeeded */
bartbedfd232009-03-26 19:07:15 +0000129 VG_USERREQ__PRE_COND_WAIT,
130 /* args: Addr cond, Addr mutex, MutexT mt */
131 VG_USERREQ__POST_COND_WAIT,
132 /* args: Addr cond, Addr mutex, Bool took_lock*/
133 VG_USERREQ__PRE_COND_SIGNAL,
134 /* args: Addr cond */
135 VG_USERREQ__POST_COND_SIGNAL,
136 /* args: Addr cond */
137 VG_USERREQ__PRE_COND_BROADCAST,
138 /* args: Addr cond */
139 VG_USERREQ__POST_COND_BROADCAST,
140 /* args: Addr cond */
sewardjaf44c822007-11-25 14:01:38 +0000141
bartbedfd232009-03-26 19:07:15 +0000142 /* To notify the drd tool of a sem_init call. */
143 VG_USERREQ__PRE_SEM_INIT,
144 /* args: Addr sem, Word pshared, Word value */
145 /* To notify the drd tool of a sem_init call. */
146 VG_USERREQ__POST_SEM_INIT,
147 /* args: Addr sem */
148 /* To notify the drd tool of a sem_destroy call. */
149 VG_USERREQ__PRE_SEM_DESTROY,
150 /* args: Addr sem */
151 /* To notify the drd tool of a sem_destroy call. */
152 VG_USERREQ__POST_SEM_DESTROY,
153 /* args: Addr sem */
bart25f9f542009-07-23 16:31:39 +0000154 /* To notify the drd tool of a sem_open call. */
155 VG_USERREQ__PRE_SEM_OPEN,
156 /* args: Addr name, Word oflag, Word mode, Word value */
157 /* To notify the drd tool of a sem_open call. */
158 VG_USERREQ__POST_SEM_OPEN,
159 /* args: Addr sem, Word oflag, Word mode, Word value */
160 /* To notify the drd tool of a sem_close call. */
161 VG_USERREQ__PRE_SEM_CLOSE,
162 /* args: Addr sem */
163 /* To notify the drd tool of a sem_close call. */
164 VG_USERREQ__POST_SEM_CLOSE,
165 /* args: Addr sem */
bartbedfd232009-03-26 19:07:15 +0000166 /* To notify the drd tool of a sem_wait call. */
167 VG_USERREQ__PRE_SEM_WAIT,
168 /* args: Addr sem */
169 /* To notify the drd tool of a sem_wait call. */
170 VG_USERREQ__POST_SEM_WAIT,
171 /* args: Addr sem, Bool waited */
172 /* To notify the drd tool before a sem_post call. */
173 VG_USERREQ__PRE_SEM_POST,
174 /* args: Addr sem */
175 /* To notify the drd tool after a sem_post call. */
176 VG_USERREQ__POST_SEM_POST,
177 /* args: Addr sem, Bool waited */
sewardj85642922008-01-14 11:54:56 +0000178
bartbedfd232009-03-26 19:07:15 +0000179 /* To notify the drd tool of a pthread_barrier_init call. */
180 VG_USERREQ__PRE_BARRIER_INIT,
181 /* args: Addr barrier, BarrierT type, Word count, Bool reinit */
182 /* To notify the drd tool of a pthread_barrier_init call. */
183 VG_USERREQ__POST_BARRIER_INIT,
184 /* args: Addr barrier, BarrierT type */
185 /* To notify the drd tool of a pthread_barrier_destroy call. */
186 VG_USERREQ__PRE_BARRIER_DESTROY,
187 /* args: Addr barrier, BarrierT type. */
188 /* To notify the drd tool of a pthread_barrier_destroy call. */
189 VG_USERREQ__POST_BARRIER_DESTROY,
190 /* args: Addr barrier, BarrierT type. */
191 /* To notify the drd tool of a pthread_barrier_wait call. */
192 VG_USERREQ__PRE_BARRIER_WAIT,
193 /* args: Addr barrier, BarrierT type. */
194 /* To notify the drd tool of a pthread_barrier_wait call. */
195 VG_USERREQ__POST_BARRIER_WAIT,
196 /* args: Addr barrier, BarrierT type, Word has_waited, Word serializing */
sewardj85642922008-01-14 11:54:56 +0000197
bartbedfd232009-03-26 19:07:15 +0000198 /* To notify the drd tool of a pthread_rwlock_init call. */
199 VG_USERREQ__PRE_RWLOCK_INIT,
bart63eb9892014-03-19 18:48:01 +0000200 /* args: Addr rwlock */
201 /* To notify the drd tool of a pthread_rwlock_init call. */
202 VG_USERREQ__POST_RWLOCK_INIT,
203 /* args: Addr rwlock */
204 /* To notify the drd tool of a pthread_rwlock_destroy call. */
205 VG_USERREQ__PRE_RWLOCK_DESTROY,
bartd45d9952009-05-31 18:53:54 +0000206 /* args: Addr rwlock, RwLockT */
bartbedfd232009-03-26 19:07:15 +0000207 /* To notify the drd tool of a pthread_rwlock_destroy call. */
208 VG_USERREQ__POST_RWLOCK_DESTROY,
bartd45d9952009-05-31 18:53:54 +0000209 /* args: Addr rwlock, RwLockT */
bartbedfd232009-03-26 19:07:15 +0000210 /* To notify the drd tool of a pthread_rwlock_rdlock call. */
211 VG_USERREQ__PRE_RWLOCK_RDLOCK,
bartd45d9952009-05-31 18:53:54 +0000212 /* args: Addr rwlock, RwLockT */
bartbedfd232009-03-26 19:07:15 +0000213 /* To notify the drd tool of a pthread_rwlock_rdlock call. */
214 VG_USERREQ__POST_RWLOCK_RDLOCK,
bartd45d9952009-05-31 18:53:54 +0000215 /* args: Addr rwlock, RwLockT, Bool took_lock */
bartbedfd232009-03-26 19:07:15 +0000216 /* To notify the drd tool of a pthread_rwlock_wrlock call. */
217 VG_USERREQ__PRE_RWLOCK_WRLOCK,
bartd45d9952009-05-31 18:53:54 +0000218 /* args: Addr rwlock, RwLockT */
bartbedfd232009-03-26 19:07:15 +0000219 /* To notify the drd tool of a pthread_rwlock_wrlock call. */
220 VG_USERREQ__POST_RWLOCK_WRLOCK,
bartd45d9952009-05-31 18:53:54 +0000221 /* args: Addr rwlock, RwLockT, Bool took_lock */
bartbedfd232009-03-26 19:07:15 +0000222 /* To notify the drd tool of a pthread_rwlock_unlock call. */
223 VG_USERREQ__PRE_RWLOCK_UNLOCK,
bartd45d9952009-05-31 18:53:54 +0000224 /* args: Addr rwlock, RwLockT */
bartbedfd232009-03-26 19:07:15 +0000225 /* To notify the drd tool of a pthread_rwlock_unlock call. */
226 VG_USERREQ__POST_RWLOCK_UNLOCK
bartd45d9952009-05-31 18:53:54 +0000227 /* args: Addr rwlock, RwLockT, Bool unlocked */
bart00344642008-03-01 15:27:41 +0000228
sewardj8eb8bab2015-07-21 14:44:28 +0000229#if defined(VGO_solaris)
230 ,
231 /* To notify the drd tool of a bind_guard call from runtime linker. */
232 VG_USERREQ__RTLD_BIND_GUARD,
233 /* args: Int flags */
234 /* To notify the drd tool of a bind_clear call from runtime linker. */
235 VG_USERREQ__RTLD_BIND_CLEAR
236 /* args: Int flags */
237#endif /* VGO_solaris */
sewardjaf44c822007-11-25 14:01:38 +0000238};
239
bartd45d9952009-05-31 18:53:54 +0000240/**
bart09dc13f2009-02-14 15:13:31 +0000241 * Error checking on POSIX recursive mutexes, POSIX error checking mutexes,
bartd45d9952009-05-31 18:53:54 +0000242 * POSIX default mutexes and POSIX spinlocks happens the code in drd_mutex.c.
243 * The values defined below specify the mutex type.
bart09dc13f2009-02-14 15:13:31 +0000244 */
bartd45d9952009-05-31 18:53:54 +0000245typedef enum {
246 mutex_type_unknown = -1,
247 mutex_type_invalid_mutex = 0,
248 mutex_type_recursive_mutex = 1,
249 mutex_type_errorcheck_mutex = 2,
250 mutex_type_default_mutex = 3,
251 mutex_type_spinlock = 4,
bartf056aab2014-06-09 07:55:14 +0000252 mutex_type_cxa_guard = 5,
bartd45d9952009-05-31 18:53:54 +0000253} MutexT;
254
255/**
256 * Error checking on POSIX reader/writer locks and user-defined reader/writer
257 * locks happens by the code in drd_rwlock.c. The values defined below specify
258 * the rwlock type.
259 */
260typedef enum {
261 pthread_rwlock = 1,
262 user_rwlock = 2,
263} RwLockT;
sewardjaf44c822007-11-25 14:01:38 +0000264
bart09dc13f2009-02-14 15:13:31 +0000265/*
266 * Error checking on POSIX barriers and GOMP barriers happens by the same
267 * code. The integer values defined below specify the type of a barrier with
268 * a given client address.
269 */
bartd45d9952009-05-31 18:53:54 +0000270typedef enum {
271 pthread_barrier = 1,
272 gomp_barrier = 2,
273} BarrierT;
sewardjaf44c822007-11-25 14:01:38 +0000274
bart09dc13f2009-02-14 15:13:31 +0000275
bart7d5f5232011-03-13 09:08:10 +0000276extern Bool DRD_(g_free_is_write);
277
bart09dc13f2009-02-14 15:13:31 +0000278void DRD_(clientreq_init)(void);
bart5f57be92008-07-01 08:48:56 +0000279
bart3c1e9d82008-06-30 17:10:29 +0000280
sewardjaf44c822007-11-25 14:01:38 +0000281#endif // __DRD_CLIENTREQ_H