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
;
19 using __sanitizer::tid_t
;
21 // This header should NOT include any other headers.
22 // All functions in this header are extern "C" and start with __tsan_.
30 // This function should be called at the very beginning of the process,
31 // before any instrumented code is executed and before any call to malloc.
32 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_init();
34 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_flush_memory();
36 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read1(void *addr
);
37 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read2(void *addr
);
38 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read4(void *addr
);
39 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read8(void *addr
);
40 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read16(void *addr
);
42 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write1(void *addr
);
43 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write2(void *addr
);
44 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write4(void *addr
);
45 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write8(void *addr
);
46 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write16(void *addr
);
48 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read2(const void *addr
);
49 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read4(const void *addr
);
50 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read8(const void *addr
);
51 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_read16(const void *addr
);
53 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write2(void *addr
);
54 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write4(void *addr
);
55 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write8(void *addr
);
56 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_unaligned_write16(void *addr
);
58 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read1_pc(void *addr
, void *pc
);
59 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read2_pc(void *addr
, void *pc
);
60 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read4_pc(void *addr
, void *pc
);
61 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read8_pc(void *addr
, void *pc
);
62 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_read16_pc(void *addr
, void *pc
);
64 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write1_pc(void *addr
, void *pc
);
65 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write2_pc(void *addr
, void *pc
);
66 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write4_pc(void *addr
, void *pc
);
67 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write8_pc(void *addr
, void *pc
);
68 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_write16_pc(void *addr
, void *pc
);
70 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_vptr_read(void **vptr_p
);
71 SANITIZER_INTERFACE_ATTRIBUTE
72 void __tsan_vptr_update(void **vptr_p
, void *new_val
);
74 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_func_entry(void *call_pc
);
75 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_func_exit();
77 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_ignore_thread_begin();
78 SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_ignore_thread_end();
80 SANITIZER_INTERFACE_ATTRIBUTE
81 void *__tsan_external_register_tag(const char *object_type
);
82 SANITIZER_INTERFACE_ATTRIBUTE
83 void __tsan_external_register_header(void *tag
, const char *header
);
84 SANITIZER_INTERFACE_ATTRIBUTE
85 void __tsan_external_assign_tag(void *addr
, void *tag
);
86 SANITIZER_INTERFACE_ATTRIBUTE
87 void __tsan_external_read(void *addr
, void *caller_pc
, void *tag
);
88 SANITIZER_INTERFACE_ATTRIBUTE
89 void __tsan_external_write(void *addr
, void *caller_pc
, void *tag
);
91 SANITIZER_INTERFACE_ATTRIBUTE
92 void __tsan_read_range(void *addr
, unsigned long size
); // NOLINT
93 SANITIZER_INTERFACE_ATTRIBUTE
94 void __tsan_write_range(void *addr
, unsigned long size
); // NOLINT
96 // User may provide function that would be called right when TSan detects
97 // an error. The argument 'report' is an opaque pointer that can be used to
98 // gather additional information using other TSan report API functions.
99 SANITIZER_INTERFACE_ATTRIBUTE
100 void __tsan_on_report(void *report
);
102 // If TSan is currently reporting a detected issue on the current thread,
103 // returns an opaque pointer to the current report. Otherwise returns NULL.
104 SANITIZER_INTERFACE_ATTRIBUTE
105 void *__tsan_get_current_report();
107 // Returns a report's description (issue type), number of duplicate issues
108 // found, counts of array data (stack traces, memory operations, locations,
109 // mutexes, threads, unique thread IDs) and a stack trace of a sleep() call (if
110 // one was involved in the issue).
111 SANITIZER_INTERFACE_ATTRIBUTE
112 int __tsan_get_report_data(void *report
, const char **description
, int *count
,
113 int *stack_count
, int *mop_count
, int *loc_count
,
114 int *mutex_count
, int *thread_count
,
115 int *unique_tid_count
, void **sleep_trace
,
118 // Returns information about stack traces included in the report.
119 SANITIZER_INTERFACE_ATTRIBUTE
120 int __tsan_get_report_stack(void *report
, uptr idx
, void **trace
,
123 // Returns information about memory operations included in the report.
124 SANITIZER_INTERFACE_ATTRIBUTE
125 int __tsan_get_report_mop(void *report
, uptr idx
, int *tid
, void **addr
,
126 int *size
, int *write
, int *atomic
, void **trace
,
129 // Returns information about locations included in the report.
130 SANITIZER_INTERFACE_ATTRIBUTE
131 int __tsan_get_report_loc(void *report
, uptr idx
, const char **type
,
132 void **addr
, uptr
*start
, uptr
*size
, int *tid
,
133 int *fd
, int *suppressable
, void **trace
,
136 SANITIZER_INTERFACE_ATTRIBUTE
137 int __tsan_get_report_loc_object_type(void *report
, uptr idx
,
138 const char **object_type
);
140 // Returns information about mutexes included in the report.
141 SANITIZER_INTERFACE_ATTRIBUTE
142 int __tsan_get_report_mutex(void *report
, uptr idx
, uptr
*mutex_id
, void **addr
,
143 int *destroyed
, void **trace
, uptr trace_size
);
145 // Returns information about threads included in the report.
146 SANITIZER_INTERFACE_ATTRIBUTE
147 int __tsan_get_report_thread(void *report
, uptr idx
, int *tid
, tid_t
*os_id
,
148 int *running
, const char **name
, int *parent_tid
,
149 void **trace
, uptr trace_size
);
151 // Returns information about unique thread IDs included in the report.
152 SANITIZER_INTERFACE_ATTRIBUTE
153 int __tsan_get_report_unique_tid(void *report
, uptr idx
, int *tid
);
155 // Returns the type of the pointer (heap, stack, global, ...) and if possible
156 // also the starting address (e.g. of a heap allocation) and size.
157 SANITIZER_INTERFACE_ATTRIBUTE
158 const char *__tsan_locate_address(uptr addr
, char *name
, uptr name_size
,
159 uptr
*region_address
, uptr
*region_size
);
161 // Returns the allocation stack for a heap pointer.
162 SANITIZER_INTERFACE_ATTRIBUTE
163 int __tsan_get_alloc_stack(uptr addr
, uptr
*trace
, uptr size
, int *thread_id
,
166 #endif // SANITIZER_GO
174 // These should match declarations from public tsan_interface_atomic.h header.
175 typedef unsigned char a8
;
176 typedef unsigned short a16
; // NOLINT
177 typedef unsigned int a32
;
178 typedef unsigned long long a64
; // NOLINT
179 #if !SANITIZER_GO && (defined(__SIZEOF_INT128__) \
180 || (__clang_major__ * 100 + __clang_minor__ >= 302)) && !defined(__mips64)
181 __extension__
typedef __int128 a128
;
182 # define __TSAN_HAS_INT128 1
184 # define __TSAN_HAS_INT128 0
187 // Part of ABI, do not change.
188 // http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?view=markup
201 SANITIZER_INTERFACE_ATTRIBUTE
202 a8
__tsan_atomic8_load(const volatile a8
*a
, morder mo
);
203 SANITIZER_INTERFACE_ATTRIBUTE
204 a16
__tsan_atomic16_load(const volatile a16
*a
, morder mo
);
205 SANITIZER_INTERFACE_ATTRIBUTE
206 a32
__tsan_atomic32_load(const volatile a32
*a
, morder mo
);
207 SANITIZER_INTERFACE_ATTRIBUTE
208 a64
__tsan_atomic64_load(const volatile a64
*a
, morder mo
);
209 #if __TSAN_HAS_INT128
210 SANITIZER_INTERFACE_ATTRIBUTE
211 a128
__tsan_atomic128_load(const volatile a128
*a
, morder mo
);
214 SANITIZER_INTERFACE_ATTRIBUTE
215 void __tsan_atomic8_store(volatile a8
*a
, a8 v
, morder mo
);
216 SANITIZER_INTERFACE_ATTRIBUTE
217 void __tsan_atomic16_store(volatile a16
*a
, a16 v
, morder mo
);
218 SANITIZER_INTERFACE_ATTRIBUTE
219 void __tsan_atomic32_store(volatile a32
*a
, a32 v
, morder mo
);
220 SANITIZER_INTERFACE_ATTRIBUTE
221 void __tsan_atomic64_store(volatile a64
*a
, a64 v
, morder mo
);
222 #if __TSAN_HAS_INT128
223 SANITIZER_INTERFACE_ATTRIBUTE
224 void __tsan_atomic128_store(volatile a128
*a
, a128 v
, morder mo
);
227 SANITIZER_INTERFACE_ATTRIBUTE
228 a8
__tsan_atomic8_exchange(volatile a8
*a
, a8 v
, morder mo
);
229 SANITIZER_INTERFACE_ATTRIBUTE
230 a16
__tsan_atomic16_exchange(volatile a16
*a
, a16 v
, morder mo
);
231 SANITIZER_INTERFACE_ATTRIBUTE
232 a32
__tsan_atomic32_exchange(volatile a32
*a
, a32 v
, morder mo
);
233 SANITIZER_INTERFACE_ATTRIBUTE
234 a64
__tsan_atomic64_exchange(volatile a64
*a
, a64 v
, morder mo
);
235 #if __TSAN_HAS_INT128
236 SANITIZER_INTERFACE_ATTRIBUTE
237 a128
__tsan_atomic128_exchange(volatile a128
*a
, a128 v
, morder mo
);
240 SANITIZER_INTERFACE_ATTRIBUTE
241 a8
__tsan_atomic8_fetch_add(volatile a8
*a
, a8 v
, morder mo
);
242 SANITIZER_INTERFACE_ATTRIBUTE
243 a16
__tsan_atomic16_fetch_add(volatile a16
*a
, a16 v
, morder mo
);
244 SANITIZER_INTERFACE_ATTRIBUTE
245 a32
__tsan_atomic32_fetch_add(volatile a32
*a
, a32 v
, morder mo
);
246 SANITIZER_INTERFACE_ATTRIBUTE
247 a64
__tsan_atomic64_fetch_add(volatile a64
*a
, a64 v
, morder mo
);
248 #if __TSAN_HAS_INT128
249 SANITIZER_INTERFACE_ATTRIBUTE
250 a128
__tsan_atomic128_fetch_add(volatile a128
*a
, a128 v
, morder mo
);
253 SANITIZER_INTERFACE_ATTRIBUTE
254 a8
__tsan_atomic8_fetch_sub(volatile a8
*a
, a8 v
, morder mo
);
255 SANITIZER_INTERFACE_ATTRIBUTE
256 a16
__tsan_atomic16_fetch_sub(volatile a16
*a
, a16 v
, morder mo
);
257 SANITIZER_INTERFACE_ATTRIBUTE
258 a32
__tsan_atomic32_fetch_sub(volatile a32
*a
, a32 v
, morder mo
);
259 SANITIZER_INTERFACE_ATTRIBUTE
260 a64
__tsan_atomic64_fetch_sub(volatile a64
*a
, a64 v
, morder mo
);
261 #if __TSAN_HAS_INT128
262 SANITIZER_INTERFACE_ATTRIBUTE
263 a128
__tsan_atomic128_fetch_sub(volatile a128
*a
, a128 v
, morder mo
);
266 SANITIZER_INTERFACE_ATTRIBUTE
267 a8
__tsan_atomic8_fetch_and(volatile a8
*a
, a8 v
, morder mo
);
268 SANITIZER_INTERFACE_ATTRIBUTE
269 a16
__tsan_atomic16_fetch_and(volatile a16
*a
, a16 v
, morder mo
);
270 SANITIZER_INTERFACE_ATTRIBUTE
271 a32
__tsan_atomic32_fetch_and(volatile a32
*a
, a32 v
, morder mo
);
272 SANITIZER_INTERFACE_ATTRIBUTE
273 a64
__tsan_atomic64_fetch_and(volatile a64
*a
, a64 v
, morder mo
);
274 #if __TSAN_HAS_INT128
275 SANITIZER_INTERFACE_ATTRIBUTE
276 a128
__tsan_atomic128_fetch_and(volatile a128
*a
, a128 v
, morder mo
);
279 SANITIZER_INTERFACE_ATTRIBUTE
280 a8
__tsan_atomic8_fetch_or(volatile a8
*a
, a8 v
, morder mo
);
281 SANITIZER_INTERFACE_ATTRIBUTE
282 a16
__tsan_atomic16_fetch_or(volatile a16
*a
, a16 v
, morder mo
);
283 SANITIZER_INTERFACE_ATTRIBUTE
284 a32
__tsan_atomic32_fetch_or(volatile a32
*a
, a32 v
, morder mo
);
285 SANITIZER_INTERFACE_ATTRIBUTE
286 a64
__tsan_atomic64_fetch_or(volatile a64
*a
, a64 v
, morder mo
);
287 #if __TSAN_HAS_INT128
288 SANITIZER_INTERFACE_ATTRIBUTE
289 a128
__tsan_atomic128_fetch_or(volatile a128
*a
, a128 v
, morder mo
);
292 SANITIZER_INTERFACE_ATTRIBUTE
293 a8
__tsan_atomic8_fetch_xor(volatile a8
*a
, a8 v
, morder mo
);
294 SANITIZER_INTERFACE_ATTRIBUTE
295 a16
__tsan_atomic16_fetch_xor(volatile a16
*a
, a16 v
, morder mo
);
296 SANITIZER_INTERFACE_ATTRIBUTE
297 a32
__tsan_atomic32_fetch_xor(volatile a32
*a
, a32 v
, morder mo
);
298 SANITIZER_INTERFACE_ATTRIBUTE
299 a64
__tsan_atomic64_fetch_xor(volatile a64
*a
, a64 v
, morder mo
);
300 #if __TSAN_HAS_INT128
301 SANITIZER_INTERFACE_ATTRIBUTE
302 a128
__tsan_atomic128_fetch_xor(volatile a128
*a
, a128 v
, morder mo
);
305 SANITIZER_INTERFACE_ATTRIBUTE
306 a8
__tsan_atomic8_fetch_nand(volatile a8
*a
, a8 v
, morder mo
);
307 SANITIZER_INTERFACE_ATTRIBUTE
308 a16
__tsan_atomic16_fetch_nand(volatile a16
*a
, a16 v
, morder mo
);
309 SANITIZER_INTERFACE_ATTRIBUTE
310 a32
__tsan_atomic32_fetch_nand(volatile a32
*a
, a32 v
, morder mo
);
311 SANITIZER_INTERFACE_ATTRIBUTE
312 a64
__tsan_atomic64_fetch_nand(volatile a64
*a
, a64 v
, morder mo
);
313 #if __TSAN_HAS_INT128
314 SANITIZER_INTERFACE_ATTRIBUTE
315 a128
__tsan_atomic128_fetch_nand(volatile a128
*a
, a128 v
, morder mo
);
318 SANITIZER_INTERFACE_ATTRIBUTE
319 int __tsan_atomic8_compare_exchange_strong(volatile a8
*a
, a8
*c
, a8 v
,
320 morder mo
, morder fmo
);
321 SANITIZER_INTERFACE_ATTRIBUTE
322 int __tsan_atomic16_compare_exchange_strong(volatile a16
*a
, a16
*c
, a16 v
,
323 morder mo
, morder fmo
);
324 SANITIZER_INTERFACE_ATTRIBUTE
325 int __tsan_atomic32_compare_exchange_strong(volatile a32
*a
, a32
*c
, a32 v
,
326 morder mo
, morder fmo
);
327 SANITIZER_INTERFACE_ATTRIBUTE
328 int __tsan_atomic64_compare_exchange_strong(volatile a64
*a
, a64
*c
, a64 v
,
329 morder mo
, morder fmo
);
330 #if __TSAN_HAS_INT128
331 SANITIZER_INTERFACE_ATTRIBUTE
332 int __tsan_atomic128_compare_exchange_strong(volatile a128
*a
, a128
*c
, a128 v
,
333 morder mo
, morder fmo
);
336 SANITIZER_INTERFACE_ATTRIBUTE
337 int __tsan_atomic8_compare_exchange_weak(volatile a8
*a
, a8
*c
, a8 v
, morder mo
,
339 SANITIZER_INTERFACE_ATTRIBUTE
340 int __tsan_atomic16_compare_exchange_weak(volatile a16
*a
, a16
*c
, a16 v
,
341 morder mo
, morder fmo
);
342 SANITIZER_INTERFACE_ATTRIBUTE
343 int __tsan_atomic32_compare_exchange_weak(volatile a32
*a
, a32
*c
, a32 v
,
344 morder mo
, morder fmo
);
345 SANITIZER_INTERFACE_ATTRIBUTE
346 int __tsan_atomic64_compare_exchange_weak(volatile a64
*a
, a64
*c
, a64 v
,
347 morder mo
, morder fmo
);
348 #if __TSAN_HAS_INT128
349 SANITIZER_INTERFACE_ATTRIBUTE
350 int __tsan_atomic128_compare_exchange_weak(volatile a128
*a
, a128
*c
, a128 v
,
351 morder mo
, morder fmo
);
354 SANITIZER_INTERFACE_ATTRIBUTE
355 a8
__tsan_atomic8_compare_exchange_val(volatile a8
*a
, a8 c
, a8 v
, morder mo
,
357 SANITIZER_INTERFACE_ATTRIBUTE
358 a16
__tsan_atomic16_compare_exchange_val(volatile a16
*a
, a16 c
, a16 v
,
359 morder mo
, morder fmo
);
360 SANITIZER_INTERFACE_ATTRIBUTE
361 a32
__tsan_atomic32_compare_exchange_val(volatile a32
*a
, a32 c
, a32 v
,
362 morder mo
, morder fmo
);
363 SANITIZER_INTERFACE_ATTRIBUTE
364 a64
__tsan_atomic64_compare_exchange_val(volatile a64
*a
, a64 c
, a64 v
,
365 morder mo
, morder fmo
);
366 #if __TSAN_HAS_INT128
367 SANITIZER_INTERFACE_ATTRIBUTE
368 a128
__tsan_atomic128_compare_exchange_val(volatile a128
*a
, a128 c
, a128 v
,
369 morder mo
, morder fmo
);
372 SANITIZER_INTERFACE_ATTRIBUTE
373 void __tsan_atomic_thread_fence(morder mo
);
374 SANITIZER_INTERFACE_ATTRIBUTE
375 void __tsan_atomic_signal_fence(morder mo
);
377 SANITIZER_INTERFACE_ATTRIBUTE
378 void __tsan_go_atomic32_load(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
379 SANITIZER_INTERFACE_ATTRIBUTE
380 void __tsan_go_atomic64_load(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
381 SANITIZER_INTERFACE_ATTRIBUTE
382 void __tsan_go_atomic32_store(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
383 SANITIZER_INTERFACE_ATTRIBUTE
384 void __tsan_go_atomic64_store(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
385 SANITIZER_INTERFACE_ATTRIBUTE
386 void __tsan_go_atomic32_fetch_add(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
387 SANITIZER_INTERFACE_ATTRIBUTE
388 void __tsan_go_atomic64_fetch_add(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
389 SANITIZER_INTERFACE_ATTRIBUTE
390 void __tsan_go_atomic32_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
391 SANITIZER_INTERFACE_ATTRIBUTE
392 void __tsan_go_atomic64_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
, u8
*a
);
393 SANITIZER_INTERFACE_ATTRIBUTE
394 void __tsan_go_atomic32_compare_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
,
396 SANITIZER_INTERFACE_ATTRIBUTE
397 void __tsan_go_atomic64_compare_exchange(ThreadState
*thr
, uptr cpc
, uptr pc
,
401 } // namespace __tsan
403 #endif // TSAN_INTERFACE_H