drd.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. ----------------------------------------------------------------
  3. Notice that the following BSD-style license applies to this one
  4. file (drd.h) only. The rest of Valgrind is licensed under the
  5. terms of the GNU General Public License, version 2, unless
  6. otherwise indicated. See the COPYING file in the source
  7. distribution for details.
  8. ----------------------------------------------------------------
  9. This file is part of DRD, a Valgrind tool for verification of
  10. multithreaded programs.
  11. Copyright (C) 2006-2017 Bart Van Assche <bvanassche@acm.org>.
  12. All rights reserved.
  13. Redistribution and use in source and binary forms, with or without
  14. modification, are permitted provided that the following conditions
  15. are met:
  16. 1. Redistributions of source code must retain the above copyright
  17. notice, this list of conditions and the following disclaimer.
  18. 2. The origin of this software must not be misrepresented; you must
  19. not claim that you wrote the original software. If you use this
  20. software in a product, an acknowledgment in the product
  21. documentation would be appreciated but is not required.
  22. 3. Altered source versions must be plainly marked as such, and must
  23. not be misrepresented as being the original software.
  24. 4. The name of the author may not be used to endorse or promote
  25. products derived from this software without specific prior written
  26. permission.
  27. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  28. OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  31. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  35. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. ----------------------------------------------------------------
  39. Notice that the above BSD-style license applies to this one file
  40. (drd.h) only. The entire rest of Valgrind is licensed under
  41. the terms of the GNU General Public License, version 2. See the
  42. COPYING file in the source distribution for details.
  43. ----------------------------------------------------------------
  44. */
  45. #ifndef __VALGRIND_DRD_H
  46. #define __VALGRIND_DRD_H
  47. #include "valgrind.h"
  48. /** Obtain the thread ID assigned by Valgrind's core. */
  49. #define DRD_GET_VALGRIND_THREADID \
  50. (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
  51. VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID, \
  52. 0, 0, 0, 0, 0)
  53. /** Obtain the thread ID assigned by DRD. */
  54. #define DRD_GET_DRD_THREADID \
  55. (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
  56. VG_USERREQ__DRD_GET_DRD_THREAD_ID, \
  57. 0, 0, 0, 0, 0)
  58. /** Tell DRD not to complain about data races for the specified variable. */
  59. #define DRD_IGNORE_VAR(x) ANNOTATE_BENIGN_RACE_SIZED(&(x), sizeof(x), "")
  60. /** Tell DRD to no longer ignore data races for the specified variable. */
  61. #define DRD_STOP_IGNORING_VAR(x) \
  62. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_FINISH_SUPPRESSION, \
  63. &(x), sizeof(x), 0, 0, 0)
  64. /**
  65. * Tell DRD to trace all memory accesses for the specified variable
  66. * until the memory that was allocated for the variable is freed.
  67. */
  68. #define DRD_TRACE_VAR(x) \
  69. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_TRACE_ADDR, \
  70. &(x), sizeof(x), 0, 0, 0)
  71. /**
  72. * Tell DRD to stop tracing memory accesses for the specified variable.
  73. */
  74. #define DRD_STOP_TRACING_VAR(x) \
  75. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_STOP_TRACE_ADDR, \
  76. &(x), sizeof(x), 0, 0, 0)
  77. /**
  78. * @defgroup RaceDetectionAnnotations Data race detection annotations.
  79. *
  80. * @see See also the source file <a href="http://code.google.com/p/data-race-test/source/browse/trunk/dynamic_annotations/dynamic_annotations.h</a>
  81. * in the ThreadSanitizer project.
  82. */
  83. /*@{*/
  84. #ifndef __HELGRIND_H
  85. /**
  86. * Tell DRD to insert a happens-before mark. addr is the address of an object
  87. * that is not a pthread synchronization object.
  88. */
  89. #define ANNOTATE_HAPPENS_BEFORE(addr) \
  90. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE, \
  91. addr, 0, 0, 0, 0)
  92. /**
  93. * Tell DRD that the memory accesses executed after this annotation will
  94. * happen after all memory accesses performed before all preceding
  95. * ANNOTATE_HAPPENS_BEFORE(addr). addr is the address of an object that is not
  96. * a pthread synchronization object. Inserting a happens-after annotation
  97. * before any other thread has passed by a happens-before annotation for the
  98. * same address is an error.
  99. */
  100. #define ANNOTATE_HAPPENS_AFTER(addr) \
  101. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER, \
  102. addr, 0, 0, 0, 0)
  103. #else /* __HELGRIND_H */
  104. #undef ANNOTATE_CONDVAR_LOCK_WAIT
  105. #undef ANNOTATE_CONDVAR_WAIT
  106. #undef ANNOTATE_CONDVAR_SIGNAL
  107. #undef ANNOTATE_CONDVAR_SIGNAL_ALL
  108. #undef ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX
  109. #undef ANNOTATE_PUBLISH_MEMORY_RANGE
  110. #undef ANNOTATE_BARRIER_INIT
  111. #undef ANNOTATE_BARRIER_WAIT_BEFORE
  112. #undef ANNOTATE_BARRIER_WAIT_AFTER
  113. #undef ANNOTATE_BARRIER_DESTROY
  114. #undef ANNOTATE_PCQ_CREATE
  115. #undef ANNOTATE_PCQ_DESTROY
  116. #undef ANNOTATE_PCQ_PUT
  117. #undef ANNOTATE_PCQ_GET
  118. #undef ANNOTATE_BENIGN_RACE
  119. #undef ANNOTATE_BENIGN_RACE_SIZED
  120. #undef ANNOTATE_IGNORE_READS_BEGIN
  121. #undef ANNOTATE_IGNORE_READS_END
  122. #undef ANNOTATE_IGNORE_WRITES_BEGIN
  123. #undef ANNOTATE_IGNORE_WRITES_END
  124. #undef ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN
  125. #undef ANNOTATE_IGNORE_READS_AND_WRITES_END
  126. #undef ANNOTATE_NEW_MEMORY
  127. #undef ANNOTATE_TRACE_MEMORY
  128. #undef ANNOTATE_THREAD_NAME
  129. #endif /* __HELGRIND_H */
  130. /**
  131. * Tell DRD that waiting on the condition variable at address cv has succeeded
  132. * and a lock on the mutex at address mtx is now held. Since DRD always inserts
  133. * a happens before relation between the pthread_cond_signal() or
  134. * pthread_cond_broadcast() call that wakes up a pthread_cond_wait() or
  135. * pthread_cond_timedwait() call and the woken up thread, this macro has been
  136. * defined such that it has no effect.
  137. */
  138. #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, mtx) do { } while(0)
  139. /**
  140. * Tell DRD that the condition variable at address cv is about to be signaled.
  141. */
  142. #define ANNOTATE_CONDVAR_SIGNAL(cv) do { } while(0)
  143. /**
  144. * Tell DRD that the condition variable at address cv is about to be signaled.
  145. */
  146. #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) do { } while(0)
  147. /**
  148. * Tell DRD that waiting on condition variable at address cv succeeded and that
  149. * the memory operations performed after this annotation should be considered
  150. * to happen after the matching ANNOTATE_CONDVAR_SIGNAL(cv). Since this is the
  151. * default behavior of DRD, this macro and the macro above have been defined
  152. * such that they have no effect.
  153. */
  154. #define ANNOTATE_CONDVAR_WAIT(cv) do { } while(0)
  155. /**
  156. * Tell DRD to consider the memory operations that happened before a mutex
  157. * unlock event and after the subsequent mutex lock event on the same mutex as
  158. * ordered. This is how DRD always behaves, so this macro has been defined
  159. * such that it has no effect.
  160. */
  161. #define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mtx) do { } while(0)
  162. /** Deprecated -- don't use this annotation. */
  163. #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mtx) do { } while(0)
  164. /**
  165. * Tell DRD to handle the specified memory range like a pure happens-before
  166. * detector would do. Since this is how DRD always behaves, this annotation
  167. * has been defined such that it has no effect.
  168. */
  169. #define ANNOTATE_PUBLISH_MEMORY_RANGE(addr, size) do { } while(0)
  170. /** Deprecated -- don't use this annotation. */
  171. #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(addr, size) do { } while(0)
  172. /** Deprecated -- don't use this annotation. */
  173. #define ANNOTATE_SWAP_MEMORY_RANGE(addr, size) do { } while(0)
  174. #ifndef __HELGRIND_H
  175. /** Tell DRD that a reader-writer lock object has been initialized. */
  176. #define ANNOTATE_RWLOCK_CREATE(rwlock) \
  177. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE, \
  178. rwlock, 0, 0, 0, 0);
  179. /** Tell DRD that a reader-writer lock object has been destroyed. */
  180. #define ANNOTATE_RWLOCK_DESTROY(rwlock) \
  181. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY, \
  182. rwlock, 0, 0, 0, 0);
  183. /**
  184. * Tell DRD that a reader-writer lock has been acquired. is_w == 1 means that
  185. * a write lock has been obtained, is_w == 0 means that a read lock has been
  186. * obtained.
  187. */
  188. #define ANNOTATE_RWLOCK_ACQUIRED(rwlock, is_w) \
  189. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED, \
  190. rwlock, is_w, 0, 0, 0)
  191. #endif /* __HELGRIND_H */
  192. /**
  193. * Tell DRD that a reader lock has been acquired on a reader-writer
  194. * synchronization object.
  195. */
  196. #define ANNOTATE_READERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 0)
  197. /**
  198. * Tell DRD that a writer lock has been acquired on a reader-writer
  199. * synchronization object.
  200. */
  201. #define ANNOTATE_WRITERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 1)
  202. #ifndef __HELGRIND_H
  203. /**
  204. * Tell DRD that a reader-writer lock is about to be released. is_w == 1 means
  205. * that a write lock is about to be released, is_w == 0 means that a read lock
  206. * is about to be released.
  207. */
  208. #define ANNOTATE_RWLOCK_RELEASED(rwlock, is_w) \
  209. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED, \
  210. rwlock, is_w, 0, 0, 0);
  211. #endif /* __HELGRIND_H */
  212. /**
  213. * Tell DRD that a reader lock is about to be released.
  214. */
  215. #define ANNOTATE_READERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 0)
  216. /**
  217. * Tell DRD that a writer lock is about to be released.
  218. */
  219. #define ANNOTATE_WRITERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 1)
  220. /** Tell DRD that a semaphore object is going to be initialized. */
  221. #define ANNOTATE_SEM_INIT_PRE(sem, value) \
  222. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_INIT_PRE, \
  223. sem, value, 0, 0, 0);
  224. /** Tell DRD that a semaphore object has been destroyed. */
  225. #define ANNOTATE_SEM_DESTROY_POST(sem) \
  226. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_DESTROY_POST, \
  227. sem, 0, 0, 0, 0);
  228. /** Tell DRD that a semaphore is going to be acquired. */
  229. #define ANNOTATE_SEM_WAIT_PRE(sem) \
  230. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_PRE, \
  231. sem, 0, 0, 0, 0)
  232. /** Tell DRD that a semaphore has been acquired. */
  233. #define ANNOTATE_SEM_WAIT_POST(sem) \
  234. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_POST, \
  235. sem, 0, 0, 0, 0)
  236. /** Tell DRD that a semaphore is going to be released. */
  237. #define ANNOTATE_SEM_POST_PRE(sem) \
  238. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_POST_PRE, \
  239. sem, 0, 0, 0, 0)
  240. /*
  241. * Report that a barrier has been initialized with a given barrier count. The
  242. * third argument specifies whether or not reinitialization is allowed, that
  243. * is, whether or not it is allowed to call barrier_init() several times
  244. * without calling barrier_destroy().
  245. */
  246. #define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
  247. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
  248. "ANNOTATE_BARRIER_INIT", barrier, \
  249. count, reinitialization_allowed, 0)
  250. /* Report that a barrier has been destroyed. */
  251. #define ANNOTATE_BARRIER_DESTROY(barrier) \
  252. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
  253. "ANNOTATE_BARRIER_DESTROY", \
  254. barrier, 0, 0, 0)
  255. /* Report that the calling thread is about to start waiting for a barrier. */
  256. #define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
  257. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
  258. "ANNOTATE_BARRIER_WAIT_BEFORE", \
  259. barrier, 0, 0, 0)
  260. /* Report that the calling thread has just finished waiting for a barrier. */
  261. #define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
  262. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
  263. "ANNOTATE_BARRIER_WAIT_AFTER", \
  264. barrier, 0, 0, 0)
  265. /**
  266. * Tell DRD that a FIFO queue has been created. The abbreviation PCQ stands for
  267. * <em>producer-consumer</em>.
  268. */
  269. #define ANNOTATE_PCQ_CREATE(pcq) do { } while(0)
  270. /** Tell DRD that a FIFO queue has been destroyed. */
  271. #define ANNOTATE_PCQ_DESTROY(pcq) do { } while(0)
  272. /**
  273. * Tell DRD that an element has been added to the FIFO queue at address pcq.
  274. */
  275. #define ANNOTATE_PCQ_PUT(pcq) do { } while(0)
  276. /**
  277. * Tell DRD that an element has been removed from the FIFO queue at address pcq,
  278. * and that DRD should insert a happens-before relationship between the memory
  279. * accesses that occurred before the corresponding ANNOTATE_PCQ_PUT(pcq)
  280. * annotation and the memory accesses after this annotation. Correspondence
  281. * between PUT and GET annotations happens in FIFO order. Since locking
  282. * of the queue is needed anyway to add elements to or to remove elements from
  283. * the queue, for DRD all four FIFO annotations are defined as no-ops.
  284. */
  285. #define ANNOTATE_PCQ_GET(pcq) do { } while(0)
  286. /**
  287. * Tell DRD that data races at the specified address are expected and must not
  288. * be reported.
  289. */
  290. #define ANNOTATE_BENIGN_RACE(addr, descr) \
  291. ANNOTATE_BENIGN_RACE_SIZED(addr, sizeof(*addr), descr)
  292. /* Same as ANNOTATE_BENIGN_RACE(addr, descr), but applies to
  293. the memory range [addr, addr + size). */
  294. #define ANNOTATE_BENIGN_RACE_SIZED(addr, size, descr) \
  295. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_SUPPRESSION, \
  296. addr, size, 0, 0, 0)
  297. /** Tell DRD to ignore all reads performed by the current thread. */
  298. #define ANNOTATE_IGNORE_READS_BEGIN() \
  299. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \
  300. 0, 0, 0, 0, 0);
  301. /** Tell DRD to no longer ignore the reads performed by the current thread. */
  302. #define ANNOTATE_IGNORE_READS_END() \
  303. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \
  304. 1, 0, 0, 0, 0);
  305. /** Tell DRD to ignore all writes performed by the current thread. */
  306. #define ANNOTATE_IGNORE_WRITES_BEGIN() \
  307. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \
  308. 0, 0, 0, 0, 0)
  309. /** Tell DRD to no longer ignore the writes performed by the current thread. */
  310. #define ANNOTATE_IGNORE_WRITES_END() \
  311. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \
  312. 1, 0, 0, 0, 0)
  313. /** Tell DRD to ignore all memory accesses performed by the current thread. */
  314. #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
  315. do { ANNOTATE_IGNORE_READS_BEGIN(); ANNOTATE_IGNORE_WRITES_BEGIN(); } while(0)
  316. /**
  317. * Tell DRD to no longer ignore the memory accesses performed by the current
  318. * thread.
  319. */
  320. #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
  321. do { ANNOTATE_IGNORE_READS_END(); ANNOTATE_IGNORE_WRITES_END(); } while(0)
  322. /**
  323. * Tell DRD that size bytes starting at addr has been allocated by a custom
  324. * memory allocator.
  325. */
  326. #define ANNOTATE_NEW_MEMORY(addr, size) \
  327. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_CLEAN_MEMORY, \
  328. addr, size, 0, 0, 0)
  329. /** Ask DRD to report every access to the specified address. */
  330. #define ANNOTATE_TRACE_MEMORY(addr) DRD_TRACE_VAR(*(char*)(addr))
  331. /**
  332. * Tell DRD to assign the specified name to the current thread. This name will
  333. * be used in error messages printed by DRD.
  334. */
  335. #define ANNOTATE_THREAD_NAME(name) \
  336. VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_SET_THREAD_NAME, \
  337. name, 0, 0, 0, 0)
  338. /*@}*/
  339. /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
  340. This enum comprises an ABI exported by Valgrind to programs
  341. which use client requests. DO NOT CHANGE THE ORDER OF THESE
  342. ENTRIES, NOR DELETE ANY -- add new ones at the end.
  343. */
  344. enum {
  345. /* Ask the DRD tool to discard all information about memory accesses */
  346. /* and client objects for the specified range. This client request is */
  347. /* binary compatible with the similarly named Helgrind client request. */
  348. VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),
  349. /* args: Addr, SizeT. */
  350. /* Ask the DRD tool the thread ID assigned by Valgrind. */
  351. VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'),
  352. /* args: none. */
  353. /* Ask the DRD tool the thread ID assigned by DRD. */
  354. VG_USERREQ__DRD_GET_DRD_THREAD_ID,
  355. /* args: none. */
  356. /* To tell the DRD tool to suppress data race detection on the */
  357. /* specified address range. */
  358. VG_USERREQ__DRD_START_SUPPRESSION,
  359. /* args: start address, size in bytes */
  360. /* To tell the DRD tool no longer to suppress data race detection on */
  361. /* the specified address range. */
  362. VG_USERREQ__DRD_FINISH_SUPPRESSION,
  363. /* args: start address, size in bytes */
  364. /* To ask the DRD tool to trace all accesses to the specified range. */
  365. VG_USERREQ__DRD_START_TRACE_ADDR,
  366. /* args: Addr, SizeT. */
  367. /* To ask the DRD tool to stop tracing accesses to the specified range. */
  368. VG_USERREQ__DRD_STOP_TRACE_ADDR,
  369. /* args: Addr, SizeT. */
  370. /* Tell DRD whether or not to record memory loads in the calling thread. */
  371. VG_USERREQ__DRD_RECORD_LOADS,
  372. /* args: Bool. */
  373. /* Tell DRD whether or not to record memory stores in the calling thread. */
  374. VG_USERREQ__DRD_RECORD_STORES,
  375. /* args: Bool. */
  376. /* Set the name of the thread that performs this client request. */
  377. VG_USERREQ__DRD_SET_THREAD_NAME,
  378. /* args: null-terminated character string. */
  379. /* Tell DRD that a DRD annotation has not yet been implemented. */
  380. VG_USERREQ__DRD_ANNOTATION_UNIMP,
  381. /* args: char*. */
  382. /* Tell DRD that a user-defined semaphore synchronization object
  383. * is about to be created. */
  384. VG_USERREQ__DRD_ANNOTATE_SEM_INIT_PRE,
  385. /* args: Addr, UInt value. */
  386. /* Tell DRD that a user-defined semaphore synchronization object
  387. * has been destroyed. */
  388. VG_USERREQ__DRD_ANNOTATE_SEM_DESTROY_POST,
  389. /* args: Addr. */
  390. /* Tell DRD that a user-defined semaphore synchronization
  391. * object is going to be acquired (semaphore wait). */
  392. VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_PRE,
  393. /* args: Addr. */
  394. /* Tell DRD that a user-defined semaphore synchronization
  395. * object has been acquired (semaphore wait). */
  396. VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_POST,
  397. /* args: Addr. */
  398. /* Tell DRD that a user-defined semaphore synchronization
  399. * object is about to be released (semaphore post). */
  400. VG_USERREQ__DRD_ANNOTATE_SEM_POST_PRE,
  401. /* args: Addr. */
  402. /* Tell DRD to ignore the inter-thread ordering introduced by a mutex. */
  403. VG_USERREQ__DRD_IGNORE_MUTEX_ORDERING,
  404. /* args: Addr. */
  405. /* Tell DRD that a user-defined reader-writer synchronization object
  406. * has been created. */
  407. VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE
  408. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 14,
  409. /* args: Addr. */
  410. /* Tell DRD that a user-defined reader-writer synchronization object
  411. * is about to be destroyed. */
  412. VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY
  413. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 15,
  414. /* args: Addr. */
  415. /* Tell DRD that a lock on a user-defined reader-writer synchronization
  416. * object has been acquired. */
  417. VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED
  418. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 17,
  419. /* args: Addr, Int is_rw. */
  420. /* Tell DRD that a lock on a user-defined reader-writer synchronization
  421. * object is about to be released. */
  422. VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED
  423. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 18,
  424. /* args: Addr, Int is_rw. */
  425. /* Tell DRD that a Helgrind annotation has not yet been implemented. */
  426. VG_USERREQ__HELGRIND_ANNOTATION_UNIMP
  427. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 32,
  428. /* args: char*. */
  429. /* Tell DRD to insert a happens-before annotation. */
  430. VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE
  431. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 33,
  432. /* args: Addr. */
  433. /* Tell DRD to insert a happens-after annotation. */
  434. VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER
  435. = VG_USERREQ_TOOL_BASE('H','G') + 256 + 34,
  436. /* args: Addr. */
  437. };
  438. /**
  439. * @addtogroup RaceDetectionAnnotations
  440. */
  441. /*@{*/
  442. #ifdef __cplusplus
  443. /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads.
  444. Instead of doing
  445. ANNOTATE_IGNORE_READS_BEGIN();
  446. ... = x;
  447. ANNOTATE_IGNORE_READS_END();
  448. one can use
  449. ... = ANNOTATE_UNPROTECTED_READ(x); */
  450. template <typename T>
  451. inline T ANNOTATE_UNPROTECTED_READ(const volatile T& x) {
  452. ANNOTATE_IGNORE_READS_BEGIN();
  453. const T result = x;
  454. ANNOTATE_IGNORE_READS_END();
  455. return result;
  456. }
  457. /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
  458. #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
  459. namespace { \
  460. static class static_var##_annotator \
  461. { \
  462. public: \
  463. static_var##_annotator() \
  464. { \
  465. ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \
  466. #static_var ": " description); \
  467. } \
  468. } the_##static_var##_annotator; \
  469. }
  470. #endif
  471. /*@}*/
  472. #endif /* __VALGRIND_DRD_H */