bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 1 | |
| 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 | |
bart | 2356798 | 2009-02-14 10:58:45 +0000 | [diff] [blame] | 16 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
| 17 | All rights reserved. |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 18 | |
| 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 | */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 72 | enum |
| 73 | { |
| 74 | /* Ask the core the thread ID assigned by Valgrind. */ |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 75 | 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, |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 79 | /* 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. */ |
bart | e747176 | 2009-03-11 18:51:22 +0000 | [diff] [blame^] | 96 | |
| 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. */ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | |
bart | 8e1033f | 2008-12-25 09:31:40 +0000 | [diff] [blame] | 105 | /** 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 | |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 114 | static __inline__ |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 115 | int 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 | |
| 123 | static __inline__ |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 124 | int vg_get_drd_threadid(void) |
| 125 | { |
| 126 | int res; |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 127 | VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_GET_DRD_THREAD_ID, |
| 128 | 0, 0, 0, 0, 0); |
bart | 3c1e9d8 | 2008-06-30 17:10:29 +0000 | [diff] [blame] | 129 | return res; |
| 130 | } |
| 131 | |
| 132 | static __inline__ |
| 133 | void 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 | |
| 140 | static __inline__ |
| 141 | void 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 */ |