bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 2 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 3 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 4 | |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 5 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
bart | 39934d6 | 2009-02-15 16:18:03 +0000 | [diff] [blame] | 26 | #include "drd_basics.h" /* DRD_() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 27 | #include "drd_bitmap.h" |
| 28 | #include "drd_error.h" |
| 29 | #include "drd_suppression.h" |
bart | 39934d6 | 2009-02-15 16:18:03 +0000 | [diff] [blame] | 30 | #include "pub_drd_bitmap.h" |
| 31 | #include "pub_tool_basics.h" /* Addr, SizeT */ |
| 32 | #include "pub_tool_debuginfo.h" /* VG_(get_objname)() */ |
| 33 | #include "pub_tool_libcassert.h" /* tl_assert() */ |
| 34 | #include "pub_tool_libcbase.h" /* VG_(memset) */ |
| 35 | #include "pub_tool_libcprint.h" /* VG_(printf) */ |
| 36 | #include "pub_tool_machine.h" /* VG_(get_IP)() */ |
| 37 | #include "pub_tool_mallocfree.h" /* VG_(malloc), VG_(free) */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 38 | |
| 39 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 40 | /* Forward declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 41 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 42 | struct bitmap2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 43 | |
| 44 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 45 | /* Local function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 46 | |
| 47 | static void bm2_merge(struct bitmap2* const bm2l, |
| 48 | const struct bitmap2* const bm2r); |
| 49 | |
| 50 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 51 | /* Local variables. */ |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 52 | |
| 53 | static ULong s_bitmap_creation_count; |
| 54 | |
| 55 | |
| 56 | /* Function definitions. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 57 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 58 | struct bitmap* DRD_(bm_new)() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 59 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 60 | unsigned i; |
| 61 | struct bitmap* bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 62 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 63 | /* If this assert fails, fix the definition of BITS_PER_BITS_PER_UWORD */ |
| 64 | /* in drd_bitmap.h. */ |
| 65 | tl_assert((1 << BITS_PER_BITS_PER_UWORD) == BITS_PER_UWORD); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 66 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 67 | bm = VG_(malloc)("drd.bitmap.bn.1", sizeof(*bm)); |
| 68 | tl_assert(bm); |
| 69 | /* Cache initialization. a1 is initialized with a value that never can */ |
| 70 | /* match any valid address: the upper ADDR0_BITS bits of a1 are always */ |
| 71 | /* zero for a valid cache entry. */ |
| 72 | for (i = 0; i < N_CACHE_ELEM; i++) |
| 73 | { |
| 74 | bm->cache[i].a1 = ~(UWord)1; |
| 75 | bm->cache[i].bm2 = 0; |
| 76 | } |
| 77 | bm->oset = VG_(OSetGen_Create)(0, 0, VG_(malloc), "drd.bitmap.bn.2", |
| 78 | VG_(free)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 79 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 80 | s_bitmap_creation_count++; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 81 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 82 | return bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 85 | void DRD_(bm_delete)(struct bitmap* const bm) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 86 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 87 | struct bitmap2* bm2; |
| 88 | struct bitmap2ref* bm2ref; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 89 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 90 | tl_assert(bm); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 91 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 92 | VG_(OSetGen_ResetIter)(bm->oset); |
| 93 | for ( ; (bm2ref = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
| 94 | { |
| 95 | bm2 = bm2ref->bm2; |
| 96 | tl_assert(bm2->refcnt >= 1); |
| 97 | if (--bm2->refcnt == 0) |
| 98 | { |
| 99 | VG_(free)(bm2); |
| 100 | } |
| 101 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 102 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 103 | VG_(OSetGen_Destroy)(bm->oset); |
| 104 | VG_(free)(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 108 | * Record an access of type access_type at addresses a .. a + size - 1 in |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 109 | * bitmap bm. |
| 110 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 111 | void DRD_(bm_access_range)(struct bitmap* const bm, |
| 112 | const Addr a1, const Addr a2, |
| 113 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 114 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 115 | Addr b, b_next; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 116 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 117 | tl_assert(bm); |
| 118 | tl_assert(a1 < a2); |
| 119 | /* The current implementation of bm_access_range does not work for the */ |
| 120 | /* ADDR0_COUNT highest addresses in the address range. At least on Linux */ |
| 121 | /* this is not a problem since the upper part of the address space is */ |
| 122 | /* reserved for the kernel. */ |
| 123 | tl_assert(a2 + ADDR0_COUNT > a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 124 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 125 | for (b = a1; b < a2; b = b_next) |
| 126 | { |
| 127 | Addr b_start; |
| 128 | Addr b_end; |
| 129 | struct bitmap2* bm2; |
| 130 | SPLIT_ADDRESS(b); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 131 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 132 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 133 | if (b_next > a2) |
| 134 | { |
| 135 | b_next = a2; |
| 136 | } |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 137 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 138 | bm2 = bm2_lookup_or_insert_exclusive(bm, b1); |
| 139 | tl_assert(bm2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 140 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 141 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 142 | b_start = a1; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 143 | else |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 144 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 145 | b_start = (bm2->addr << ADDR0_BITS); |
| 146 | else |
| 147 | break; |
| 148 | tl_assert(a1 <= b_start && b_start <= a2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 149 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 150 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 151 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 152 | else |
| 153 | b_end = a2; |
| 154 | tl_assert(a1 <= b_end && b_end <= a2); |
| 155 | tl_assert(b_start < b_end); |
| 156 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 157 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 158 | if (access_type == eLoad) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 159 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 160 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++) |
| 161 | { |
| 162 | bm0_set(bm2->bm1.bm0_r, b0); |
| 163 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 164 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 165 | else |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 166 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 167 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++) |
| 168 | { |
| 169 | bm0_set(bm2->bm1.bm0_w, b0); |
| 170 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 171 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 172 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 173 | } |
| 174 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 175 | void DRD_(bm_access_range_load)(struct bitmap* const bm, |
| 176 | const Addr a1, const Addr a2) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 177 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 178 | DRD_(bm_access_range)(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 179 | } |
| 180 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 181 | void DRD_(bm_access_load_1)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 182 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 183 | bm_access_aligned_load(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 184 | } |
| 185 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 186 | void DRD_(bm_access_load_2)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 187 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 188 | if ((a1 & 1) == 0) |
| 189 | bm_access_aligned_load(bm, a1, 2); |
| 190 | else |
| 191 | DRD_(bm_access_range)(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 192 | } |
| 193 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 194 | void DRD_(bm_access_load_4)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 195 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 196 | if ((a1 & 3) == 0) |
| 197 | bm_access_aligned_load(bm, a1, 4); |
| 198 | else |
| 199 | DRD_(bm_access_range)(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 200 | } |
| 201 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 202 | void DRD_(bm_access_load_8)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 203 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 204 | if ((a1 & 7) == 0) |
| 205 | bm_access_aligned_load(bm, a1, 8); |
| 206 | else if ((a1 & 3) == 0) |
| 207 | { |
| 208 | bm_access_aligned_load(bm, a1 + 0, 4); |
| 209 | bm_access_aligned_load(bm, a1 + 4, 4); |
| 210 | } |
| 211 | else |
| 212 | DRD_(bm_access_range)(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 213 | } |
| 214 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 215 | void DRD_(bm_access_range_store)(struct bitmap* const bm, |
| 216 | const Addr a1, const Addr a2) |
bart | f5acbbc | 2008-05-10 08:22:20 +0000 | [diff] [blame] | 217 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 218 | DRD_(bm_access_range)(bm, a1, a2, eStore); |
bart | f5acbbc | 2008-05-10 08:22:20 +0000 | [diff] [blame] | 219 | } |
| 220 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 221 | void DRD_(bm_access_store_1)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 222 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 223 | bm_access_aligned_store(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 224 | } |
| 225 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 226 | void DRD_(bm_access_store_2)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 227 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 228 | if ((a1 & 1) == 0) |
| 229 | bm_access_aligned_store(bm, a1, 2); |
| 230 | else |
| 231 | DRD_(bm_access_range)(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 232 | } |
| 233 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 234 | void DRD_(bm_access_store_4)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 235 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 236 | if ((a1 & 3) == 0) |
| 237 | bm_access_aligned_store(bm, a1, 4); |
| 238 | else |
| 239 | DRD_(bm_access_range)(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 240 | } |
| 241 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 242 | void DRD_(bm_access_store_8)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 243 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 244 | if ((a1 & 7) == 0) |
| 245 | bm_access_aligned_store(bm, a1, 8); |
| 246 | else if ((a1 & 3) == 0) |
| 247 | { |
| 248 | bm_access_aligned_store(bm, a1 + 0, 4); |
| 249 | bm_access_aligned_store(bm, a1 + 4, 4); |
| 250 | } |
| 251 | else |
| 252 | DRD_(bm_access_range)(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 253 | } |
| 254 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 255 | Bool DRD_(bm_has)(struct bitmap* const bm, const Addr a1, const Addr a2, |
| 256 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 257 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 258 | Addr b; |
| 259 | for (b = a1; b < a2; b++) |
| 260 | { |
| 261 | if (! DRD_(bm_has_1)(bm, b, access_type)) |
| 262 | { |
| 263 | return False; |
| 264 | } |
| 265 | } |
| 266 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 267 | } |
| 268 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 269 | Bool |
| 270 | DRD_(bm_has_any_load)(struct bitmap* const bm, const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 271 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 272 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 273 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 274 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 275 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 276 | for (b = a1; b < a2; b = b_next) |
| 277 | { |
| 278 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 279 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 280 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 281 | if (b_next > a2) |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 282 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 283 | b_next = a2; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 284 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 285 | |
| 286 | if (bm2) |
| 287 | { |
| 288 | Addr b_start; |
| 289 | Addr b_end; |
| 290 | UWord b0; |
| 291 | const struct bitmap1* const p1 = &bm2->bm1; |
| 292 | |
| 293 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 294 | b_start = a1; |
| 295 | else |
| 296 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 297 | b_start = (bm2->addr << ADDR0_BITS); |
| 298 | else |
| 299 | break; |
| 300 | tl_assert(a1 <= b_start && b_start <= a2); |
| 301 | |
| 302 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 303 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 304 | else |
| 305 | b_end = a2; |
| 306 | tl_assert(a1 <= b_end && b_end <= a2); |
| 307 | tl_assert(b_start < b_end); |
| 308 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 309 | |
| 310 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 311 | { |
| 312 | if (bm0_is_set(p1->bm0_r, b0)) |
| 313 | { |
| 314 | return True; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | return 0; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 320 | } |
| 321 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 322 | Bool DRD_(bm_has_any_store)(struct bitmap* const bm, |
| 323 | const Addr a1, const Addr a2) |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 324 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 325 | Addr b, b_next; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 326 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 327 | tl_assert(bm); |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 328 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 329 | for (b = a1; b < a2; b = b_next) |
| 330 | { |
| 331 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 332 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 333 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 334 | if (b_next > a2) |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 335 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 336 | b_next = a2; |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame] | 337 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 338 | |
| 339 | if (bm2) |
| 340 | { |
| 341 | Addr b_start; |
| 342 | Addr b_end; |
| 343 | UWord b0; |
| 344 | const struct bitmap1* const p1 = &bm2->bm1; |
| 345 | |
| 346 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 347 | b_start = a1; |
| 348 | else |
| 349 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 350 | b_start = (bm2->addr << ADDR0_BITS); |
| 351 | else |
| 352 | break; |
| 353 | tl_assert(a1 <= b_start && b_start <= a2); |
| 354 | |
| 355 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 356 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 357 | else |
| 358 | b_end = a2; |
| 359 | tl_assert(a1 <= b_end && b_end <= a2); |
| 360 | tl_assert(b_start < b_end); |
| 361 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 362 | |
| 363 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 364 | { |
| 365 | if (bm0_is_set(p1->bm0_w, b0)) |
| 366 | { |
| 367 | return True; |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 373 | } |
| 374 | |
bart | c2c81db | 2008-05-10 11:19:10 +0000 | [diff] [blame] | 375 | /* Return True if there is a read access, write access or both */ |
| 376 | /* to any of the addresses in the range [ a1, a2 [ in bitmap bm. */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 377 | Bool DRD_(bm_has_any_access)(struct bitmap* const bm, |
| 378 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 379 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 380 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 381 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 382 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 383 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 384 | for (b = a1; b < a2; b = b_next) |
| 385 | { |
| 386 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 387 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 388 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 389 | if (b_next > a2) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 390 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 391 | b_next = a2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 392 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 393 | |
| 394 | if (bm2) |
| 395 | { |
| 396 | Addr b_start; |
| 397 | Addr b_end; |
| 398 | UWord b0; |
| 399 | const struct bitmap1* const p1 = &bm2->bm1; |
| 400 | |
| 401 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 402 | b_start = a1; |
| 403 | else |
| 404 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 405 | b_start = (bm2->addr << ADDR0_BITS); |
| 406 | else |
| 407 | break; |
| 408 | tl_assert(a1 <= b_start && b_start <= a2); |
| 409 | |
| 410 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 411 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 412 | else |
| 413 | b_end = a2; |
| 414 | tl_assert(a1 <= b_end && b_end <= a2); |
| 415 | tl_assert(b_start < b_end); |
| 416 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 417 | |
| 418 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 419 | { |
| 420 | if (bm0_is_set(p1->bm0_r, b0) | bm0_is_set(p1->bm0_w, b0)) |
| 421 | { |
| 422 | return True; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 428 | } |
| 429 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 430 | /** |
| 431 | * Report whether an access of type access_type at address a is recorded in |
| 432 | * bitmap bm. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 433 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 434 | Bool DRD_(bm_has_1)(struct bitmap* const bm, |
| 435 | const Addr a, const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 436 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 437 | const struct bitmap2* p2; |
| 438 | const struct bitmap1* p1; |
| 439 | const UWord* p0; |
| 440 | const UWord a0 = a & ADDR0_MASK; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 441 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 442 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 443 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 444 | p2 = bm2_lookup(bm, a >> ADDR0_BITS); |
| 445 | if (p2) |
| 446 | { |
| 447 | p1 = &p2->bm1; |
| 448 | p0 = (access_type == eLoad) ? p1->bm0_r : p1->bm0_w; |
| 449 | return bm0_is_set(p0, a0) ? True : False; |
| 450 | } |
| 451 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 452 | } |
| 453 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 454 | void DRD_(bm_clear)(struct bitmap* const bm, const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 455 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 456 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 457 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 458 | tl_assert(bm); |
| 459 | tl_assert(a1); |
| 460 | tl_assert(a1 <= a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 461 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 462 | for (b = a1; b < a2; b = b_next) |
| 463 | { |
| 464 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, b >> ADDR0_BITS); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 465 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 466 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 467 | if (b_next > a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 468 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 469 | b_next = a2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 470 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 471 | |
| 472 | if (p2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 473 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 474 | Addr c = b; |
| 475 | /* If the first address in the bitmap that must be cleared does not */ |
| 476 | /* start on an UWord boundary, start clearing the first addresses. */ |
| 477 | if (UWORD_LSB(c)) |
| 478 | { |
| 479 | Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD; |
| 480 | if (c_next > b_next) |
| 481 | c_next = b_next; |
| 482 | bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c); |
| 483 | bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c); |
| 484 | c = c_next; |
| 485 | } |
| 486 | /* If some UWords have to be cleared entirely, do this now. */ |
| 487 | if (UWORD_LSB(c) == 0) |
| 488 | { |
| 489 | const Addr c_next = UWORD_MSB(b_next); |
| 490 | tl_assert(UWORD_LSB(c) == 0); |
| 491 | tl_assert(UWORD_LSB(c_next) == 0); |
| 492 | tl_assert(c_next <= b_next); |
| 493 | tl_assert(c <= c_next); |
| 494 | if (c_next > c) |
| 495 | { |
| 496 | UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD; |
| 497 | VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8); |
| 498 | VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8); |
| 499 | c = c_next; |
| 500 | } |
| 501 | } |
| 502 | /* If the last address in the bitmap that must be cleared does not */ |
| 503 | /* fall on an UWord boundary, clear the last addresses. */ |
| 504 | /* tl_assert(c <= b_next); */ |
| 505 | bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c); |
| 506 | bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 507 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 508 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 509 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 510 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 511 | /** |
| 512 | * Clear all references to loads in bitmap bm starting at address a1 and |
| 513 | * up to but not including address a2. |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 514 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 515 | void DRD_(bm_clear_load)(struct bitmap* const bm, const Addr a1, const Addr a2) |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 516 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 517 | Addr a; |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 518 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 519 | for (a = a1; a < a2; a++) |
| 520 | { |
| 521 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, a >> ADDR0_BITS); |
| 522 | if (p2) |
| 523 | { |
| 524 | bm0_clear(p2->bm1.bm0_r, a & ADDR0_MASK); |
| 525 | } |
| 526 | } |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 527 | } |
| 528 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 529 | /** |
| 530 | * Clear all references to stores in bitmap bm starting at address a1 and |
| 531 | * up to but not including address a2. |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 532 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 533 | void DRD_(bm_clear_store)(struct bitmap* const bm, |
| 534 | const Addr a1, const Addr a2) |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 535 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 536 | Addr a; |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 537 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 538 | for (a = a1; a < a2; a++) |
| 539 | { |
| 540 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, a >> ADDR0_BITS); |
| 541 | if (p2) |
| 542 | { |
| 543 | bm0_clear(p2->bm1.bm0_w, a & ADDR0_MASK); |
| 544 | } |
| 545 | } |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 546 | } |
| 547 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 548 | /** |
| 549 | * Clear bitmap bm starting at address a1 and up to but not including address |
| 550 | * a2. Return True if and only if any of the addresses was set before |
| 551 | * clearing. |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 552 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 553 | Bool DRD_(bm_test_and_clear)(struct bitmap* const bm, |
| 554 | const Addr a1, const Addr a2) |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 555 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 556 | Bool result; |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 557 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 558 | result = DRD_(bm_has_any_access)(bm, a1, a2) != 0; |
| 559 | DRD_(bm_clear)(bm, a1, a2); |
| 560 | return result; |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 561 | } |
| 562 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 563 | Bool DRD_(bm_has_conflict_with)(struct bitmap* const bm, |
| 564 | const Addr a1, const Addr a2, |
| 565 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 566 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 567 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 568 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 569 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 570 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 571 | for (b = a1; b < a2; b = b_next) |
| 572 | { |
| 573 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 574 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 575 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 576 | if (b_next > a2) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 577 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 578 | b_next = a2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 579 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 580 | |
| 581 | if (bm2) |
| 582 | { |
| 583 | Addr b_start; |
| 584 | Addr b_end; |
| 585 | UWord b0; |
| 586 | const struct bitmap1* const p1 = &bm2->bm1; |
| 587 | |
| 588 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 589 | b_start = a1; |
| 590 | else |
| 591 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 592 | b_start = (bm2->addr << ADDR0_BITS); |
| 593 | else |
| 594 | break; |
| 595 | tl_assert(a1 <= b_start && b_start <= a2); |
| 596 | |
| 597 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 598 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 599 | else |
| 600 | b_end = a2; |
| 601 | tl_assert(a1 <= b_end && b_end <= a2); |
| 602 | tl_assert(b_start < b_end); |
| 603 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 604 | |
| 605 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 606 | { |
| 607 | if (access_type == eLoad) |
| 608 | { |
| 609 | if (bm0_is_set(p1->bm0_w, b0)) |
| 610 | { |
| 611 | return True; |
| 612 | } |
| 613 | } |
| 614 | else |
| 615 | { |
| 616 | tl_assert(access_type == eStore); |
| 617 | if (bm0_is_set(p1->bm0_r, b0) |
| 618 | | bm0_is_set(p1->bm0_w, b0)) |
| 619 | { |
| 620 | return True; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 627 | } |
| 628 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 629 | Bool DRD_(bm_load_has_conflict_with)(struct bitmap* const bm, |
| 630 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 631 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 632 | return DRD_(bm_has_conflict_with)(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 633 | } |
| 634 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 635 | Bool DRD_(bm_load_1_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 636 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 637 | return bm_aligned_load_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 638 | } |
| 639 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 640 | Bool DRD_(bm_load_2_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 641 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 642 | if ((a1 & 1) == 0) |
| 643 | return bm_aligned_load_has_conflict_with(bm, a1, 2); |
| 644 | else |
| 645 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 646 | } |
| 647 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 648 | Bool DRD_(bm_load_4_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 649 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 650 | if ((a1 & 3) == 0) |
| 651 | return bm_aligned_load_has_conflict_with(bm, a1, 4); |
| 652 | else |
| 653 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 654 | } |
| 655 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 656 | Bool DRD_(bm_load_8_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 657 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 658 | if ((a1 & 7) == 0) |
| 659 | return bm_aligned_load_has_conflict_with(bm, a1, 8); |
| 660 | else |
| 661 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 662 | } |
| 663 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 664 | Bool DRD_(bm_store_1_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 665 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 666 | return bm_aligned_store_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 667 | } |
| 668 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 669 | Bool DRD_(bm_store_2_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 670 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 671 | if ((a1 & 1) == 0) |
| 672 | return bm_aligned_store_has_conflict_with(bm, a1, 2); |
| 673 | else |
| 674 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 675 | } |
| 676 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 677 | Bool DRD_(bm_store_4_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 678 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 679 | if ((a1 & 3) == 0) |
| 680 | return bm_aligned_store_has_conflict_with(bm, a1, 4); |
| 681 | else |
| 682 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 683 | } |
| 684 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 685 | Bool DRD_(bm_store_8_has_conflict_with)(struct bitmap* const bm, const Addr a1) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 686 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 687 | if ((a1 & 7) == 0) |
| 688 | return bm_aligned_store_has_conflict_with(bm, a1, 8); |
| 689 | else |
| 690 | return DRD_(bm_has_conflict_with)(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 691 | } |
| 692 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 693 | Bool DRD_(bm_store_has_conflict_with)(struct bitmap* const bm, |
| 694 | const Addr a1, const Addr a2) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 695 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 696 | return DRD_(bm_has_conflict_with)(bm, a1, a2, eStore); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 697 | } |
| 698 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 699 | /** |
| 700 | * Return True if the two bitmaps *lhs and *rhs are identical, and false |
| 701 | * if not. |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 702 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 703 | Bool DRD_(bm_equal)(struct bitmap* const lhs, struct bitmap* const rhs) |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 704 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 705 | struct bitmap2* bm2l; |
| 706 | struct bitmap2ref* bm2l_ref; |
| 707 | struct bitmap2* bm2r; |
| 708 | const struct bitmap2ref* bm2r_ref; |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 709 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 710 | /* It's not possible to have two independent iterators over the same OSet, */ |
| 711 | /* so complain if lhs == rhs. */ |
| 712 | tl_assert(lhs != rhs); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 713 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 714 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 715 | VG_(OSetGen_ResetIter)(rhs->oset); |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 716 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 717 | for ( ; (bm2l_ref = VG_(OSetGen_Next)(lhs->oset)) != 0; ) |
| 718 | { |
| 719 | while (bm2l_ref |
| 720 | && (bm2l = bm2l_ref->bm2) |
| 721 | && bm2l |
| 722 | && ! DRD_(bm_has_any_access)(lhs, |
| 723 | bm2l->addr << ADDR0_BITS, |
| 724 | (bm2l->addr + 1) << ADDR0_BITS)) |
| 725 | { |
| 726 | bm2l_ref = VG_(OSetGen_Next)(lhs->oset); |
| 727 | } |
| 728 | if (bm2l_ref == 0) |
| 729 | break; |
| 730 | tl_assert(bm2l); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 731 | #if 0 |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 732 | VG_(message)(Vg_DebugMsg, "bm_equal: at 0x%lx", bm2l->addr << ADDR0_BITS); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 733 | #endif |
| 734 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 735 | bm2r_ref = VG_(OSetGen_Next)(rhs->oset); |
| 736 | if (bm2r_ref == 0) |
| 737 | { |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 738 | #if 0 |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 739 | VG_(message)(Vg_DebugMsg, "bm_equal: no match found"); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 740 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 741 | return False; |
| 742 | } |
| 743 | bm2r = bm2r_ref->bm2; |
| 744 | tl_assert(bm2r); |
| 745 | tl_assert(DRD_(bm_has_any_access)(rhs, |
| 746 | bm2r->addr << ADDR0_BITS, |
| 747 | (bm2r->addr + 1) << ADDR0_BITS)); |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 748 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 749 | if (bm2l != bm2r |
| 750 | && (bm2l->addr != bm2r->addr |
| 751 | || VG_(memcmp)(&bm2l->bm1, &bm2r->bm1, sizeof(bm2l->bm1)) != 0)) |
| 752 | { |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 753 | #if 0 |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 754 | VG_(message)(Vg_DebugMsg, "bm_equal: rhs 0x%lx -- returning false", |
| 755 | bm2r->addr << ADDR0_BITS); |
| 756 | #endif |
| 757 | return False; |
| 758 | } |
| 759 | } |
| 760 | bm2r = VG_(OSetGen_Next)(rhs->oset); |
| 761 | if (bm2r) |
| 762 | { |
| 763 | tl_assert(DRD_(bm_has_any_access)(rhs, |
| 764 | bm2r->addr << ADDR0_BITS, |
| 765 | (bm2r->addr + 1) << ADDR0_BITS)); |
| 766 | #if 0 |
| 767 | VG_(message)(Vg_DebugMsg, |
| 768 | "bm_equal: remaining rhs 0x%lx -- returning false", |
bart | a3f6109 | 2008-05-04 07:46:20 +0000 | [diff] [blame] | 769 | bm2r->addr << ADDR0_BITS); |
| 770 | #endif |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 771 | return False; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 772 | } |
| 773 | return True; |
bart | 7cd7d7f | 2008-04-14 16:10:01 +0000 | [diff] [blame] | 774 | } |
| 775 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 776 | void DRD_(bm_swap)(struct bitmap* const bm1, struct bitmap* const bm2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 777 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 778 | OSet* const tmp = bm1->oset; |
| 779 | bm1->oset = bm2->oset; |
| 780 | bm2->oset = tmp; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 781 | } |
| 782 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 783 | /** Merge bitmaps *lhs and *rhs into *lhs. */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 784 | void DRD_(bm_merge2)(struct bitmap* const lhs, |
| 785 | struct bitmap* const rhs) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 786 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 787 | struct bitmap2* bm2l; |
| 788 | struct bitmap2ref* bm2l_ref; |
| 789 | struct bitmap2* bm2r; |
| 790 | const struct bitmap2ref* bm2r_ref; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 791 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 792 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 793 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 794 | for ( ; (bm2r_ref = VG_(OSetGen_Next)(rhs->oset)) != 0; ) |
| 795 | { |
| 796 | bm2r = bm2r_ref->bm2; |
| 797 | bm2l_ref = VG_(OSetGen_Lookup)(lhs->oset, &bm2r->addr); |
| 798 | if (bm2l_ref) |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 799 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 800 | bm2l = bm2l_ref->bm2; |
| 801 | if (bm2l != bm2r) |
| 802 | { |
| 803 | if (bm2l->refcnt > 1) |
| 804 | bm2l = bm2_make_exclusive(lhs, bm2l_ref); |
| 805 | bm2_merge(bm2l, bm2r); |
| 806 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 807 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 808 | else |
| 809 | { |
| 810 | bm2_insert_addref(lhs, bm2r); |
| 811 | } |
| 812 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Report whether there are any RW / WR / WW patterns in lhs and rhs. |
| 817 | * @param lhs First bitmap. |
| 818 | * @param rhs Bitmap to be compared with lhs. |
| 819 | * @return !=0 if there are data races, == 0 if there are none. |
| 820 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 821 | int DRD_(bm_has_races)(struct bitmap* const lhs, struct bitmap* const rhs) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 822 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 823 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 824 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 825 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 826 | for (;;) |
| 827 | { |
| 828 | const struct bitmap2ref* bm2l_ref; |
| 829 | const struct bitmap2ref* bm2r_ref; |
| 830 | const struct bitmap2* bm2l; |
| 831 | const struct bitmap2* bm2r; |
| 832 | const struct bitmap1* bm1l; |
| 833 | const struct bitmap1* bm1r; |
| 834 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 835 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 836 | bm2l_ref = VG_(OSetGen_Next)(lhs->oset); |
| 837 | bm2l = bm2l_ref->bm2; |
| 838 | bm2r_ref = VG_(OSetGen_Next)(rhs->oset); |
| 839 | bm2r = bm2r_ref->bm2; |
| 840 | while (bm2l && bm2r && bm2l->addr != bm2r->addr) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 841 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 842 | if (bm2l->addr < bm2r->addr) |
| 843 | bm2l = (bm2l_ref = VG_(OSetGen_Next)(lhs->oset))->bm2; |
| 844 | else |
| 845 | bm2r = (bm2r_ref = VG_(OSetGen_Next)(rhs->oset))->bm2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 846 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 847 | if (bm2l == 0 || bm2r == 0) |
| 848 | break; |
| 849 | |
| 850 | bm1l = &bm2l->bm1; |
| 851 | bm1r = &bm2r->bm1; |
| 852 | |
| 853 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 854 | { |
| 855 | unsigned b; |
| 856 | for (b = 0; b < BITS_PER_UWORD; b++) |
| 857 | { |
| 858 | UWord const access_mask |
| 859 | = ((bm1l->bm0_r[k] & bm0_mask(b)) ? LHS_R : 0) |
| 860 | | ((bm1l->bm0_w[k] & bm0_mask(b)) ? LHS_W : 0) |
| 861 | | ((bm1r->bm0_r[k] & bm0_mask(b)) ? RHS_R : 0) |
| 862 | | ((bm1r->bm0_w[k] & bm0_mask(b)) ? RHS_W : 0); |
| 863 | Addr const a = MAKE_ADDRESS(bm2l->addr, k * BITS_PER_UWORD | b); |
| 864 | if (HAS_RACE(access_mask) && ! DRD_(is_suppressed)(a, a + 1)) |
| 865 | { |
| 866 | return 1; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 872 | } |
| 873 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 874 | void DRD_(bm_print)(struct bitmap* const bm) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 875 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 876 | struct bitmap2* bm2; |
| 877 | struct bitmap2ref* bm2ref; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 878 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 879 | VG_(OSetGen_ResetIter)(bm->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 880 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 881 | for ( ; (bm2ref = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
| 882 | { |
| 883 | const struct bitmap1* bm1; |
| 884 | unsigned b; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 885 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 886 | bm2 = bm2ref->bm2; |
| 887 | bm1 = &bm2->bm1; |
| 888 | for (b = 0; b < ADDR0_COUNT; b++) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 889 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 890 | const Addr a = (bm2->addr << ADDR0_BITS) | b; |
| 891 | const Bool r = bm0_is_set(bm1->bm0_r, b) != 0; |
| 892 | const Bool w = bm0_is_set(bm1->bm0_w, b) != 0; |
| 893 | if (r || w) |
| 894 | { |
| 895 | VG_(printf)("0x%08lx %c %c\n", |
| 896 | a, |
| 897 | w ? 'W' : ' ', |
| 898 | r ? 'R' : ' '); |
| 899 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 900 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 901 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 902 | } |
| 903 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 904 | ULong DRD_(bm_get_bitmap_creation_count)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 905 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 906 | return s_bitmap_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 907 | } |
| 908 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 909 | ULong DRD_(bm_get_bitmap2_node_creation_count)(void) |
bart | 588d90f | 2008-04-06 13:05:58 +0000 | [diff] [blame] | 910 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 911 | return s_bitmap2_node_creation_count; |
bart | 588d90f | 2008-04-06 13:05:58 +0000 | [diff] [blame] | 912 | } |
| 913 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 914 | ULong DRD_(bm_get_bitmap2_creation_count)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 915 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 916 | return s_bitmap2_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 917 | } |
| 918 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 919 | /** Allocate and initialize a second level bitmap. */ |
| 920 | static struct bitmap2* bm2_new(const UWord a1) |
| 921 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 922 | struct bitmap2* bm2; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 923 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 924 | bm2 = VG_(malloc)("drd.bitmap.bm2n.1", sizeof(*bm2)); |
| 925 | bm2->addr = a1; |
| 926 | bm2->refcnt = 1; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 927 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 928 | s_bitmap2_creation_count++; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 929 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 930 | return bm2; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /** Make a copy of a shared second level bitmap such that the copy can be |
| 934 | * modified. |
| 935 | * |
| 936 | * @param a1 client address shifted right by ADDR0_BITS. |
| 937 | * @param bm bitmap pointer. |
| 938 | */ |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 939 | static struct bitmap2* bm2_make_exclusive(struct bitmap* const bm, |
| 940 | struct bitmap2ref* const bm2ref) |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 941 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 942 | UWord a1; |
| 943 | struct bitmap2* bm2; |
| 944 | struct bitmap2* bm2_copy; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 945 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 946 | tl_assert(bm); |
| 947 | tl_assert(bm2ref); |
| 948 | bm2 = bm2ref->bm2; |
| 949 | tl_assert(bm2); |
| 950 | tl_assert(bm2->refcnt > 1); |
| 951 | bm2->refcnt--; |
| 952 | tl_assert(bm2->refcnt >= 1); |
| 953 | a1 = bm2->addr; |
| 954 | bm2_copy = bm2_new(a1); |
| 955 | tl_assert(bm2_copy); |
| 956 | tl_assert(bm2_copy->addr == a1); |
| 957 | tl_assert(bm2_copy->refcnt == 1); |
| 958 | VG_(memcpy)(&bm2_copy->bm1, &bm2->bm1, sizeof(bm2->bm1)); |
| 959 | bm2ref->bm2 = bm2_copy; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 960 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 961 | bm_update_cache(bm, a1, bm2_copy); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 962 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 963 | return bm2_copy; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 964 | } |
| 965 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 966 | static void bm2_merge(struct bitmap2* const bm2l, |
| 967 | const struct bitmap2* const bm2r) |
| 968 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 969 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 970 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 971 | tl_assert(bm2l); |
| 972 | tl_assert(bm2r); |
| 973 | tl_assert(bm2l->addr == bm2r->addr); |
| 974 | tl_assert(bm2l->refcnt == 1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 975 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 976 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 977 | { |
| 978 | bm2l->bm1.bm0_r[k] |= bm2r->bm1.bm0_r[k]; |
| 979 | } |
| 980 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 981 | { |
| 982 | bm2l->bm1.bm0_w[k] |= bm2r->bm1.bm0_w[k]; |
| 983 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 984 | } |