bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 4 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 5 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 6 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 11 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 12 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 13 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 14 | This file is part of drd, a Valgrind tool for verification of |
| 15 | multithreaded programs. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 16 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 17 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
| 18 | All rights reserved. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 19 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 20 | Redistribution and use in source and binary forms, with or without |
| 21 | modification, are permitted provided that the following conditions |
| 22 | are met: |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 23 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 24 | 1. Redistributions of source code must retain the above copyright |
| 25 | notice, this list of conditions and the following disclaimer. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 26 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 27 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 31 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 32 | 3. Altered source versions must be plainly marked as such, and must |
| 33 | not be misrepresented as being the original software. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 34 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 35 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 38 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 39 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 50 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 51 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 52 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 53 | 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. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 57 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 58 | ---------------------------------------------------------------- |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 59 | */ |
| 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. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 72 | */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 73 | enum |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 74 | { |
| 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. */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 81 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 82 | /* 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 */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 90 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 91 | /* 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. */ |
bart | e747176 | 2009-03-11 18:51:22 +0000 | [diff] [blame] | 97 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 98 | /* 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 | }; |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 104 | |
| 105 | |
bart | 8e1033f | 2008-12-25 09:31:40 +0000 | [diff] [blame] | 106 | /** 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 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 115 | static __inline__ |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 116 | int vg_get_valgrind_threadid(void) |
| 117 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 118 | 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; |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static __inline__ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 125 | int vg_get_drd_threadid(void) |
| 126 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 127 | 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; |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static __inline__ |
| 134 | void vg_drd_ignore_range(const void* const p, const int size) |
| 135 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 136 | int res; |
| 137 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_SUPPRESSION, |
| 138 | p, size, 0, 0, 0); |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static __inline__ |
| 142 | void vg_drd_trace_range(const void* const p, const int size) |
| 143 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 144 | int res; |
| 145 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_TRACE_ADDR, |
| 146 | p, size, 0, 0, 0); |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
| 150 | #endif /* __VALGRIND_DRD_H */ |