blob: 011fe38d82cd8bce17381720e5e9caaa857f8210 [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
bart3c1e9d82008-06-30 17:10:29 +00002
3/*
bartbedfd232009-03-26 19:07:15 +00004 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +00005
bartbedfd232009-03-26 19:07:15 +00006 Notice that the following BSD-style license applies to this one
7 file (drd.h) only. The rest of Valgrind is licensed under the
8 terms of the GNU General Public License, version 2, unless
9 otherwise indicated. See the COPYING file in the source
10 distribution for details.
bart3c1e9d82008-06-30 17:10:29 +000011
bartbedfd232009-03-26 19:07:15 +000012 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +000013
bartbedfd232009-03-26 19:07:15 +000014 This file is part of drd, a Valgrind tool for verification of
15 multithreaded programs.
bart3c1e9d82008-06-30 17:10:29 +000016
bartbedfd232009-03-26 19:07:15 +000017 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
18 All rights reserved.
bart3c1e9d82008-06-30 17:10:29 +000019
bartbedfd232009-03-26 19:07:15 +000020 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions
22 are met:
bart3c1e9d82008-06-30 17:10:29 +000023
bartbedfd232009-03-26 19:07:15 +000024 1. Redistributions of source code must retain the above copyright
25 notice, this list of conditions and the following disclaimer.
bart3c1e9d82008-06-30 17:10:29 +000026
bartbedfd232009-03-26 19:07:15 +000027 2. The origin of this software must not be misrepresented; you must
28 not claim that you wrote the original software. If you use this
29 software in a product, an acknowledgment in the product
30 documentation would be appreciated but is not required.
bart3c1e9d82008-06-30 17:10:29 +000031
bartbedfd232009-03-26 19:07:15 +000032 3. Altered source versions must be plainly marked as such, and must
33 not be misrepresented as being the original software.
bart3c1e9d82008-06-30 17:10:29 +000034
bartbedfd232009-03-26 19:07:15 +000035 4. The name of the author may not be used to endorse or promote
36 products derived from this software without specific prior written
37 permission.
bart3c1e9d82008-06-30 17:10:29 +000038
bartbedfd232009-03-26 19:07:15 +000039 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
40 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
43 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
45 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bart3c1e9d82008-06-30 17:10:29 +000050
bartbedfd232009-03-26 19:07:15 +000051 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +000052
bartbedfd232009-03-26 19:07:15 +000053 Notice that the above BSD-style license applies to this one file
54 (drd.h) only. The entire rest of Valgrind is licensed under
55 the terms of the GNU General Public License, version 2. See the
56 COPYING file in the source distribution for details.
bart3c1e9d82008-06-30 17:10:29 +000057
bartbedfd232009-03-26 19:07:15 +000058 ----------------------------------------------------------------
bart3c1e9d82008-06-30 17:10:29 +000059*/
60
61#ifndef __VALGRIND_DRD_H
62#define __VALGRIND_DRD_H
63
64
65#include "valgrind.h"
66
67
68/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
69 This enum comprises an ABI exported by Valgrind to programs
70 which use client requests. DO NOT CHANGE THE ORDER OF THESE
71 ENTRIES, NOR DELETE ANY -- add new ones at the end.
bartbedfd232009-03-26 19:07:15 +000072*/
bart3c1e9d82008-06-30 17:10:29 +000073enum
bartbedfd232009-03-26 19:07:15 +000074 {
75 /* Ask the core the thread ID assigned by Valgrind. */
76 VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'),
77 /* args: none. */
78 /* Ask the core the thread ID assigned by DRD. */
79 VG_USERREQ__DRD_GET_DRD_THREAD_ID,
80 /* args: none. */
bart3c1e9d82008-06-30 17:10:29 +000081
bartbedfd232009-03-26 19:07:15 +000082 /* To tell the drd tool to suppress data race detection on the */
83 /* specified address range. */
84 VG_USERREQ__DRD_START_SUPPRESSION,
85 /* args: start address, size in bytes */
86 /* To tell the drd tool no longer to suppress data race detection on */
87 /* the specified address range. */
88 VG_USERREQ__DRD_FINISH_SUPPRESSION,
89 /* args: start address, size in bytes */
bart3c1e9d82008-06-30 17:10:29 +000090
bartbedfd232009-03-26 19:07:15 +000091 /* To ask the drd tool to trace all accesses to the specified range. */
92 VG_USERREQ__DRD_START_TRACE_ADDR,
93 /* args: Addr, SizeT. */
94 /* To ask the drd tool to stop tracing accesses to the specified range. */
95 VG_USERREQ__DRD_STOP_TRACE_ADDR,
96 /* args: Addr, SizeT. */
barte7471762009-03-11 18:51:22 +000097
bartbedfd232009-03-26 19:07:15 +000098 /* To ask the drd tool to discard all information about memory accesses */
99 /* and client objects for the specified range. This client request is */
100 /* binary compatible with the similarly named Helgrind client request. */
101 VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),
102 /* args: Addr, SizeT. */
103 };
bart3c1e9d82008-06-30 17:10:29 +0000104
105
bart8e1033f2008-12-25 09:31:40 +0000106/** Tell DRD to suppress data race detection on the specified variable. */
107#define DRD_IGNORE_VAR(x) vg_drd_ignore_range(&(x), sizeof(x))
108
109/** Tell DRD to trace all memory accesses on the specified variable.
110 * until the memory that was allocated for the variable is freed.
111 */
112#define DRD_TRACE_VAR(x) vg_drd_trace_range(&(x), sizeof(x))
113
114
bart3c1e9d82008-06-30 17:10:29 +0000115static __inline__
bart5f57be92008-07-01 08:48:56 +0000116int vg_get_valgrind_threadid(void)
117{
bartbedfd232009-03-26 19:07:15 +0000118 int res;
119 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID,
120 0, 0, 0, 0, 0);
121 return res;
bart5f57be92008-07-01 08:48:56 +0000122}
123
124static __inline__
bart3c1e9d82008-06-30 17:10:29 +0000125int vg_get_drd_threadid(void)
126{
bartbedfd232009-03-26 19:07:15 +0000127 int res;
128 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_DRD_THREAD_ID,
129 0, 0, 0, 0, 0);
130 return res;
bart3c1e9d82008-06-30 17:10:29 +0000131}
132
133static __inline__
134void vg_drd_ignore_range(const void* const p, const int size)
135{
bartbedfd232009-03-26 19:07:15 +0000136 int res;
137 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION,
138 p, size, 0, 0, 0);
bart3c1e9d82008-06-30 17:10:29 +0000139}
140
141static __inline__
142void vg_drd_trace_range(const void* const p, const int size)
143{
bartbedfd232009-03-26 19:07:15 +0000144 int res;
145 VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_TRACE_ADDR,
146 p, size, 0, 0, 0);
bart3c1e9d82008-06-30 17:10:29 +0000147}
148
149
150#endif /* __VALGRIND_DRD_H */