Debian Codegraph @

build/sanitizers/TsanOptions.cpp

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "mozilla/Attributes.h"
7 #include "mozilla/Types.h"
8
9 //
10 // When running with ThreadSanitizer, we need to explicitly set some
11 // options specific to our codebase to prevent errors during runtime.
12 // To override these, set the TSAN_OPTIONS environment variable.
13 //
14 // Currently, these are:
15 //
16 // abort_on_error=1 - Causes TSan to abort instead of using exit().
17 // halt_on_error=1 - Causes TSan to stop on the first race detected.
18 //
19 // report_signal_unsafe=0 - Required to avoid TSan deadlocks when
20 // receiving external signals (e.g. SIGINT manually on console).
21 //
22 // allocator_may_return_null=1 - Tell TSan to return NULL when an allocation
23 // fails instead of aborting the program. This allows us to handle failing
24 // allocations the same way we would handle them with a regular allocator and
25 // also uncovers potential bugs that might occur in these situations.
26 //
27 extern "C" MOZ_EXPORT const char* __tsan_default_options() {
28 return "halt_on_error=1:abort_on_error=1:report_signal_unsafe=0"
29 ":allocator_may_return_null=1";
30 }
31
32 //
33 // When running with ThreadSanitizer, we sometimes need to suppress existing
34 // races. However, in any case, it should be either because
35 //
36 // 1) a bug is on file. In this case, the bug number should always be
37 // included with the suppression.
38 //
39 // or 2) this is an intentional race. Please be very careful with judging
40 // races as intentional and benign. Races in C++ are undefined behavior
41 // and compilers increasingly rely on exploiting this for optimizations.
42 // Hence, many seemingly benign races cause harmful or unexpected
43 // side-effects.
44 //
45 // See also:
46 // https://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong
47 //
48 //
49 // Also, when adding any race suppressions here, make sure to always add
50 // a signature for each of the two race stacks. Sometimes, TSan fails to
51 // symbolize one of the two traces and this can cause suppressed races to
52 // show up intermittently.
53 //
54 // clang-format off
55 extern "C" MOZ_EXPORT const char* __tsan_default_suppressions() {
56 return "# Add your suppressions below\n"
57
58 // External uninstrumented libraries
59 // These are default suppressions for external libraries that probably
60 // every application would want to include if it potentially loads external
61 // libraries like GTK/X and hence their dependencies.
62 "called_from_lib:libappmenu-gtk3-parser\n"
63 "called_from_lib:libatk-1\n"
64 "called_from_lib:libcairo.so\n"
65 "called_from_lib:libcairo-gobject\n"
66 "called_from_lib:libdconfsettings\n"
67 "called_from_lib:libEGL_nvidia\n"
68 "called_from_lib:libfontconfig.so\n"
69 "called_from_lib:libfontconfig1\n"
70 "called_from_lib:libgdk-3\n"
71 "called_from_lib:libgdk_pixbuf\n"
72 "called_from_lib:libgdk-x11\n"
73 "called_from_lib:libgio-2\n"
74 "called_from_lib:libglib-1\n"
75 "called_from_lib:libglib-2\n"
76 "called_from_lib:libgobject\n"
77 "called_from_lib:libgtk-3\n"
78 "called_from_lib:libgtk-x11\n"
79 "called_from_lib:libgvfscommon\n"
80 "called_from_lib:libgvfsdbus\n"
81 "called_from_lib:libibus-1\n"
82 "called_from_lib:libnvidia-eglcore\n"
83 "called_from_lib:libnvidia-glsi\n"
84 "called_from_lib:libogg.so\n"
85 "called_from_lib:libpango-1\n"
86 "called_from_lib:libpangocairo\n"
87 "called_from_lib:libpangoft2\n"
88 "called_from_lib:pango-basic-fc\n"
89 "called_from_lib:libpixman-1\n"
90 "called_from_lib:libpulse.so\n"
91 "called_from_lib:libpulsecommon\n"
92 "called_from_lib:libsecret-1\n"
93 "called_from_lib:libunity-gtk3-parser\n"
94 "called_from_lib:libvorbis.so\n"
95 "called_from_lib:libvorbisfile\n"
96 "called_from_lib:libwayland-client\n"
97 "called_from_lib:libX11.so\n"
98 "called_from_lib:libX11-xcb\n"
99 "called_from_lib:libXau\n"
100 "called_from_lib:libxcb.so\n"
101 "called_from_lib:libXcomposite\n"
102 "called_from_lib:libXcursor\n"
103 "called_from_lib:libXdamage\n"
104 "called_from_lib:libXdmcp\n"
105 "called_from_lib:libXext\n"
106 "called_from_lib:libXfixes\n"
107 "called_from_lib:libXi.so\n"
108 "called_from_lib:libXrandr\n"
109 "called_from_lib:libXrender\n"
110 "called_from_lib:libXss\n"
111
112
113 // TSan internals
114 "race:__tsan::ProcessPendingSignals\n"
115 "race:__tsan::CallUserSignalHandler\n"
116
117
118
119
120
121 // Uninstrumented code causing false positives
122
123 // These libraries are uninstrumented and cause mutex false positives.
124 // However, they can be unloaded by GTK early which we cannot avoid.
125 "mutex:libGL.so\n"
126 "mutex:libGLdispatch\n"
127 "mutex:libGLX\n"
128 // Bug 1637707 - permanent
129 "mutex:libEGL_mesa.so\n"
130 // ~GLContextGLX unlocks a libGL mutex.
131 "mutex:GLContextGLX::~GLContextGLX\n"
132 // Bug 1825171
133 "mutex:libffi.so\n"
134 "mutex:wl_registry_destroy\n"
135 // Bug 1824768
136 "mutex:libdbus-1\n"
137 "mutex:swrast_dri.so\n"
138 "mutex:libgallium-*.so\n"
139 // Bug 1651446 - permanent (ffmpeg)
140 "race:libavcodec.so*\n"
141 "race:libavutil.so*\n"
142 // For some reason, the suppressions on libpulse.so
143 // through `called_from_lib` only work partially.
144 "race:libpulse.so\n"
145 "race:pa_context_suspend_source_by_index\n"
146 "race:pa_context_unref\n"
147 "race:pa_format_info_set_prop_string_array\n"
148 "race:pa_stream_get_index\n"
149 "race:pa_stream_update_timing_info\n"
150 "race:vorbis_synthesis_init\n"
151 // This is a callback from libglib-2 that is apparently
152 // not fully suppressed through `called_from_lib`.
153 "race:g_main_context_dispatch\n"
154 // This is likely a false positive involving a mutex from GTK.
155 // See also bug 1642653 - permanent.
156 "mutex:GetMaiAtkType\n"
157 // Bug 1688716 - Failure due to fire_glxtest_process
158 // calling into uninstrumented external graphics driver code.
159 // For example: iris_dri.so and swrast_dri.so.
160 "race:fire_glxtest_process\n"
161 "race:iris_dri\n"
162 // Bug 1824768
163 "race:libLLVM-12\n"
164 "race:radeonsi_dri\n"
165 // Bug 1722721 - WebRender using uninstrumented Mesa drivers
166 "race:swrast_dri.so\n"
167 "race:libgallium-*.so\n"
168 // Bug 1825171
169 "race:libffi.so\n"
170 "race:mozilla::widget::WaylandBuffer::BufferReleaseCallbackHandler\n"
171
172
173
174
175 // Deadlock reports on single-threaded runtime.
176 //
177 // This is a known false positive from TSan where it reports
178 // a potential deadlock even though all mutexes are only
179 // taken by a single thread. For applications/tasks where we
180 // are absolutely sure that no second thread will be involved
181 // we should suppress these issues.
182 //
183 // See also https://github.com/google/sanitizers/issues/488
184
185 // Bug 1614605 - permanent
186 "deadlock:SanctionsTestServer\n"
187 "deadlock:OCSPStaplingServer\n"
188 // Bug 1643087 - permanent
189 "deadlock:BadCertAndPinningServer\n"
190 // Bug 1606804 - permanent
191 "deadlock:cert_storage::SecurityState::open_db\n"
192 "deadlock:cert_storage::SecurityState::add_certs\n"
193 // Bug 1651770 - permanent
194 "deadlock:mozilla::camera::LockAndDispatch\n"
195 // Bug 1606804 - permanent
196 "deadlock:third_party/rust/rkv/src/env.rs\n"
197 // Bug 1680655 - permanent
198 "deadlock:EncryptedClientHelloServer\n"
199 // Bug 1682861 - permanent
200 "deadlock:nsDOMWindowUtils::CompareCanvases\n"
201
202
203
204
205
206 // Benign races in third-party code (should be fixed upstream)
207
208 // No Bug - permanent
209 // No Upstream Bug Filed!
210 //
211 // SIMD Initialization in libjpeg, potentially runs
212 // initialization twice, but otherwise benign. Init
213 // routine itself is in native assembler.
214 "race:init_simd\n"
215 "race:simd_support\n"
216 "race:jsimd_can_ycc_rgb\n"
217 // Bug 1615228 - permanent
218 // No Upstream Bug Filed!
219 //
220 // Likely benign race in ipc/chromium/ where we set
221 // `message_loop_` to `NULL` on two threads when stopping
222 // a thread at the same time it is already finishing.
223 "race:base::Thread::Stop\n"
224 // Bug 1615569 - permanent
225 // No Upstream Bug Filed!
226 //
227 // NSS is using freebl from two different threads but freebl isn't
228 // that threadsafe.
229 "race:mp_exptmod.max_window_bits\n"
230 // Bug 1652499 - permanent
231 // No Upstream Bug Filed!
232 //
233 // Likely benign race in webrtc.org code - race while updating the
234 // minimum log severity.
235 "race:Loggable\n"
236 "race:UpdateMinLogSeverity\n"
237 // Bug 1652174 - permanent
238 // Upstream Bug: https://github.com/libevent/libevent/issues/777
239 //
240 // Likely benign write-write race in libevent to set a sticky boolean
241 // flag to true.
242 "race:event_debug_mode_too_late\n"
243
244 // Bug 1653618 - permanent
245 // Upstream Bug: https://github.com/sctplab/usrsctp/issues/507
246 //
247 // Might lead to scheduled timers in libusrsctp getting dropped?
248 "race:sctp_handle_tick\n"
249 "race:sctp_handle_sack\n"
250 // Bug 1648604 - permanent
251 // Upstream Bug: https://github.com/sctplab/usrsctp/issues/482
252 //
253 // Likely benign race in libusrsctp allocator during a free.
254 "race:system_base_info\n"
255 // Benign lock-order-inversion in libusrsctp
256 // No upstream bug filed!
257 "deadlock:sctp_add_to_readq\n"
258
259 // Bug 1153409 - permanent
260 // No Upstream Bug Filed!
261 //
262 // Probably benign - sqlite has a few optimizations where it does
263 // racy reads and then does properly synchronized integrity checks
264 // afterwards. Some concern of compiler optimizations messing this
265 // up due to "volatile" being too weak for this.
266 "race:third_party/sqlite3/*\n"
267 "deadlock:third_party/sqlite3/*\n"
268 // Bug 1674770 - permanent
269 // Upstream Bug: https://github.com/Amanieu/parking_lot/issues/257
270 //
271 // parking_lot using incorrect atomic orderings in RwLock, upstream
272 // fix already up for review.
273 "race:StrongRuleNode::ensure_child\n"
274 // No Bug - permanent
275 // Upstream Bugs:
276 //
277 // * https://github.com/rayon-rs/rayon/issues/812
278 // * https://github.com/crossbeam-rs/crossbeam/issues/589
279 //
280 // Probably a false-positive from crossbeam's deque not being
281 // understood by tsan.
282 "race:crossbeam_deque*::resize\n"
283 "race:crossbeam_deque*::push\n"
284 "race:crossbeam_deque*::write\n"
285 "race:crossbeam_deque*::read\n"
286 "race:crossbeam_deque*::steal\n"
287 // Bug 1805819 - permanent
288 // No Upstream Bug Filed!
289 //
290 // False positive in libc's tzset_internal
291 // See https://crbug.com/379738 also
292 "race:tzset_internal\n"
293
294
295
296
297
298 // The rest of these suppressions are miscellaneous issues in gecko
299 // that should be investigated and ideally fixed.
300
301 // Bug 1671574 - Permanent
302 // The StartupCache thread intentionally races with the main thread to
303 // trigger OS-level paging. It is never joined with the main thread.
304 "thread:StartupCache\n"
305
306 // Bug 1734262 - Permanent
307 // When spawning async processes, we create a helper thread to wait for
308 // the process to terminate in order to asynchronously report the exit
309 // code to Gecko. This thread waits on a syscall for the process to end,
310 // which means there's no easy way to cancel and join it during Gecko
311 // shutdown. Suppress thread leak reports for this thread.
312 "thread:CreateMonitorThread\n"
313
314 // Bug 1601600
315 "race:SkARGB32_Blitter\n"
316 "race:SkARGB32_Shader_Blitter\n"
317 "race:SkARGB32_Opaque_Blitter\n"
318 "race:SkRasterPipelineBlitter\n"
319 "race:Clamp_S32_D32_nofilter_trans_shaderproc\n"
320 "race:SkSpriteBlitter_Memcpy\n"
321
322 // Bug 1606800
323 "race:CallInitFunc\n"
324
325 // Bug 1606803
326 "race:ipv6_is_present\n"
327
328 // Bug 1615123
329 "race:_dl_deallocate_tls\n"
330 "race:__libc_memalign\n"
331
332 // Bug 1664803
333 "race:Sampler::sSigHandlerCoordinator\n"
334
335 // Bug 1656068
336 "race:WebRtcAec_Create\n"
337
338 // No Bug - Logging bug in Mochitests
339 "race:mochitest/ssltunnel/ssltunnel.cpp\n"
340
341 // This thread does not seem to be stopped/joined.
342 // ImageBridgeChild should be turned back into a background
343 // task queue in bug 1647628, in which case these suppressions
344 // can be removed.
345 "race:mozilla::layers::ImageBridgeChild::ShutDown\n"
346
347 // Bug 1652530
348 "mutex:XErrorTrap\n"
349
350 // Bug 1671601
351 "race:CamerasParent::ActorDestroy\n"
352 "race:CamerasParent::DispatchToVideoCaptureThread\n"
353
354 // Bug 1623541
355 "race:VRShMem::PullSystemState\n"
356 "race:VRShMem::PushSystemState\n"
357 "race:VRShMem::PullBrowserState\n"
358 "race:VRShMem::PushBrowserState\n"
359
360 // Bug 1682951
361 "race:storage::Connection::Release\n"
362
363 // Bug 1683357
364 "race:image::ImageSurfaceCache::SuggestedSizeInternal\n"
365 "race:image::RasterImage::SetMetadata\n"
366 "race:image::RasterImage::GetWidth\n"
367
368 // Bug 1722721 - This is a benign race creating worker/SW compositor threads.
369 "race:webrender::profiler::register_thread\n"
370
371 // Bug 1722721 - This is a false positive during SW-WR rendering.
372 "race:scale_blit\n"
373
374 "race:mozilla::gl::MesaMemoryLeakWorkaround\n"
375
376 // Bug 1733908
377 "race:js::wasm::Code::bestTier\n"
378 "race:js::wasm::Code::commitTier2\n"
379 "race:js::wasm::Code::setTier2\n"
380 "race:js::wasm::Code::setAndBorrowTier2\n"
381
382 // Bug 1755449
383 // The Glean init thread is used to perform I/O and other blocking operations.
384 // It is never joined with the main thread, but this is being re-evaluated.
385 "thread:glean::initialize\n"
386
387 // Bug 1822605 - permanent
388 // A race exists in libvulkan_lvp.so. This was previously addressed in bug
389 // 1816713. However, libvulkan_lvp.so is unloaded so a called_from_lib
390 // suppression cannot be used.
391 "race:libvulkan_lvp.so\n"
392
393 // Bug 1894073 - false positive
394 // TSan isn't aware of IPC; see bug for detailed explanation.
395 "race:LaunchAppWithForkServer\n"
396
397 // End of suppressions.
398 ; // Please keep this semicolon.
399 }
400 // clang-format on