blob: 8d7ad1a34c5073a7b0674ec71bbaf71ddf4222c8 [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
sewardjaf44c822007-11-25 14:01:38 +00002/*
bart86562bd2009-02-16 19:43:56 +00003 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00004
bart86562bd2009-02-16 19:43:56 +00005 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
sewardjaf44c822007-11-25 14:01:38 +00006
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
bart99edb292009-02-15 15:59:20 +000026/*
27 * A bitmap is a data structure that contains information about which
28 * addresses have been accessed for reading or writing within a given
29 * segment.
30 */
sewardjaf44c822007-11-25 14:01:38 +000031
32
bart33e56c92008-03-24 06:41:30 +000033#ifndef __PUB_DRD_BITMAP_H
34#define __PUB_DRD_BITMAP_H
sewardjaf44c822007-11-25 14:01:38 +000035
36
bart8f822af2009-06-08 18:20:42 +000037#include "drd_basics.h" /* DRD_() */
sewardjaf44c822007-11-25 14:01:38 +000038#include "pub_tool_basics.h" /* Addr, SizeT */
bart8f822af2009-06-08 18:20:42 +000039#include "pub_tool_oset.h" /* struct _OSet */
sewardjaf44c822007-11-25 14:01:38 +000040
41
bart99edb292009-02-15 15:59:20 +000042/* Defines. */
sewardjaf44c822007-11-25 14:01:38 +000043
44#define LHS_R (1<<0)
45#define LHS_W (1<<1)
46#define RHS_R (1<<2)
47#define RHS_W (1<<3)
bartbedfd232009-03-26 19:07:15 +000048#define HAS_RACE(a) ((((a) & RHS_W) && ((a) & (LHS_R | LHS_W))) \
49 || (((a) & LHS_W) && ((a) & (RHS_R | RHS_W))))
sewardjaf44c822007-11-25 14:01:38 +000050
51
bart99edb292009-02-15 15:59:20 +000052/* Forward declarations. */
53
sewardjaf44c822007-11-25 14:01:38 +000054struct bitmap;
55
56
bart99edb292009-02-15 15:59:20 +000057/* Datatype definitions. */
58
bart5e234ac2008-03-16 08:39:54 +000059typedef enum { eLoad, eStore, eStart, eEnd } BmAccessTypeT;
sewardjaf44c822007-11-25 14:01:38 +000060
bart8f822af2009-06-08 18:20:42 +000061struct bm_cache_elem
62{
63 Addr a1;
64 struct bitmap2* bm2;
65};
66
67#define DRD_BITMAP_N_CACHE_ELEM 4
68
69/* Complete bitmap. */
70struct bitmap
71{
72 struct bm_cache_elem cache[DRD_BITMAP_N_CACHE_ELEM];
73 OSet* oset;
74};
75
sewardjaf44c822007-11-25 14:01:38 +000076
bart99edb292009-02-15 15:59:20 +000077/* Function declarations. */
bart588d90f2008-04-06 13:05:58 +000078
bart99edb292009-02-15 15:59:20 +000079struct bitmap* DRD_(bm_new)(void);
80void DRD_(bm_delete)(struct bitmap* const bm);
bart8f822af2009-06-08 18:20:42 +000081void DRD_(bm_init)(struct bitmap* const bm);
82void DRD_(bm_cleanup)(struct bitmap* const bm);
bart99edb292009-02-15 15:59:20 +000083void DRD_(bm_access_range)(struct bitmap* const bm,
84 const Addr a1, const Addr a2,
85 const BmAccessTypeT access_type);
86void DRD_(bm_access_range_load)(struct bitmap* const bm,
87 const Addr a1, const Addr a2);
88void DRD_(bm_access_load_1)(struct bitmap* const bm, const Addr a1);
89void DRD_(bm_access_load_2)(struct bitmap* const bm, const Addr a1);
90void DRD_(bm_access_load_4)(struct bitmap* const bm, const Addr a1);
91void DRD_(bm_access_load_8)(struct bitmap* const bm, const Addr a1);
92void DRD_(bm_access_range_store)(struct bitmap* const bm,
93 const Addr a1, const Addr a2);
94void DRD_(bm_access_store_1)(struct bitmap* const bm, const Addr a1);
95void DRD_(bm_access_store_2)(struct bitmap* const bm, const Addr a1);
96void DRD_(bm_access_store_4)(struct bitmap* const bm, const Addr a1);
97void DRD_(bm_access_store_8)(struct bitmap* const bm, const Addr a1);
98Bool DRD_(bm_has)(struct bitmap* const bm,
99 const Addr a1, const Addr a2,
100 const BmAccessTypeT access_type);
101Bool DRD_(bm_has_any_load)(struct bitmap* const bm,
102 const Addr a1, const Addr a2);
103Bool DRD_(bm_has_any_store)(struct bitmap* const bm,
104 const Addr a1, const Addr a2);
105Bool DRD_(bm_has_any_access)(struct bitmap* const bm,
106 const Addr a1, const Addr a2);
107Bool DRD_(bm_has_1)(struct bitmap* const bm,
108 const Addr address, const BmAccessTypeT access_type);
109void DRD_(bm_clear)(struct bitmap* const bm,
110 const Addr a1, const Addr a2);
111void DRD_(bm_clear_load)(struct bitmap* const bm,
112 const Addr a1, const Addr a2);
113void DRD_(bm_clear_store)(struct bitmap* const bm,
114 const Addr a1, const Addr a2);
115Bool DRD_(bm_test_and_clear)(struct bitmap* const bm,
116 const Addr a1, const Addr a2);
117Bool DRD_(bm_has_conflict_with)(struct bitmap* const bm,
118 const Addr a1, const Addr a2,
119 const BmAccessTypeT access_type);
120Bool DRD_(bm_load_1_has_conflict_with)(struct bitmap* const bm, const Addr a1);
121Bool DRD_(bm_load_2_has_conflict_with)(struct bitmap* const bm, const Addr a1);
122Bool DRD_(bm_load_4_has_conflict_with)(struct bitmap* const bm, const Addr a1);
123Bool DRD_(bm_load_8_has_conflict_with)(struct bitmap* const bm, const Addr a1);
124Bool DRD_(bm_load_has_conflict_with)(struct bitmap* const bm,
125 const Addr a1, const Addr a2);
126Bool DRD_(bm_store_1_has_conflict_with)(struct bitmap* const bm,const Addr a1);
127Bool DRD_(bm_store_2_has_conflict_with)(struct bitmap* const bm,const Addr a1);
128Bool DRD_(bm_store_4_has_conflict_with)(struct bitmap* const bm,const Addr a1);
129Bool DRD_(bm_store_8_has_conflict_with)(struct bitmap* const bm,const Addr a1);
130Bool DRD_(bm_store_has_conflict_with)(struct bitmap* const bm,
131 const Addr a1, const Addr a2);
132Bool DRD_(bm_equal)(struct bitmap* const lhs, struct bitmap* const rhs);
133void DRD_(bm_swap)(struct bitmap* const bm1, struct bitmap* const bm2);
bart8f822af2009-06-08 18:20:42 +0000134void DRD_(bm_merge2)(struct bitmap* const lhs, struct bitmap* const rhs);
135void DRD_(bm_unmark)(struct bitmap* bm);
136Bool DRD_(bm_is_marked)(struct bitmap* bm, const Addr a);
137void DRD_(bm_mark)(struct bitmap* bm1, struct bitmap* bm2);
138void DRD_(bm_clear_marked)(struct bitmap* bm);
139void DRD_(bm_merge2_marked)(struct bitmap* const lhs, struct bitmap* const rhs);
140void DRD_(bm_remove_cleared_marked)(struct bitmap* bm);
bart99edb292009-02-15 15:59:20 +0000141int DRD_(bm_has_races)(struct bitmap* const bm1,
142 struct bitmap* const bm2);
143void DRD_(bm_report_races)(ThreadId const tid1, ThreadId const tid2,
144 struct bitmap* const bm1,
145 struct bitmap* const bm2);
146void DRD_(bm_print)(struct bitmap* bm);
147ULong DRD_(bm_get_bitmap_creation_count)(void);
bart99edb292009-02-15 15:59:20 +0000148ULong DRD_(bm_get_bitmap2_creation_count)(void);
bart7b706b32009-05-10 06:55:39 +0000149ULong DRD_(bm_get_bitmap2_merge_count)(void);
sewardjaf44c822007-11-25 14:01:38 +0000150
bart33e56c92008-03-24 06:41:30 +0000151#endif /* __PUB_DRD_BITMAP_H */