blob: 76c60b5862a52196faa33cb2029acf4b26387c33 [file] [log] [blame]
bart3c1e9d82008-06-30 17:10:29 +00001
2/*
3 ----------------------------------------------------------------
4
5 Notice that the following BSD-style license applies to this one
6 file (drd.h) only. The rest of Valgrind is licensed under the
7 terms of the GNU General Public License, version 2, unless
8 otherwise indicated. See the COPYING file in the source
9 distribution for details.
10
11 ----------------------------------------------------------------
12
13 This file is part of drd, a Valgrind tool for verification of
14 multithreaded programs.
15
bart23567982009-02-14 10:58:45 +000016 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
17 All rights reserved.
bart3c1e9d82008-06-30 17:10:29 +000018
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions
21 are met:
22
23 1. Redistributions of source code must retain the above copyright
24 notice, this list of conditions and the following disclaimer.
25
26 2. The origin of this software must not be misrepresented; you must
27 not claim that you wrote the original software. If you use this
28 software in a product, an acknowledgment in the product
29 documentation would be appreciated but is not required.
30
31 3. Altered source versions must be plainly marked as such, and must
32 not be misrepresented as being the original software.
33
34 4. The name of the author may not be used to endorse or promote
35 products derived from this software without specific prior written
36 permission.
37
38 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
39 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
42 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
44 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
46 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
47 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
48 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
50 ----------------------------------------------------------------
51
52 Notice that the above BSD-style license applies to this one file
53 (drd.h) only. The entire rest of Valgrind is licensed under
54 the terms of the GNU General Public License, version 2. See the
55 COPYING file in the source distribution for details.
56
57 ----------------------------------------------------------------
58*/
59
60#ifndef __VALGRIND_DRD_H
61#define __VALGRIND_DRD_H
62
63
64#include "valgrind.h"
65
66
67/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
68 This enum comprises an ABI exported by Valgrind to programs
69 which use client requests. DO NOT CHANGE THE ORDER OF THESE
70 ENTRIES, NOR DELETE ANY -- add new ones at the end.
71 */
bart3c1e9d82008-06-30 17:10:29 +000072enum
73{
74 /* Ask the core the thread ID assigned by Valgrind. */
bart5f57be92008-07-01 08:48:56 +000075 VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'),
76 /* args: none. */
77 /* Ask the core the thread ID assigned by DRD. */
78 VG_USERREQ__DRD_GET_DRD_THREAD_ID,
bart3c1e9d82008-06-30 17:10:29 +000079 /* args: none. */
80
81 /* To tell the drd tool to suppress data race detection on the specified */
82 /* address range. */
83 VG_USERREQ__DRD_START_SUPPRESSION,
84 /* args: start address, size in bytes */
85 /* To tell the drd tool no longer to suppress data race detection on the */
86 /* specified address range. */
87 VG_USERREQ__DRD_FINISH_SUPPRESSION,
88 /* args: start address, size in bytes */
89
90 /* To ask the drd tool to trace all accesses to the specified range. */
91 VG_USERREQ__DRD_START_TRACE_ADDR,
92 /* args: Addr, SizeT. */
93 /* To ask the drd tool to stop tracing accesses to the specified range. */
94 VG_USERREQ__DRD_STOP_TRACE_ADDR,
95 /* args: Addr, SizeT. */
barte7471762009-03-11 18:51:22 +000096
97 /* To ask the drd tool to discard all information about memory accesses */
98 /* and client objects for the specified range. This client request is */
99 /* binary compatible with the similarly named Helgrind client request. */
100 VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),
101 /* args: Addr, SizeT. */
bart3c1e9d82008-06-30 17:10:29 +0000102};
103
104
bart8e1033f2008-12-25 09:31:40 +0000105/** Tell DRD to suppress data race detection on the specified variable. */
106#define DRD_IGNORE_VAR(x) vg_drd_ignore_range(&(x), sizeof(x))
107
108/** Tell DRD to trace all memory accesses on the specified variable.
109 * until the memory that was allocated for the variable is freed.
110 */
111#define DRD_TRACE_VAR(x) vg_drd_trace_range(&(x), sizeof(x))
112
113
bart3c1e9d82008-06-30 17:10:29 +0000114static __inline__
bart5f57be92008-07-01 08:48:56 +0000115int vg_get_valgrind_threadid(void)
116{
117 int res;
118 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID,
119 0, 0, 0, 0, 0);
120 return res;
121}
122
123static __inline__
bart3c1e9d82008-06-30 17:10:29 +0000124int vg_get_drd_threadid(void)
125{
126 int res;
bart5f57be92008-07-01 08:48:56 +0000127 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_DRD_THREAD_ID,
128 0, 0, 0, 0, 0);
bart3c1e9d82008-06-30 17:10:29 +0000129 return res;
130}
131
132static __inline__
133void vg_drd_ignore_range(const void* const p, const int size)
134{
135 int res;
136 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION,
137 p, size, 0, 0, 0);
138}
139
140static __inline__
141void vg_drd_trace_range(const void* const p, const int size)
142{
143 int res;
144 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_TRACE_ADDR,
145 p, size, 0, 0, 0);
146}
147
148
149#endif /* __VALGRIND_DRD_H */