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
20constexpr inline bool IsEnabled = true;
21
22inline void futexAcquire(void *addr, void *addr2 = nullptr)
23{
24 // A futex call ensures total ordering on the futex words
25 // (in either success or failure of the call). Instruct TSAN accordingly,
26 // as TSAN does not understand the futex(2) syscall (or equivalent).
28 if (addr2)
30}
31
32inline void futexRelease(void *addr, void *addr2 = nullptr)
33{
34 if (addr2)
37}
38
39inline void latchWait(const void *addr)
40{
41 ::__tsan_acquire(const_cast<void *>(addr));
42}
43
44inline void latchCountDown(void *addr)
45{
47}
48
49inline void mutexPreLock(void *addr, unsigned flags)
50{
52}
53
54inline void mutexPostLock(void *addr, unsigned flags, int recursion)
55{
57}
58
59inline void mutexPreUnlock(void *addr, unsigned flags)
60{
62}
63
64inline void mutexPostUnlock(void *addr, unsigned flags)
65{
67}
68
69enum : unsigned {
74};
75#else
76constexpr inline bool IsEnabled = false;
77
78inline void futexAcquire(void *, void * = nullptr) {}
79inline void futexRelease(void *, void * = nullptr) {}
80inline void latchCountDown(void *) {}
81inline void latchWait(const void *) {}
82
83enum : unsigned {
88};
89inline void mutexPreLock(void *, unsigned) {}
90inline void mutexPostLock(void *, unsigned, int) {}
91inline void mutexPreUnlock(void *, unsigned) {}
92inline void mutexPostUnlock(void *, unsigned) {}
93#endif // QT_BUILDING_UNDER_TSAN
94} // namespace QtTsan
95
96QT_END_NAMESPACE
97
98#endif // QTSAN_IMPL_H
void futexRelease(void *, void *=nullptr)
Definition qtsan_impl.h:79
void latchCountDown(void *)
Definition qtsan_impl.h:80
void mutexPostUnlock(void *, unsigned)
Definition qtsan_impl.h:92
void futexAcquire(void *, void *=nullptr)
Definition qtsan_impl.h:78
void latchWait(const void *)
Definition qtsan_impl.h:81
void mutexPreUnlock(void *, unsigned)
Definition qtsan_impl.h:91
void mutexPreLock(void *, unsigned)
Definition qtsan_impl.h:89
void mutexPostLock(void *, unsigned, int)
Definition qtsan_impl.h:90
constexpr bool IsEnabled
Definition qtsan_impl.h:76
@ MutexWriteReentrant
Definition qtsan_impl.h:84
@ ReadLock
Definition qtsan_impl.h:87
@ TryLockFailed
Definition qtsan_impl.h:86
@ TryLock
Definition qtsan_impl.h:85
#define __has_include(x)
#define __has_feature(x)