Skip to content

Commit 8a96e0f

Browse files
committed
RSan
Without value support
1 parent 6146a88 commit 8a96e0f

21 files changed

+2569
-27
lines changed

compiler-rt/lib/tsan/rtl/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ set(TSAN_SOURCES
4949
tsan_symbolize.cpp
5050
tsan_sync.cpp
5151
tsan_vector_clock.cpp
52+
rsan.cpp
53+
rsan_report.cpp
54+
rsan_stacktrace.cpp
5255
)
5356

5457
set(TSAN_CXX_SOURCES
@@ -59,6 +62,10 @@ set(TSAN_PREINIT_SOURCES
5962
tsan_preinit.cpp
6063
)
6164

65+
set_source_files_properties(tsan_interface_atomic.cpp PROPERTIES COMPILE_FLAGS -std=c++20)
66+
set_source_files_properties(tsan_mman.cpp PROPERTIES COMPILE_FLAGS -std=c++20)
67+
set_source_files_properties(tsan_rtl_mutex.cpp PROPERTIES COMPILE_FLAGS -std=c++20)
68+
6269
if(APPLE)
6370
list(APPEND TSAN_SOURCES
6471
tsan_interceptors_mac.cpp

compiler-rt/lib/tsan/rtl/rsan.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "rsan_vectorclock.hpp"
2+
#include "rsan_robustnessmodel.hpp"
3+
#include "rsan_instrument.hpp"
4+
#include "rsan_map.hpp"
5+
#include "rsan_arena.hpp"
6+
7+
namespace Robustness{
8+
} // namespace Robustness
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#pragma once
2+
#include "rsan_defs.hpp"
3+
namespace Robustness::Action{
4+
struct StoreAction{
5+
ThreadId tid;
6+
Address addr;
7+
int size;
8+
};
9+
struct LoadAction{
10+
ThreadId tid;
11+
Address addr;
12+
int size;
13+
};
14+
struct AtomicVerifyAction{
15+
ThreadId tid;
16+
Address addr;
17+
morder mo;
18+
int size;
19+
};
20+
struct AtomicVerifyStoreAction{
21+
ThreadId tid;
22+
Address addr;
23+
morder mo;
24+
int size;
25+
};
26+
struct AtomicLoadAction{
27+
ThreadId tid;
28+
Address addr;
29+
morder mo;
30+
int size;
31+
bool rmw;
32+
DebugInfo dbg;
33+
};
34+
struct AtomicStoreAction{
35+
ThreadId tid;
36+
Address addr;
37+
morder mo;
38+
int size;
39+
uint64_t oldValue;
40+
uint64_t newValue;
41+
DebugInfo dbg;
42+
};
43+
struct AtomicRMWAction{
44+
ThreadId tid;
45+
Address addr;
46+
morder mo;
47+
int size;
48+
uint64_t oldValue;
49+
uint64_t newValue;
50+
DebugInfo dbg;
51+
};
52+
struct AtomicCasAction{
53+
ThreadId tid;
54+
Address addr;
55+
morder mo;
56+
int size;
57+
uint64_t oldValue;
58+
uint64_t newValue;
59+
bool success;
60+
DebugInfo dbg;
61+
};
62+
struct FenceAction{
63+
ThreadId tid;
64+
morder mo;
65+
};
66+
struct TrackAction{
67+
ThreadId tid;
68+
Address addr;
69+
uint64_t value;
70+
};
71+
struct WaitAction{
72+
ThreadId tid;
73+
Address addr;
74+
uint64_t value;
75+
DebugInfo dbg;
76+
};
77+
struct BcasAction{
78+
ThreadId tid;
79+
Address addr;
80+
uint64_t value;
81+
DebugInfo dbg;
82+
};
83+
struct ThreadCreate{
84+
ThreadId creator, createe;
85+
};
86+
struct ThreadJoin{
87+
ThreadId absorber, absorbee;
88+
};
89+
struct Free{
90+
ThreadId tid;
91+
Address addr;
92+
uptr size;
93+
DebugInfo dbg;
94+
};
95+
}
96+
97+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
#include "rsan_vector.h"
3+
#include "rsan_defs.hpp"
4+
#include "sanitizer_common/sanitizer_placement_new.h"
5+
6+
namespace Robustness {
7+
template< class T >
8+
class Arena {
9+
10+
//const FACTOR = 2;
11+
static const u8 BASE = 8;
12+
13+
u64 cv = 0;
14+
u64 ci = 0;
15+
16+
Vector<Vector<T>> vs;
17+
Arena(const Arena&) = delete;
18+
19+
20+
public:
21+
Arena() = default;
22+
~Arena() {
23+
for (auto& v : vs)
24+
v.clear();
25+
}
26+
27+
T* allocate(){
28+
if (cv == vs.size()){
29+
vs.push_back();
30+
vs[cv].resize(BASE << (cv));
31+
ci = 0;
32+
}
33+
DCHECK_GT(vs.size(), cv);
34+
DCHECK_GT(vs[cv].size(), ci);
35+
auto ret = &vs[cv][ci++];
36+
DCHECK_GT(ret, 0);
37+
if (ci >= vs[cv].size()){
38+
++cv;
39+
}
40+
41+
new (ret) T();
42+
return ret;
43+
}
44+
};
45+
} // namespace Robustness
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#pragma once
2+
#include "tsan_defs.h"
3+
#include "tsan_rtl.h"
4+
#include "sanitizer_common/sanitizer_libc.h"
5+
#include "sanitizer_common/sanitizer_allocator_internal.h"
6+
7+
//class __tsan::ThreadState;
8+
9+
namespace Robustness{
10+
using __tsan::s8;
11+
using __tsan::u8;
12+
using __tsan::s16;
13+
using __tsan::u16;
14+
using __tsan::s32;
15+
using __tsan::u32;
16+
using __tsan::s64;
17+
using __tsan::u64;
18+
using __tsan::uptr;
19+
typedef s64 timestamp_t;
20+
typedef s64 ssize_t;
21+
typedef u64 uint64_t;
22+
typedef s64 int64_t;
23+
typedef __PTRDIFF_TYPE__ ptrdiff_t;
24+
typedef __SIZE_TYPE__ size_t;
25+
26+
typedef u8 uint8_t;;
27+
28+
typedef u64 Address;
29+
typedef u64 LocationId;
30+
31+
typedef u32 ThreadId;
32+
33+
using __tsan::InternalScopedString;
34+
35+
using __tsan::flags;
36+
37+
using __sanitizer::IsAligned;
38+
39+
using __sanitizer::LowLevelAllocator;
40+
using __sanitizer::InternalAlloc;
41+
using __sanitizer::InternalFree;
42+
using __sanitizer::internal_memcpy;
43+
using __sanitizer::internal_memmove;
44+
using __sanitizer::internal_memset;
45+
using __sanitizer::RoundUpTo;
46+
using __sanitizer::RoundUpToPowerOfTwo;
47+
using __sanitizer::GetPageSizeCached;
48+
using __sanitizer::MostSignificantSetBitIndex;
49+
using __sanitizer::MmapOrDie;
50+
using __sanitizer::UnmapOrDie;
51+
using __sanitizer::Max;
52+
using __sanitizer::Swap;
53+
using __sanitizer::forward;
54+
using __sanitizer::move;
55+
56+
using __sanitizer::Printf;
57+
using __sanitizer::Report;
58+
59+
using __sanitizer::Lock;
60+
using __sanitizer::Mutex;
61+
62+
template <typename T1, typename T2>
63+
struct Pair{
64+
T1 first;
65+
T2 second;
66+
};
67+
template <typename T1, typename T2>
68+
auto pair(T1 fst, T2 snd){
69+
return Pair<T1, T2>{fst, snd};
70+
}
71+
72+
using __tsan::max;
73+
using __tsan::min;
74+
75+
enum class ViolationType{
76+
read, write,
77+
};
78+
79+
struct DebugInfo {
80+
__tsan::ThreadState* thr = nullptr;
81+
uptr pc = 0xDEADBEEF;
82+
};
83+
84+
template<class>
85+
inline constexpr bool always_false_v = false;
86+
87+
inline bool isRobustness() {
88+
return __tsan::flags()->enable_robustness;
89+
}
90+
} // namespace Robustness

0 commit comments

Comments
 (0)