blob: 8bfdeeb504092e7d15bc9adb7e332125115b8c24 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
2 This file is part of drd, a data race detector.
3
sewardj85642922008-01-14 11:54:56 +00004 Copyright (C) 2006-2008 Bart Van Assche
sewardjaf44c822007-11-25 14:01:38 +00005 bart.vanassche@gmail.com
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
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
30
bart33e56c92008-03-24 06:41:30 +000031#ifndef __PUB_DRD_BITMAP_H
32#define __PUB_DRD_BITMAP_H
sewardjaf44c822007-11-25 14:01:38 +000033
34
35#include "pub_tool_basics.h" /* Addr, SizeT */
36
37
38// Constant definitions.
39
40#define LHS_R (1<<0)
41#define LHS_W (1<<1)
42#define RHS_R (1<<2)
43#define RHS_W (1<<3)
44#define HAS_RACE(a) ((((a) & RHS_W) && ((a) & (LHS_R | LHS_W))) \
45 || (((a) & LHS_W) && ((a) & (RHS_R | RHS_W))))
46
47
48// Forward declarations.
49struct bitmap;
50
51
52// Datatype definitions.
bart5e234ac2008-03-16 08:39:54 +000053typedef enum { eLoad, eStore, eStart, eEnd } BmAccessTypeT;
sewardjaf44c822007-11-25 14:01:38 +000054
55
56// Function declarations.
57struct bitmap* bm_new(void);
58void bm_delete(struct bitmap* const bm);
bart36556122008-03-13 19:24:30 +000059void bm_access_range_load(struct bitmap* const bm,
60 const Addr a1, const Addr a2);
barta79df6e2008-03-14 17:07:51 +000061void bm_access_load_1(struct bitmap* const bm, const Addr a1);
62void bm_access_load_2(struct bitmap* const bm, const Addr a1);
63void bm_access_load_4(struct bitmap* const bm, const Addr a1);
64void bm_access_load_8(struct bitmap* const bm, const Addr a1);
65void bm_access_store_1(struct bitmap* const bm, const Addr a1);
66void bm_access_store_2(struct bitmap* const bm, const Addr a1);
67void bm_access_store_4(struct bitmap* const bm, const Addr a1);
68void bm_access_store_8(struct bitmap* const bm, const Addr a1);
bart36556122008-03-13 19:24:30 +000069void bm_access_range_store(struct bitmap* const bm,
70 const Addr a1, const Addr a2);
sewardjaf44c822007-11-25 14:01:38 +000071Bool bm_has(const struct bitmap* const bm,
bart36556122008-03-13 19:24:30 +000072 const Addr a1, const Addr a2,
sewardjaf44c822007-11-25 14:01:38 +000073 const BmAccessTypeT access_type);
bartd4907072008-03-30 18:41:07 +000074Bool bm_has_any_load(const struct bitmap* const bm,
75 const Addr a1, const Addr a2);
76Bool bm_has_any_store(const struct bitmap* const bm,
77 const Addr a1, const Addr a2);
sewardjaf44c822007-11-25 14:01:38 +000078UWord bm_has_any_access(const struct bitmap* const bm,
bart36556122008-03-13 19:24:30 +000079 const Addr a1, const Addr a2);
sewardjaf44c822007-11-25 14:01:38 +000080UWord bm_has_1(const struct bitmap* const bm,
bart36556122008-03-13 19:24:30 +000081 const Addr address, const BmAccessTypeT access_type);
sewardjaf44c822007-11-25 14:01:38 +000082void bm_clear(const struct bitmap* const bm,
bart36556122008-03-13 19:24:30 +000083 const Addr a1, const Addr a2);
bart9c4224c2008-03-29 14:40:08 +000084void bm_clear_load(const struct bitmap* const bm,
85 const Addr a1, const Addr a2);
86void bm_clear_store(const struct bitmap* const bm,
87 const Addr a1, const Addr a2);
bart8bf2f8b2008-03-30 17:56:43 +000088Bool bm_test_and_clear(const struct bitmap* const bm,
89 const Addr a1, const Addr a2);
sewardjaf44c822007-11-25 14:01:38 +000090Bool bm_has_conflict_with(const struct bitmap* const bm,
bart36556122008-03-13 19:24:30 +000091 const Addr a1, const Addr a2,
sewardjaf44c822007-11-25 14:01:38 +000092 const BmAccessTypeT access_type);
barta79df6e2008-03-14 17:07:51 +000093Bool bm_load_1_has_conflict_with(const struct bitmap* const bm, const Addr a1);
94Bool bm_load_2_has_conflict_with(const struct bitmap* const bm, const Addr a1);
95Bool bm_load_4_has_conflict_with(const struct bitmap* const bm, const Addr a1);
96Bool bm_load_8_has_conflict_with(const struct bitmap* const bm, const Addr a1);
bart36556122008-03-13 19:24:30 +000097Bool bm_load_has_conflict_with(const struct bitmap* const bm,
98 const Addr a1, const Addr a2);
barta79df6e2008-03-14 17:07:51 +000099Bool bm_store_1_has_conflict_with(const struct bitmap* const bm,const Addr a1);
100Bool bm_store_2_has_conflict_with(const struct bitmap* const bm,const Addr a1);
101Bool bm_store_4_has_conflict_with(const struct bitmap* const bm,const Addr a1);
102Bool bm_store_8_has_conflict_with(const struct bitmap* const bm,const Addr a1);
bart36556122008-03-13 19:24:30 +0000103Bool bm_store_has_conflict_with(const struct bitmap* const bm,
104 const Addr a1, const Addr a2);
sewardjaf44c822007-11-25 14:01:38 +0000105void bm_swap(struct bitmap* const bm1, struct bitmap* const bm2);
106void bm_merge2(struct bitmap* const lhs,
107 const struct bitmap* const rhs);
108int bm_has_races(const struct bitmap* const bm1,
109 const struct bitmap* const bm2);
110void bm_report_races(ThreadId const tid1, ThreadId const tid2,
111 const struct bitmap* const bm1,
112 const struct bitmap* const bm2);
113void bm_print(const struct bitmap* bm);
114ULong bm_get_bitmap_creation_count(void);
115ULong bm_get_bitmap2_creation_count(void);
bart33e56c92008-03-24 06:41:30 +0000116void bm_test(void);
sewardjaf44c822007-11-25 14:01:38 +0000117
118
bart33e56c92008-03-24 06:41:30 +0000119#endif /* __PUB_DRD_BITMAP_H */