Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:25:17

0001 // Copyright (C) 2017 Intel Corporation.
0002 // Copyright (C) 2022 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 // Qt-Security score:significant reason:default
0005 
0006 #ifndef QTSAN_IMPL_H
0007 #define QTSAN_IMPL_H
0008 
0009 #include <QtCore/qglobal.h>
0010 
0011 #if (__has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)) && __has_include(<sanitizer/tsan_interface.h>)
0012 #  define QT_BUILDING_UNDER_TSAN
0013 #  include <sanitizer/tsan_interface.h>
0014 #endif
0015 
0016 QT_BEGIN_NAMESPACE
0017 
0018 namespace QtTsan {
0019 #ifdef QT_BUILDING_UNDER_TSAN
0020 inline void futexAcquire(void *addr, void *addr2 = nullptr)
0021 {
0022     // A futex call ensures total ordering on the futex words
0023     // (in either success or failure of the call). Instruct TSAN accordingly,
0024     // as TSAN does not understand the futex(2) syscall (or equivalent).
0025     ::__tsan_acquire(addr);
0026     if (addr2)
0027         ::__tsan_acquire(addr2);
0028 }
0029 
0030 inline void futexRelease(void *addr, void *addr2 = nullptr)
0031 {
0032     if (addr2)
0033         ::__tsan_release(addr2);
0034     ::__tsan_release(addr);
0035 }
0036 
0037 inline void latchWait(const void *addr)
0038 {
0039     ::__tsan_acquire(const_cast<void *>(addr));
0040 }
0041 
0042 inline void latchCountDown(void *addr)
0043 {
0044     ::__tsan_release(addr);
0045 }
0046 
0047 inline void mutexPreLock(void *addr, unsigned flags)
0048 {
0049     ::__tsan_mutex_pre_lock(addr, flags);
0050 }
0051 
0052 inline void mutexPostLock(void *addr, unsigned flags, int recursion)
0053 {
0054     ::__tsan_mutex_post_lock(addr, flags, recursion);
0055 }
0056 
0057 inline void mutexPreUnlock(void *addr, unsigned flags)
0058 {
0059     ::__tsan_mutex_pre_unlock(addr, flags);
0060 }
0061 
0062 inline void mutexPostUnlock(void *addr, unsigned flags)
0063 {
0064     ::__tsan_mutex_post_unlock(addr, flags);
0065 }
0066 
0067 enum : unsigned {
0068     MutexWriteReentrant = ::__tsan_mutex_write_reentrant,
0069     TryLock = ::__tsan_mutex_try_lock,
0070     TryLockFailed = ::__tsan_mutex_try_lock_failed,
0071     ReadLock = ::__tsan_mutex_read_lock,
0072 };
0073 #else
0074 inline void futexAcquire(void *, void * = nullptr) {}
0075 inline void futexRelease(void *, void * = nullptr) {}
0076 inline void latchCountDown(void *) {}
0077 inline void latchWait(const void *) {}
0078 
0079 enum : unsigned {
0080     MutexWriteReentrant,
0081     TryLock,
0082     TryLockFailed,
0083     ReadLock,
0084 };
0085 inline void mutexPreLock(void *, unsigned) {}
0086 inline void mutexPostLock(void *, unsigned, int) {}
0087 inline void mutexPreUnlock(void *, unsigned) {}
0088 inline void mutexPostUnlock(void *, unsigned) {}
0089 #endif // QT_BUILDING_UNDER_TSAN
0090 } // namespace QtTsan
0091 
0092 QT_END_NAMESPACE
0093 
0094 #endif // QTSAN_IMPL_H