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