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