Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtsan_impl.h
Go to the documentation of this file.
1// Copyright (C) 2017 Intel Corporation.
2// Copyright (C) 2022 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QTSAN_IMPL_H
7#define QTSAN_IMPL_H
8
9#include <QtCore/qglobal.h>
10
11#if (__has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)) && __has_include(<sanitizer/tsan_interface.h>)
12# define QT_BUILDING_UNDER_TSAN
13# include <sanitizer/tsan_interface.h>
14#endif
15
16QT_BEGIN_NAMESPACE
17
18namespace QtTsan {
19#ifdef QT_BUILDING_UNDER_TSAN
20inline void futexAcquire(void *addr, void *addr2 = nullptr)
21{
22 // A futex call ensures total ordering on the futex words
23 // (in either success or failure of the call). Instruct TSAN accordingly,
24 // as TSAN does not understand the futex(2) syscall (or equivalent).
26 if (addr2)
28}
29
30inline void futexRelease(void *addr, void *addr2 = nullptr)
31{
32 if (addr2)
35}
36
37inline void latchWait(const void *addr)
38{
39 ::__tsan_acquire(const_cast<void *>(addr));
40}
41
42inline void latchCountDown(void *addr)
43{
45}
46
47inline void mutexPreLock(void *addr, unsigned flags)
48{
50}
51
52inline void mutexPostLock(void *addr, unsigned flags, int recursion)
53{
55}
56
57inline void mutexPreUnlock(void *addr, unsigned flags)
58{
60}
61
62inline void mutexPostUnlock(void *addr, unsigned flags)
63{
65}
66
67enum : unsigned {
72};
73#else
74inline void futexAcquire(void *, void * = nullptr) {}
75inline void futexRelease(void *, void * = nullptr) {}
76inline void latchCountDown(void *) {}
77inline void latchWait(const void *) {}
78
79enum : unsigned {
84};
85inline void mutexPreLock(void *, unsigned) {}
86inline void mutexPostLock(void *, unsigned, int) {}
87inline void mutexPreUnlock(void *, unsigned) {}
88inline void mutexPostUnlock(void *, unsigned) {}
89#endif // QT_BUILDING_UNDER_TSAN
90} // namespace QtTsan
91
92QT_END_NAMESPACE
93
94#endif // QTSAN_IMPL_H
void futexRelease(void *, void *=nullptr)
Definition qtsan_impl.h:75
void latchCountDown(void *)
Definition qtsan_impl.h:76
void mutexPostUnlock(void *, unsigned)
Definition qtsan_impl.h:88
void futexAcquire(void *, void *=nullptr)
Definition qtsan_impl.h:74
void latchWait(const void *)
Definition qtsan_impl.h:77
void mutexPreUnlock(void *, unsigned)
Definition qtsan_impl.h:87
void mutexPreLock(void *, unsigned)
Definition qtsan_impl.h:85
void mutexPostLock(void *, unsigned, int)
Definition qtsan_impl.h:86
@ MutexWriteReentrant
Definition qtsan_impl.h:81
@ ReadLock
Definition qtsan_impl.h:80
@ TryLockFailed
Definition qtsan_impl.h:83
@ TryLock
Definition qtsan_impl.h:82
#define __has_include(x)
#define __has_feature(x)