-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatarace.h
127 lines (100 loc) · 3.77 KB
/
datarace.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/** @file datarace.h
* @brief Data race detection code.
*/
#ifndef __DATARACE_H__
#define __DATARACE_H__
#include "config.h"
#include <stdint.h>
#include "modeltypes.h"
#include "classlist.h"
#include "hashset.h"
struct ShadowTable {
void * array[65536];
};
struct ShadowBaseTable {
uint64_t array[65536];
};
struct DataRace {
/* Clock and thread associated with first action. This won't change in
response to synchronization. */
thread_id_t oldthread;
modelclock_t oldclock;
/* Record whether this is a write, so we can tell the user. */
bool isoldwrite;
/* Model action associated with second action. This could change as
a result of synchronization. */
ModelAction *newaction;
/* Record whether this is a write, so we can tell the user. */
bool isnewwrite;
/* Address of data race. */
const void *address;
void * backtrace[64];
int numframes;
};
#define MASK16BIT 0xffff
void initRaceDetector();
void atomraceCheckWrite(thread_id_t thread, void *location);
void atomraceCheckRead(thread_id_t thread, const void *location);
void recordWrite(thread_id_t thread, void *location);
void recordCalloc(void *location, size_t size);
void assert_race(struct DataRace *race);
bool hasNonAtomicStore(const void *location);
void setAtomicStoreFlag(const void *location);
void getStoreThreadAndClock(const void *address, thread_id_t * thread, modelclock_t * clock);
void raceCheckRead8(thread_id_t thread, const void *location);
void raceCheckRead16(thread_id_t thread, const void *location);
void raceCheckRead32(thread_id_t thread, const void *location);
void raceCheckRead64(thread_id_t thread, const void *location);
void raceCheckWrite8(thread_id_t thread, const void *location);
void raceCheckWrite16(thread_id_t thread, const void *location);
void raceCheckWrite32(thread_id_t thread, const void *location);
void raceCheckWrite64(thread_id_t thread, const void *location);
void raceCheckWriteMemop(thread_id_t thread, const void *location, size_t size);
void raceCheckReadMemop(thread_id_t thread, const void *location, size_t size);
#ifdef COLLECT_STAT
void print_normal_accesses();
#endif
/**
* @brief A record of information for detecting data races
*/
struct RaceRecord {
modelclock_t *readClock;
thread_id_t *thread;
int numReads : 31;
int isAtomic : 1;
thread_id_t writeThread;
modelclock_t writeClock;
};
unsigned int race_hash(struct DataRace *race);
bool race_equals(struct DataRace *r1, struct DataRace *r2);
#define INITCAPACITY 4
#define ISSHORTRECORD(x) ((x)&0x1)
#define THREADMASK 0x3f
#define RDTHREADID(x) (((x)>>1)&THREADMASK)
#define READMASK 0x1ffffff
#define READVECTOR(x) (((x)>>7)&READMASK)
#define WRTHREADID(x) (((x)>>32)&THREADMASK)
#define WRITEMASK READMASK
#define WRITEVECTOR(x) (((x)>>38)&WRITEMASK)
#define ATOMICMASK (0x1ULL << 63)
#define NONATOMICMASK ~(0x1ULL << 63)
/**
* The basic encoding idea is that (void *) either:
* -# points to a full record (RaceRecord) or
* -# encodes the information in a 64 bit word. Encoding is as
* follows:
* - lowest bit set to 1
* - next 6 bits are read thread id
* - next 25 bits are read clock vector
* - next 6 bits are write thread id
* - next 25 bits are write clock vector
* - highest bit is 1 if the write is from an atomic
*/
#define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 7) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<38))
#define MAXTHREADID (THREADMASK-1)
#define MAXREADVECTOR (READMASK-1)
#define MAXWRITEVECTOR (WRITEMASK-1)
#define INVALIDSHADOWVAL 0x2ULL
#define CHECKBOUNDARY(location, bits) ((((uintptr_t)location & MASK16BIT) + bits) <= MASK16BIT)
typedef HashSet<struct DataRace *, uintptr_t, 0, model_malloc, model_calloc, model_free, race_hash, race_equals> RaceSet;
#endif /* __DATARACE_H__ */