Skip to content

Commit 220e596

Browse files
VladimirBelyavskythiagomacieira
authored andcommitted
QThread/Unix: intercept exceptions only with Glibc
See 5677b70 for details why we need such specific exception handling for Glibc. In short, on Glibc, pthread_cancel and pthread_exit are implemented by throwing a special kind of exception that can be caught, but must always be rethrown. That exception is then used to activate the cancellation clean-up handlers. But for libc++ on Apple platforms we can simply wrap it as noexcept to guarantee that std::terminate() will be called in case of any unhandled exception. Task-number: QTBUG-141803 Pick-to: 6.10 6.8 Change-Id: Iaa88d3a8091425206ee2735e835ae74fd087e9e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
1 parent 37d5025 commit 220e596

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/corelib/thread/qthread_unix.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,28 @@ static void setCurrentThreadName(const char *name)
358358
#endif
359359

360360
namespace {
361+
#if defined(__GLIBCXX__) && !defined(QT_NO_EXCEPTIONS)
361362
template <typename T>
362363
void terminate_on_exception(T &&t)
363364
{
364-
#ifndef QT_NO_EXCEPTIONS
365365
try {
366-
#endif
367366
std::forward<T>(t)();
368-
#ifndef QT_NO_EXCEPTIONS
369-
#ifdef __GLIBCXX__
370-
// POSIX thread cancellation under glibc is implemented by throwing an exception
371-
// of this type. Do what libstdc++ is doing and handle it specially in order not to
372-
// abort the application if user's code calls a cancellation function.
373367
} catch (abi::__forced_unwind &) {
368+
// POSIX thread cancellation under glibc is implemented by throwing an exception
369+
// of this type. Do what libstdc++ is doing and handle it specially in order not to
370+
// abort the application if user's code calls a cancellation function.
374371
throw;
375-
#endif // __GLIBCXX__
376372
} catch (...) {
377373
std::terminate();
378374
}
379-
#endif // QT_NO_EXCEPTIONS
380375
}
376+
#else
377+
template <typename T>
378+
void terminate_on_exception(T &&t) noexcept
379+
{
380+
std::forward<T>(t)();
381+
}
382+
#endif // defined(__GLIBCXX__) && !defined(QT_NO_EXCEPTIONS)
381383
} // unnamed namespace
382384

383385
void *QThreadPrivate::start(void *arg)

0 commit comments

Comments
 (0)