]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/tsan/go/tsan_go.cc
1 //===-- tsan_go.cc --------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // ThreadSanitizer runtime for Go language.
12 //===----------------------------------------------------------------------===//
15 #include "tsan_symbolize.h"
16 #include "sanitizer_common/sanitizer_common.h"
21 void InitializeInterceptors() {
24 void InitializeDynamicAnnotations() {
27 bool IsExpectedReport(uptr addr
, uptr size
) {
31 void *internal_start_thread(void(*func
)(void*), void *arg
) {
35 void internal_join_thread(void *th
) {
38 ReportLocation
*SymbolizeData(uptr addr
) {
42 ReportStack
*NewReportStackEntry(uptr addr
) {
43 ReportStack
*ent
= (ReportStack
*)internal_alloc(MBlockReportStack
,
45 internal_memset(ent
, 0, sizeof(*ent
));
50 void *internal_alloc(MBlockType typ
, uptr sz
) {
51 return InternalAlloc(sz
);
54 void internal_free(void *p
) {
58 struct SymbolizeContext
{
68 static void (*symbolize_cb
)(SymbolizeContext
*ctx
);
70 ReportStack
*SymbolizeCode(uptr addr
) {
71 ReportStack
*s
= (ReportStack
*)internal_alloc(MBlockReportStack
,
73 internal_memset(s
, 0, sizeof(*s
));
76 internal_memset(&ctx
, 0, sizeof(ctx
));
81 s
->func
= internal_strdup(ctx
.func
? ctx
.func
: "??");
82 s
->file
= internal_strdup(ctx
.file
? ctx
.file
: "-");
91 static ThreadState
*main_thr
;
94 static ThreadState
*AllocGoroutine() {
95 ThreadState
*thr
= (ThreadState
*)internal_alloc(MBlockThreadContex
,
97 internal_memset(thr
, 0, sizeof(*thr
));
101 void __tsan_init(ThreadState
**thrp
, void (*cb
)(SymbolizeContext
*cb
)) {
103 ThreadState
*thr
= AllocGoroutine();
104 main_thr
= *thrp
= thr
;
110 // FIXME: Not necessary thread 0.
111 ThreadState
*thr
= main_thr
;
112 int res
= Finalize(thr
);
116 void __tsan_map_shadow(uptr addr
, uptr size
) {
117 MapShadow(addr
, size
);
120 void __tsan_read(ThreadState
*thr
, void *addr
, void *pc
) {
121 MemoryRead(thr
, (uptr
)pc
, (uptr
)addr
, kSizeLog1
);
124 void __tsan_read_pc(ThreadState
*thr
, void *addr
, uptr callpc
, uptr pc
) {
126 FuncEntry(thr
, callpc
);
127 MemoryRead(thr
, (uptr
)pc
, (uptr
)addr
, kSizeLog1
);
132 void __tsan_write(ThreadState
*thr
, void *addr
, void *pc
) {
133 MemoryWrite(thr
, (uptr
)pc
, (uptr
)addr
, kSizeLog1
);
136 void __tsan_write_pc(ThreadState
*thr
, void *addr
, uptr callpc
, uptr pc
) {
138 FuncEntry(thr
, callpc
);
139 MemoryWrite(thr
, (uptr
)pc
, (uptr
)addr
, kSizeLog1
);
144 void __tsan_read_range(ThreadState
*thr
, void *addr
, uptr size
, uptr pc
) {
145 MemoryAccessRange(thr
, (uptr
)pc
, (uptr
)addr
, size
, false);
148 void __tsan_write_range(ThreadState
*thr
, void *addr
, uptr size
, uptr pc
) {
149 MemoryAccessRange(thr
, (uptr
)pc
, (uptr
)addr
, size
, true);
152 void __tsan_func_enter(ThreadState
*thr
, void *pc
) {
153 FuncEntry(thr
, (uptr
)pc
);
156 void __tsan_func_exit(ThreadState
*thr
) {
160 void __tsan_malloc(void *p
, uptr sz
) {
163 MemoryResetRange(0, 0, (uptr
)p
, sz
);
166 void __tsan_go_start(ThreadState
*parent
, ThreadState
**pthr
, void *pc
) {
167 ThreadState
*thr
= AllocGoroutine();
169 int goid
= ThreadCreate(parent
, (uptr
)pc
, 0, true);
170 ThreadStart(thr
, goid
, 0);
173 void __tsan_go_end(ThreadState
*thr
) {
178 void __tsan_acquire(ThreadState
*thr
, void *addr
) {
179 Acquire(thr
, 0, (uptr
)addr
);
182 void __tsan_release(ThreadState
*thr
, void *addr
) {
183 ReleaseStore(thr
, 0, (uptr
)addr
);
186 void __tsan_release_merge(ThreadState
*thr
, void *addr
) {
187 Release(thr
, 0, (uptr
)addr
);
190 void __tsan_finalizer_goroutine(ThreadState
*thr
) {
191 AcquireGlobal(thr
, 0);
194 void __tsan_mutex_before_lock(ThreadState
*thr
, uptr addr
, bool write
) {
197 void __tsan_mutex_after_lock(ThreadState
*thr
, uptr addr
, bool write
) {
199 MutexLock(thr
, 0, addr
);
201 MutexReadLock(thr
, 0, addr
);
204 void __tsan_mutex_before_unlock(ThreadState
*thr
, uptr addr
, bool write
) {
206 MutexUnlock(thr
, 0, addr
);
208 MutexReadUnlock(thr
, 0, addr
);
212 } // namespace __tsan
214 namespace __sanitizer
{
216 void SymbolizerPrepareForSandboxing() {
217 // Nothing to do here for Go.
220 } // namespace __sanitizer