2 * @brief Data race detection code.
10 #include "modeltypes.h"
11 #include "classlist.h"
18 struct ShadowBaseTable {
19 uint64_t array[65536];
23 /* Clock and thread associated with first action. This won't change in
24 response to synchronization. */
26 thread_id_t oldthread;
27 modelclock_t oldclock;
28 /* Record whether this is a write, so we can tell the user. */
31 /* Model action associated with second action. This could change as
32 a result of synchronization. */
33 ModelAction *newaction;
34 /* Record whether this is a write, so we can tell the user. */
37 /* Address of data race. */
43 #define MASK16BIT 0xffff
45 void initRaceDetector();
46 void atomraceCheckWrite(thread_id_t thread, void *location);
47 void atomraceCheckRead(thread_id_t thread, const void *location);
48 void recordWrite(thread_id_t thread, void *location);
49 void recordCalloc(void *location, size_t size);
50 void assert_race(struct DataRace *race);
51 bool hasNonAtomicStore(const void *location);
52 void setAtomicStoreFlag(const void *location);
53 void getStoreThreadAndClock(const void *address, thread_id_t * thread, modelclock_t * clock);
55 void raceCheckRead8(thread_id_t thread, const void *location);
56 void raceCheckRead16(thread_id_t thread, const void *location);
57 void raceCheckRead32(thread_id_t thread, const void *location);
58 void raceCheckRead64(thread_id_t thread, const void *location);
60 void raceCheckWrite8(thread_id_t thread, const void *location);
61 void raceCheckWrite16(thread_id_t thread, const void *location);
62 void raceCheckWrite32(thread_id_t thread, const void *location);
63 void raceCheckWrite64(thread_id_t thread, const void *location);
65 void raceCheckWriteMemop(thread_id_t thread, const void *location, size_t size);
66 void raceCheckReadMemop(thread_id_t thread, const void *location, size_t size);
69 void print_normal_accesses();
73 * @brief A record of information for detecting data races
76 modelclock_t *readClock;
80 thread_id_t writeThread;
81 modelclock_t writeClock;
84 unsigned int race_hash(struct DataRace *race);
85 bool race_equals(struct DataRace *r1, struct DataRace *r2);
87 #define INITCAPACITY 4
89 #define ISSHORTRECORD(x) ((x)&0x1)
91 #define THREADMASK 0x3f
92 #define RDTHREADID(x) (((x)>>1)&THREADMASK)
93 #define READMASK 0x1ffffff
94 #define READVECTOR(x) (((x)>>7)&READMASK)
96 #define WRTHREADID(x) (((x)>>32)&THREADMASK)
98 #define WRITEMASK READMASK
99 #define WRITEVECTOR(x) (((x)>>38)&WRITEMASK)
101 #define ATOMICMASK (0x1ULL << 63)
102 #define NONATOMICMASK ~(0x1ULL << 63)
105 * The basic encoding idea is that (void *) either:
106 * -# points to a full record (RaceRecord) or
107 * -# encodes the information in a 64 bit word. Encoding is as
109 * - lowest bit set to 1
110 * - next 6 bits are read thread id
111 * - next 25 bits are read clock vector
112 * - next 6 bits are write thread id
113 * - next 25 bits are write clock vector
114 * - highest bit is 1 if the write is from an atomic
116 #define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 7) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<38))
118 #define MAXTHREADID (THREADMASK-1)
119 #define MAXREADVECTOR (READMASK-1)
120 #define MAXWRITEVECTOR (WRITEMASK-1)
122 #define INVALIDSHADOWVAL 0x2ULL
123 #define CHECKBOUNDARY(location, bits) ((((uintptr_t)location & MASK16BIT) + bits) <= MASK16BIT)
125 typedef HashSet<struct DataRace *, uintptr_t, 0, model_malloc, model_calloc, model_free, race_hash, race_equals> RaceSet;
127 #endif /* __DATARACE_H__ */