sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
bart | 922304f | 2011-03-13 12:02:44 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 2 of the |
| 9 | License, or (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307, USA. |
| 20 | |
| 21 | The GNU General Public License is contained in the file COPYING. |
| 22 | */ |
| 23 | |
| 24 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 25 | /* |
| 26 | * A bitmap is a data structure that contains information about which |
| 27 | * addresses have been accessed for reading or writing within a given |
| 28 | * segment. |
| 29 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 30 | |
| 31 | |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 32 | #ifndef __PUB_DRD_BITMAP_H |
| 33 | #define __PUB_DRD_BITMAP_H |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 34 | |
| 35 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 36 | #include "drd_basics.h" /* DRD_() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 37 | #include "pub_tool_basics.h" /* Addr, SizeT */ |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 38 | #include "pub_tool_oset.h" /* struct _OSet */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 39 | |
| 40 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 41 | /* Defines. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 42 | |
| 43 | #define LHS_R (1<<0) |
| 44 | #define LHS_W (1<<1) |
| 45 | #define RHS_R (1<<2) |
| 46 | #define RHS_W (1<<3) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 47 | #define HAS_RACE(a) ((((a) & RHS_W) && ((a) & (LHS_R | LHS_W))) \ |
| 48 | || (((a) & LHS_W) && ((a) & (RHS_R | RHS_W)))) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 49 | |
| 50 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 51 | /* Forward declarations. */ |
| 52 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 53 | struct bitmap; |
| 54 | |
| 55 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 56 | /* Datatype definitions. */ |
| 57 | |
bart | 5e234ac | 2008-03-16 08:39:54 +0000 | [diff] [blame] | 58 | typedef enum { eLoad, eStore, eStart, eEnd } BmAccessTypeT; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 59 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 60 | struct bm_cache_elem |
| 61 | { |
| 62 | Addr a1; |
| 63 | struct bitmap2* bm2; |
| 64 | }; |
| 65 | |
| 66 | #define DRD_BITMAP_N_CACHE_ELEM 4 |
| 67 | |
| 68 | /* Complete bitmap. */ |
| 69 | struct bitmap |
| 70 | { |
| 71 | struct bm_cache_elem cache[DRD_BITMAP_N_CACHE_ELEM]; |
| 72 | OSet* oset; |
| 73 | }; |
| 74 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 75 | |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 76 | /* Function declarations. */ |
bart | 588d90f | 2008-04-06 13:05:58 +0000 | [diff] [blame] | 77 | |
bart | e44bccc | 2012-01-18 09:46:57 +0000 | [diff] [blame] | 78 | void DRD_(bm_module_init)(void); |
| 79 | void DRD_(bm_module_cleanup)(void); |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 80 | struct bitmap* DRD_(bm_new)(void); |
| 81 | void DRD_(bm_delete)(struct bitmap* const bm); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 82 | void DRD_(bm_init)(struct bitmap* const bm); |
| 83 | void DRD_(bm_cleanup)(struct bitmap* const bm); |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 84 | void DRD_(bm_access_range)(struct bitmap* const bm, |
| 85 | const Addr a1, const Addr a2, |
| 86 | const BmAccessTypeT access_type); |
| 87 | void DRD_(bm_access_range_load)(struct bitmap* const bm, |
| 88 | const Addr a1, const Addr a2); |
| 89 | void DRD_(bm_access_load_1)(struct bitmap* const bm, const Addr a1); |
| 90 | void DRD_(bm_access_load_2)(struct bitmap* const bm, const Addr a1); |
| 91 | void DRD_(bm_access_load_4)(struct bitmap* const bm, const Addr a1); |
| 92 | void DRD_(bm_access_load_8)(struct bitmap* const bm, const Addr a1); |
| 93 | void DRD_(bm_access_range_store)(struct bitmap* const bm, |
| 94 | const Addr a1, const Addr a2); |
| 95 | void DRD_(bm_access_store_1)(struct bitmap* const bm, const Addr a1); |
| 96 | void DRD_(bm_access_store_2)(struct bitmap* const bm, const Addr a1); |
| 97 | void DRD_(bm_access_store_4)(struct bitmap* const bm, const Addr a1); |
| 98 | void DRD_(bm_access_store_8)(struct bitmap* const bm, const Addr a1); |
| 99 | Bool DRD_(bm_has)(struct bitmap* const bm, |
| 100 | const Addr a1, const Addr a2, |
| 101 | const BmAccessTypeT access_type); |
bart | 59d93d7 | 2011-12-12 19:02:34 +0000 | [diff] [blame] | 102 | Bool DRD_(bm_has_any_load_g)(struct bitmap* const bm); |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 103 | Bool DRD_(bm_has_any_load)(struct bitmap* const bm, |
| 104 | const Addr a1, const Addr a2); |
| 105 | Bool DRD_(bm_has_any_store)(struct bitmap* const bm, |
| 106 | const Addr a1, const Addr a2); |
| 107 | Bool DRD_(bm_has_any_access)(struct bitmap* const bm, |
| 108 | const Addr a1, const Addr a2); |
| 109 | Bool DRD_(bm_has_1)(struct bitmap* const bm, |
| 110 | const Addr address, const BmAccessTypeT access_type); |
| 111 | void DRD_(bm_clear)(struct bitmap* const bm, |
| 112 | const Addr a1, const Addr a2); |
| 113 | void DRD_(bm_clear_load)(struct bitmap* const bm, |
| 114 | const Addr a1, const Addr a2); |
| 115 | void DRD_(bm_clear_store)(struct bitmap* const bm, |
| 116 | const Addr a1, const Addr a2); |
| 117 | Bool DRD_(bm_test_and_clear)(struct bitmap* const bm, |
| 118 | const Addr a1, const Addr a2); |
| 119 | Bool DRD_(bm_has_conflict_with)(struct bitmap* const bm, |
| 120 | const Addr a1, const Addr a2, |
| 121 | const BmAccessTypeT access_type); |
| 122 | Bool DRD_(bm_load_1_has_conflict_with)(struct bitmap* const bm, const Addr a1); |
| 123 | Bool DRD_(bm_load_2_has_conflict_with)(struct bitmap* const bm, const Addr a1); |
| 124 | Bool DRD_(bm_load_4_has_conflict_with)(struct bitmap* const bm, const Addr a1); |
| 125 | Bool DRD_(bm_load_8_has_conflict_with)(struct bitmap* const bm, const Addr a1); |
| 126 | Bool DRD_(bm_load_has_conflict_with)(struct bitmap* const bm, |
| 127 | const Addr a1, const Addr a2); |
| 128 | Bool DRD_(bm_store_1_has_conflict_with)(struct bitmap* const bm,const Addr a1); |
| 129 | Bool DRD_(bm_store_2_has_conflict_with)(struct bitmap* const bm,const Addr a1); |
| 130 | Bool DRD_(bm_store_4_has_conflict_with)(struct bitmap* const bm,const Addr a1); |
| 131 | Bool DRD_(bm_store_8_has_conflict_with)(struct bitmap* const bm,const Addr a1); |
| 132 | Bool DRD_(bm_store_has_conflict_with)(struct bitmap* const bm, |
| 133 | const Addr a1, const Addr a2); |
| 134 | Bool DRD_(bm_equal)(struct bitmap* const lhs, struct bitmap* const rhs); |
| 135 | void DRD_(bm_swap)(struct bitmap* const bm1, struct bitmap* const bm2); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 136 | void DRD_(bm_merge2)(struct bitmap* const lhs, struct bitmap* const rhs); |
| 137 | void DRD_(bm_unmark)(struct bitmap* bm); |
| 138 | Bool DRD_(bm_is_marked)(struct bitmap* bm, const Addr a); |
| 139 | void DRD_(bm_mark)(struct bitmap* bm1, struct bitmap* bm2); |
| 140 | void DRD_(bm_clear_marked)(struct bitmap* bm); |
| 141 | void DRD_(bm_merge2_marked)(struct bitmap* const lhs, struct bitmap* const rhs); |
| 142 | void DRD_(bm_remove_cleared_marked)(struct bitmap* bm); |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 143 | int DRD_(bm_has_races)(struct bitmap* const bm1, |
| 144 | struct bitmap* const bm2); |
| 145 | void DRD_(bm_report_races)(ThreadId const tid1, ThreadId const tid2, |
| 146 | struct bitmap* const bm1, |
| 147 | struct bitmap* const bm2); |
| 148 | void DRD_(bm_print)(struct bitmap* bm); |
| 149 | ULong DRD_(bm_get_bitmap_creation_count)(void); |
bart | 99edb29 | 2009-02-15 15:59:20 +0000 | [diff] [blame] | 150 | ULong DRD_(bm_get_bitmap2_creation_count)(void); |
bart | 7b706b3 | 2009-05-10 06:55:39 +0000 | [diff] [blame] | 151 | ULong DRD_(bm_get_bitmap2_merge_count)(void); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 152 | |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 153 | #endif /* __PUB_DRD_BITMAP_H */ |