xref: /freebsd/contrib/llvm-project/compiler-rt/include/sanitizer/tsan_interface_atomic.h (revision 1c4ee7dfb8affed302171232b0f612e6bcba3c10)
1 //===-- tsan_interface_atomic.h ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //
11 // Public interface header for TSan atomics.
12 //===----------------------------------------------------------------------===//
13 #ifndef TSAN_INTERFACE_ATOMIC_H
14 #define TSAN_INTERFACE_ATOMIC_H
15 
16 #include <sanitizer/common_interface_defs.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef char __tsan_atomic8;
23 typedef short __tsan_atomic16;
24 typedef int __tsan_atomic32;
25 typedef long __tsan_atomic64;
26 #if defined(__SIZEOF_INT128__) ||                                              \
27     (__clang_major__ * 100 + __clang_minor__ >= 302)
28 __extension__ typedef __int128 __tsan_atomic128;
29 #define __TSAN_HAS_INT128 1
30 #else
31 #define __TSAN_HAS_INT128 0
32 #endif
33 
34 // Part of ABI, do not change.
35 // https://github.com/llvm/llvm-project/blob/main/libcxx/include/atomic
36 typedef enum {
37   __tsan_memory_order_relaxed,
38   __tsan_memory_order_consume,
39   __tsan_memory_order_acquire,
40   __tsan_memory_order_release,
41   __tsan_memory_order_acq_rel,
42   __tsan_memory_order_seq_cst
43 } __tsan_memory_order;
44 
45 __tsan_atomic8 SANITIZER_CDECL
46 __tsan_atomic8_load(const volatile __tsan_atomic8 *a, __tsan_memory_order mo);
47 __tsan_atomic16 SANITIZER_CDECL
48 __tsan_atomic16_load(const volatile __tsan_atomic16 *a, __tsan_memory_order mo);
49 __tsan_atomic32 SANITIZER_CDECL
50 __tsan_atomic32_load(const volatile __tsan_atomic32 *a, __tsan_memory_order mo);
51 __tsan_atomic64 SANITIZER_CDECL
52 __tsan_atomic64_load(const volatile __tsan_atomic64 *a, __tsan_memory_order mo);
53 #if __TSAN_HAS_INT128
54 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_load(
55     const volatile __tsan_atomic128 *a, __tsan_memory_order mo);
56 #endif
57 
58 void SANITIZER_CDECL __tsan_atomic8_store(volatile __tsan_atomic8 *a,
59                                           __tsan_atomic8 v,
60                                           __tsan_memory_order mo);
61 void SANITIZER_CDECL __tsan_atomic16_store(volatile __tsan_atomic16 *a,
62                                            __tsan_atomic16 v,
63                                            __tsan_memory_order mo);
64 void SANITIZER_CDECL __tsan_atomic32_store(volatile __tsan_atomic32 *a,
65                                            __tsan_atomic32 v,
66                                            __tsan_memory_order mo);
67 void SANITIZER_CDECL __tsan_atomic64_store(volatile __tsan_atomic64 *a,
68                                            __tsan_atomic64 v,
69                                            __tsan_memory_order mo);
70 #if __TSAN_HAS_INT128
71 void SANITIZER_CDECL __tsan_atomic128_store(volatile __tsan_atomic128 *a,
72                                             __tsan_atomic128 v,
73                                             __tsan_memory_order mo);
74 #endif
75 
76 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_exchange(
77     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
78 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_exchange(
79     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
80 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_exchange(
81     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
82 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_exchange(
83     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
84 #if __TSAN_HAS_INT128
85 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_exchange(
86     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
87 #endif
88 
89 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_add(
90     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
91 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_add(
92     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
93 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_add(
94     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
95 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_add(
96     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
97 #if __TSAN_HAS_INT128
98 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_add(
99     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
100 #endif
101 
102 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_sub(
103     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
104 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_sub(
105     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
106 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_sub(
107     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
108 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_sub(
109     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
110 #if __TSAN_HAS_INT128
111 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_sub(
112     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
113 #endif
114 
115 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_and(
116     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
117 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_and(
118     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
119 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_and(
120     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
121 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_and(
122     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
123 #if __TSAN_HAS_INT128
124 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_and(
125     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
126 #endif
127 
128 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_or(
129     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
130 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_or(
131     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
132 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_or(
133     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
134 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_or(
135     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
136 #if __TSAN_HAS_INT128
137 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_or(
138     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
139 #endif
140 
141 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_xor(
142     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
143 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_xor(
144     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
145 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_xor(
146     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
147 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_xor(
148     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
149 #if __TSAN_HAS_INT128
150 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_xor(
151     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
152 #endif
153 
154 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_nand(
155     volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
156 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_nand(
157     volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
158 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_nand(
159     volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
160 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_nand(
161     volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
162 #if __TSAN_HAS_INT128
163 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_nand(
164     volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
165 #endif
166 
167 int SANITIZER_CDECL __tsan_atomic8_compare_exchange_weak(
168     volatile __tsan_atomic8 *a, __tsan_atomic8 *c, __tsan_atomic8 v,
169     __tsan_memory_order mo, __tsan_memory_order fail_mo);
170 int SANITIZER_CDECL __tsan_atomic16_compare_exchange_weak(
171     volatile __tsan_atomic16 *a, __tsan_atomic16 *c, __tsan_atomic16 v,
172     __tsan_memory_order mo, __tsan_memory_order fail_mo);
173 int SANITIZER_CDECL __tsan_atomic32_compare_exchange_weak(
174     volatile __tsan_atomic32 *a, __tsan_atomic32 *c, __tsan_atomic32 v,
175     __tsan_memory_order mo, __tsan_memory_order fail_mo);
176 int SANITIZER_CDECL __tsan_atomic64_compare_exchange_weak(
177     volatile __tsan_atomic64 *a, __tsan_atomic64 *c, __tsan_atomic64 v,
178     __tsan_memory_order mo, __tsan_memory_order fail_mo);
179 #if __TSAN_HAS_INT128
180 int SANITIZER_CDECL __tsan_atomic128_compare_exchange_weak(
181     volatile __tsan_atomic128 *a, __tsan_atomic128 *c, __tsan_atomic128 v,
182     __tsan_memory_order mo, __tsan_memory_order fail_mo);
183 #endif
184 
185 int SANITIZER_CDECL __tsan_atomic8_compare_exchange_strong(
186     volatile __tsan_atomic8 *a, __tsan_atomic8 *c, __tsan_atomic8 v,
187     __tsan_memory_order mo, __tsan_memory_order fail_mo);
188 int SANITIZER_CDECL __tsan_atomic16_compare_exchange_strong(
189     volatile __tsan_atomic16 *a, __tsan_atomic16 *c, __tsan_atomic16 v,
190     __tsan_memory_order mo, __tsan_memory_order fail_mo);
191 int SANITIZER_CDECL __tsan_atomic32_compare_exchange_strong(
192     volatile __tsan_atomic32 *a, __tsan_atomic32 *c, __tsan_atomic32 v,
193     __tsan_memory_order mo, __tsan_memory_order fail_mo);
194 int SANITIZER_CDECL __tsan_atomic64_compare_exchange_strong(
195     volatile __tsan_atomic64 *a, __tsan_atomic64 *c, __tsan_atomic64 v,
196     __tsan_memory_order mo, __tsan_memory_order fail_mo);
197 #if __TSAN_HAS_INT128
198 int SANITIZER_CDECL __tsan_atomic128_compare_exchange_strong(
199     volatile __tsan_atomic128 *a, __tsan_atomic128 *c, __tsan_atomic128 v,
200     __tsan_memory_order mo, __tsan_memory_order fail_mo);
201 #endif
202 
203 __tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_compare_exchange_val(
204     volatile __tsan_atomic8 *a, __tsan_atomic8 c, __tsan_atomic8 v,
205     __tsan_memory_order mo, __tsan_memory_order fail_mo);
206 __tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_compare_exchange_val(
207     volatile __tsan_atomic16 *a, __tsan_atomic16 c, __tsan_atomic16 v,
208     __tsan_memory_order mo, __tsan_memory_order fail_mo);
209 __tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_compare_exchange_val(
210     volatile __tsan_atomic32 *a, __tsan_atomic32 c, __tsan_atomic32 v,
211     __tsan_memory_order mo, __tsan_memory_order fail_mo);
212 __tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_compare_exchange_val(
213     volatile __tsan_atomic64 *a, __tsan_atomic64 c, __tsan_atomic64 v,
214     __tsan_memory_order mo, __tsan_memory_order fail_mo);
215 #if __TSAN_HAS_INT128
216 __tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_compare_exchange_val(
217     volatile __tsan_atomic128 *a, __tsan_atomic128 c, __tsan_atomic128 v,
218     __tsan_memory_order mo, __tsan_memory_order fail_mo);
219 #endif
220 
221 void SANITIZER_CDECL __tsan_atomic_thread_fence(__tsan_memory_order mo);
222 void SANITIZER_CDECL __tsan_atomic_signal_fence(__tsan_memory_order mo);
223 
224 #ifdef __cplusplus
225 } // extern "C"
226 #endif
227 
228 #endif // TSAN_INTERFACE_ATOMIC_H
229