1 //===-- tsan_interface.h ----------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 // The functions declared in this header will be inserted by the instrumentation
12 // This header can be included by the instrumented program or by TSan tests.
13 //===----------------------------------------------------------------------===//
14 #ifndef TSAN_INTERFACE_H
15 #define TSAN_INTERFACE_H
17 #include <sanitizer_common/sanitizer_internal_defs.h>
18 using __sanitizer::uptr
;
20 // This header should NOT include any other headers.
21 // All functions in this header are extern "C" and start with __tsan_.
29 // This function should be called at the very beginning of the process,
30 // before any instrumented code is executed and before any call to malloc.
31 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_init();
33 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read1(void *addr
);
34 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read2(void *addr
);
35 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read4(void *addr
);
36 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read8(void *addr
);
37 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read16(void *addr
);
39 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write1(void *addr
);
40 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write2(void *addr
);
41 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write4(void *addr
);
42 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write8(void *addr
);
43 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write16(void *addr
);
45 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read2(const void *addr
);
46 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read4(const void *addr
);
47 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read8(const void *addr
);
48 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read16(const void *addr
);
50 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write2(void *addr
);
51 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write4(void *addr
);
52 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write8(void *addr
);
53 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write16(void *addr
);
55 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read1_pc(void *addr
, void *pc
);
56 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read2_pc(void *addr
, void *pc
);
57 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read4_pc(void *addr
, void *pc
);
58 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read8_pc(void *addr
, void *pc
);
59 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read16_pc(void *addr
, void *pc
);
61 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write1_pc(void *addr
, void *pc
);
62 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write2_pc(void *addr
, void *pc
);
63 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write4_pc(void *addr
, void *pc
);
64 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write8_pc(void *addr
, void *pc
);
65 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write16_pc(void *addr
, void *pc
);
67 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_vptr_read(void **vptr_p
);
68 SANITIZER_INTERFACE_ATTRIBUTE
69 void __tsan_vptr_update(void **vptr_p
, void *new_val
);
71 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_func_entry(void *call_pc
);
72 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_func_exit();
74 SANITIZER_INTERFACE_ATTRIBUTE
75 void __tsan_read_range(void *addr
, unsigned long size
); // NOLINT
76 SANITIZER_INTERFACE_ATTRIBUTE
77 void __tsan_write_range(void *addr
, unsigned long size
); // NOLINT
79 // User may provide function that would be called right when TSan detects
80 // an error. The argument 'report' is an opaque pointer that can be used to
81 // gather additional information using other TSan report API functions.
82 SANITIZER_INTERFACE_ATTRIBUTE
83 void __tsan_on_report(void *report
);
85 // If TSan is currently reporting a detected issue on the current thread,
86 // returns an opaque pointer to the current report. Otherwise returns NULL.
87 SANITIZER_INTERFACE_ATTRIBUTE
88 void *__tsan_get_current_report();
90 // Returns a report's description (issue type), number of duplicate issues
91 // found, counts of array data (stack traces, memory operations, locations,
92 // mutexes, threads, unique thread IDs) and a stack trace of a sleep() call (if
93 // one was involved in the issue).
94 SANITIZER_INTERFACE_ATTRIBUTE
95 int __tsan_get_report_data(void *report
, const char **description
, int *count
,
96 int *stack_count
, int *mop_count
, int *loc_count
,
97 int *mutex_count
, int *thread_count
,
98 int *unique_tid_count
, void **sleep_trace
,
101 // Returns information about stack traces included in the report.
102 SANITIZER_INTERFACE_ATTRIBUTE
103 int __tsan_get_report_stack(void *report
, uptr idx
, void **trace
,
106 // Returns information about memory operations included in the report.
107 SANITIZER_INTERFACE_ATTRIBUTE
108 int __tsan_get_report_mop(void *report
, uptr idx
, int *tid
, void **addr
,
109 int *size
, int *write
, int *atomic
, void **trace
,
112 // Returns information about locations included in the report.
113 SANITIZER_INTERFACE_ATTRIBUTE
114 int __tsan_get_report_loc(void *report
, uptr idx
, const char **type
,
115 void **addr
, uptr
*start
, uptr
*size
, int *tid
,
116 int *fd
, int *suppressable
, void **trace
,
119 // Returns information about mutexes included in the report.
120 SANITIZER_INTERFACE_ATTRIBUTE
121 int __tsan_get_report_mutex(void *report
, uptr idx
, uptr
*mutex_id
, void **addr
,
122 int *destroyed
, void **trace
, uptr trace_size
);
124 // Returns information about threads included in the report.
125 SANITIZER_INTERFACE_ATTRIBUTE
126 int __tsan_get_report_thread(void *report
, uptr idx
, int *tid
, uptr
*os_id
,
127 int *running
, const char **name
, int *parent_tid
,
128 void **trace
, uptr trace_size
);
130 // Returns information about unique thread IDs included in the report.
131 SANITIZER_INTERFACE_ATTRIBUTE
132 int __tsan_get_report_unique_tid(void *report
, uptr idx
, int *tid
);
134 #endif // SANITIZER_GO
142 // These should match declarations from public tsan_interface_atomic.h header.
143 typedef unsigned char a8
;
144 typedef unsigned short a16
; // NOLINT
145 typedef unsigned int a32
;
146 typedef unsigned long long a64
; // NOLINT
147 #if !SANITIZER_GO && (defined(__SIZEOF_INT128__) \
148 || (__clang_major__ * 100 + __clang_minor__ >= 302)) && !defined(__mips64)
149 __extension__
typedef __int128 a128
;
150 # define __TSAN_HAS_INT128 1
152 # define __TSAN_HAS_INT128 0
155 // Part of ABI, do not change.
156 // http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?view=markup
169 SANITIZER_INTERFACE_ATTRIBUTE
170 a8
__tsan_atomic8_load(const volatile a8
*a
, morder mo
);
171 SANITIZER_INTERFACE_ATTRIBUTE
172 a16
__tsan_atomic16_load(const volatile a16
*a
, morder mo
);
173 SANITIZER_INTERFACE_ATTRIBUTE
174 a32
__tsan_atomic32_load(const volatile a32
*a
, morder mo
);
175 SANITIZER_INTERFACE_ATTRIBUTE
176 a64
__tsan_atomic64_load(const volatile a64
*a
, morder mo
);
177 #if __TSAN_HAS_INT128
178 SANITIZER_INTERFACE_ATTRIBUTE
179 a128
__tsan_atomic128_load(const volatile a128
*a
, morder mo
);
182 SANITIZER_INTERFACE_ATTRIBUTE
183 void __tsan_atomic8_store(volatile a8
*a
, a8 v
, morder mo
);
184 SANITIZER_INTERFACE_ATTRIBUTE
185 void __tsan_atomic16_store(volatile a16
*a
, a16 v
, morder mo
);
186 SANITIZER_INTERFACE_ATTRIBUTE
187 void __tsan_atomic32_store(volatile a32
*a
, a32 v
, morder mo
);
188 SANITIZER_INTERFACE_ATTRIBUTE
189 void __tsan_atomic64_store(volatile a64
*a
, a64 v
, morder mo
);
190 #if __TSAN_HAS_INT128
191 SANITIZER_INTERFACE_ATTRIBUTE
192 void __tsan_atomic128_store(volatile a128
*a
, a128 v
, morder mo
);
195 SANITIZER_INTERFACE_ATTRIBUTE
196 a8
__tsan_atomic8_exchange(volatile a8
*a
, a8 v
, morder mo
);
197 SANITIZER_INTERFACE_ATTRIBUTE
198 a16
__tsan_atomic16_exchange(volatile a16
*a
, a16 v
, morder mo
);
199 SANITIZER_INTERFACE_ATTRIBUTE
200 a32
__tsan_atomic32_exchange(volatile a32
*a
, a32 v
, morder mo
);
201 SANITIZER_INTERFACE_ATTRIBUTE
202 a64
__tsan_atomic64_exchange(volatile a64
*a
, a64 v
, morder mo
);
203 #if __TSAN_HAS_INT128
204 SANITIZER_INTERFACE_ATTRIBUTE
205 a128
__tsan_atomic128_exchange(volatile a128
*a
, a128 v
, morder mo
);
208 SANITIZER_INTERFACE_ATTRIBUTE
209 a8
__tsan_atomic8_fetch_add(volatile a8
*a
, a8 v
, morder mo
);
210 SANITIZER_INTERFACE_ATTRIBUTE
211 a16
__tsan_atomic16_fetch_add(volatile a16
*a
, a16 v
, morder mo
);
212 SANITIZER_INTERFACE_ATTRIBUTE
213 a32
__tsan_atomic32_fetch_add(volatile a32
*a
, a32 v
, morder mo
);
214 SANITIZER_INTERFACE_ATTRIBUTE
215 a64
__tsan_atomic64_fetch_add(volatile a64
*a
, a64 v
, morder mo
);
216 #if __TSAN_HAS_INT128
217 SANITIZER_INTERFACE_ATTRIBUTE
218 a128
__tsan_atomic128_fetch_add(volatile a128
*a
, a128 v
, morder mo
);
221 SANITIZER_INTERFACE_ATTRIBUTE
222 a8
__tsan_atomic8_fetch_sub(volatile a8
*a
, a8 v
, morder mo
);
223 SANITIZER_INTERFACE_ATTRIBUTE
224 a16
__tsan_atomic16_fetch_sub(volatile a16
*a
, a16 v
, morder mo
);
225 SANITIZER_INTERFACE_ATTRIBUTE
226 a32
__tsan_atomic32_fetch_sub(volatile a32
*a
, a32 v
, morder mo
);
227 SANITIZER_INTERFACE_ATTRIBUTE
228 a64
__tsan_atomic64_fetch_sub(volatile a64
*a
, a64 v
, morder mo
);
229 #if __TSAN_HAS_INT128
230 SANITIZER_INTERFACE_ATTRIBUTE
231 a128
__tsan_atomic128_fetch_sub(volatile a128
*a
, a128 v
, morder mo
);
234 SANITIZER_INTERFACE_ATTRIBUTE
235 a8
__tsan_atomic8_fetch_and(volatile a8
*a
, a8 v
, morder mo
);
236 SANITIZER_INTERFACE_ATTRIBUTE
237 a16
__tsan_atomic16_fetch_and(volatile a16
*a
, a16 v
, morder mo
);
238 SANITIZER_INTERFACE_ATTRIBUTE
239 a32
__tsan_atomic32_fetch_and(volatile a32
*a
, a32 v
, morder mo
);
240 SANITIZER_INTERFACE_ATTRIBUTE
241 a64
__tsan_atomic64_fetch_and(volatile a64
*a
, a64 v
, morder mo
);
242 #if __TSAN_HAS_INT128
243 SANITIZER_INTERFACE_ATTRIBUTE
244 a128
__tsan_atomic128_fetch_and(volatile a128
*a
, a128 v
, morder mo
);
247 SANITIZER_INTERFACE_ATTRIBUTE
248 a8
__tsan_atomic8_fetch_or(volatile a8
*a
, a8 v
, morder mo
);
249 SANITIZER_INTERFACE_ATTRIBUTE
250 a16
__tsan_atomic16_fetch_or(volatile a16
*a
, a16 v
, morder mo
);
251 SANITIZER_INTERFACE_ATTRIBUTE
252 a32
__tsan_atomic32_fetch_or(volatile a32
*a
, a32 v
, morder mo
);
253 SANITIZER_INTERFACE_ATTRIBUTE
254 a64
__tsan_atomic64_fetch_or(volatile a64
*a
, a64 v
, morder mo
);
255 #if __TSAN_HAS_INT128
256 SANITIZER_INTERFACE_ATTRIBUTE
257 a128
__tsan_atomic128_fetch_or(volatile a128
*a
, a128 v
, morder mo
);
260 SANITIZER_INTERFACE_ATTRIBUTE
261 a8
__tsan_atomic8_fetch_xor(volatile a8
*a
, a8 v
, morder mo
);
262 SANITIZER_INTERFACE_ATTRIBUTE
263 a16
__tsan_atomic16_fetch_xor(volatile a16
*a
, a16 v
, morder mo
);
264 SANITIZER_INTERFACE_ATTRIBUTE
265 a32
__tsan_atomic32_fetch_xor(volatile a32
*a
, a32 v
, morder mo
);
266 SANITIZER_INTERFACE_ATTRIBUTE
267 a64
__tsan_atomic64_fetch_xor(volatile a64
*a
, a64 v
, morder mo
);
268 #if __TSAN_HAS_INT128
269 SANITIZER_INTERFACE_ATTRIBUTE
270 a128
__tsan_atomic128_fetch_xor(volatile a128
*a
, a128 v
, morder mo
);
273 SANITIZER_INTERFACE_ATTRIBUTE
274 a8
__tsan_atomic8_fetch_nand(volatile a8
*a
, a8 v
, morder mo
);
275 SANITIZER_INTERFACE_ATTRIBUTE
276 a16
__tsan_atomic16_fetch_nand(volatile a16
*a
, a16 v
, morder mo
);
277 SANITIZER_INTERFACE_ATTRIBUTE
278 a32
__tsan_atomic32_fetch_nand(volatile a32
*a
, a32 v
, morder mo
);
279 SANITIZER_INTERFACE_ATTRIBUTE
280 a64
__tsan_atomic64_fetch_nand(volatile a64
*a
, a64 v
, morder mo
);
281 #if __TSAN_HAS_INT128
282 SANITIZER_INTERFACE_ATTRIBUTE
283 a128
__tsan_atomic128_fetch_nand(volatile a128
*a
, a128 v
, morder mo
);
286 SANITIZER_INTERFACE_ATTRIBUTE
287 int __tsan_atomic8_compare_exchange_strong(volatile a8
*a
, a8
*c
, a8 v
,
288 morder mo
, morder fmo
);
289 SANITIZER_INTERFACE_ATTRIBUTE
290 int __tsan_atomic16_compare_exchange_strong(volatile a16
*a
, a16
*c
, a16 v
,
291 morder mo
, morder fmo
);
292 SANITIZER_INTERFACE_ATTRIBUTE
293 int __tsan_atomic32_compare_exchange_strong(volatile a32
*a
, a32
*c
, a32 v
,
294 morder mo
, morder fmo
);
295 SANITIZER_INTERFACE_ATTRIBUTE
296 int __tsan_atomic64_compare_exchange_strong(volatile a64
*a
, a64
*c
, a64 v
,
297 morder mo
, morder fmo
);
298 #if __TSAN_HAS_INT128
299 SANITIZER_INTERFACE_ATTRIBUTE
300 int __tsan_atomic128_compare_exchange_strong(volatile a128
*a
, a128
*c
, a128 v
,
301 morder mo
, morder fmo
);
304 SANITIZER_INTERFACE_ATTRIBUTE
305 int __tsan_atomic8_compare_exchange_weak(volatile a8
*a
, a8
*c
, a8 v
, morder mo
,
307 SANITIZER_INTERFACE_ATTRIBUTE
308 int __tsan_atomic16_compare_exchange_weak(volatile a16
*a
, a16
*c
, a16 v
,
309 morder mo
, morder fmo
);
310 SANITIZER_INTERFACE_ATTRIBUTE
311 int __tsan_atomic32_compare_exchange_weak(volatile a32
*a
, a32
*c
, a32 v
,
312 morder mo
, morder fmo
);
313 SANITIZER_INTERFACE_ATTRIBUTE
314 int __tsan_atomic64_compare_exchange_weak(volatile a64
*a
, a64
*c
, a64 v
,
315 morder mo
, morder fmo
);
316 #if __TSAN_HAS_INT128
317 SANITIZER_INTERFACE_ATTRIBUTE
318 int __tsan_atomic128_compare_exchange_weak(volatile a128
*a
, a128
*c
, a128 v
,
319 morder mo
, morder fmo
);
322 SANITIZER_INTERFACE_ATTRIBUTE
323 a8
__tsan_atomic8_compare_exchange_val(volatile a8
*a
, a8 c
, a8 v
, morder mo
,
325 SANITIZER_INTERFACE_ATTRIBUTE
326 a16
__tsan_atomic16_compare_exchange_val(volatile a16
*a
, a16 c
, a16 v
,
327 morder mo
, morder fmo
);
328 SANITIZER_INTERFACE_ATTRIBUTE
329 a32
__tsan_atomic32_compare_exchange_val(volatile a32
*a
, a32 c
, a32 v
,
330 morder mo
, morder fmo
);
331 SANITIZER_INTERFACE_ATTRIBUTE
332 a64
__tsan_atomic64_compare_exchange_val(volatile a64
*a
, a64 c
, a64 v
,
333 morder mo
, morder fmo
);
334 #if __TSAN_HAS_INT128
335 SANITIZER_INTERFACE_ATTRIBUTE
336 a128
__tsan_atomic128_compare_exchange_val(volatile a128
*a
, a128 c
, a128 v
,
337 morder mo
, morder fmo
);
340 SANITIZER_INTERFACE_ATTRIBUTE
341 void __tsan_atomic_thread_fence(morder mo
);
342 SANITIZER_INTERFACE_ATTRIBUTE
343 void __tsan_atomic_signal_fence(morder mo
);
345 SANITIZER_INTERFACE_ATTRIBUTE
346 void __tsan_go_atomic32_load(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
347 SANITIZER_INTERFACE_ATTRIBUTE
348 void __tsan_go_atomic64_load(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
349 SANITIZER_INTERFACE_ATTRIBUTE
350 void __tsan_go_atomic32_store(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
351 SANITIZER_INTERFACE_ATTRIBUTE
352 void __tsan_go_atomic64_store(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
353 SANITIZER_INTERFACE_ATTRIBUTE
354 void __tsan_go_atomic32_fetch_add(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
355 SANITIZER_INTERFACE_ATTRIBUTE
356 void __tsan_go_atomic64_fetch_add(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
357 SANITIZER_INTERFACE_ATTRIBUTE
358 void __tsan_go_atomic32_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
359 SANITIZER_INTERFACE_ATTRIBUTE
360 void __tsan_go_atomic64_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
361 SANITIZER_INTERFACE_ATTRIBUTE
362 void __tsan_go_atomic32_compare_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
,
364 SANITIZER_INTERFACE_ATTRIBUTE
365 void __tsan_go_atomic64_compare_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
,
369 } // namespace __tsan
371 #endif // TSAN_INTERFACE_H